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