Merge "Fix indicator crash" into devel/master
[platform/core/uifw/dali-adaptor.git] / adaptors / ecore / wayland / window-impl-ecore-wl.cpp
1 /*
2  * Copyright (c) 2017 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include <window-impl.h>
20
21 // EXTERNAL HEADERS
22 // Ecore is littered with C style cast
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wold-style-cast"
25 #include <Ecore.h>
26 #include <Ecore_Wayland.h>
27 #include <tizen-extension-client-protocol.h>
28
29 #include <dali/integration-api/core.h>
30 #include <dali/integration-api/system-overlay.h>
31 #include <dali/public-api/render-tasks/render-task.h>
32 #include <dali/public-api/render-tasks/render-task-list.h>
33 #include <orientation.h>
34
35 // INTERNAL HEADERS
36 #include <window-render-surface.h>
37 #include <drag-and-drop-detector-impl.h>
38 #include <ecore-indicator-impl.h>
39 #include <window-visibility-observer.h>
40 #include <orientation-impl.h>
41
42 namespace
43 {
44 const float INDICATOR_ANIMATION_DURATION( 0.18f ); // 180 milli seconds
45 const float INDICATOR_SHOW_Y_POSITION( 0.0f );
46 const float INDICATOR_HIDE_Y_POSITION( -52.0f );
47 }
48
49 namespace Dali
50 {
51 namespace Internal
52 {
53 namespace Adaptor
54 {
55
56 #if defined(DEBUG_ENABLED)
57 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
58 #endif
59
60 /**
61  * TODO: Abstract Window class out and move this into a window implementation for Ecore
62  */
63 struct Window::EventHandler
64 {
65   /**
66    * Constructor
67    * @param[in]  window  A pointer to the window class.
68    */
69   EventHandler( Window* window )
70   : mWindow( window ),
71     mWindowPropertyHandler( NULL ),
72     mWindowIconifyStateHandler( NULL ),
73     mWindowVisibilityStateHandler( NULL ),
74     mWindowFocusInHandler( NULL ),
75     mWindowFocusOutHandler( NULL ),
76     mEcoreWindow( 0 ),
77     mDisplay( NULL ),
78     mEventQueue( NULL ),
79     mTizenPolicy( NULL ),
80     mTizenDisplayPolicy( NULL ),
81     mNotificationLevel( -1 ),
82     mNotificationChangeState( 0 ),
83     mNotificationLevelChangeDone( true ),
84     mScreenMode( 0 ),
85     mScreenModeChangeState( 0 ),
86     mScreenModeChangeDone( true ),
87     mBrightness( 0 ),
88     mBrightnessChangeState( 0 ),
89     mBrightnessChangeDone( true )
90   {
91     // store ecore window handle
92     ECore::WindowRenderSurface* wlWindow( dynamic_cast< ECore::WindowRenderSurface * >( mWindow->mSurface ) );
93     if( wlWindow )
94     {
95       mEcoreWindow = wlWindow->GetWlWindow();
96     }
97     DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no ecore Wl window");
98
99     if( mWindow->mEcoreEventHander )
100     {
101       mWindowIconifyStateHandler = ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this );
102       mWindowVisibilityStateHandler = ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE, EcoreEventWindowVisibilityChanged, this );
103       mWindowFocusInHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this );
104       mWindowFocusOutHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this );
105     }
106
107     mDisplay = ecore_wl_display_get();
108
109     if( mDisplay )
110     {
111       wl_display* displayWrapper = static_cast< wl_display* >( wl_proxy_create_wrapper( mDisplay ) );
112       if( displayWrapper )
113       {
114         mEventQueue = wl_display_create_queue( mDisplay );
115         if( mEventQueue )
116         {
117           wl_proxy_set_queue( reinterpret_cast< wl_proxy* >( displayWrapper ), mEventQueue );
118
119           wl_registry* registry = wl_display_get_registry( displayWrapper );
120           wl_registry_add_listener( registry, &mRegistryListener, this );
121         }
122
123         wl_proxy_wrapper_destroy( displayWrapper );
124       }
125     }
126   }
127
128   /**
129    * Destructor
130    */
131   ~EventHandler()
132   {
133     if ( mWindowPropertyHandler )
134     {
135       ecore_event_handler_del( mWindowPropertyHandler );
136     }
137
138     if ( mWindowIconifyStateHandler )
139     {
140       ecore_event_handler_del( mWindowIconifyStateHandler );
141     }
142
143     if ( mWindowVisibilityStateHandler )
144     {
145       ecore_event_handler_del( mWindowVisibilityStateHandler );
146     }
147
148     if( mWindowFocusInHandler )
149     {
150       ecore_event_handler_del( mWindowFocusInHandler );
151     }
152
153     if( mWindowFocusOutHandler )
154     {
155       ecore_event_handler_del( mWindowFocusOutHandler );
156     }
157
158     if( mEventQueue )
159     {
160       wl_event_queue_destroy( mEventQueue );
161     }
162   }
163
164   // Static methods
165
166   /// Called when the window properties are changed.
167   static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
168   {
169     return EINA_FALSE;
170   }
171
172   /// Called when the window iconify state is changed.
173   static Eina_Bool EcoreEventWindowIconifyStateChanged( void* data, int type, void* event )
174   {
175     Ecore_Wl_Event_Window_Iconify_State_Change* iconifyChangedEvent( static_cast< Ecore_Wl_Event_Window_Iconify_State_Change* >( event ) );
176     EventHandler* handler( static_cast< EventHandler* >( data ) );
177     Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
178
179     if ( handler && handler->mWindow )
180     {
181       WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
182       if ( observer && ( iconifyChangedEvent->win == static_cast< unsigned int> ( ecore_wl_window_id_get( handler->mEcoreWindow ) ) ) )
183       {
184         if( iconifyChangedEvent->iconified == EINA_TRUE )
185         {
186           observer->OnWindowHidden();
187           DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Iconfied\n", handler->mEcoreWindow );
188         }
189         else
190         {
191           observer->OnWindowShown();
192           DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Shown\n", handler->mEcoreWindow );
193         }
194         handled = ECORE_CALLBACK_DONE;
195       }
196     }
197
198     return handled;
199   }
200
201   /// Called when the window visibility is changed.
202   static Eina_Bool EcoreEventWindowVisibilityChanged( void* data, int type, void* event )
203   {
204     Ecore_Wl_Event_Window_Visibility_Change* visibilityChangedEvent( static_cast< Ecore_Wl_Event_Window_Visibility_Change* >( event ) );
205     EventHandler* handler( static_cast< EventHandler* >( data ) );
206     Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
207
208     if ( handler && handler->mWindow )
209     {
210       WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
211       if ( observer && ( visibilityChangedEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( handler->mEcoreWindow ) ) ) )
212       {
213         if( visibilityChangedEvent->fully_obscured == 1 )
214         {
215           observer->OnWindowHidden();
216           DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) full obscured\n", handler->mEcoreWindow );
217         }
218         else
219         {
220           observer->OnWindowShown();
221           DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Shown\n", handler->mEcoreWindow );
222         }
223         handled = ECORE_CALLBACK_DONE;
224       }
225     }
226
227     return handled;
228   }
229
230   /// Called when the window gains focus
231   static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
232   {
233     Ecore_Wl_Event_Focus_In* focusInEvent( static_cast< Ecore_Wl_Event_Focus_In* >( event ) );
234     EventHandler* handler( static_cast< EventHandler* >( data ) );
235
236     if ( handler && handler->mWindow && focusInEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
237     {
238       DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n" );
239
240       handler->mWindow->mFocusChangedSignal.Emit( true );
241     }
242
243     return ECORE_CALLBACK_PASS_ON;
244   }
245
246   /// Called when the window loses focus
247   static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
248   {
249     Ecore_Wl_Event_Focus_Out* focusOutEvent( static_cast< Ecore_Wl_Event_Focus_Out* >( event ) );
250     EventHandler* handler( static_cast< EventHandler* >( data ) );
251
252     if ( handler && handler->mWindow && focusOutEvent->win == static_cast< unsigned int >(ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
253     {
254       DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n" );
255
256       handler->mWindow->mFocusChangedSignal.Emit( false );
257     }
258
259     return ECORE_CALLBACK_PASS_ON;
260   }
261
262   static void RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
263   {
264     Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
265
266     if( strcmp( interface, tizen_policy_interface.name ) == 0 )
267     {
268       eventHandler->mTizenPolicy = static_cast< tizen_policy* >( wl_registry_bind( registry, name, &tizen_policy_interface, version ) );
269       if( !eventHandler->mTizenPolicy )
270       {
271         DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n" );
272         return;
273       }
274
275       tizen_policy_add_listener( eventHandler->mTizenPolicy, &eventHandler->mTizenPolicyListener, data );
276
277       DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_policy_add_listener is called.\n" );
278     }
279     else if( strcmp( interface, tizen_display_policy_interface.name ) == 0 )
280     {
281       eventHandler->mTizenDisplayPolicy = static_cast< tizen_display_policy* >( wl_registry_bind( registry, name, &tizen_display_policy_interface, version ) );
282       if( !eventHandler->mTizenDisplayPolicy )
283       {
284         DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n" );
285         return;
286       }
287
288       tizen_display_policy_add_listener( eventHandler->mTizenDisplayPolicy, &eventHandler->mTizenDisplayPolicyListener, data );
289
290       DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n" );
291     }
292   }
293
294   static void RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
295   {
296     Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
297     eventHandler->mTizenPolicy = NULL;
298     eventHandler->mTizenDisplayPolicy = NULL;
299   }
300
301   static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
302   {
303     Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
304
305     eventHandler->mNotificationLevel = level;
306     eventHandler->mNotificationChangeState = state;
307     eventHandler->mNotificationLevelChangeDone = true;
308
309     DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state );
310   }
311
312   static void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
313   {
314     Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
315
316     eventHandler->mScreenMode = mode;
317     eventHandler->mScreenModeChangeState = state;
318     eventHandler->mScreenModeChangeDone = true;
319
320     DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state );
321   }
322
323   static void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
324   {
325     Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
326
327     eventHandler->mBrightness = brightness;
328     eventHandler->mBrightnessChangeState = state;
329     eventHandler->mBrightnessChangeDone = true;
330
331     DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state );
332   }
333
334   const struct wl_registry_listener mRegistryListener =
335   {
336      RegistryGlobalCallback,
337      RegistryGlobalCallbackRemove
338   };
339
340   const struct tizen_policy_listener mTizenPolicyListener =
341   {
342      NULL,
343      NULL,
344      TizenPolicyNotificationChangeDone,
345      NULL,
346      TizenPolicyScreenModeChangeDone,
347      NULL,
348      NULL,
349      NULL,
350      NULL
351   };
352
353   const struct tizen_display_policy_listener mTizenDisplayPolicyListener =
354   {
355     DisplayPolicyBrightnessChangeDone
356   };
357
358   // Data
359   Window* mWindow;
360   Ecore_Event_Handler* mWindowPropertyHandler;
361   Ecore_Event_Handler* mWindowIconifyStateHandler;
362   Ecore_Event_Handler* mWindowVisibilityStateHandler;
363   Ecore_Event_Handler* mWindowFocusInHandler;
364   Ecore_Event_Handler* mWindowFocusOutHandler;
365   Ecore_Wl_Window* mEcoreWindow;
366
367   wl_display* mDisplay;
368   wl_event_queue* mEventQueue;
369   tizen_policy* mTizenPolicy;
370   tizen_display_policy* mTizenDisplayPolicy;
371
372   int mNotificationLevel;
373   uint32_t mNotificationChangeState;
374   bool mNotificationLevelChangeDone;
375
376   int mScreenMode;
377   uint32_t mScreenModeChangeState;
378   bool mScreenModeChangeDone;
379
380   int mBrightness;
381   uint32_t mBrightnessChangeState;
382   bool mBrightnessChangeDone;
383 };
384
385 Window* Window::New(const PositionSize& posSize, const std::string& name, const std::string& className, bool isTransparent)
386 {
387   Window* window = new Window();
388   window->mIsTransparent = isTransparent;
389   window->Initialize(posSize, name, className);
390   return window;
391 }
392
393 void Window::SetAdaptor(Dali::Adaptor& adaptor)
394 {
395   DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
396   mStarted = true;
397
398   // Only create one overlay per window
399   Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
400   Integration::Core& core = adaptorImpl.GetCore();
401   mOverlay = &core.GetSystemOverlay();
402
403   Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
404   taskList.CreateTask();
405
406   mAdaptor = &adaptorImpl;
407   mAdaptor->AddObserver( *this );
408
409   // Can only create the detector when we know the Core has been instantiated.
410   mDragAndDropDetector = DragAndDropDetector::New();
411   mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
412
413   if( mOrientation )
414   {
415     mOrientation->SetAdaptor(adaptor);
416   }
417
418   if( mIndicator != NULL )
419   {
420     mIndicator->SetAdaptor(mAdaptor);
421   }
422 }
423
424 RenderSurface* Window::GetSurface()
425 {
426   return mSurface;
427 }
428
429 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
430 {
431   DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
432   DALI_ASSERT_DEBUG(mOverlay);
433
434   ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
435   DALI_ASSERT_DEBUG(wlSurface);
436
437   if( wlSurface )
438   {
439     Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
440
441     mIndicatorVisible = visibleMode;
442
443     if ( mIndicatorVisible == Dali::Window::VISIBLE )
444     {
445       // when the indicator is visible, set proper mode for indicator server according to bg mode
446       if ( mIndicatorOpacityMode == Dali::Window::OPAQUE )
447       {
448         ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
449       }
450       else if ( mIndicatorOpacityMode == Dali::Window::TRANSLUCENT )
451       {
452         ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSLUCENT);
453       }
454       else if ( mIndicatorOpacityMode == Dali::Window::TRANSPARENT )
455       {
456         ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
457       }
458     }
459     else
460     {
461       // when the indicator is not visible, set TRANSPARENT mode for indicator server
462       ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSPARENT); // it means hidden indicator
463     }
464   }
465
466   DoShowIndicator( mIndicatorOrientation );
467 }
468
469 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
470 {
471   DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
472
473   DoRotateIndicator( orientation );
474 }
475
476 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
477 {
478   mIndicatorOpacityMode = opacityMode;
479
480   if( mIndicator != NULL )
481   {
482     mIndicator->SetOpacityMode( opacityMode );
483   }
484 }
485
486 void Window::SetClass(std::string name, std::string klass)
487 {
488   ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
489
490   if( wlSurface )
491   {
492     Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
493     ecore_wl_window_title_set( wlWindow, name.c_str() );
494     ecore_wl_window_class_name_set( wlWindow, klass.c_str() );
495   }
496   else
497   {
498     DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window has no surface\n" );
499   }
500 }
501
502 Window::Window()
503 : mSurface( NULL ),
504   mIndicatorVisible( Dali::Window::VISIBLE ),
505   mIndicatorIsShown( false ),
506   mShowRotatedIndicatorOnClose( false ),
507   mStarted( false ),
508   mIsTransparent( false ),
509   mWMRotationAppSet( false ),
510   mEcoreEventHander( true ),
511   mIsFocusAcceptable( true ),
512   mVisible( true ),
513   mOpaqueState( false ),
514   mIndicator( NULL ),
515   mIndicatorOrientation( Dali::Window::PORTRAIT ),
516   mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
517   mIndicatorOpacityMode( Dali::Window::OPAQUE ),
518   mOverlay( NULL ),
519   mAdaptor( NULL ),
520   mType( Dali::DevelWindow::NORMAL ),
521   mEventHandler( NULL ),
522   mPreferredOrientation( Dali::Window::PORTRAIT ),
523   mSupportedAuxiliaryHints(),
524   mAuxiliaryHints(),
525   mIndicatorVisibilityChangedSignal(),
526   mFocusChangedSignal(),
527   mResizedSignal(),
528   mDeleteRequestSignal()
529 {
530 }
531
532 Window::~Window()
533 {
534   delete mEventHandler;
535
536   if( mIndicator )
537   {
538     mIndicator->Close();
539     delete mIndicator;
540   }
541
542   if ( mAdaptor )
543   {
544     mAdaptor->RemoveObserver( *this );
545     mAdaptor->SetDragAndDropDetector( NULL );
546     mAdaptor = NULL;
547   }
548
549   delete mSurface;
550
551   mSupportedAuxiliaryHints.clear();
552   mAuxiliaryHints.clear();
553 }
554
555 void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
556 {
557   // create an Wayland window by default
558   Any surface;
559   ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
560
561   mSurface = windowSurface;
562   SetClass( name, className );
563   windowSurface->Map();
564
565   mOrientation = Orientation::New(this);
566
567   // create event handler for Wayland window
568   mEventHandler = new EventHandler( this );
569
570   // get auxiliary hint
571   Eina_List* hints = ecore_wl_window_aux_hints_supported_get( mEventHandler->mEcoreWindow );
572   if( hints )
573   {
574     Eina_List* l = NULL;
575     char* hint = NULL;
576
577     for( l = hints, ( hint =  static_cast< char* >( eina_list_data_get(l) ) ); l; l = eina_list_next(l), ( hint = static_cast< char* >( eina_list_data_get(l) ) ) )
578     {
579       mSupportedAuxiliaryHints.push_back( hint );
580
581       DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::Initialize: %s\n", hint );
582     }
583   }
584 }
585
586 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
587 {
588   if( mIndicator == NULL )
589   {
590     if( mIndicatorVisible != Dali::Window::INVISIBLE )
591     {
592       mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
593       mIndicator->SetOpacityMode( mIndicatorOpacityMode );
594       Dali::Actor actor = mIndicator->GetActor();
595       SetIndicatorActorRotation();
596       mOverlay->Add(actor);
597     }
598     // else don't create a hidden indicator
599   }
600   else // Already have indicator
601   {
602     if( mIndicatorVisible == Dali::Window::VISIBLE )
603     {
604       // If we are resuming, and rotation has changed,
605       if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
606       {
607         // then close current indicator and open new one
608         mShowRotatedIndicatorOnClose = true;
609         mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
610         // Don't show actor - will contain indicator for old orientation.
611       }
612     }
613   }
614
615   // set indicator visible mode
616   if( mIndicator != NULL )
617   {
618     mIndicator->SetVisible( mIndicatorVisible );
619   }
620
621   bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
622   SetIndicatorProperties( show, lastOrientation );
623   mIndicatorIsShown = show;
624 }
625
626 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
627 {
628   if( mIndicatorIsShown )
629   {
630     mShowRotatedIndicatorOnClose = true;
631     mNextIndicatorOrientation = orientation;
632     mIndicator->Close(); // May synchronously call IndicatorClosed() callback
633   }
634   else
635   {
636     // Save orientation for when the indicator is next shown
637     mShowRotatedIndicatorOnClose = false;
638     mNextIndicatorOrientation = orientation;
639   }
640 }
641
642 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
643 {
644   ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
645
646   if( wlSurface )
647   {
648     Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
649     if ( isShow )
650     {
651       ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_ON);
652     }
653     else
654     {
655       ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_OFF);
656     }
657   }
658 }
659
660 void Window::IndicatorTypeChanged(Indicator::Type type)
661 {
662 #if defined(DALI_PROFILE_MOBILE)
663   ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
664
665   if( wlSurface )
666   {
667     Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
668     switch(type)
669     {
670       case Indicator::INDICATOR_TYPE_1:
671         ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
672         break;
673
674       case Indicator::INDICATOR_TYPE_2:
675         ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_HIDDEN);
676         break;
677
678       case Indicator::INDICATOR_TYPE_UNKNOWN:
679       default:
680         break;
681     }
682   }
683 #endif //MOBILE
684 }
685
686 void Window::IndicatorClosed( IndicatorInterface* indicator )
687 {
688   DALI_LOG_TRACE_METHOD( gWindowLogFilter );
689
690   if( mShowRotatedIndicatorOnClose )
691   {
692     Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
693     mIndicator->Open(mNextIndicatorOrientation);
694     mIndicatorOrientation = mNextIndicatorOrientation;
695     SetIndicatorActorRotation();
696     DoShowIndicator(currentOrientation);
697   }
698 }
699
700 void Window::IndicatorVisibilityChanged(bool isVisible)
701 {
702   mIndicatorVisibilityChangedSignal.Emit(isVisible);
703 }
704
705 void Window::SetIndicatorActorRotation()
706 {
707   DALI_LOG_TRACE_METHOD( gWindowLogFilter );
708   DALI_ASSERT_DEBUG( mIndicator != NULL );
709
710   Dali::Actor actor = mIndicator->GetActor();
711   switch( mIndicatorOrientation )
712   {
713     case Dali::Window::PORTRAIT:
714       actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
715       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
716       actor.SetOrientation( Degree(0), Vector3::ZAXIS );
717       break;
718     case Dali::Window::PORTRAIT_INVERSE:
719       actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
720       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
721       actor.SetOrientation( Degree(180), Vector3::ZAXIS );
722       break;
723     case Dali::Window::LANDSCAPE:
724       actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
725       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
726       actor.SetOrientation( Degree(270), Vector3::ZAXIS );
727       break;
728     case Dali::Window::LANDSCAPE_INVERSE:
729       actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
730       actor.SetAnchorPoint(  AnchorPoint::TOP_CENTER );
731       actor.SetOrientation( Degree(90), Vector3::ZAXIS );
732       break;
733   }
734 }
735
736 void Window::Raise()
737 {
738   ecore_wl_window_raise( mEventHandler->mEcoreWindow );
739 }
740
741 void Window::Lower()
742 {
743   ecore_wl_window_lower( mEventHandler->mEcoreWindow );
744 }
745
746 void Window::Activate()
747 {
748   ecore_wl_window_activate( mEventHandler->mEcoreWindow );
749 }
750
751 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
752 {
753   return mDragAndDropDetector;
754 }
755
756 Dali::Any Window::GetNativeHandle() const
757 {
758   if(mEventHandler)
759   {
760     return mEventHandler->mEcoreWindow;
761   }
762   else
763   {
764     return Dali::Any();
765   }
766 }
767
768 void Window::OnStart()
769 {
770   DoShowIndicator( mIndicatorOrientation );
771 }
772
773 void Window::OnPause()
774 {
775 }
776
777 void Window::OnResume()
778 {
779   // resume indicator status
780   if( mIndicator != NULL )
781   {
782     // Restore own indicator opacity
783     // Send opacity mode to indicator service when app resumed
784     mIndicator->SetOpacityMode( mIndicatorOpacityMode );
785   }
786 }
787
788 void Window::OnStop()
789 {
790   if( mIndicator )
791   {
792     mIndicator->Close();
793   }
794
795   delete mIndicator;
796   mIndicator = NULL;
797 }
798
799 void Window::OnDestroy()
800 {
801   mAdaptor = NULL;
802 }
803
804 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
805 {
806   bool found = false;
807
808   for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
809   {
810     if(mAvailableOrientations[i] == orientation)
811     {
812       found = true;
813       break;
814     }
815   }
816
817   if( ! found )
818   {
819     mAvailableOrientations.push_back(orientation);
820     SetAvailableOrientations( mAvailableOrientations );
821   }
822 }
823
824 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
825 {
826   for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
827        iter != mAvailableOrientations.end(); ++iter )
828   {
829     if( *iter == orientation )
830     {
831       mAvailableOrientations.erase( iter );
832       break;
833     }
834   }
835   SetAvailableOrientations( mAvailableOrientations );
836 }
837
838 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
839 {
840   int rotations[4];
841   for( std::size_t i = 0; i < mAvailableOrientations.size(); ++i )
842   {
843     rotations[i] = static_cast< int >( mAvailableOrientations[i] );
844   }
845   ecore_wl_window_rotation_available_rotations_set( mEventHandler->mEcoreWindow, rotations, mAvailableOrientations.size() );
846 }
847
848 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
849 {
850   return mAvailableOrientations;
851 }
852
853 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
854 {
855   mPreferredOrientation = orientation;
856
857   ecore_wl_window_rotation_preferred_rotation_set( mEventHandler->mEcoreWindow, orientation );
858 }
859
860 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
861 {
862   return mPreferredOrientation;
863 }
864
865 void Window::SetAcceptFocus( bool accept )
866 {
867   mIsFocusAcceptable = accept;
868
869   ecore_wl_window_focus_skip_set( mEventHandler->mEcoreWindow, !accept );
870 }
871
872 bool Window::IsFocusAcceptable()
873 {
874   return mIsFocusAcceptable;
875 }
876
877 void Window::Show()
878 {
879   mVisible = true;
880   ecore_wl_window_show( mEventHandler->mEcoreWindow );
881
882   // Need an update request
883   if( mAdaptor )
884   {
885     mAdaptor->RequestUpdateOnce();
886   }
887 }
888
889 void Window::Hide()
890 {
891   mVisible = false;
892   ecore_wl_window_hide( mEventHandler->mEcoreWindow );
893 }
894
895 bool Window::IsVisible() const
896 {
897   return mVisible;
898 }
899
900 void Window::RotationDone( int orientation, int width, int height )
901 {
902   PositionSize positionSize( 0, 0, width, height );
903
904   mAdaptor->SurfaceSizeChanged( positionSize );
905
906   // Emit signal
907   mResizedSignal.Emit( positionSize.width, positionSize.height );
908
909   Dali::Window::WindowOrientation windowOrientation;
910   switch( orientation )
911   {
912     case 0:
913     {
914       windowOrientation = Dali::Window::PORTRAIT;
915       break;
916     }
917     case 90:
918     {
919       windowOrientation = Dali::Window::LANDSCAPE;
920       break;
921     }
922     case 180:
923     {
924       windowOrientation = Dali::Window::PORTRAIT_INVERSE;
925       break;
926     }
927     case 270:
928     {
929       windowOrientation = Dali::Window::LANDSCAPE_INVERSE;
930       break;
931     }
932     default:
933     {
934       windowOrientation = Dali::Window::PORTRAIT;
935       break;
936     }
937   }
938
939   ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
940   wlSurface->RequestRotation( windowOrientation, positionSize.width, positionSize.height );
941 }
942
943 unsigned int Window::GetSupportedAuxiliaryHintCount()
944 {
945   return mSupportedAuxiliaryHints.size();
946 }
947
948 std::string Window::GetSupportedAuxiliaryHint( unsigned int index )
949 {
950   if( index >= GetSupportedAuxiliaryHintCount() )
951   {
952     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
953   }
954
955   return mSupportedAuxiliaryHints[index];
956 }
957
958 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
959 {
960   bool supported = false;
961
962   // Check if the hint is suppported
963   for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
964   {
965     if( *iter == hint )
966     {
967       supported = true;
968       break;
969     }
970   }
971
972   if( !supported )
973   {
974     DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
975     return 0;
976   }
977
978   // Check if the hint is already added
979   for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
980   {
981     if( mAuxiliaryHints[i].first == hint )
982     {
983       // Just change the value
984       mAuxiliaryHints[i].second = value;
985
986       DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
987
988       return i + 1;   // id is index + 1
989     }
990   }
991
992   // Add the hint
993   mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
994
995   unsigned int id = mAuxiliaryHints.size();
996
997   ecore_wl_window_aux_hint_add( mEventHandler->mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
998
999   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
1000
1001   return id;
1002 }
1003
1004 bool Window::RemoveAuxiliaryHint( unsigned int id )
1005 {
1006   if( id == 0 || id > mAuxiliaryHints.size() )
1007   {
1008     DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
1009     return false;
1010   }
1011
1012   mAuxiliaryHints[id - 1].second = std::string();
1013
1014   ecore_wl_window_aux_hint_del( mEventHandler->mEcoreWindow, static_cast< int >( id ) );
1015
1016   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
1017
1018   return true;
1019 }
1020
1021 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
1022 {
1023   if( id == 0 || id > mAuxiliaryHints.size() )
1024   {
1025     DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
1026     return false;
1027   }
1028
1029   mAuxiliaryHints[id - 1].second = value;
1030
1031   ecore_wl_window_aux_hint_change( mEventHandler->mEcoreWindow, static_cast< int >( id ), value.c_str() );
1032
1033   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, mAuxiliaryHints[id - 1].first.c_str(), mAuxiliaryHints[id - 1].second.c_str() );
1034
1035   return true;
1036 }
1037
1038 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
1039 {
1040   if( id == 0 || id > mAuxiliaryHints.size() )
1041   {
1042     DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
1043     return std::string();
1044   }
1045
1046   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintValue: id = %d, hint = %s, value = %s\n", id, mAuxiliaryHints[id - 1].first.c_str(), mAuxiliaryHints[id - 1].second.c_str() );
1047
1048   return mAuxiliaryHints[id - 1].second;
1049 }
1050
1051 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
1052 {
1053   for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
1054   {
1055     if( mAuxiliaryHints[i].first == hint )
1056     {
1057       DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
1058       return i + 1;
1059     }
1060   }
1061
1062   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
1063
1064   return 0;
1065 }
1066
1067 void Window::SetInputRegion( const Rect< int >& inputRegion )
1068 {
1069   ecore_wl_window_input_region_set( mEventHandler->mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
1070
1071   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetInputRegion: x = %d, y = %d, w = %d, h = %d\n", inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
1072 }
1073
1074 void Window::SetType( Dali::DevelWindow::Type type )
1075 {
1076   Ecore_Wl_Window_Type windowType;
1077
1078   if( type != mType )
1079   {
1080     switch( type )
1081     {
1082       case Dali::DevelWindow::NORMAL:
1083       {
1084         windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1085         break;
1086       }
1087       case Dali::DevelWindow::NOTIFICATION:
1088       {
1089         windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1090         break;
1091       }
1092       case Dali::DevelWindow::UTILITY:
1093       {
1094         windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1095         break;
1096       }
1097       case Dali::DevelWindow::DIALOG:
1098       {
1099         windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1100         break;
1101       }
1102       default:
1103       {
1104         windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1105         break;
1106       }
1107     }
1108
1109     ecore_wl_window_type_set( mEventHandler->mEcoreWindow, windowType );
1110   }
1111
1112   mType = type;
1113 }
1114
1115 Dali::DevelWindow::Type Window::GetType() const
1116 {
1117   return mType;
1118 }
1119
1120 bool Window::SetNotificationLevel( Dali::DevelWindow::NotificationLevel::Type level )
1121 {
1122   if( mType != Dali::DevelWindow::NOTIFICATION )
1123   {
1124     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
1125     return false;
1126   }
1127
1128   while( !mEventHandler->mTizenPolicy )
1129   {
1130     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1131   }
1132
1133   int notificationLevel;
1134
1135   switch( level )
1136   {
1137     case Dali::DevelWindow::NotificationLevel::NONE:
1138     {
1139       notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1140       break;
1141     }
1142     case Dali::DevelWindow::NotificationLevel::BASE:
1143     {
1144       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1145       break;
1146     }
1147     case Dali::DevelWindow::NotificationLevel::MEDIUM:
1148     {
1149       notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1150       break;
1151     }
1152     case Dali::DevelWindow::NotificationLevel::HIGH:
1153     {
1154       notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1155       break;
1156     }
1157     case Dali::DevelWindow::NotificationLevel::TOP:
1158     {
1159       notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1160       break;
1161     }
1162     default:
1163     {
1164       DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: invalid level [%d]\n", level );
1165       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1166       break;
1167     }
1168   }
1169
1170   mEventHandler->mNotificationLevelChangeDone = false;
1171   mEventHandler->mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1172
1173   tizen_policy_set_notification_level( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), notificationLevel );
1174
1175   int count = 0;
1176
1177   while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1178   {
1179     ecore_wl_flush();
1180     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1181     count++;
1182   }
1183
1184   if( !mEventHandler->mNotificationLevelChangeDone )
1185   {
1186     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mEventHandler->mNotificationChangeState );
1187     return false;
1188   }
1189   else if( mEventHandler->mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1190   {
1191     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Permission denied! [%d]\n", level );
1192     return false;
1193   }
1194
1195   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level is changed [%d]\n", mEventHandler->mNotificationLevel );
1196
1197   return true;
1198 }
1199
1200 Dali::DevelWindow::NotificationLevel::Type Window::GetNotificationLevel()
1201 {
1202   if( mType != Dali::DevelWindow::NOTIFICATION )
1203   {
1204     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
1205     return Dali::DevelWindow::NotificationLevel::NONE;
1206   }
1207
1208   while( !mEventHandler->mTizenPolicy )
1209   {
1210     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1211   }
1212
1213   int count = 0;
1214
1215   while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1216   {
1217     ecore_wl_flush();
1218     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1219     count++;
1220   }
1221
1222   if( !mEventHandler->mNotificationLevelChangeDone )
1223   {
1224     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Error! [%d]\n", mEventHandler->mNotificationChangeState );
1225     return Dali::DevelWindow::NotificationLevel::NONE;
1226   }
1227
1228   Dali::DevelWindow::NotificationLevel::Type level;
1229
1230   switch( mEventHandler->mNotificationLevel )
1231   {
1232     case TIZEN_POLICY_LEVEL_NONE:
1233     {
1234       level = Dali::DevelWindow::NotificationLevel::NONE;
1235       break;
1236     }
1237     case TIZEN_POLICY_LEVEL_DEFAULT:
1238     {
1239       level = Dali::DevelWindow::NotificationLevel::BASE;
1240       break;
1241     }
1242     case TIZEN_POLICY_LEVEL_MEDIUM:
1243     {
1244       level = Dali::DevelWindow::NotificationLevel::MEDIUM;
1245       break;
1246     }
1247     case TIZEN_POLICY_LEVEL_HIGH:
1248     {
1249       level = Dali::DevelWindow::NotificationLevel::HIGH;
1250       break;
1251     }
1252     case TIZEN_POLICY_LEVEL_TOP:
1253     {
1254       level = Dali::DevelWindow::NotificationLevel::TOP;
1255       break;
1256     }
1257     default:
1258     {
1259       DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: invalid level [%d]\n", mEventHandler->mNotificationLevel );
1260       level = Dali::DevelWindow::NotificationLevel::NONE;
1261       break;
1262     }
1263   }
1264
1265   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: level [%d]\n", mEventHandler->mNotificationLevel );
1266
1267   return level;
1268 }
1269
1270 void Window::SetOpaqueState( bool opaque )
1271 {
1272   while( !mEventHandler->mTizenPolicy )
1273   {
1274     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1275   }
1276
1277   tizen_policy_set_opaque_state( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), ( opaque ? 1 : 0 ) );
1278
1279   mOpaqueState = opaque;
1280
1281   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
1282 }
1283
1284 bool Window::IsOpaqueState()
1285 {
1286   return mOpaqueState;
1287 }
1288
1289 bool Window::SetScreenMode( Dali::DevelWindow::ScreenMode::Type screenMode )
1290 {
1291   while( !mEventHandler->mTizenPolicy )
1292   {
1293     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1294   }
1295
1296   mEventHandler->mScreenModeChangeDone = false;
1297   mEventHandler->mScreenModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1298
1299   unsigned int mode = 0;
1300
1301   switch( screenMode )
1302   {
1303     case Dali::DevelWindow::ScreenMode::DEFAULT:
1304     {
1305       mode = 0;
1306       break;
1307     }
1308     case Dali::DevelWindow::ScreenMode::ALWAYS_ON:
1309     {
1310       mode = 1;
1311       break;
1312     }
1313   }
1314
1315   tizen_policy_set_window_screen_mode( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), mode );
1316
1317   int count = 0;
1318
1319   while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1320   {
1321     ecore_wl_flush();
1322     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1323     count++;
1324   }
1325
1326   if( !mEventHandler->mScreenModeChangeDone )
1327   {
1328     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode change is failed [%d, %d]\n", screenMode, mEventHandler->mScreenModeChangeState );
1329     return false;
1330   }
1331   else if( mEventHandler->mScreenModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1332   {
1333     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Permission denied! [%d]\n", screenMode );
1334     return false;
1335   }
1336
1337   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode is changed [%d]\n", mEventHandler->mScreenMode );
1338
1339   return true;
1340 }
1341
1342 Dali::DevelWindow::ScreenMode::Type Window::GetScreenMode()
1343 {
1344   while( !mEventHandler->mTizenPolicy )
1345   {
1346     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1347   }
1348
1349   int count = 0;
1350
1351   while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1352   {
1353     ecore_wl_flush();
1354     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1355     count++;
1356   }
1357
1358   if( !mEventHandler->mScreenModeChangeDone )
1359   {
1360     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: Error! [%d]\n", mEventHandler->mScreenModeChangeState );
1361     return Dali::DevelWindow::ScreenMode::DEFAULT;
1362   }
1363
1364   Dali::DevelWindow::ScreenMode::Type screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1365
1366   switch( mEventHandler->mScreenMode )
1367   {
1368     case 0:
1369     {
1370       screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1371       break;
1372     }
1373     case 1:
1374     {
1375       screenMode = Dali::DevelWindow::ScreenMode::ALWAYS_ON;
1376       break;
1377     }
1378   }
1379
1380   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: screen mode [%d]\n", mEventHandler->mScreenMode );
1381
1382   return screenMode;
1383 }
1384
1385 bool Window::SetBrightness( int brightness )
1386 {
1387   if( brightness < 0 || brightness > 100 )
1388   {
1389     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
1390     return false;
1391   }
1392
1393   while( !mEventHandler->mTizenDisplayPolicy )
1394   {
1395     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1396   }
1397
1398   mEventHandler->mBrightnessChangeDone = false;
1399   mEventHandler->mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1400
1401   tizen_display_policy_set_window_brightness( mEventHandler->mTizenDisplayPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), brightness );
1402
1403   int count = 0;
1404
1405   while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1406   {
1407     ecore_wl_flush();
1408     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1409     count++;
1410   }
1411
1412   if( !mEventHandler->mBrightnessChangeDone )
1413   {
1414     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mEventHandler->mBrightnessChangeState );
1415     return false;
1416   }
1417   else if( mEventHandler->mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1418   {
1419     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Permission denied! [%d]\n", brightness );
1420     return false;
1421   }
1422
1423   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness is changed [%d]\n", mEventHandler->mBrightness );
1424
1425   return true;
1426 }
1427
1428 int Window::GetBrightness()
1429 {
1430   while( !mEventHandler->mTizenDisplayPolicy )
1431   {
1432     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1433   }
1434
1435   int count = 0;
1436
1437   while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1438   {
1439     ecore_wl_flush();
1440     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1441     count++;
1442   }
1443
1444   if( !mEventHandler->mBrightnessChangeDone )
1445   {
1446     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Error! [%d]\n", mEventHandler->mBrightnessChangeState );
1447     return 0;
1448   }
1449
1450   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Brightness [%d]\n", mEventHandler->mBrightness );
1451
1452   return mEventHandler->mBrightness;
1453 }
1454
1455 } // Adaptor
1456
1457 } // Internal
1458
1459 } // Dali
1460
1461 #pragma GCC diagnostic pop