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