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