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