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