[4.0] Add logs in Application
[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
45 const float INDICATOR_ANIMATION_DURATION( 0.18f ); // 180 milli seconds
46 const float INDICATOR_SHOW_Y_POSITION( 0.0f );
47 const float INDICATOR_HIDE_Y_POSITION( -52.0f );
48
49 const uint32_t MAX_TIZEN_CLIENT_VERSION = 7;
50
51 }
52
53 namespace Dali
54 {
55 namespace Internal
56 {
57 namespace Adaptor
58 {
59
60 #if defined(DEBUG_ENABLED)
61 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
62 #endif
63
64 /**
65  * TODO: Abstract Window class out and move this into a window implementation for Ecore
66  */
67 struct Window::EventHandler
68 {
69   /**
70    * Constructor
71    * @param[in]  window  A pointer to the window class.
72    */
73   EventHandler( Window* window )
74   : mWindow( window ),
75     mEcoreEventHandler(),
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     mScreenOffMode( 0 ),
85     mScreenOffModeChangeState( 0 ),
86     mScreenOffModeChangeDone( 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       mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this ) );
102       mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this ) );
103       mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this ) );
104       mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_OUTPUT_TRANSFORM, EcoreEventOutputTransform, this) );
105       mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_IGNORE_OUTPUT_TRANSFORM, EcoreEventIgnoreOutputTransform, this) );
106     }
107
108     mDisplay = ecore_wl_display_get();
109
110     if( mDisplay )
111     {
112       wl_display* displayWrapper = static_cast< wl_display* >( wl_proxy_create_wrapper( mDisplay ) );
113       if( displayWrapper )
114       {
115         mEventQueue = wl_display_create_queue( mDisplay );
116         if( mEventQueue )
117         {
118           wl_proxy_set_queue( reinterpret_cast< wl_proxy* >( displayWrapper ), mEventQueue );
119
120           wl_registry* registry = wl_display_get_registry( displayWrapper );
121           wl_registry_add_listener( registry, &mRegistryListener, this );
122         }
123
124         wl_proxy_wrapper_destroy( displayWrapper );
125       }
126     }
127   }
128
129   /**
130    * Destructor
131    */
132   ~EventHandler()
133   {
134     for( Dali::Vector< Ecore_Event_Handler* >::Iterator iter = mEcoreEventHandler.Begin(), endIter = mEcoreEventHandler.End(); iter != endIter; ++iter )
135     {
136       ecore_event_handler_del( *iter );
137     }
138     mEcoreEventHandler.Clear();
139
140     if( mEventQueue )
141     {
142       wl_event_queue_destroy( mEventQueue );
143     }
144   }
145
146   // Static methods
147
148   /// Called when the window iconify state is changed.
149   static Eina_Bool EcoreEventWindowIconifyStateChanged( void* data, int type, void* event )
150   {
151     Ecore_Wl_Event_Window_Iconify_State_Change* iconifyChangedEvent( static_cast< Ecore_Wl_Event_Window_Iconify_State_Change* >( event ) );
152     EventHandler* handler( static_cast< EventHandler* >( data ) );
153     Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
154
155     if ( handler && handler->mWindow )
156     {
157       WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
158       if ( observer && ( iconifyChangedEvent->win == static_cast< unsigned int> ( ecore_wl_window_id_get( handler->mEcoreWindow ) ) ) )
159       {
160         if( iconifyChangedEvent->iconified == EINA_TRUE )
161         {
162           handler->mWindow->mIconified = true;
163           if( handler->mWindow->mVisible )
164           {
165             observer->OnWindowHidden();
166           }
167           DALI_LOG_RELEASE_INFO( "EcoreEventWindowIconifyStateChanged: Iconified, mVisible [%d]\n", handler->mWindow->mVisible );
168         }
169         else
170         {
171           handler->mWindow->mIconified = false;
172           if( handler->mWindow->mVisible )
173           {
174             observer->OnWindowShown();
175           }
176           DALI_LOG_RELEASE_INFO( "EcoreEventWindowIconifyStateChanged: Deiconified, mVisible [%d]\n", handler->mWindow->mVisible );
177         }
178         handled = ECORE_CALLBACK_DONE;
179       }
180     }
181
182     return handled;
183   }
184
185   /// Called when the window gains focus
186   static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
187   {
188     Ecore_Wl_Event_Focus_In* focusInEvent( static_cast< Ecore_Wl_Event_Focus_In* >( event ) );
189     EventHandler* handler( static_cast< EventHandler* >( data ) );
190
191     if ( handler && handler->mWindow && focusInEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
192     {
193       DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n" );
194
195       handler->mWindow->mFocusChangedSignal.Emit( true );
196     }
197
198     return ECORE_CALLBACK_PASS_ON;
199   }
200
201   /// Called when the window loses focus
202   static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
203   {
204     Ecore_Wl_Event_Focus_Out* focusOutEvent( static_cast< Ecore_Wl_Event_Focus_Out* >( event ) );
205     EventHandler* handler( static_cast< EventHandler* >( data ) );
206
207     if ( handler && handler->mWindow && focusOutEvent->win == static_cast< unsigned int >(ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
208     {
209       DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n" );
210
211       handler->mWindow->mFocusChangedSignal.Emit( false );
212     }
213
214     return ECORE_CALLBACK_PASS_ON;
215   }
216
217   /// Called when the output is transformed
218   static Eina_Bool EcoreEventOutputTransform( void* data, int type, void* event )
219   {
220     Ecore_Wl_Event_Output_Transform* transformEvent( static_cast< Ecore_Wl_Event_Output_Transform* >( event ) );
221     EventHandler* handler( static_cast< EventHandler* >( data ) );
222
223     if ( handler && handler->mWindow && transformEvent->output == ecore_wl_window_output_find( handler->mEcoreWindow ) )
224     {
225       DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%p) EcoreEventOutputTransform\n", handler->mEcoreWindow );
226
227       ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( handler->mWindow->mSurface ) );
228       if( wlSurface )
229       {
230         wlSurface->OutputTransformed();
231
232         PositionSize positionSize = wlSurface->GetPositionSize();
233         handler->mWindow->mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
234         handler->mWindow->mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
235       }
236     }
237
238     return ECORE_CALLBACK_PASS_ON;
239   }
240
241   /// Called when the output transform should be ignored
242   static Eina_Bool EcoreEventIgnoreOutputTransform( void* data, int type, void* event )
243   {
244     Ecore_Wl_Event_Ignore_Output_Transform* ignoreTransformEvent( static_cast< Ecore_Wl_Event_Ignore_Output_Transform* >( event ) );
245     EventHandler* handler( static_cast< EventHandler* >( data ) );
246
247     if ( handler && handler->mWindow && ignoreTransformEvent->win == handler->mEcoreWindow )
248     {
249       DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%p) EcoreEventIgnoreOutputTransform\n", handler->mEcoreWindow );
250
251       ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( handler->mWindow->mSurface ) );
252       if( wlSurface )
253       {
254         wlSurface->OutputTransformed();
255
256         PositionSize positionSize = wlSurface->GetPositionSize();
257         handler->mWindow->mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
258         handler->mWindow->mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
259       }
260     }
261
262     return ECORE_CALLBACK_PASS_ON;
263   }
264
265   static void RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
266   {
267     Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
268
269     if( strcmp( interface, tizen_policy_interface.name ) == 0 )
270     {
271       uint32_t clientVersion = std::min( version, MAX_TIZEN_CLIENT_VERSION );
272
273       eventHandler->mTizenPolicy = static_cast< tizen_policy* >( wl_registry_bind( registry, name, &tizen_policy_interface, clientVersion ) );
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* tizenPolicy, struct wl_surface* surface, uint32_t isConformant )
307   {
308   }
309
310   static void TizenPolicyConformantArea( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t conformantPart, 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* tizenPolicy, uint32_t childId )
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* tizenPolicy, struct wl_surface* surface, uint32_t iconified, uint32_t force )
341   {
342   }
343
344   static void TizenPolicySupportedAuxiliaryHints( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, struct wl_array* hints, uint32_t numNints )
345   {
346   }
347
348   static void TizenPolicyAllowedAuxiliaryHint( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int id )
349   {
350   }
351
352   static void TizenPolicyAuxiliaryMessage( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, const char* key, const char* val, struct wl_array* options )
353   {
354   }
355
356   static void TizenPolicyConformantRegion( void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t conformantPart, 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      TizenPolicySupportedAuxiliaryHints,
386      TizenPolicyAllowedAuxiliaryHint,
387      TizenPolicyAuxiliaryMessage,
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   DALI_LOG_RELEASE_INFO( "Window::Raise is called.\n" );
785 }
786
787 void Window::Lower()
788 {
789   ecore_wl_window_lower( mEventHandler->mEcoreWindow );
790
791   DALI_LOG_RELEASE_INFO( "Window::Lower is called.\n" );
792 }
793
794 void Window::Activate()
795 {
796   ecore_wl_window_activate( mEventHandler->mEcoreWindow );
797
798   DALI_LOG_RELEASE_INFO( "Window::Activate is called.\n" );
799 }
800
801 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
802 {
803   return mDragAndDropDetector;
804 }
805
806 Dali::Any Window::GetNativeHandle() const
807 {
808   if(mEventHandler)
809   {
810     return mEventHandler->mEcoreWindow;
811   }
812   else
813   {
814     return Dali::Any();
815   }
816 }
817
818 void Window::OnStart()
819 {
820   DoShowIndicator( mIndicatorOrientation );
821 }
822
823 void Window::OnPause()
824 {
825 }
826
827 void Window::OnResume()
828 {
829   // resume indicator status
830   if( mIndicator != NULL )
831   {
832     // Restore own indicator opacity
833     // Send opacity mode to indicator service when app resumed
834     mIndicator->SetOpacityMode( mIndicatorOpacityMode );
835   }
836 }
837
838 void Window::OnStop()
839 {
840   if( mIndicator )
841   {
842     mIndicator->Close();
843   }
844
845   delete mIndicator;
846   mIndicator = NULL;
847 }
848
849 void Window::OnDestroy()
850 {
851   mAdaptor = NULL;
852 }
853
854 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
855 {
856   bool found = false;
857
858   if ( orientation <= Dali::Window::LANDSCAPE_INVERSE )
859   {
860     for( std::size_t i = 0; i < mAvailableOrientations.size(); i++ )
861     {
862       if( mAvailableOrientations[i] == orientation )
863       {
864         found = true;
865         break;
866       }
867     }
868
869     if( ! found )
870     {
871       mAvailableOrientations.push_back(orientation);
872       SetAvailableOrientations( mAvailableOrientations );
873     }
874   }
875 }
876
877 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
878 {
879   for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
880        iter != mAvailableOrientations.end(); ++iter )
881   {
882     if( *iter == orientation )
883     {
884       mAvailableOrientations.erase( iter );
885       break;
886     }
887   }
888   SetAvailableOrientations( mAvailableOrientations );
889 }
890
891 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
892 {
893   int rotations[4];
894   for( std::size_t i = 0; i < mAvailableOrientations.size(); ++i )
895   {
896     rotations[i] = static_cast< int >( mAvailableOrientations[i] );
897   }
898   ecore_wl_window_rotation_available_rotations_set( mEventHandler->mEcoreWindow, rotations, mAvailableOrientations.size() );
899 }
900
901 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
902 {
903   return mAvailableOrientations;
904 }
905
906 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
907 {
908   mPreferredOrientation = orientation;
909
910   ecore_wl_window_rotation_preferred_rotation_set( mEventHandler->mEcoreWindow, orientation );
911 }
912
913 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
914 {
915   return mPreferredOrientation;
916 }
917
918 void Window::SetAcceptFocus( bool accept )
919 {
920   mIsFocusAcceptable = accept;
921
922   ecore_wl_window_focus_skip_set( mEventHandler->mEcoreWindow, !accept );
923 }
924
925 bool Window::IsFocusAcceptable() const
926 {
927   return mIsFocusAcceptable;
928 }
929
930 void Window::Show()
931 {
932   mVisible = true;
933   ecore_wl_window_show( mEventHandler->mEcoreWindow );
934
935   DALI_LOG_RELEASE_INFO( "Window::Show is called : mIconified [%d]\n", mIconified );
936
937   if( !mIconified )
938   {
939     if( mAdaptor )
940     {
941       WindowVisibilityObserver* observer( mAdaptor );
942       observer->OnWindowShown();
943     }
944   }
945 }
946
947 void Window::Hide()
948 {
949   mVisible = false;
950   ecore_wl_window_hide( mEventHandler->mEcoreWindow );
951
952   DALI_LOG_RELEASE_INFO( "Window::Hide is called : mIconified [%d]\n", mIconified );
953
954   if( !mIconified )
955   {
956     if( mAdaptor )
957     {
958       WindowVisibilityObserver* observer( mAdaptor );
959       observer->OnWindowHidden();
960     }
961   }
962 }
963
964 bool Window::IsVisible() const
965 {
966   return mVisible;
967 }
968
969 void Window::RotationDone( int orientation, int width, int height )
970 {
971   ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
972   if( wlSurface )
973   {
974     wlSurface->RequestRotation( orientation, width, height );
975   }
976
977   mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( width, height ) );
978
979   // Emit signal
980   mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) );
981
982   mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( width, height ) );
983 }
984
985 void Window::SetIndicatorVisibleMode( Dali::Window::IndicatorVisibleMode mode )
986 {
987   mIndicatorVisible = mode;
988 }
989
990 unsigned int Window::GetSupportedAuxiliaryHintCount() const
991 {
992   return mSupportedAuxiliaryHints.size();
993 }
994
995 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
996 {
997   if( index >= GetSupportedAuxiliaryHintCount() )
998   {
999     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
1000   }
1001
1002   return mSupportedAuxiliaryHints[index];
1003 }
1004
1005 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
1006 {
1007   bool supported = false;
1008
1009   // Check if the hint is suppported
1010   for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
1011   {
1012     if( *iter == hint )
1013     {
1014       supported = true;
1015       break;
1016     }
1017   }
1018
1019   if( !supported )
1020   {
1021     DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
1022     return 0;
1023   }
1024
1025   // Check if the hint is already added
1026   for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
1027   {
1028     if( mAuxiliaryHints[i].first == hint )
1029     {
1030       // Just change the value
1031       mAuxiliaryHints[i].second = value;
1032
1033       DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
1034
1035       return i + 1;   // id is index + 1
1036     }
1037   }
1038
1039   // Add the hint
1040   mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
1041
1042   unsigned int id = mAuxiliaryHints.size();
1043
1044   ecore_wl_window_aux_hint_add( mEventHandler->mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
1045
1046   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
1047
1048   return id;
1049 }
1050
1051 bool Window::RemoveAuxiliaryHint( unsigned int id )
1052 {
1053   if( id == 0 || id > mAuxiliaryHints.size() )
1054   {
1055     DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
1056     return false;
1057   }
1058
1059   mAuxiliaryHints[id - 1].second = std::string();
1060
1061   ecore_wl_window_aux_hint_del( mEventHandler->mEcoreWindow, static_cast< int >( id ) );
1062
1063   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
1064
1065   return true;
1066 }
1067
1068 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
1069 {
1070   if( id == 0 || id > mAuxiliaryHints.size() )
1071   {
1072     DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
1073     return false;
1074   }
1075
1076   mAuxiliaryHints[id - 1].second = value;
1077
1078   ecore_wl_window_aux_hint_change( mEventHandler->mEcoreWindow, static_cast< int >( id ), value.c_str() );
1079
1080   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() );
1081
1082   return true;
1083 }
1084
1085 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
1086 {
1087   if( id == 0 || id > mAuxiliaryHints.size() )
1088   {
1089     DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
1090     return std::string();
1091   }
1092
1093   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() );
1094
1095   return mAuxiliaryHints[id - 1].second;
1096 }
1097
1098 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
1099 {
1100   for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
1101   {
1102     if( mAuxiliaryHints[i].first == hint )
1103     {
1104       DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
1105       return i + 1;
1106     }
1107   }
1108
1109   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
1110
1111   return 0;
1112 }
1113
1114 void Window::SetInputRegion( const Rect< int >& inputRegion )
1115 {
1116   ecore_wl_window_input_region_set( mEventHandler->mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
1117
1118   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 );
1119 }
1120
1121 void Window::SetType( Dali::Window::Type type )
1122 {
1123   Ecore_Wl_Window_Type windowType;
1124
1125   if( type != mType )
1126   {
1127     switch( type )
1128     {
1129       case Dali::Window::NORMAL:
1130       {
1131         windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1132         break;
1133       }
1134       case Dali::Window::NOTIFICATION:
1135       {
1136         windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1137         break;
1138       }
1139       case Dali::Window::UTILITY:
1140       {
1141         windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1142         break;
1143       }
1144       case Dali::Window::DIALOG:
1145       {
1146         windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1147         break;
1148       }
1149       default:
1150       {
1151         windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1152         break;
1153       }
1154     }
1155
1156     ecore_wl_window_type_set( mEventHandler->mEcoreWindow, windowType );
1157   }
1158
1159   mType = type;
1160 }
1161
1162 Dali::Window::Type Window::GetType() const
1163 {
1164   return mType;
1165 }
1166
1167 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
1168 {
1169   if( mType != Dali::Window::NOTIFICATION )
1170   {
1171     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
1172     return false;
1173   }
1174
1175   while( !mEventHandler->mTizenPolicy )
1176   {
1177     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1178   }
1179
1180   int notificationLevel;
1181
1182   switch( level )
1183   {
1184     case Dali::Window::NotificationLevel::NONE:
1185     {
1186       notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1187       break;
1188     }
1189     case Dali::Window::NotificationLevel::BASE:
1190     {
1191       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1192       break;
1193     }
1194     case Dali::Window::NotificationLevel::MEDIUM:
1195     {
1196       notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1197       break;
1198     }
1199     case Dali::Window::NotificationLevel::HIGH:
1200     {
1201       notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1202       break;
1203     }
1204     case Dali::Window::NotificationLevel::TOP:
1205     {
1206       notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1207       break;
1208     }
1209     default:
1210     {
1211       DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: invalid level [%d]\n", level );
1212       notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1213       break;
1214     }
1215   }
1216
1217   mEventHandler->mNotificationLevelChangeDone = false;
1218   mEventHandler->mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1219
1220   tizen_policy_set_notification_level( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), notificationLevel );
1221
1222   int count = 0;
1223
1224   while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1225   {
1226     ecore_wl_flush();
1227     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1228     count++;
1229   }
1230
1231   if( !mEventHandler->mNotificationLevelChangeDone )
1232   {
1233     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mEventHandler->mNotificationChangeState );
1234     return false;
1235   }
1236   else if( mEventHandler->mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1237   {
1238     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Permission denied! [%d]\n", level );
1239     return false;
1240   }
1241
1242   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level is changed [%d]\n", mEventHandler->mNotificationLevel );
1243
1244   return true;
1245 }
1246
1247 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
1248 {
1249   if( mType != Dali::Window::NOTIFICATION )
1250   {
1251     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
1252     return Dali::Window::NotificationLevel::NONE;
1253   }
1254
1255   while( !mEventHandler->mTizenPolicy )
1256   {
1257     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1258   }
1259
1260   int count = 0;
1261
1262   while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1263   {
1264     ecore_wl_flush();
1265     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1266     count++;
1267   }
1268
1269   if( !mEventHandler->mNotificationLevelChangeDone )
1270   {
1271     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Error! [%d]\n", mEventHandler->mNotificationChangeState );
1272     return Dali::Window::NotificationLevel::NONE;
1273   }
1274
1275   Dali::Window::NotificationLevel::Type level;
1276
1277   switch( mEventHandler->mNotificationLevel )
1278   {
1279     case TIZEN_POLICY_LEVEL_NONE:
1280     {
1281       level = Dali::Window::NotificationLevel::NONE;
1282       break;
1283     }
1284     case TIZEN_POLICY_LEVEL_DEFAULT:
1285     {
1286       level = Dali::Window::NotificationLevel::BASE;
1287       break;
1288     }
1289     case TIZEN_POLICY_LEVEL_MEDIUM:
1290     {
1291       level = Dali::Window::NotificationLevel::MEDIUM;
1292       break;
1293     }
1294     case TIZEN_POLICY_LEVEL_HIGH:
1295     {
1296       level = Dali::Window::NotificationLevel::HIGH;
1297       break;
1298     }
1299     case TIZEN_POLICY_LEVEL_TOP:
1300     {
1301       level = Dali::Window::NotificationLevel::TOP;
1302       break;
1303     }
1304     default:
1305     {
1306       DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: invalid level [%d]\n", mEventHandler->mNotificationLevel );
1307       level = Dali::Window::NotificationLevel::NONE;
1308       break;
1309     }
1310   }
1311
1312   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: level [%d]\n", mEventHandler->mNotificationLevel );
1313
1314   return level;
1315 }
1316
1317 void Window::SetOpaqueState( bool opaque )
1318 {
1319   while( !mEventHandler->mTizenPolicy )
1320   {
1321     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1322   }
1323
1324   tizen_policy_set_opaque_state( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), ( opaque ? 1 : 0 ) );
1325
1326   mOpaqueState = opaque;
1327
1328   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
1329 }
1330
1331 bool Window::IsOpaqueState() const
1332 {
1333   return mOpaqueState;
1334 }
1335
1336 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
1337 {
1338   while( !mEventHandler->mTizenPolicy )
1339   {
1340     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1341   }
1342
1343   mEventHandler->mScreenOffModeChangeDone = false;
1344   mEventHandler->mScreenOffModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1345
1346   unsigned int mode = 0;
1347
1348   switch( screenOffMode )
1349   {
1350     case Dali::Window::ScreenOffMode::TIMEOUT:
1351     {
1352       mode = 0;
1353       break;
1354     }
1355     case Dali::Window::ScreenOffMode::NEVER:
1356     {
1357       mode = 1;
1358       break;
1359     }
1360   }
1361
1362   tizen_policy_set_window_screen_mode( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), mode );
1363
1364   int count = 0;
1365
1366   while( !mEventHandler->mScreenOffModeChangeDone && count < 3 )
1367   {
1368     ecore_wl_flush();
1369     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1370     count++;
1371   }
1372
1373   if( !mEventHandler->mScreenOffModeChangeDone )
1374   {
1375     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenOffMode: Screen mode change is failed [%d, %d]\n", screenOffMode, mEventHandler->mScreenOffModeChangeState );
1376     return false;
1377   }
1378   else if( mEventHandler->mScreenOffModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1379   {
1380     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenOffMode: Permission denied! [%d]\n", screenOffMode );
1381     return false;
1382   }
1383
1384   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenOffMode: Screen mode is changed [%d]\n", mEventHandler->mScreenOffMode );
1385
1386   return true;
1387 }
1388
1389 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
1390 {
1391   while( !mEventHandler->mTizenPolicy )
1392   {
1393     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1394   }
1395
1396   int count = 0;
1397
1398   while( !mEventHandler->mScreenOffModeChangeDone && count < 3 )
1399   {
1400     ecore_wl_flush();
1401     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1402     count++;
1403   }
1404
1405   if( !mEventHandler->mScreenOffModeChangeDone )
1406   {
1407     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenOffMode: Error! [%d]\n", mEventHandler->mScreenOffModeChangeState );
1408     return Dali::Window::ScreenOffMode::TIMEOUT;
1409   }
1410
1411   Dali::Window::ScreenOffMode::Type screenMode = Dali::Window::ScreenOffMode::TIMEOUT;
1412
1413   switch( mEventHandler->mScreenOffMode )
1414   {
1415     case 0:
1416     {
1417       screenMode = Dali::Window::ScreenOffMode::TIMEOUT;
1418       break;
1419     }
1420     case 1:
1421     {
1422       screenMode = Dali::Window::ScreenOffMode::NEVER;
1423       break;
1424     }
1425   }
1426
1427   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenOffMode: screen mode [%d]\n", mEventHandler->mScreenOffMode );
1428
1429   return screenMode;
1430 }
1431
1432 bool Window::SetBrightness( int brightness )
1433 {
1434   if( brightness < 0 || brightness > 100 )
1435   {
1436     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
1437     return false;
1438   }
1439
1440   while( !mEventHandler->mTizenDisplayPolicy )
1441   {
1442     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1443   }
1444
1445   mEventHandler->mBrightnessChangeDone = false;
1446   mEventHandler->mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1447
1448   tizen_display_policy_set_window_brightness( mEventHandler->mTizenDisplayPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), brightness );
1449
1450   int count = 0;
1451
1452   while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1453   {
1454     ecore_wl_flush();
1455     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1456     count++;
1457   }
1458
1459   if( !mEventHandler->mBrightnessChangeDone )
1460   {
1461     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mEventHandler->mBrightnessChangeState );
1462     return false;
1463   }
1464   else if( mEventHandler->mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1465   {
1466     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Permission denied! [%d]\n", brightness );
1467     return false;
1468   }
1469
1470   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness is changed [%d]\n", mEventHandler->mBrightness );
1471
1472   return true;
1473 }
1474
1475 int Window::GetBrightness() const
1476 {
1477   while( !mEventHandler->mTizenDisplayPolicy )
1478   {
1479     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1480   }
1481
1482   int count = 0;
1483
1484   while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1485   {
1486     ecore_wl_flush();
1487     wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1488     count++;
1489   }
1490
1491   if( !mEventHandler->mBrightnessChangeDone )
1492   {
1493     DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Error! [%d]\n", mEventHandler->mBrightnessChangeState );
1494     return 0;
1495   }
1496
1497   DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Brightness [%d]\n", mEventHandler->mBrightness );
1498
1499   return mEventHandler->mBrightness;
1500 }
1501
1502 void Window::SetSize( Dali::Window::WindowSize size )
1503 {
1504   if( !mResizeEnabled )
1505   {
1506     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
1507     mResizeEnabled = true;
1508   }
1509
1510   PositionSize positionSize = mSurface->GetPositionSize();
1511
1512   if( positionSize.width != size.GetWidth() || positionSize.height != size.GetHeight() )
1513   {
1514     positionSize.width = size.GetWidth();
1515     positionSize.height = size.GetHeight();
1516
1517     mSurface->MoveResize( positionSize );
1518
1519     mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
1520
1521     // Emit signal
1522     mResizedSignal.Emit( Dali::Window::WindowSize( positionSize.width, positionSize.height ) );
1523
1524     mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
1525   }
1526 }
1527
1528 Dali::Window::WindowSize Window::GetSize() const
1529 {
1530   PositionSize positionSize = mSurface->GetPositionSize();
1531
1532   return Dali::Window::WindowSize( positionSize.width, positionSize.height );
1533 }
1534
1535 void Window::SetPosition( Dali::Window::WindowPosition position )
1536 {
1537   if( !mResizeEnabled )
1538   {
1539     AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
1540     mResizeEnabled = true;
1541   }
1542
1543   PositionSize positionSize = mSurface->GetPositionSize();
1544
1545   if( positionSize.x != position.GetX() || positionSize.y != position.GetY() )
1546   {
1547     positionSize.x = position.GetX();
1548     positionSize.y = position.GetY();
1549
1550     mSurface->MoveResize( positionSize );
1551   }
1552 }
1553
1554 Dali::Window::WindowPosition Window::GetPosition() const
1555 {
1556   PositionSize positionSize = mSurface->GetPositionSize();
1557
1558   return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
1559 }
1560
1561 void Window::SetTransparency( bool transparent )
1562 {
1563   ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
1564   if( wlSurface )
1565   {
1566     wlSurface->SetTransparency( transparent );
1567   }
1568 }
1569
1570 } // Adaptor
1571
1572 } // Internal
1573
1574 } // Dali
1575
1576 #pragma GCC diagnostic pop