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>
23 #include <Ecore_Wayland.h>
24 #include <tizen-extension-client-protocol.h>
26 #include <dali/integration-api/core.h>
27 #include <dali/integration-api/system-overlay.h>
28 #include <dali/public-api/render-tasks/render-task.h>
29 #include <dali/public-api/render-tasks/render-task-list.h>
30 #include <orientation.h>
33 #include <window-render-surface.h>
34 #include <drag-and-drop-detector-impl.h>
35 #include <ecore-indicator-impl.h>
36 #include <window-visibility-observer.h>
37 #include <orientation-impl.h>
41 const float INDICATOR_ANIMATION_DURATION( 0.18f ); // 180 milli seconds
42 const float INDICATOR_SHOW_Y_POSITION( 0.0f );
43 const float INDICATOR_HIDE_Y_POSITION( -52.0f );
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
58 * TODO: Abstract Window class out and move this into a window implementation for Ecore
60 struct Window::EventHandler
64 * @param[in] window A pointer to the window class.
66 EventHandler( Window* window )
68 mWindowPropertyHandler( NULL ),
69 mWindowIconifyStateHandler( NULL ),
70 mWindowFocusInHandler( NULL ),
71 mWindowFocusOutHandler( NULL ),
76 mTizenDisplayPolicy( NULL ),
77 mNotificationLevel( -1 ),
78 mNotificationChangeState( 0 ),
79 mNotificationLevelChangeDone( true ),
81 mScreenModeChangeState( 0 ),
82 mScreenModeChangeDone( true )
84 // store ecore window handle
85 ECore::WindowRenderSurface* wlWindow( dynamic_cast< ECore::WindowRenderSurface * >( mWindow->mSurface ) );
88 mEcoreWindow = wlWindow->GetWlWindow();
90 DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no ecore Wl window");
92 if( mWindow->mEcoreEventHander )
94 mWindowIconifyStateHandler = ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this );
95 mWindowFocusInHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this );
96 mWindowFocusOutHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this );
99 mDisplay = ecore_wl_display_get();
101 wl_display* displayWrapper = static_cast< wl_display* >( wl_proxy_create_wrapper( mDisplay ) );
104 mEventQueue = wl_display_create_queue( mDisplay );
107 wl_proxy_set_queue( reinterpret_cast< wl_proxy* >( displayWrapper ), mEventQueue );
109 wl_registry* registry = wl_display_get_registry( displayWrapper );
110 wl_registry_add_listener( registry, &mRegistryListener, this );
113 wl_proxy_wrapper_destroy( displayWrapper );
122 if ( mWindowPropertyHandler )
124 ecore_event_handler_del( mWindowPropertyHandler );
126 if ( mWindowIconifyStateHandler )
128 ecore_event_handler_del( mWindowIconifyStateHandler );
130 if( mWindowFocusInHandler )
132 ecore_event_handler_del( mWindowFocusInHandler );
134 if( mWindowFocusOutHandler )
136 ecore_event_handler_del( mWindowFocusOutHandler );
140 wl_event_queue_destroy( mEventQueue );
146 /// Called when the window properties are changed.
147 static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
152 /// Called when the window iconify state is changed.
153 static Eina_Bool EcoreEventWindowIconifyStateChanged( void* data, int type, void* event )
155 Ecore_Wl_Event_Window_Iconify_State_Change* iconifyChangedEvent( static_cast< Ecore_Wl_Event_Window_Iconify_State_Change* >( event ) );
156 EventHandler* handler( static_cast< EventHandler* >( data ) );
157 Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
159 if ( handler && handler->mWindow )
161 WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
162 if ( observer && ( iconifyChangedEvent->win == static_cast< unsigned int> ( ecore_wl_window_id_get( handler->mEcoreWindow ) ) ) )
164 if( iconifyChangedEvent->iconified == EINA_TRUE )
166 observer->OnWindowHidden();
167 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Iconfied\n", handler->mEcoreWindow );
171 observer->OnWindowShown();
172 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Shown\n", handler->mEcoreWindow );
174 handled = ECORE_CALLBACK_DONE;
181 /// Called when the window gains focus
182 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
184 Ecore_Wl_Event_Focus_In* focusInEvent( static_cast< Ecore_Wl_Event_Focus_In* >( event ) );
185 EventHandler* handler( static_cast< EventHandler* >( data ) );
187 if ( handler && handler->mWindow && focusInEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
189 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n" );
191 handler->mWindow->mFocusChangedSignal.Emit( true );
194 return ECORE_CALLBACK_PASS_ON;
197 /// Called when the window loses focus
198 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
200 Ecore_Wl_Event_Focus_Out* focusOutEvent( static_cast< Ecore_Wl_Event_Focus_Out* >( event ) );
201 EventHandler* handler( static_cast< EventHandler* >( data ) );
203 if ( handler && handler->mWindow && focusOutEvent->win == static_cast< unsigned int >(ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
205 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n" );
207 handler->mWindow->mFocusChangedSignal.Emit( false );
210 return ECORE_CALLBACK_PASS_ON;
213 static void RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
215 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
217 if( strcmp( interface, tizen_policy_interface.name ) == 0 )
219 eventHandler->mTizenPolicy = static_cast< tizen_policy* >( wl_registry_bind( registry, name, &tizen_policy_interface, version ) );
220 if( !eventHandler->mTizenPolicy )
222 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n" );
226 tizen_policy_add_listener( eventHandler->mTizenPolicy, &eventHandler->mTizenPolicyListener, data );
228 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_policy_add_listener is called.\n" );
230 else if( strcmp( interface, tizen_display_policy_interface.name ) == 0 )
232 eventHandler->mTizenDisplayPolicy = static_cast< tizen_display_policy* >( wl_registry_bind( registry, name, &tizen_display_policy_interface, version ) );
233 if( !eventHandler->mTizenDisplayPolicy )
235 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n" );
239 tizen_display_policy_add_listener( eventHandler->mTizenDisplayPolicy, &eventHandler->mTizenDisplayPolicyListener, data );
241 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n" );
245 static void RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
247 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
248 eventHandler->mTizenPolicy = NULL;
249 eventHandler->mTizenDisplayPolicy = NULL;
252 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
254 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
256 eventHandler->mNotificationLevel = level;
257 eventHandler->mNotificationChangeState = state;
258 eventHandler->mNotificationLevelChangeDone = true;
260 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state );
263 static void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
265 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
267 eventHandler->mScreenMode = mode;
268 eventHandler->mScreenModeChangeState = state;
269 eventHandler->mScreenModeChangeDone = true;
271 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state );
274 static void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
276 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
278 eventHandler->mBrightness = brightness;
279 eventHandler->mBrightnessChangeState = state;
280 eventHandler->mBrightnessChangeDone = true;
282 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state );
285 const struct wl_registry_listener mRegistryListener =
287 RegistryGlobalCallback,
288 RegistryGlobalCallbackRemove
291 const struct tizen_policy_listener mTizenPolicyListener =
295 TizenPolicyNotificationChangeDone,
297 TizenPolicyScreenModeChangeDone,
304 const struct tizen_display_policy_listener mTizenDisplayPolicyListener =
306 DisplayPolicyBrightnessChangeDone
311 Ecore_Event_Handler* mWindowPropertyHandler;
312 Ecore_Event_Handler* mWindowIconifyStateHandler;
313 Ecore_Event_Handler* mWindowFocusInHandler;
314 Ecore_Event_Handler* mWindowFocusOutHandler;
315 Ecore_Wl_Window* mEcoreWindow;
317 wl_display* mDisplay;
318 wl_event_queue* mEventQueue;
319 tizen_policy* mTizenPolicy;
320 tizen_display_policy* mTizenDisplayPolicy;
322 int mNotificationLevel;
323 uint32_t mNotificationChangeState;
324 bool mNotificationLevelChangeDone;
327 uint32_t mScreenModeChangeState;
328 bool mScreenModeChangeDone;
331 uint32_t mBrightnessChangeState;
332 bool mBrightnessChangeDone;
335 Window* Window::New(const PositionSize& posSize, const std::string& name, const std::string& className, bool isTransparent)
337 Window* window = new Window();
338 window->mIsTransparent = isTransparent;
339 window->Initialize(posSize, name, className);
343 void Window::SetAdaptor(Dali::Adaptor& adaptor)
345 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
348 // Only create one overlay per window
349 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
350 Integration::Core& core = adaptorImpl.GetCore();
351 mOverlay = &core.GetSystemOverlay();
353 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
354 taskList.CreateTask();
356 mAdaptor = &adaptorImpl;
357 mAdaptor->AddObserver( *this );
359 // Can only create the detector when we know the Core has been instantiated.
360 mDragAndDropDetector = DragAndDropDetector::New();
361 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
365 mOrientation->SetAdaptor(adaptor);
368 if( mIndicator != NULL )
370 mIndicator->SetAdaptor(mAdaptor);
374 RenderSurface* Window::GetSurface()
379 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
381 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
382 DALI_ASSERT_DEBUG(mOverlay);
384 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
385 DALI_ASSERT_DEBUG(wlSurface);
389 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
391 mIndicatorVisible = visibleMode;
393 if ( mIndicatorVisible == Dali::Window::VISIBLE )
395 // when the indicator is visible, set proper mode for indicator server according to bg mode
396 if ( mIndicatorOpacityMode == Dali::Window::OPAQUE )
398 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
400 else if ( mIndicatorOpacityMode == Dali::Window::TRANSLUCENT )
402 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSLUCENT);
404 else if ( mIndicatorOpacityMode == Dali::Window::TRANSPARENT )
406 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
411 // when the indicator is not visible, set TRANSPARENT mode for indicator server
412 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSPARENT); // it means hidden indicator
416 DoShowIndicator( mIndicatorOrientation );
419 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
421 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
423 DoRotateIndicator( orientation );
426 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
428 mIndicatorOpacityMode = opacityMode;
430 if( mIndicator != NULL )
432 mIndicator->SetOpacityMode( opacityMode );
436 void Window::SetClass(std::string name, std::string klass)
438 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
442 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
443 ecore_wl_window_title_set( wlWindow, name.c_str() );
444 ecore_wl_window_class_name_set( wlWindow, klass.c_str() );
448 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window has no surface\n" );
454 mIndicatorVisible( Dali::Window::VISIBLE ),
455 mIndicatorIsShown( false ),
456 mShowRotatedIndicatorOnClose( false ),
458 mIsTransparent( false ),
459 mWMRotationAppSet( false ),
460 mEcoreEventHander( true ),
461 mIsFocusAcceptable( true ),
463 mOpaqueState( false ),
465 mIndicatorOrientation( Dali::Window::PORTRAIT ),
466 mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
467 mIndicatorOpacityMode( Dali::Window::OPAQUE ),
470 mType( Dali::DevelWindow::NORMAL ),
471 mEventHandler( NULL ),
472 mPreferredOrientation( Dali::Window::PORTRAIT ),
473 mSupportedAuxiliaryHints(),
480 delete mEventHandler;
490 mAdaptor->RemoveObserver( *this );
491 mAdaptor->SetDragAndDropDetector( NULL );
497 mSupportedAuxiliaryHints.clear();
498 mAuxiliaryHints.clear();
501 void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
503 // create an Wayland window by default
505 ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
507 mSurface = windowSurface;
508 SetClass( name, className );
509 windowSurface->Map();
511 mOrientation = Orientation::New(this);
513 // create event handler for Wayland window
514 mEventHandler = new EventHandler( this );
516 // get auxiliary hint
517 Eina_List* hints = ecore_wl_window_aux_hints_supported_get( mEventHandler->mEcoreWindow );
523 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) ) ) )
525 mSupportedAuxiliaryHints.push_back( hint );
527 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::Initialize: %s\n", hint );
532 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
534 if( mIndicator == NULL )
536 if( mIndicatorVisible != Dali::Window::INVISIBLE )
538 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
539 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
540 Dali::Actor actor = mIndicator->GetActor();
541 SetIndicatorActorRotation();
542 mOverlay->Add(actor);
544 // else don't create a hidden indicator
546 else // Already have indicator
548 if( mIndicatorVisible == Dali::Window::VISIBLE )
550 // If we are resuming, and rotation has changed,
551 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
553 // then close current indicator and open new one
554 mShowRotatedIndicatorOnClose = true;
555 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
556 // Don't show actor - will contain indicator for old orientation.
561 // set indicator visible mode
562 if( mIndicator != NULL )
564 mIndicator->SetVisible( mIndicatorVisible );
567 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
568 SetIndicatorProperties( show, lastOrientation );
569 mIndicatorIsShown = show;
572 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
574 if( mIndicatorIsShown )
576 mShowRotatedIndicatorOnClose = true;
577 mNextIndicatorOrientation = orientation;
578 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
582 // Save orientation for when the indicator is next shown
583 mShowRotatedIndicatorOnClose = false;
584 mNextIndicatorOrientation = orientation;
588 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
590 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
594 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
597 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_ON);
601 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_OFF);
606 void Window::IndicatorTypeChanged(Indicator::Type type)
608 #if defined(DALI_PROFILE_MOBILE)
609 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
613 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
616 case Indicator::INDICATOR_TYPE_1:
617 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
620 case Indicator::INDICATOR_TYPE_2:
621 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_HIDDEN);
624 case Indicator::INDICATOR_TYPE_UNKNOWN:
632 void Window::IndicatorClosed( IndicatorInterface* indicator )
634 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
636 if( mShowRotatedIndicatorOnClose )
638 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
639 mIndicator->Open(mNextIndicatorOrientation);
640 mIndicatorOrientation = mNextIndicatorOrientation;
641 SetIndicatorActorRotation();
642 DoShowIndicator(currentOrientation);
646 void Window::IndicatorVisibilityChanged(bool isVisible)
648 mIndicatorVisibilityChangedSignal.Emit(isVisible);
651 void Window::SetIndicatorActorRotation()
653 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
654 DALI_ASSERT_DEBUG( mIndicator != NULL );
656 Dali::Actor actor = mIndicator->GetActor();
657 switch( mIndicatorOrientation )
659 case Dali::Window::PORTRAIT:
660 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
661 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
662 actor.SetOrientation( Degree(0), Vector3::ZAXIS );
664 case Dali::Window::PORTRAIT_INVERSE:
665 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
666 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
667 actor.SetOrientation( Degree(180), Vector3::ZAXIS );
669 case Dali::Window::LANDSCAPE:
670 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
671 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
672 actor.SetOrientation( Degree(270), Vector3::ZAXIS );
674 case Dali::Window::LANDSCAPE_INVERSE:
675 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
676 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
677 actor.SetOrientation( Degree(90), Vector3::ZAXIS );
684 ecore_wl_window_raise( mEventHandler->mEcoreWindow );
689 ecore_wl_window_lower( mEventHandler->mEcoreWindow );
692 void Window::Activate()
694 ecore_wl_window_activate( mEventHandler->mEcoreWindow );
697 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
699 return mDragAndDropDetector;
702 Dali::Any Window::GetNativeHandle() const
706 return mEventHandler->mEcoreWindow;
714 void Window::OnStart()
716 DoShowIndicator( mIndicatorOrientation );
719 void Window::OnPause()
723 void Window::OnResume()
725 // resume indicator status
726 if( mIndicator != NULL )
728 // Restore own indicator opacity
729 // Send opacity mode to indicator service when app resumed
730 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
734 void Window::OnStop()
745 void Window::OnDestroy()
750 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
754 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
756 if(mAvailableOrientations[i] == orientation)
765 mAvailableOrientations.push_back(orientation);
766 SetAvailableOrientations( mAvailableOrientations );
770 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
772 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
773 iter != mAvailableOrientations.end(); ++iter )
775 if( *iter == orientation )
777 mAvailableOrientations.erase( iter );
781 SetAvailableOrientations( mAvailableOrientations );
784 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
787 for( std::size_t i = 0; i < mAvailableOrientations.size(); ++i )
789 rotations[i] = static_cast< int >( mAvailableOrientations[i] );
791 ecore_wl_window_rotation_available_rotations_set( mEventHandler->mEcoreWindow, rotations, mAvailableOrientations.size() );
794 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
796 return mAvailableOrientations;
799 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
801 mPreferredOrientation = orientation;
803 ecore_wl_window_rotation_preferred_rotation_set( mEventHandler->mEcoreWindow, orientation );
806 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
808 return mPreferredOrientation;
811 void Window::SetAcceptFocus( bool accept )
813 mIsFocusAcceptable = accept;
815 ecore_wl_window_focus_skip_set( mEventHandler->mEcoreWindow, !accept );
818 bool Window::IsFocusAcceptable()
820 return mIsFocusAcceptable;
826 ecore_wl_window_show( mEventHandler->mEcoreWindow );
828 // Need an update request
831 mAdaptor->RequestUpdateOnce();
838 ecore_wl_window_hide( mEventHandler->mEcoreWindow );
841 bool Window::IsVisible() const
846 void Window::RotationDone( int orientation, int width, int height )
848 ecore_wl_window_rotation_change_done_send( mEventHandler->mEcoreWindow );
851 unsigned int Window::GetSupportedAuxiliaryHintCount()
853 return mSupportedAuxiliaryHints.size();
856 std::string Window::GetSupportedAuxiliaryHint( unsigned int index )
858 if( index >= GetSupportedAuxiliaryHintCount() )
860 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
863 return mSupportedAuxiliaryHints[index];
866 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
868 bool supported = false;
870 // Check if the hint is suppported
871 for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
882 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
886 // Check if the hint is already added
887 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
889 if( mAuxiliaryHints[i].first == hint )
891 // Just change the value
892 mAuxiliaryHints[i].second = value;
894 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
896 return i + 1; // id is index + 1
901 mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
903 unsigned int id = mAuxiliaryHints.size();
905 ecore_wl_window_aux_hint_add( mEventHandler->mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
907 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
912 bool Window::RemoveAuxiliaryHint( unsigned int id )
914 if( id == 0 || id > mAuxiliaryHints.size() )
916 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
920 mAuxiliaryHints[id - 1].second = std::string();
922 ecore_wl_window_aux_hint_del( mEventHandler->mEcoreWindow, static_cast< int >( id ) );
924 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
929 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
931 if( id == 0 || id > mAuxiliaryHints.size() )
933 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
937 mAuxiliaryHints[id - 1].second = value;
939 ecore_wl_window_aux_hint_change( mEventHandler->mEcoreWindow, static_cast< int >( id ), value.c_str() );
941 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() );
946 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
948 if( id == 0 || id > mAuxiliaryHints.size() )
950 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
951 return std::string();
954 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() );
956 return mAuxiliaryHints[id - 1].second;
959 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
961 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
963 if( mAuxiliaryHints[i].first == hint )
965 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
970 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
975 void Window::SetInputRegion( const Rect< int >& inputRegion )
977 ecore_wl_window_input_region_set( mEventHandler->mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
979 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 );
982 void Window::SetType( Dali::DevelWindow::Type type )
984 Ecore_Wl_Window_Type windowType;
990 case Dali::DevelWindow::NORMAL:
992 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
995 case Dali::DevelWindow::NOTIFICATION:
997 windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1000 case Dali::DevelWindow::UTILITY:
1002 windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1005 case Dali::DevelWindow::DIALOG:
1007 windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1012 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1017 ecore_wl_window_type_set( mEventHandler->mEcoreWindow, windowType );
1023 Dali::DevelWindow::Type Window::GetType() const
1028 bool Window::SetNotificationLevel( Dali::DevelWindow::NotificationLevel::Type level )
1030 if( mType != Dali::DevelWindow::NOTIFICATION )
1032 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
1036 while( !mEventHandler->mTizenPolicy )
1038 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1041 int notificationLevel;
1045 case Dali::DevelWindow::NotificationLevel::NONE:
1047 notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1050 case Dali::DevelWindow::NotificationLevel::BASE:
1052 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1055 case Dali::DevelWindow::NotificationLevel::MEDIUM:
1057 notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1060 case Dali::DevelWindow::NotificationLevel::HIGH:
1062 notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1065 case Dali::DevelWindow::NotificationLevel::TOP:
1067 notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1072 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: invalid level [%d]\n", level );
1073 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1078 mEventHandler->mNotificationLevelChangeDone = false;
1079 mEventHandler->mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1081 tizen_policy_set_notification_level( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), notificationLevel );
1085 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1088 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1092 if( !mEventHandler->mNotificationLevelChangeDone )
1094 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mEventHandler->mNotificationChangeState );
1097 else if( mEventHandler->mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1099 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Permission denied! [%d]\n", level );
1103 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level is changed [%d]\n", mEventHandler->mNotificationLevel );
1108 Dali::DevelWindow::NotificationLevel::Type Window::GetNotificationLevel()
1110 if( mType != Dali::DevelWindow::NOTIFICATION )
1112 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
1113 return Dali::DevelWindow::NotificationLevel::NONE;
1116 while( !mEventHandler->mTizenPolicy )
1118 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1123 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1126 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1130 if( !mEventHandler->mNotificationLevelChangeDone )
1132 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Error! [%d]\n", mEventHandler->mNotificationChangeState );
1133 return Dali::DevelWindow::NotificationLevel::NONE;
1136 Dali::DevelWindow::NotificationLevel::Type level;
1138 switch( mEventHandler->mNotificationLevel )
1140 case TIZEN_POLICY_LEVEL_NONE:
1142 level = Dali::DevelWindow::NotificationLevel::NONE;
1145 case TIZEN_POLICY_LEVEL_DEFAULT:
1147 level = Dali::DevelWindow::NotificationLevel::BASE;
1150 case TIZEN_POLICY_LEVEL_MEDIUM:
1152 level = Dali::DevelWindow::NotificationLevel::MEDIUM;
1155 case TIZEN_POLICY_LEVEL_HIGH:
1157 level = Dali::DevelWindow::NotificationLevel::HIGH;
1160 case TIZEN_POLICY_LEVEL_TOP:
1162 level = Dali::DevelWindow::NotificationLevel::TOP;
1167 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: invalid level [%d]\n", mEventHandler->mNotificationLevel );
1168 level = Dali::DevelWindow::NotificationLevel::NONE;
1173 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: level [%d]\n", mEventHandler->mNotificationLevel );
1178 void Window::SetOpaqueState( bool opaque )
1180 while( !mEventHandler->mTizenPolicy )
1182 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1185 tizen_policy_set_opaque_state( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), ( opaque ? 1 : 0 ) );
1187 mOpaqueState = opaque;
1189 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
1192 bool Window::IsOpaqueState()
1194 return mOpaqueState;
1197 bool Window::SetScreenMode( Dali::DevelWindow::ScreenMode::Type screenMode )
1199 while( !mEventHandler->mTizenPolicy )
1201 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1204 mEventHandler->mScreenModeChangeDone = false;
1205 mEventHandler->mScreenModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1207 unsigned int mode = 0;
1209 switch( screenMode )
1211 case Dali::DevelWindow::ScreenMode::DEFAULT:
1216 case Dali::DevelWindow::ScreenMode::ALWAYS_ON:
1223 tizen_policy_set_window_screen_mode( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), mode );
1227 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1230 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1234 if( !mEventHandler->mScreenModeChangeDone )
1236 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode change is failed [%d, %d]\n", screenMode, mEventHandler->mScreenModeChangeState );
1239 else if( mEventHandler->mScreenModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1241 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Permission denied! [%d]\n", screenMode );
1245 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode is changed [%d]\n", mEventHandler->mScreenMode );
1250 Dali::DevelWindow::ScreenMode::Type Window::GetScreenMode()
1252 while( !mEventHandler->mTizenPolicy )
1254 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1259 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1262 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1266 if( !mEventHandler->mScreenModeChangeDone )
1268 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: Error! [%d]\n", mEventHandler->mScreenModeChangeState );
1269 return Dali::DevelWindow::ScreenMode::DEFAULT;
1272 Dali::DevelWindow::ScreenMode::Type screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1274 switch( mEventHandler->mScreenMode )
1278 screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1283 screenMode = Dali::DevelWindow::ScreenMode::ALWAYS_ON;
1288 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: screen mode [%d]\n", mEventHandler->mScreenMode );
1293 bool Window::SetBrightness( int brightness )
1295 if( brightness < 0 || brightness > 100 )
1297 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
1301 while( !mEventHandler->mTizenDisplayPolicy )
1303 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1306 mEventHandler->mBrightnessChangeDone = false;
1307 mEventHandler->mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1309 tizen_display_policy_set_window_brightness( mEventHandler->mTizenDisplayPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), brightness );
1313 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1316 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1320 if( !mEventHandler->mBrightnessChangeDone )
1322 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mEventHandler->mBrightnessChangeState );
1325 else if( mEventHandler->mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1327 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Permission denied! [%d]\n", brightness );
1331 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness is changed [%d]\n", mEventHandler->mBrightness );
1336 int Window::GetBrightness()
1338 while( !mEventHandler->mTizenDisplayPolicy )
1340 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1345 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1348 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1352 if( !mEventHandler->mBrightnessChangeDone )
1354 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Error! [%d]\n", mEventHandler->mBrightnessChangeState );
1358 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Brightness [%d]\n", mEventHandler->mBrightness );
1360 return mEventHandler->mBrightness;