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