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