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