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