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