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