2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 #include <window-impl.h>
22 // Ecore is littered with C style cast
23 #pragma GCC diagnostic push
24 #pragma GCC diagnostic ignored "-Wold-style-cast"
26 #include <Ecore_Wayland.h>
27 #include <tizen-extension-client-protocol.h>
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>
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>
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 );
56 #if defined(DEBUG_ENABLED)
57 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
61 * TODO: Abstract Window class out and move this into a window implementation for Ecore
63 struct Window::EventHandler
67 * @param[in] window A pointer to the window class.
69 EventHandler( Window* window )
71 mWindowPropertyHandler( NULL ),
72 mWindowIconifyStateHandler( NULL ),
73 mWindowFocusInHandler( NULL ),
74 mWindowFocusOutHandler( NULL ),
79 mTizenDisplayPolicy( NULL ),
80 mNotificationLevel( -1 ),
81 mNotificationChangeState( 0 ),
82 mNotificationLevelChangeDone( true ),
84 mScreenModeChangeState( 0 ),
85 mScreenModeChangeDone( true ),
87 mBrightnessChangeState( 0 ),
88 mBrightnessChangeDone( true )
90 // store ecore window handle
91 ECore::WindowRenderSurface* wlWindow( dynamic_cast< ECore::WindowRenderSurface * >( mWindow->mSurface ) );
94 mEcoreWindow = wlWindow->GetWlWindow();
96 DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no ecore Wl window");
98 if( mWindow->mEcoreEventHander )
100 mWindowIconifyStateHandler = ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this );
101 mWindowFocusInHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this );
102 mWindowFocusOutHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this );
105 mDisplay = ecore_wl_display_get();
109 wl_display* displayWrapper = static_cast< wl_display* >( wl_proxy_create_wrapper( mDisplay ) );
112 mEventQueue = wl_display_create_queue( mDisplay );
115 wl_proxy_set_queue( reinterpret_cast< wl_proxy* >( displayWrapper ), mEventQueue );
117 wl_registry* registry = wl_display_get_registry( displayWrapper );
118 wl_registry_add_listener( registry, &mRegistryListener, this );
121 wl_proxy_wrapper_destroy( displayWrapper );
131 if ( mWindowPropertyHandler )
133 ecore_event_handler_del( mWindowPropertyHandler );
135 if ( mWindowIconifyStateHandler )
137 ecore_event_handler_del( mWindowIconifyStateHandler );
139 if( mWindowFocusInHandler )
141 ecore_event_handler_del( mWindowFocusInHandler );
143 if( mWindowFocusOutHandler )
145 ecore_event_handler_del( mWindowFocusOutHandler );
149 wl_event_queue_destroy( mEventQueue );
155 /// Called when the window properties are changed.
156 static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
161 /// Called when the window iconify state is changed.
162 static Eina_Bool EcoreEventWindowIconifyStateChanged( void* data, int type, void* event )
164 Ecore_Wl_Event_Window_Iconify_State_Change* iconifyChangedEvent( static_cast< Ecore_Wl_Event_Window_Iconify_State_Change* >( event ) );
165 EventHandler* handler( static_cast< EventHandler* >( data ) );
166 Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
168 if ( handler && handler->mWindow )
170 WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
171 if ( observer && ( iconifyChangedEvent->win == static_cast< unsigned int> ( ecore_wl_window_id_get( handler->mEcoreWindow ) ) ) )
173 if( iconifyChangedEvent->iconified == EINA_TRUE )
175 observer->OnWindowHidden();
176 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Iconfied\n", handler->mEcoreWindow );
180 observer->OnWindowShown();
181 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Shown\n", handler->mEcoreWindow );
183 handled = ECORE_CALLBACK_DONE;
190 /// Called when the window gains focus
191 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
193 Ecore_Wl_Event_Focus_In* focusInEvent( static_cast< Ecore_Wl_Event_Focus_In* >( event ) );
194 EventHandler* handler( static_cast< EventHandler* >( data ) );
196 if ( handler && handler->mWindow && focusInEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
198 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n" );
200 handler->mWindow->mFocusChangedSignal.Emit( true );
203 return ECORE_CALLBACK_PASS_ON;
206 /// Called when the window loses focus
207 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
209 Ecore_Wl_Event_Focus_Out* focusOutEvent( static_cast< Ecore_Wl_Event_Focus_Out* >( event ) );
210 EventHandler* handler( static_cast< EventHandler* >( data ) );
212 if ( handler && handler->mWindow && focusOutEvent->win == static_cast< unsigned int >(ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
214 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n" );
216 handler->mWindow->mFocusChangedSignal.Emit( false );
219 return ECORE_CALLBACK_PASS_ON;
222 static void RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
224 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
226 if( strcmp( interface, tizen_policy_interface.name ) == 0 )
228 eventHandler->mTizenPolicy = static_cast< tizen_policy* >( wl_registry_bind( registry, name, &tizen_policy_interface, version ) );
229 if( !eventHandler->mTizenPolicy )
231 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n" );
235 tizen_policy_add_listener( eventHandler->mTizenPolicy, &eventHandler->mTizenPolicyListener, data );
237 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_policy_add_listener is called.\n" );
239 else if( strcmp( interface, tizen_display_policy_interface.name ) == 0 )
241 eventHandler->mTizenDisplayPolicy = static_cast< tizen_display_policy* >( wl_registry_bind( registry, name, &tizen_display_policy_interface, version ) );
242 if( !eventHandler->mTizenDisplayPolicy )
244 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n" );
248 tizen_display_policy_add_listener( eventHandler->mTizenDisplayPolicy, &eventHandler->mTizenDisplayPolicyListener, data );
250 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n" );
254 static void RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
256 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
257 eventHandler->mTizenPolicy = NULL;
258 eventHandler->mTizenDisplayPolicy = NULL;
261 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
263 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
265 eventHandler->mNotificationLevel = level;
266 eventHandler->mNotificationChangeState = state;
267 eventHandler->mNotificationLevelChangeDone = true;
269 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state );
272 static void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
274 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
276 eventHandler->mScreenMode = mode;
277 eventHandler->mScreenModeChangeState = state;
278 eventHandler->mScreenModeChangeDone = true;
280 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state );
283 static void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
285 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
287 eventHandler->mBrightness = brightness;
288 eventHandler->mBrightnessChangeState = state;
289 eventHandler->mBrightnessChangeDone = true;
291 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state );
294 const struct wl_registry_listener mRegistryListener =
296 RegistryGlobalCallback,
297 RegistryGlobalCallbackRemove
300 const struct tizen_policy_listener mTizenPolicyListener =
304 TizenPolicyNotificationChangeDone,
306 TizenPolicyScreenModeChangeDone,
313 const struct tizen_display_policy_listener mTizenDisplayPolicyListener =
315 DisplayPolicyBrightnessChangeDone
320 Ecore_Event_Handler* mWindowPropertyHandler;
321 Ecore_Event_Handler* mWindowIconifyStateHandler;
322 Ecore_Event_Handler* mWindowFocusInHandler;
323 Ecore_Event_Handler* mWindowFocusOutHandler;
324 Ecore_Wl_Window* mEcoreWindow;
326 wl_display* mDisplay;
327 wl_event_queue* mEventQueue;
328 tizen_policy* mTizenPolicy;
329 tizen_display_policy* mTizenDisplayPolicy;
331 int mNotificationLevel;
332 uint32_t mNotificationChangeState;
333 bool mNotificationLevelChangeDone;
336 uint32_t mScreenModeChangeState;
337 bool mScreenModeChangeDone;
340 uint32_t mBrightnessChangeState;
341 bool mBrightnessChangeDone;
344 Window* Window::New(const PositionSize& posSize, const std::string& name, const std::string& className, bool isTransparent)
346 Window* window = new Window();
347 window->mIsTransparent = isTransparent;
348 window->Initialize(posSize, name, className);
352 void Window::SetAdaptor(Dali::Adaptor& adaptor)
354 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
357 // Only create one overlay per window
358 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
359 Integration::Core& core = adaptorImpl.GetCore();
360 mOverlay = &core.GetSystemOverlay();
362 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
363 taskList.CreateTask();
365 mAdaptor = &adaptorImpl;
366 mAdaptor->AddObserver( *this );
368 // Can only create the detector when we know the Core has been instantiated.
369 mDragAndDropDetector = DragAndDropDetector::New();
370 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
374 mOrientation->SetAdaptor(adaptor);
377 if( mIndicator != NULL )
379 mIndicator->SetAdaptor(mAdaptor);
383 RenderSurface* Window::GetSurface()
388 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
390 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
391 DALI_ASSERT_DEBUG(mOverlay);
393 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
394 DALI_ASSERT_DEBUG(wlSurface);
398 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
400 mIndicatorVisible = visibleMode;
402 if ( mIndicatorVisible == Dali::Window::VISIBLE )
404 // when the indicator is visible, set proper mode for indicator server according to bg mode
405 if ( mIndicatorOpacityMode == Dali::Window::OPAQUE )
407 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
409 else if ( mIndicatorOpacityMode == Dali::Window::TRANSLUCENT )
411 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSLUCENT);
413 else if ( mIndicatorOpacityMode == Dali::Window::TRANSPARENT )
415 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
420 // when the indicator is not visible, set TRANSPARENT mode for indicator server
421 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSPARENT); // it means hidden indicator
425 DoShowIndicator( mIndicatorOrientation );
428 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
430 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
432 DoRotateIndicator( orientation );
435 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
437 mIndicatorOpacityMode = opacityMode;
439 if( mIndicator != NULL )
441 mIndicator->SetOpacityMode( opacityMode );
445 void Window::SetClass(std::string name, std::string klass)
447 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
451 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
452 ecore_wl_window_title_set( wlWindow, name.c_str() );
453 ecore_wl_window_class_name_set( wlWindow, klass.c_str() );
457 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window has no surface\n" );
463 mIndicatorVisible( Dali::Window::VISIBLE ),
464 mIndicatorIsShown( false ),
465 mShowRotatedIndicatorOnClose( false ),
467 mIsTransparent( false ),
468 mWMRotationAppSet( false ),
469 mEcoreEventHander( true ),
470 mIsFocusAcceptable( true ),
472 mOpaqueState( false ),
474 mIndicatorOrientation( Dali::Window::PORTRAIT ),
475 mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
476 mIndicatorOpacityMode( Dali::Window::OPAQUE ),
479 mType( Dali::DevelWindow::NORMAL ),
480 mEventHandler( NULL ),
481 mPreferredOrientation( Dali::Window::PORTRAIT ),
482 mSupportedAuxiliaryHints(),
489 delete mEventHandler;
499 mAdaptor->RemoveObserver( *this );
500 mAdaptor->SetDragAndDropDetector( NULL );
506 mSupportedAuxiliaryHints.clear();
507 mAuxiliaryHints.clear();
510 void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
512 // create an Wayland window by default
514 ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
516 mSurface = windowSurface;
517 SetClass( name, className );
518 windowSurface->Map();
520 mOrientation = Orientation::New(this);
522 // create event handler for Wayland window
523 mEventHandler = new EventHandler( this );
525 // get auxiliary hint
526 Eina_List* hints = ecore_wl_window_aux_hints_supported_get( mEventHandler->mEcoreWindow );
532 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) ) ) )
534 mSupportedAuxiliaryHints.push_back( hint );
536 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::Initialize: %s\n", hint );
541 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
543 if( mIndicator == NULL )
545 if( mIndicatorVisible != Dali::Window::INVISIBLE )
547 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
548 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
549 Dali::Actor actor = mIndicator->GetActor();
550 SetIndicatorActorRotation();
551 mOverlay->Add(actor);
553 // else don't create a hidden indicator
555 else // Already have indicator
557 if( mIndicatorVisible == Dali::Window::VISIBLE )
559 // If we are resuming, and rotation has changed,
560 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
562 // then close current indicator and open new one
563 mShowRotatedIndicatorOnClose = true;
564 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
565 // Don't show actor - will contain indicator for old orientation.
570 // set indicator visible mode
571 if( mIndicator != NULL )
573 mIndicator->SetVisible( mIndicatorVisible );
576 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
577 SetIndicatorProperties( show, lastOrientation );
578 mIndicatorIsShown = show;
581 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
583 if( mIndicatorIsShown )
585 mShowRotatedIndicatorOnClose = true;
586 mNextIndicatorOrientation = orientation;
587 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
591 // Save orientation for when the indicator is next shown
592 mShowRotatedIndicatorOnClose = false;
593 mNextIndicatorOrientation = orientation;
597 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
599 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
603 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
606 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_ON);
610 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_OFF);
615 void Window::IndicatorTypeChanged(Indicator::Type type)
617 #if defined(DALI_PROFILE_MOBILE)
618 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
622 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
625 case Indicator::INDICATOR_TYPE_1:
626 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
629 case Indicator::INDICATOR_TYPE_2:
630 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_HIDDEN);
633 case Indicator::INDICATOR_TYPE_UNKNOWN:
641 void Window::IndicatorClosed( IndicatorInterface* indicator )
643 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
645 if( mShowRotatedIndicatorOnClose )
647 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
648 mIndicator->Open(mNextIndicatorOrientation);
649 mIndicatorOrientation = mNextIndicatorOrientation;
650 SetIndicatorActorRotation();
651 DoShowIndicator(currentOrientation);
655 void Window::IndicatorVisibilityChanged(bool isVisible)
657 mIndicatorVisibilityChangedSignal.Emit(isVisible);
660 void Window::SetIndicatorActorRotation()
662 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
663 DALI_ASSERT_DEBUG( mIndicator != NULL );
665 Dali::Actor actor = mIndicator->GetActor();
666 switch( mIndicatorOrientation )
668 case Dali::Window::PORTRAIT:
669 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
670 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
671 actor.SetOrientation( Degree(0), Vector3::ZAXIS );
673 case Dali::Window::PORTRAIT_INVERSE:
674 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
675 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
676 actor.SetOrientation( Degree(180), Vector3::ZAXIS );
678 case Dali::Window::LANDSCAPE:
679 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
680 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
681 actor.SetOrientation( Degree(270), Vector3::ZAXIS );
683 case Dali::Window::LANDSCAPE_INVERSE:
684 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
685 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
686 actor.SetOrientation( Degree(90), Vector3::ZAXIS );
693 ecore_wl_window_raise( mEventHandler->mEcoreWindow );
698 ecore_wl_window_lower( mEventHandler->mEcoreWindow );
701 void Window::Activate()
703 ecore_wl_window_activate( mEventHandler->mEcoreWindow );
706 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
708 return mDragAndDropDetector;
711 Dali::Any Window::GetNativeHandle() const
715 return mEventHandler->mEcoreWindow;
723 void Window::OnStart()
725 DoShowIndicator( mIndicatorOrientation );
728 void Window::OnPause()
732 void Window::OnResume()
734 // resume indicator status
735 if( mIndicator != NULL )
737 // Restore own indicator opacity
738 // Send opacity mode to indicator service when app resumed
739 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
743 void Window::OnStop()
754 void Window::OnDestroy()
759 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
763 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
765 if(mAvailableOrientations[i] == orientation)
774 mAvailableOrientations.push_back(orientation);
775 SetAvailableOrientations( mAvailableOrientations );
779 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
781 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
782 iter != mAvailableOrientations.end(); ++iter )
784 if( *iter == orientation )
786 mAvailableOrientations.erase( iter );
790 SetAvailableOrientations( mAvailableOrientations );
793 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
796 for( std::size_t i = 0; i < mAvailableOrientations.size(); ++i )
798 rotations[i] = static_cast< int >( mAvailableOrientations[i] );
800 ecore_wl_window_rotation_available_rotations_set( mEventHandler->mEcoreWindow, rotations, mAvailableOrientations.size() );
803 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
805 return mAvailableOrientations;
808 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
810 mPreferredOrientation = orientation;
812 ecore_wl_window_rotation_preferred_rotation_set( mEventHandler->mEcoreWindow, orientation );
815 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
817 return mPreferredOrientation;
820 void Window::SetAcceptFocus( bool accept )
822 mIsFocusAcceptable = accept;
824 ecore_wl_window_focus_skip_set( mEventHandler->mEcoreWindow, !accept );
827 bool Window::IsFocusAcceptable()
829 return mIsFocusAcceptable;
835 ecore_wl_window_show( mEventHandler->mEcoreWindow );
837 // Need an update request
840 mAdaptor->RequestUpdateOnce();
847 ecore_wl_window_hide( mEventHandler->mEcoreWindow );
850 bool Window::IsVisible() const
855 void Window::RotationDone( int orientation, int width, int height )
857 ecore_wl_window_rotation_change_done_send( mEventHandler->mEcoreWindow );
860 unsigned int Window::GetSupportedAuxiliaryHintCount()
862 return mSupportedAuxiliaryHints.size();
865 std::string Window::GetSupportedAuxiliaryHint( unsigned int index )
867 if( index >= GetSupportedAuxiliaryHintCount() )
869 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
872 return mSupportedAuxiliaryHints[index];
875 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
877 bool supported = false;
879 // Check if the hint is suppported
880 for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
891 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
895 // Check if the hint is already added
896 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
898 if( mAuxiliaryHints[i].first == hint )
900 // Just change the value
901 mAuxiliaryHints[i].second = value;
903 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
905 return i + 1; // id is index + 1
910 mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
912 unsigned int id = mAuxiliaryHints.size();
914 ecore_wl_window_aux_hint_add( mEventHandler->mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
916 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
921 bool Window::RemoveAuxiliaryHint( unsigned int id )
923 if( id == 0 || id > mAuxiliaryHints.size() )
925 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
929 mAuxiliaryHints[id - 1].second = std::string();
931 ecore_wl_window_aux_hint_del( mEventHandler->mEcoreWindow, static_cast< int >( id ) );
933 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
938 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
940 if( id == 0 || id > mAuxiliaryHints.size() )
942 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
946 mAuxiliaryHints[id - 1].second = value;
948 ecore_wl_window_aux_hint_change( mEventHandler->mEcoreWindow, static_cast< int >( id ), value.c_str() );
950 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() );
955 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
957 if( id == 0 || id > mAuxiliaryHints.size() )
959 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
960 return std::string();
963 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() );
965 return mAuxiliaryHints[id - 1].second;
968 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
970 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
972 if( mAuxiliaryHints[i].first == hint )
974 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
979 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
984 void Window::SetInputRegion( const Rect< int >& inputRegion )
986 ecore_wl_window_input_region_set( mEventHandler->mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
988 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 );
991 void Window::SetType( Dali::DevelWindow::Type type )
993 Ecore_Wl_Window_Type windowType;
999 case Dali::DevelWindow::NORMAL:
1001 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1004 case Dali::DevelWindow::NOTIFICATION:
1006 windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1009 case Dali::DevelWindow::UTILITY:
1011 windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1014 case Dali::DevelWindow::DIALOG:
1016 windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1021 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1026 ecore_wl_window_type_set( mEventHandler->mEcoreWindow, windowType );
1032 Dali::DevelWindow::Type Window::GetType() const
1037 bool Window::SetNotificationLevel( Dali::DevelWindow::NotificationLevel::Type level )
1039 if( mType != Dali::DevelWindow::NOTIFICATION )
1041 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
1045 while( !mEventHandler->mTizenPolicy )
1047 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1050 int notificationLevel;
1054 case Dali::DevelWindow::NotificationLevel::NONE:
1056 notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1059 case Dali::DevelWindow::NotificationLevel::BASE:
1061 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1064 case Dali::DevelWindow::NotificationLevel::MEDIUM:
1066 notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1069 case Dali::DevelWindow::NotificationLevel::HIGH:
1071 notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1074 case Dali::DevelWindow::NotificationLevel::TOP:
1076 notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1081 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: invalid level [%d]\n", level );
1082 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1087 mEventHandler->mNotificationLevelChangeDone = false;
1088 mEventHandler->mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1090 tizen_policy_set_notification_level( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), notificationLevel );
1094 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1097 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1101 if( !mEventHandler->mNotificationLevelChangeDone )
1103 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mEventHandler->mNotificationChangeState );
1106 else if( mEventHandler->mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1108 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Permission denied! [%d]\n", level );
1112 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level is changed [%d]\n", mEventHandler->mNotificationLevel );
1117 Dali::DevelWindow::NotificationLevel::Type Window::GetNotificationLevel()
1119 if( mType != Dali::DevelWindow::NOTIFICATION )
1121 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
1122 return Dali::DevelWindow::NotificationLevel::NONE;
1125 while( !mEventHandler->mTizenPolicy )
1127 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1132 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1135 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1139 if( !mEventHandler->mNotificationLevelChangeDone )
1141 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Error! [%d]\n", mEventHandler->mNotificationChangeState );
1142 return Dali::DevelWindow::NotificationLevel::NONE;
1145 Dali::DevelWindow::NotificationLevel::Type level;
1147 switch( mEventHandler->mNotificationLevel )
1149 case TIZEN_POLICY_LEVEL_NONE:
1151 level = Dali::DevelWindow::NotificationLevel::NONE;
1154 case TIZEN_POLICY_LEVEL_DEFAULT:
1156 level = Dali::DevelWindow::NotificationLevel::BASE;
1159 case TIZEN_POLICY_LEVEL_MEDIUM:
1161 level = Dali::DevelWindow::NotificationLevel::MEDIUM;
1164 case TIZEN_POLICY_LEVEL_HIGH:
1166 level = Dali::DevelWindow::NotificationLevel::HIGH;
1169 case TIZEN_POLICY_LEVEL_TOP:
1171 level = Dali::DevelWindow::NotificationLevel::TOP;
1176 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: invalid level [%d]\n", mEventHandler->mNotificationLevel );
1177 level = Dali::DevelWindow::NotificationLevel::NONE;
1182 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: level [%d]\n", mEventHandler->mNotificationLevel );
1187 void Window::SetOpaqueState( bool opaque )
1189 while( !mEventHandler->mTizenPolicy )
1191 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1194 tizen_policy_set_opaque_state( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), ( opaque ? 1 : 0 ) );
1196 mOpaqueState = opaque;
1198 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
1201 bool Window::IsOpaqueState()
1203 return mOpaqueState;
1206 bool Window::SetScreenMode( Dali::DevelWindow::ScreenMode::Type screenMode )
1208 while( !mEventHandler->mTizenPolicy )
1210 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1213 mEventHandler->mScreenModeChangeDone = false;
1214 mEventHandler->mScreenModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1216 unsigned int mode = 0;
1218 switch( screenMode )
1220 case Dali::DevelWindow::ScreenMode::DEFAULT:
1225 case Dali::DevelWindow::ScreenMode::ALWAYS_ON:
1232 tizen_policy_set_window_screen_mode( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), mode );
1236 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1239 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1243 if( !mEventHandler->mScreenModeChangeDone )
1245 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode change is failed [%d, %d]\n", screenMode, mEventHandler->mScreenModeChangeState );
1248 else if( mEventHandler->mScreenModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1250 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Permission denied! [%d]\n", screenMode );
1254 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode is changed [%d]\n", mEventHandler->mScreenMode );
1259 Dali::DevelWindow::ScreenMode::Type Window::GetScreenMode()
1261 while( !mEventHandler->mTizenPolicy )
1263 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1268 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1271 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1275 if( !mEventHandler->mScreenModeChangeDone )
1277 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: Error! [%d]\n", mEventHandler->mScreenModeChangeState );
1278 return Dali::DevelWindow::ScreenMode::DEFAULT;
1281 Dali::DevelWindow::ScreenMode::Type screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1283 switch( mEventHandler->mScreenMode )
1287 screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1292 screenMode = Dali::DevelWindow::ScreenMode::ALWAYS_ON;
1297 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: screen mode [%d]\n", mEventHandler->mScreenMode );
1302 bool Window::SetBrightness( int brightness )
1304 if( brightness < 0 || brightness > 100 )
1306 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
1310 while( !mEventHandler->mTizenDisplayPolicy )
1312 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1315 mEventHandler->mBrightnessChangeDone = false;
1316 mEventHandler->mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1318 tizen_display_policy_set_window_brightness( mEventHandler->mTizenDisplayPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), brightness );
1322 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1325 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1329 if( !mEventHandler->mBrightnessChangeDone )
1331 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mEventHandler->mBrightnessChangeState );
1334 else if( mEventHandler->mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1336 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Permission denied! [%d]\n", brightness );
1340 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness is changed [%d]\n", mEventHandler->mBrightness );
1345 int Window::GetBrightness()
1347 while( !mEventHandler->mTizenDisplayPolicy )
1349 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1354 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1357 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1361 if( !mEventHandler->mBrightnessChangeDone )
1363 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Error! [%d]\n", mEventHandler->mBrightnessChangeState );
1367 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Brightness [%d]\n", mEventHandler->mBrightness );
1369 return mEventHandler->mBrightness;
1378 #pragma GCC diagnostic pop