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