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 mWindowVisibilityStateHandler( NULL ),
74 mWindowFocusInHandler( NULL ),
75 mWindowFocusOutHandler( NULL ),
80 mTizenDisplayPolicy( NULL ),
81 mNotificationLevel( -1 ),
82 mNotificationChangeState( 0 ),
83 mNotificationLevelChangeDone( true ),
85 mScreenModeChangeState( 0 ),
86 mScreenModeChangeDone( true ),
88 mBrightnessChangeState( 0 ),
89 mBrightnessChangeDone( true )
91 // store ecore window handle
92 ECore::WindowRenderSurface* wlWindow( dynamic_cast< ECore::WindowRenderSurface * >( mWindow->mSurface ) );
95 mEcoreWindow = wlWindow->GetWlWindow();
97 DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no ecore Wl window");
99 if( mWindow->mEcoreEventHander )
101 mWindowIconifyStateHandler = ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this );
102 mWindowVisibilityStateHandler = ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE, EcoreEventWindowVisibilityChanged, this );
103 mWindowFocusInHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this );
104 mWindowFocusOutHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this );
107 mDisplay = ecore_wl_display_get();
111 wl_display* displayWrapper = static_cast< wl_display* >( wl_proxy_create_wrapper( mDisplay ) );
114 mEventQueue = wl_display_create_queue( mDisplay );
117 wl_proxy_set_queue( reinterpret_cast< wl_proxy* >( displayWrapper ), mEventQueue );
119 wl_registry* registry = wl_display_get_registry( displayWrapper );
120 wl_registry_add_listener( registry, &mRegistryListener, this );
123 wl_proxy_wrapper_destroy( displayWrapper );
133 if ( mWindowPropertyHandler )
135 ecore_event_handler_del( mWindowPropertyHandler );
138 if ( mWindowIconifyStateHandler )
140 ecore_event_handler_del( mWindowIconifyStateHandler );
143 if ( mWindowVisibilityStateHandler )
145 ecore_event_handler_del( mWindowVisibilityStateHandler );
148 if( mWindowFocusInHandler )
150 ecore_event_handler_del( mWindowFocusInHandler );
153 if( mWindowFocusOutHandler )
155 ecore_event_handler_del( mWindowFocusOutHandler );
160 wl_event_queue_destroy( mEventQueue );
166 /// Called when the window properties are changed.
167 static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
172 /// Called when the window iconify state is changed.
173 static Eina_Bool EcoreEventWindowIconifyStateChanged( void* data, int type, void* event )
175 Ecore_Wl_Event_Window_Iconify_State_Change* iconifyChangedEvent( static_cast< Ecore_Wl_Event_Window_Iconify_State_Change* >( event ) );
176 EventHandler* handler( static_cast< EventHandler* >( data ) );
177 Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
179 if ( handler && handler->mWindow )
181 WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
182 if ( observer && ( iconifyChangedEvent->win == static_cast< unsigned int> ( ecore_wl_window_id_get( handler->mEcoreWindow ) ) ) )
184 if( iconifyChangedEvent->iconified == EINA_TRUE )
186 observer->OnWindowHidden();
187 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Iconfied\n", handler->mEcoreWindow );
191 observer->OnWindowShown();
192 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Shown\n", handler->mEcoreWindow );
194 handled = ECORE_CALLBACK_DONE;
201 /// Called when the window visibility is changed.
202 static Eina_Bool EcoreEventWindowVisibilityChanged( void* data, int type, void* event )
204 Ecore_Wl_Event_Window_Visibility_Change* visibilityChangedEvent( static_cast< Ecore_Wl_Event_Window_Visibility_Change* >( event ) );
205 EventHandler* handler( static_cast< EventHandler* >( data ) );
206 Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
208 if ( handler && handler->mWindow )
210 WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
211 if ( observer && ( visibilityChangedEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( handler->mEcoreWindow ) ) ) )
213 if( visibilityChangedEvent->fully_obscured == 1 )
215 observer->OnWindowHidden();
216 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) full obscured\n", handler->mEcoreWindow );
220 observer->OnWindowShown();
221 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Shown\n", handler->mEcoreWindow );
223 handled = ECORE_CALLBACK_DONE;
230 /// Called when the window gains focus
231 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
233 Ecore_Wl_Event_Focus_In* focusInEvent( static_cast< Ecore_Wl_Event_Focus_In* >( event ) );
234 EventHandler* handler( static_cast< EventHandler* >( data ) );
236 if ( handler && handler->mWindow && focusInEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
238 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n" );
240 handler->mWindow->mFocusChangedSignal.Emit( true );
243 return ECORE_CALLBACK_PASS_ON;
246 /// Called when the window loses focus
247 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
249 Ecore_Wl_Event_Focus_Out* focusOutEvent( static_cast< Ecore_Wl_Event_Focus_Out* >( event ) );
250 EventHandler* handler( static_cast< EventHandler* >( data ) );
252 if ( handler && handler->mWindow && focusOutEvent->win == static_cast< unsigned int >(ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
254 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n" );
256 handler->mWindow->mFocusChangedSignal.Emit( false );
259 return ECORE_CALLBACK_PASS_ON;
262 static void RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
264 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
266 if( strcmp( interface, tizen_policy_interface.name ) == 0 )
268 eventHandler->mTizenPolicy = static_cast< tizen_policy* >( wl_registry_bind( registry, name, &tizen_policy_interface, version ) );
269 if( !eventHandler->mTizenPolicy )
271 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n" );
275 tizen_policy_add_listener( eventHandler->mTizenPolicy, &eventHandler->mTizenPolicyListener, data );
277 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_policy_add_listener is called.\n" );
279 else if( strcmp( interface, tizen_display_policy_interface.name ) == 0 )
281 eventHandler->mTizenDisplayPolicy = static_cast< tizen_display_policy* >( wl_registry_bind( registry, name, &tizen_display_policy_interface, version ) );
282 if( !eventHandler->mTizenDisplayPolicy )
284 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n" );
288 tizen_display_policy_add_listener( eventHandler->mTizenDisplayPolicy, &eventHandler->mTizenDisplayPolicyListener, data );
290 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n" );
294 static void RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
296 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
297 eventHandler->mTizenPolicy = NULL;
298 eventHandler->mTizenDisplayPolicy = NULL;
301 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
303 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
305 eventHandler->mNotificationLevel = level;
306 eventHandler->mNotificationChangeState = state;
307 eventHandler->mNotificationLevelChangeDone = true;
309 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state );
312 static void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
314 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
316 eventHandler->mScreenMode = mode;
317 eventHandler->mScreenModeChangeState = state;
318 eventHandler->mScreenModeChangeDone = true;
320 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state );
323 static void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
325 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
327 eventHandler->mBrightness = brightness;
328 eventHandler->mBrightnessChangeState = state;
329 eventHandler->mBrightnessChangeDone = true;
331 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state );
334 const struct wl_registry_listener mRegistryListener =
336 RegistryGlobalCallback,
337 RegistryGlobalCallbackRemove
340 const struct tizen_policy_listener mTizenPolicyListener =
344 TizenPolicyNotificationChangeDone,
346 TizenPolicyScreenModeChangeDone,
353 const struct tizen_display_policy_listener mTizenDisplayPolicyListener =
355 DisplayPolicyBrightnessChangeDone
360 Ecore_Event_Handler* mWindowPropertyHandler;
361 Ecore_Event_Handler* mWindowIconifyStateHandler;
362 Ecore_Event_Handler* mWindowVisibilityStateHandler;
363 Ecore_Event_Handler* mWindowFocusInHandler;
364 Ecore_Event_Handler* mWindowFocusOutHandler;
365 Ecore_Wl_Window* mEcoreWindow;
367 wl_display* mDisplay;
368 wl_event_queue* mEventQueue;
369 tizen_policy* mTizenPolicy;
370 tizen_display_policy* mTizenDisplayPolicy;
372 int mNotificationLevel;
373 uint32_t mNotificationChangeState;
374 bool mNotificationLevelChangeDone;
377 uint32_t mScreenModeChangeState;
378 bool mScreenModeChangeDone;
381 uint32_t mBrightnessChangeState;
382 bool mBrightnessChangeDone;
385 Window* Window::New(const PositionSize& posSize, const std::string& name, const std::string& className, bool isTransparent)
387 Window* window = new Window();
388 window->mIsTransparent = isTransparent;
389 window->Initialize(posSize, name, className);
393 void Window::SetAdaptor(Dali::Adaptor& adaptor)
395 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
398 // Only create one overlay per window
399 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
400 Integration::Core& core = adaptorImpl.GetCore();
401 mOverlay = &core.GetSystemOverlay();
403 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
404 taskList.CreateTask();
406 mAdaptor = &adaptorImpl;
407 mAdaptor->AddObserver( *this );
409 // Can only create the detector when we know the Core has been instantiated.
410 mDragAndDropDetector = DragAndDropDetector::New();
411 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
415 mOrientation->SetAdaptor(adaptor);
418 if( mIndicator != NULL )
420 mIndicator->SetAdaptor(mAdaptor);
424 RenderSurface* Window::GetSurface()
429 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
431 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
432 DALI_ASSERT_DEBUG(mOverlay);
434 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
435 DALI_ASSERT_DEBUG(wlSurface);
439 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
441 mIndicatorVisible = visibleMode;
443 if ( mIndicatorVisible == Dali::Window::VISIBLE )
445 // when the indicator is visible, set proper mode for indicator server according to bg mode
446 if ( mIndicatorOpacityMode == Dali::Window::OPAQUE )
448 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
450 else if ( mIndicatorOpacityMode == Dali::Window::TRANSLUCENT )
452 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSLUCENT);
454 else if ( mIndicatorOpacityMode == Dali::Window::TRANSPARENT )
456 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
461 // when the indicator is not visible, set TRANSPARENT mode for indicator server
462 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSPARENT); // it means hidden indicator
466 DoShowIndicator( mIndicatorOrientation );
469 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
471 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
473 DoRotateIndicator( orientation );
476 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
478 mIndicatorOpacityMode = opacityMode;
480 if( mIndicator != NULL )
482 mIndicator->SetOpacityMode( opacityMode );
486 void Window::SetClass(std::string name, std::string klass)
488 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
492 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
493 ecore_wl_window_title_set( wlWindow, name.c_str() );
494 ecore_wl_window_class_name_set( wlWindow, klass.c_str() );
498 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window has no surface\n" );
504 mIndicatorVisible( Dali::Window::VISIBLE ),
505 mIndicatorIsShown( false ),
506 mShowRotatedIndicatorOnClose( false ),
508 mIsTransparent( false ),
509 mWMRotationAppSet( false ),
510 mEcoreEventHander( true ),
511 mIsFocusAcceptable( true ),
513 mOpaqueState( false ),
515 mIndicatorOrientation( Dali::Window::PORTRAIT ),
516 mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
517 mIndicatorOpacityMode( Dali::Window::OPAQUE ),
520 mType( Dali::DevelWindow::NORMAL ),
521 mEventHandler( NULL ),
522 mPreferredOrientation( Dali::Window::PORTRAIT ),
523 mSupportedAuxiliaryHints(),
530 delete mEventHandler;
540 mAdaptor->RemoveObserver( *this );
541 mAdaptor->SetDragAndDropDetector( NULL );
547 mSupportedAuxiliaryHints.clear();
548 mAuxiliaryHints.clear();
551 void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
553 // create an Wayland window by default
555 ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
557 mSurface = windowSurface;
558 SetClass( name, className );
559 windowSurface->Map();
561 mOrientation = Orientation::New(this);
563 // create event handler for Wayland window
564 mEventHandler = new EventHandler( this );
566 // get auxiliary hint
567 Eina_List* hints = ecore_wl_window_aux_hints_supported_get( mEventHandler->mEcoreWindow );
573 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) ) ) )
575 mSupportedAuxiliaryHints.push_back( hint );
577 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::Initialize: %s\n", hint );
582 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
584 if( mIndicator == NULL )
586 if( mIndicatorVisible != Dali::Window::INVISIBLE )
588 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
589 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
590 Dali::Actor actor = mIndicator->GetActor();
591 SetIndicatorActorRotation();
592 mOverlay->Add(actor);
594 // else don't create a hidden indicator
596 else // Already have indicator
598 if( mIndicatorVisible == Dali::Window::VISIBLE )
600 // If we are resuming, and rotation has changed,
601 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
603 // then close current indicator and open new one
604 mShowRotatedIndicatorOnClose = true;
605 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
606 // Don't show actor - will contain indicator for old orientation.
611 // set indicator visible mode
612 if( mIndicator != NULL )
614 mIndicator->SetVisible( mIndicatorVisible );
617 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
618 SetIndicatorProperties( show, lastOrientation );
619 mIndicatorIsShown = show;
622 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
624 if( mIndicatorIsShown )
626 mShowRotatedIndicatorOnClose = true;
627 mNextIndicatorOrientation = orientation;
628 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
632 // Save orientation for when the indicator is next shown
633 mShowRotatedIndicatorOnClose = false;
634 mNextIndicatorOrientation = orientation;
638 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
640 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
644 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
647 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_ON);
651 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_OFF);
656 void Window::IndicatorTypeChanged(Indicator::Type type)
658 #if defined(DALI_PROFILE_MOBILE)
659 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
663 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
666 case Indicator::INDICATOR_TYPE_1:
667 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
670 case Indicator::INDICATOR_TYPE_2:
671 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_HIDDEN);
674 case Indicator::INDICATOR_TYPE_UNKNOWN:
682 void Window::IndicatorClosed( IndicatorInterface* indicator )
684 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
686 if( mShowRotatedIndicatorOnClose )
688 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
689 mIndicator->Open(mNextIndicatorOrientation);
690 mIndicatorOrientation = mNextIndicatorOrientation;
691 SetIndicatorActorRotation();
692 DoShowIndicator(currentOrientation);
696 void Window::IndicatorVisibilityChanged(bool isVisible)
698 mIndicatorVisibilityChangedSignal.Emit(isVisible);
701 void Window::SetIndicatorActorRotation()
703 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
704 DALI_ASSERT_DEBUG( mIndicator != NULL );
706 Dali::Actor actor = mIndicator->GetActor();
707 switch( mIndicatorOrientation )
709 case Dali::Window::PORTRAIT:
710 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
711 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
712 actor.SetOrientation( Degree(0), Vector3::ZAXIS );
714 case Dali::Window::PORTRAIT_INVERSE:
715 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
716 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
717 actor.SetOrientation( Degree(180), Vector3::ZAXIS );
719 case Dali::Window::LANDSCAPE:
720 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
721 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
722 actor.SetOrientation( Degree(270), Vector3::ZAXIS );
724 case Dali::Window::LANDSCAPE_INVERSE:
725 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
726 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
727 actor.SetOrientation( Degree(90), Vector3::ZAXIS );
734 ecore_wl_window_raise( mEventHandler->mEcoreWindow );
739 ecore_wl_window_lower( mEventHandler->mEcoreWindow );
742 void Window::Activate()
744 ecore_wl_window_activate( mEventHandler->mEcoreWindow );
747 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
749 return mDragAndDropDetector;
752 Dali::Any Window::GetNativeHandle() const
756 return mEventHandler->mEcoreWindow;
764 void Window::OnStart()
766 DoShowIndicator( mIndicatorOrientation );
769 void Window::OnPause()
773 void Window::OnResume()
775 // resume indicator status
776 if( mIndicator != NULL )
778 // Restore own indicator opacity
779 // Send opacity mode to indicator service when app resumed
780 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
784 void Window::OnStop()
795 void Window::OnDestroy()
800 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
804 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
806 if(mAvailableOrientations[i] == orientation)
815 mAvailableOrientations.push_back(orientation);
816 SetAvailableOrientations( mAvailableOrientations );
820 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
822 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
823 iter != mAvailableOrientations.end(); ++iter )
825 if( *iter == orientation )
827 mAvailableOrientations.erase( iter );
831 SetAvailableOrientations( mAvailableOrientations );
834 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
837 for( std::size_t i = 0; i < mAvailableOrientations.size(); ++i )
839 rotations[i] = static_cast< int >( mAvailableOrientations[i] );
841 ecore_wl_window_rotation_available_rotations_set( mEventHandler->mEcoreWindow, rotations, mAvailableOrientations.size() );
844 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
846 return mAvailableOrientations;
849 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
851 mPreferredOrientation = orientation;
853 ecore_wl_window_rotation_preferred_rotation_set( mEventHandler->mEcoreWindow, orientation );
856 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
858 return mPreferredOrientation;
861 void Window::SetAcceptFocus( bool accept )
863 mIsFocusAcceptable = accept;
865 ecore_wl_window_focus_skip_set( mEventHandler->mEcoreWindow, !accept );
868 bool Window::IsFocusAcceptable()
870 return mIsFocusAcceptable;
876 ecore_wl_window_show( mEventHandler->mEcoreWindow );
878 // Need an update request
881 mAdaptor->RequestUpdateOnce();
888 ecore_wl_window_hide( mEventHandler->mEcoreWindow );
891 bool Window::IsVisible() const
896 void Window::RotationDone( int orientation, int width, int height )
898 ecore_wl_window_rotation_change_done_send( mEventHandler->mEcoreWindow );
901 unsigned int Window::GetSupportedAuxiliaryHintCount()
903 return mSupportedAuxiliaryHints.size();
906 std::string Window::GetSupportedAuxiliaryHint( unsigned int index )
908 if( index >= GetSupportedAuxiliaryHintCount() )
910 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
913 return mSupportedAuxiliaryHints[index];
916 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
918 bool supported = false;
920 // Check if the hint is suppported
921 for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
932 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
936 // Check if the hint is already added
937 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
939 if( mAuxiliaryHints[i].first == hint )
941 // Just change the value
942 mAuxiliaryHints[i].second = value;
944 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
946 return i + 1; // id is index + 1
951 mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
953 unsigned int id = mAuxiliaryHints.size();
955 ecore_wl_window_aux_hint_add( mEventHandler->mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
957 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
962 bool Window::RemoveAuxiliaryHint( unsigned int id )
964 if( id == 0 || id > mAuxiliaryHints.size() )
966 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
970 mAuxiliaryHints[id - 1].second = std::string();
972 ecore_wl_window_aux_hint_del( mEventHandler->mEcoreWindow, static_cast< int >( id ) );
974 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
979 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
981 if( id == 0 || id > mAuxiliaryHints.size() )
983 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
987 mAuxiliaryHints[id - 1].second = value;
989 ecore_wl_window_aux_hint_change( mEventHandler->mEcoreWindow, static_cast< int >( id ), value.c_str() );
991 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() );
996 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
998 if( id == 0 || id > mAuxiliaryHints.size() )
1000 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
1001 return std::string();
1004 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() );
1006 return mAuxiliaryHints[id - 1].second;
1009 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
1011 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
1013 if( mAuxiliaryHints[i].first == hint )
1015 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
1020 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
1025 void Window::SetInputRegion( const Rect< int >& inputRegion )
1027 ecore_wl_window_input_region_set( mEventHandler->mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
1029 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 );
1032 void Window::SetType( Dali::DevelWindow::Type type )
1034 Ecore_Wl_Window_Type windowType;
1040 case Dali::DevelWindow::NORMAL:
1042 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1045 case Dali::DevelWindow::NOTIFICATION:
1047 windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1050 case Dali::DevelWindow::UTILITY:
1052 windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1055 case Dali::DevelWindow::DIALOG:
1057 windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1062 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1067 ecore_wl_window_type_set( mEventHandler->mEcoreWindow, windowType );
1073 Dali::DevelWindow::Type Window::GetType() const
1078 bool Window::SetNotificationLevel( Dali::DevelWindow::NotificationLevel::Type level )
1080 if( mType != Dali::DevelWindow::NOTIFICATION )
1082 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
1086 while( !mEventHandler->mTizenPolicy )
1088 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1091 int notificationLevel;
1095 case Dali::DevelWindow::NotificationLevel::NONE:
1097 notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1100 case Dali::DevelWindow::NotificationLevel::BASE:
1102 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1105 case Dali::DevelWindow::NotificationLevel::MEDIUM:
1107 notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1110 case Dali::DevelWindow::NotificationLevel::HIGH:
1112 notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1115 case Dali::DevelWindow::NotificationLevel::TOP:
1117 notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1122 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: invalid level [%d]\n", level );
1123 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1128 mEventHandler->mNotificationLevelChangeDone = false;
1129 mEventHandler->mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1131 tizen_policy_set_notification_level( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), notificationLevel );
1135 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1138 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1142 if( !mEventHandler->mNotificationLevelChangeDone )
1144 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mEventHandler->mNotificationChangeState );
1147 else if( mEventHandler->mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1149 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Permission denied! [%d]\n", level );
1153 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level is changed [%d]\n", mEventHandler->mNotificationLevel );
1158 Dali::DevelWindow::NotificationLevel::Type Window::GetNotificationLevel()
1160 if( mType != Dali::DevelWindow::NOTIFICATION )
1162 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
1163 return Dali::DevelWindow::NotificationLevel::NONE;
1166 while( !mEventHandler->mTizenPolicy )
1168 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1173 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1176 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1180 if( !mEventHandler->mNotificationLevelChangeDone )
1182 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Error! [%d]\n", mEventHandler->mNotificationChangeState );
1183 return Dali::DevelWindow::NotificationLevel::NONE;
1186 Dali::DevelWindow::NotificationLevel::Type level;
1188 switch( mEventHandler->mNotificationLevel )
1190 case TIZEN_POLICY_LEVEL_NONE:
1192 level = Dali::DevelWindow::NotificationLevel::NONE;
1195 case TIZEN_POLICY_LEVEL_DEFAULT:
1197 level = Dali::DevelWindow::NotificationLevel::BASE;
1200 case TIZEN_POLICY_LEVEL_MEDIUM:
1202 level = Dali::DevelWindow::NotificationLevel::MEDIUM;
1205 case TIZEN_POLICY_LEVEL_HIGH:
1207 level = Dali::DevelWindow::NotificationLevel::HIGH;
1210 case TIZEN_POLICY_LEVEL_TOP:
1212 level = Dali::DevelWindow::NotificationLevel::TOP;
1217 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: invalid level [%d]\n", mEventHandler->mNotificationLevel );
1218 level = Dali::DevelWindow::NotificationLevel::NONE;
1223 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: level [%d]\n", mEventHandler->mNotificationLevel );
1228 void Window::SetOpaqueState( bool opaque )
1230 while( !mEventHandler->mTizenPolicy )
1232 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1235 tizen_policy_set_opaque_state( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), ( opaque ? 1 : 0 ) );
1237 mOpaqueState = opaque;
1239 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
1242 bool Window::IsOpaqueState()
1244 return mOpaqueState;
1247 bool Window::SetScreenMode( Dali::DevelWindow::ScreenMode::Type screenMode )
1249 while( !mEventHandler->mTizenPolicy )
1251 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1254 mEventHandler->mScreenModeChangeDone = false;
1255 mEventHandler->mScreenModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1257 unsigned int mode = 0;
1259 switch( screenMode )
1261 case Dali::DevelWindow::ScreenMode::DEFAULT:
1266 case Dali::DevelWindow::ScreenMode::ALWAYS_ON:
1273 tizen_policy_set_window_screen_mode( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), mode );
1277 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1280 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1284 if( !mEventHandler->mScreenModeChangeDone )
1286 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode change is failed [%d, %d]\n", screenMode, mEventHandler->mScreenModeChangeState );
1289 else if( mEventHandler->mScreenModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1291 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Permission denied! [%d]\n", screenMode );
1295 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode is changed [%d]\n", mEventHandler->mScreenMode );
1300 Dali::DevelWindow::ScreenMode::Type Window::GetScreenMode()
1302 while( !mEventHandler->mTizenPolicy )
1304 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1309 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1312 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1316 if( !mEventHandler->mScreenModeChangeDone )
1318 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: Error! [%d]\n", mEventHandler->mScreenModeChangeState );
1319 return Dali::DevelWindow::ScreenMode::DEFAULT;
1322 Dali::DevelWindow::ScreenMode::Type screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1324 switch( mEventHandler->mScreenMode )
1328 screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1333 screenMode = Dali::DevelWindow::ScreenMode::ALWAYS_ON;
1338 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: screen mode [%d]\n", mEventHandler->mScreenMode );
1343 bool Window::SetBrightness( int brightness )
1345 if( brightness < 0 || brightness > 100 )
1347 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
1351 while( !mEventHandler->mTizenDisplayPolicy )
1353 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1356 mEventHandler->mBrightnessChangeDone = false;
1357 mEventHandler->mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1359 tizen_display_policy_set_window_brightness( mEventHandler->mTizenDisplayPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), brightness );
1363 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1366 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1370 if( !mEventHandler->mBrightnessChangeDone )
1372 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mEventHandler->mBrightnessChangeState );
1375 else if( mEventHandler->mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1377 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Permission denied! [%d]\n", brightness );
1381 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness is changed [%d]\n", mEventHandler->mBrightness );
1386 int Window::GetBrightness()
1388 while( !mEventHandler->mTizenDisplayPolicy )
1390 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1395 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1398 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1402 if( !mEventHandler->mBrightnessChangeDone )
1404 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Error! [%d]\n", mEventHandler->mBrightnessChangeState );
1408 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Brightness [%d]\n", mEventHandler->mBrightness );
1410 return mEventHandler->mBrightness;
1419 #pragma GCC diagnostic pop