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 )
76 mTizenDisplayPolicy( NULL ),
77 mNotificationLevel( -1 ),
78 mNotificationChangeState( 0 ),
79 mNotificationLevelChangeDone( true ),
81 mScreenModeChangeState( 0 ),
82 mScreenModeChangeDone( true ),
84 mBrightnessChangeState( 0 ),
85 mBrightnessChangeDone( true )
87 // store ecore window handle
88 ECore::WindowRenderSurface* wlWindow( dynamic_cast< ECore::WindowRenderSurface * >( mWindow->mSurface ) );
91 mEcoreWindow = wlWindow->GetWlWindow();
93 DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no ecore Wl window");
95 if( mWindow->mEcoreEventHander )
97 mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this ) );
98 mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this ) );
99 mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this ) );
100 mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_OUTPUT_TRANSFORM, EcoreEventOutputTransform, this) );
101 mEcoreEventHandler.PushBack( ecore_event_handler_add( ECORE_WL_EVENT_IGNORE_OUTPUT_TRANSFORM, EcoreEventIgnoreOutputTransform, this) );
104 mDisplay = ecore_wl_display_get();
108 wl_display* displayWrapper = static_cast< wl_display* >( wl_proxy_create_wrapper( mDisplay ) );
111 mEventQueue = wl_display_create_queue( mDisplay );
114 wl_proxy_set_queue( reinterpret_cast< wl_proxy* >( displayWrapper ), mEventQueue );
116 wl_registry* registry = wl_display_get_registry( displayWrapper );
117 wl_registry_add_listener( registry, &mRegistryListener, this );
120 wl_proxy_wrapper_destroy( displayWrapper );
130 for( Dali::Vector< Ecore_Event_Handler* >::Iterator iter = mEcoreEventHandler.Begin(), endIter = mEcoreEventHandler.End(); iter != endIter; ++iter )
132 ecore_event_handler_del( *iter );
134 mEcoreEventHandler.Clear();
138 wl_event_queue_destroy( mEventQueue );
144 /// Called when the window iconify state is changed.
145 static Eina_Bool EcoreEventWindowIconifyStateChanged( void* data, int type, void* event )
147 Ecore_Wl_Event_Window_Iconify_State_Change* iconifyChangedEvent( static_cast< Ecore_Wl_Event_Window_Iconify_State_Change* >( event ) );
148 EventHandler* handler( static_cast< EventHandler* >( data ) );
149 Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
151 if ( handler && handler->mWindow )
153 WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
154 if ( observer && ( iconifyChangedEvent->win == static_cast< unsigned int> ( ecore_wl_window_id_get( handler->mEcoreWindow ) ) ) )
156 if( iconifyChangedEvent->iconified == EINA_TRUE )
158 observer->OnWindowHidden();
159 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Iconfied\n", handler->mEcoreWindow );
163 observer->OnWindowShown();
164 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Shown\n", handler->mEcoreWindow );
166 handled = ECORE_CALLBACK_DONE;
173 /// Called when the window gains focus
174 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
176 Ecore_Wl_Event_Focus_In* focusInEvent( static_cast< Ecore_Wl_Event_Focus_In* >( event ) );
177 EventHandler* handler( static_cast< EventHandler* >( data ) );
179 if ( handler && handler->mWindow && focusInEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
181 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n" );
183 handler->mWindow->mFocusChangedSignal.Emit( true );
186 return ECORE_CALLBACK_PASS_ON;
189 /// Called when the window loses focus
190 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
192 Ecore_Wl_Event_Focus_Out* focusOutEvent( static_cast< Ecore_Wl_Event_Focus_Out* >( event ) );
193 EventHandler* handler( static_cast< EventHandler* >( data ) );
195 if ( handler && handler->mWindow && focusOutEvent->win == static_cast< unsigned int >(ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
197 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n" );
199 handler->mWindow->mFocusChangedSignal.Emit( false );
202 return ECORE_CALLBACK_PASS_ON;
205 /// Called when the output is transformed
206 static Eina_Bool EcoreEventOutputTransform( void* data, int type, void* event )
208 Ecore_Wl_Event_Output_Transform* transformEvent( static_cast< Ecore_Wl_Event_Output_Transform* >( event ) );
209 EventHandler* handler( static_cast< EventHandler* >( data ) );
211 if ( handler && handler->mWindow && transformEvent->output == ecore_wl_window_output_find( handler->mEcoreWindow ) )
213 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( handler->mWindow->mSurface ) );
214 wlSurface->OutputTransformed();
217 return ECORE_CALLBACK_PASS_ON;
220 /// Called when the output transform should be ignored
221 static Eina_Bool EcoreEventIgnoreOutputTransform( void* data, int type, void* event )
223 Ecore_Wl_Event_Ignore_Output_Transform* ignoreTransformEvent( static_cast< Ecore_Wl_Event_Ignore_Output_Transform* >( event ) );
224 EventHandler* handler( static_cast< EventHandler* >( data ) );
226 if ( handler && handler->mWindow && ignoreTransformEvent->win == handler->mEcoreWindow )
228 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( handler->mWindow->mSurface ) );
229 wlSurface->OutputTransformed();
232 return ECORE_CALLBACK_PASS_ON;
235 static void RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
237 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
239 if( strcmp( interface, tizen_policy_interface.name ) == 0 )
241 eventHandler->mTizenPolicy = static_cast< tizen_policy* >( wl_registry_bind( registry, name, &tizen_policy_interface, version ) );
242 if( !eventHandler->mTizenPolicy )
244 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n" );
248 tizen_policy_add_listener( eventHandler->mTizenPolicy, &eventHandler->mTizenPolicyListener, data );
250 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_policy_add_listener is called.\n" );
252 else if( strcmp( interface, tizen_display_policy_interface.name ) == 0 )
254 eventHandler->mTizenDisplayPolicy = static_cast< tizen_display_policy* >( wl_registry_bind( registry, name, &tizen_display_policy_interface, version ) );
255 if( !eventHandler->mTizenDisplayPolicy )
257 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n" );
261 tizen_display_policy_add_listener( eventHandler->mTizenDisplayPolicy, &eventHandler->mTizenDisplayPolicyListener, data );
263 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n" );
267 static void RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
269 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
270 eventHandler->mTizenPolicy = NULL;
271 eventHandler->mTizenDisplayPolicy = NULL;
274 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
276 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
278 eventHandler->mNotificationLevel = level;
279 eventHandler->mNotificationChangeState = state;
280 eventHandler->mNotificationLevelChangeDone = true;
282 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state );
285 static void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
287 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
289 eventHandler->mScreenMode = mode;
290 eventHandler->mScreenModeChangeState = state;
291 eventHandler->mScreenModeChangeDone = true;
293 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state );
296 static void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
298 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
300 eventHandler->mBrightness = brightness;
301 eventHandler->mBrightnessChangeState = state;
302 eventHandler->mBrightnessChangeDone = true;
304 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state );
307 const struct wl_registry_listener mRegistryListener =
309 RegistryGlobalCallback,
310 RegistryGlobalCallbackRemove
313 const struct tizen_policy_listener mTizenPolicyListener =
317 TizenPolicyNotificationChangeDone,
319 TizenPolicyScreenModeChangeDone,
326 const struct tizen_display_policy_listener mTizenDisplayPolicyListener =
328 DisplayPolicyBrightnessChangeDone
333 Dali::Vector< Ecore_Event_Handler* > mEcoreEventHandler;
334 Ecore_Wl_Window* mEcoreWindow;
336 wl_display* mDisplay;
337 wl_event_queue* mEventQueue;
338 tizen_policy* mTizenPolicy;
339 tizen_display_policy* mTizenDisplayPolicy;
341 int mNotificationLevel;
342 uint32_t mNotificationChangeState;
343 bool mNotificationLevelChangeDone;
346 uint32_t mScreenModeChangeState;
347 bool mScreenModeChangeDone;
350 uint32_t mBrightnessChangeState;
351 bool mBrightnessChangeDone;
354 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
356 Window* window = new Window();
357 window->mIsTransparent = isTransparent;
358 window->Initialize( positionSize, name, className );
362 void Window::SetAdaptor(Dali::Adaptor& adaptor)
364 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
367 // Only create one overlay per window
368 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
369 Integration::Core& core = adaptorImpl.GetCore();
370 mOverlay = &core.GetSystemOverlay();
372 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
373 taskList.CreateTask();
375 mAdaptor = &adaptorImpl;
376 mAdaptor->AddObserver( *this );
378 // Can only create the detector when we know the Core has been instantiated.
379 mDragAndDropDetector = DragAndDropDetector::New();
380 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
384 mOrientation->SetAdaptor(adaptor);
387 if( mIndicator != NULL )
389 mIndicator->SetAdaptor(mAdaptor);
393 RenderSurface* Window::GetSurface()
398 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
400 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
401 DALI_ASSERT_DEBUG(mOverlay);
403 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
404 DALI_ASSERT_DEBUG(wlSurface);
408 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
410 mIndicatorVisible = visibleMode;
412 if ( mIndicatorVisible == Dali::Window::VISIBLE )
414 // when the indicator is visible, set proper mode for indicator server according to bg mode
415 if ( mIndicatorOpacityMode == Dali::Window::OPAQUE )
417 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
419 else if ( mIndicatorOpacityMode == Dali::Window::TRANSLUCENT )
421 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSLUCENT);
423 else if ( mIndicatorOpacityMode == Dali::Window::TRANSPARENT )
425 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
430 // when the indicator is not visible, set TRANSPARENT mode for indicator server
431 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSPARENT); // it means hidden indicator
435 DoShowIndicator( mIndicatorOrientation );
438 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
440 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
442 DoRotateIndicator( orientation );
445 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
447 mIndicatorOpacityMode = opacityMode;
449 if( mIndicator != NULL )
451 mIndicator->SetOpacityMode( opacityMode );
455 void Window::SetClass(std::string name, std::string klass)
457 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
461 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
462 ecore_wl_window_title_set( wlWindow, name.c_str() );
463 ecore_wl_window_class_name_set( wlWindow, klass.c_str() );
467 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window has no surface\n" );
473 mIndicatorVisible( Dali::Window::VISIBLE ),
474 mIndicatorIsShown( false ),
475 mShowRotatedIndicatorOnClose( false ),
477 mIsTransparent( false ),
478 mWMRotationAppSet( false ),
479 mEcoreEventHander( true ),
480 mIsFocusAcceptable( true ),
482 mOpaqueState( false ),
483 mResizeEnabled( false ),
485 mIndicatorOrientation( Dali::Window::PORTRAIT ),
486 mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
487 mIndicatorOpacityMode( Dali::Window::OPAQUE ),
490 mType( Dali::DevelWindow::NORMAL ),
491 mEventHandler( NULL ),
492 mPreferredOrientation( Dali::Window::PORTRAIT ),
493 mSupportedAuxiliaryHints(),
495 mIndicatorVisibilityChangedSignal(),
496 mFocusChangedSignal(),
498 mDeleteRequestSignal()
504 delete mEventHandler;
514 mAdaptor->RemoveObserver( *this );
515 mAdaptor->SetDragAndDropDetector( NULL );
521 mSupportedAuxiliaryHints.clear();
522 mAuxiliaryHints.clear();
525 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
527 // create an Wayland window by default
529 ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( positionSize, surface, name, mIsTransparent );
531 mSurface = windowSurface;
533 // create event handler for Wayland window
534 mEventHandler = new EventHandler( this );
536 // get auxiliary hint
537 Eina_List* hints = ecore_wl_window_aux_hints_supported_get( mEventHandler->mEcoreWindow );
543 for( l = hints, ( hint = static_cast< char* >( eina_list_data_get(l) ) ); l; l = eina_list_next(l), ( hint = static_cast< char* >( eina_list_data_get(l) ) ) )
545 mSupportedAuxiliaryHints.push_back( hint );
547 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::Initialize: %s\n", hint );
551 if( !positionSize.IsEmpty() )
553 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
554 mResizeEnabled = true;
557 SetClass( name, className );
558 windowSurface->Map();
560 mOrientation = Orientation::New(this);
563 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
565 if( mIndicator == NULL )
567 if( mIndicatorVisible != Dali::Window::INVISIBLE )
569 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
570 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
571 Dali::Actor actor = mIndicator->GetActor();
572 SetIndicatorActorRotation();
573 mOverlay->Add(actor);
575 // else don't create a hidden indicator
577 else // Already have indicator
579 if( mIndicatorVisible == Dali::Window::VISIBLE )
581 // If we are resuming, and rotation has changed,
582 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
584 // then close current indicator and open new one
585 mShowRotatedIndicatorOnClose = true;
586 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
587 // Don't show actor - will contain indicator for old orientation.
592 // set indicator visible mode
593 if( mIndicator != NULL )
595 mIndicator->SetVisible( mIndicatorVisible );
598 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
599 SetIndicatorProperties( show, lastOrientation );
600 mIndicatorIsShown = show;
603 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
605 if( mIndicatorIsShown )
607 mShowRotatedIndicatorOnClose = true;
608 mNextIndicatorOrientation = orientation;
609 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
613 // Save orientation for when the indicator is next shown
614 mShowRotatedIndicatorOnClose = false;
615 mNextIndicatorOrientation = orientation;
619 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
621 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
625 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
628 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_ON);
632 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_OFF);
637 void Window::IndicatorTypeChanged(Indicator::Type type)
639 #if defined(DALI_PROFILE_MOBILE)
640 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
644 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
647 case Indicator::INDICATOR_TYPE_1:
648 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
651 case Indicator::INDICATOR_TYPE_2:
652 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_HIDDEN);
655 case Indicator::INDICATOR_TYPE_UNKNOWN:
663 void Window::IndicatorClosed( IndicatorInterface* indicator )
665 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
667 if( mShowRotatedIndicatorOnClose )
669 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
670 mIndicator->Open(mNextIndicatorOrientation);
671 mIndicatorOrientation = mNextIndicatorOrientation;
672 SetIndicatorActorRotation();
673 DoShowIndicator(currentOrientation);
677 void Window::IndicatorVisibilityChanged(bool isVisible)
679 mIndicatorVisibilityChangedSignal.Emit(isVisible);
682 void Window::SetIndicatorActorRotation()
684 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
685 DALI_ASSERT_DEBUG( mIndicator != NULL );
687 Dali::Actor actor = mIndicator->GetActor();
688 switch( mIndicatorOrientation )
690 case Dali::Window::PORTRAIT:
691 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
692 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
693 actor.SetOrientation( Degree(0), Vector3::ZAXIS );
695 case Dali::Window::PORTRAIT_INVERSE:
696 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
697 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
698 actor.SetOrientation( Degree(180), Vector3::ZAXIS );
700 case Dali::Window::LANDSCAPE:
701 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
702 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
703 actor.SetOrientation( Degree(270), Vector3::ZAXIS );
705 case Dali::Window::LANDSCAPE_INVERSE:
706 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
707 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
708 actor.SetOrientation( Degree(90), Vector3::ZAXIS );
715 ecore_wl_window_raise( mEventHandler->mEcoreWindow );
720 ecore_wl_window_lower( mEventHandler->mEcoreWindow );
723 void Window::Activate()
725 ecore_wl_window_activate( mEventHandler->mEcoreWindow );
728 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
730 return mDragAndDropDetector;
733 Dali::Any Window::GetNativeHandle() const
737 return mEventHandler->mEcoreWindow;
745 void Window::OnStart()
747 DoShowIndicator( mIndicatorOrientation );
750 void Window::OnPause()
754 void Window::OnResume()
756 // resume indicator status
757 if( mIndicator != NULL )
759 // Restore own indicator opacity
760 // Send opacity mode to indicator service when app resumed
761 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
765 void Window::OnStop()
776 void Window::OnDestroy()
781 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
785 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
787 if(mAvailableOrientations[i] == orientation)
796 mAvailableOrientations.push_back(orientation);
797 SetAvailableOrientations( mAvailableOrientations );
801 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
803 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
804 iter != mAvailableOrientations.end(); ++iter )
806 if( *iter == orientation )
808 mAvailableOrientations.erase( iter );
812 SetAvailableOrientations( mAvailableOrientations );
815 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
818 for( std::size_t i = 0; i < mAvailableOrientations.size(); ++i )
820 rotations[i] = static_cast< int >( mAvailableOrientations[i] );
822 ecore_wl_window_rotation_available_rotations_set( mEventHandler->mEcoreWindow, rotations, mAvailableOrientations.size() );
825 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
827 return mAvailableOrientations;
830 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
832 mPreferredOrientation = orientation;
834 ecore_wl_window_rotation_preferred_rotation_set( mEventHandler->mEcoreWindow, orientation );
837 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
839 return mPreferredOrientation;
842 void Window::SetAcceptFocus( bool accept )
844 mIsFocusAcceptable = accept;
846 ecore_wl_window_focus_skip_set( mEventHandler->mEcoreWindow, !accept );
849 bool Window::IsFocusAcceptable()
851 return mIsFocusAcceptable;
857 ecore_wl_window_show( mEventHandler->mEcoreWindow );
859 // Need an update request
862 mAdaptor->RequestUpdateOnce();
869 ecore_wl_window_hide( mEventHandler->mEcoreWindow );
872 bool Window::IsVisible() const
877 void Window::RotationDone( int orientation, int width, int height )
879 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
880 wlSurface->RequestRotation( orientation, width, height );
882 mAdaptor->SurfaceResizePrepare( Dali::Adaptor::SurfaceSize( width, height ) );
885 mResizedSignal.Emit( Dali::DevelWindow::WindowSize( width, height ) );
887 mAdaptor->SurfaceResizeComplete( Dali::Adaptor::SurfaceSize( width, height ) );
890 unsigned int Window::GetSupportedAuxiliaryHintCount()
892 return mSupportedAuxiliaryHints.size();
895 std::string Window::GetSupportedAuxiliaryHint( unsigned int index )
897 if( index >= GetSupportedAuxiliaryHintCount() )
899 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
902 return mSupportedAuxiliaryHints[index];
905 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
907 bool supported = false;
909 // Check if the hint is suppported
910 for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
921 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
925 // Check if the hint is already added
926 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
928 if( mAuxiliaryHints[i].first == hint )
930 // Just change the value
931 mAuxiliaryHints[i].second = value;
933 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
935 return i + 1; // id is index + 1
940 mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
942 unsigned int id = mAuxiliaryHints.size();
944 ecore_wl_window_aux_hint_add( mEventHandler->mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
946 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
951 bool Window::RemoveAuxiliaryHint( unsigned int id )
953 if( id == 0 || id > mAuxiliaryHints.size() )
955 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
959 mAuxiliaryHints[id - 1].second = std::string();
961 ecore_wl_window_aux_hint_del( mEventHandler->mEcoreWindow, static_cast< int >( id ) );
963 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
968 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
970 if( id == 0 || id > mAuxiliaryHints.size() )
972 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
976 mAuxiliaryHints[id - 1].second = value;
978 ecore_wl_window_aux_hint_change( mEventHandler->mEcoreWindow, static_cast< int >( id ), value.c_str() );
980 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() );
985 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
987 if( id == 0 || id > mAuxiliaryHints.size() )
989 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
990 return std::string();
993 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() );
995 return mAuxiliaryHints[id - 1].second;
998 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
1000 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
1002 if( mAuxiliaryHints[i].first == hint )
1004 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
1009 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
1014 void Window::SetInputRegion( const Rect< int >& inputRegion )
1016 ecore_wl_window_input_region_set( mEventHandler->mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
1018 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 );
1021 void Window::SetType( Dali::DevelWindow::Type type )
1023 Ecore_Wl_Window_Type windowType;
1029 case Dali::DevelWindow::NORMAL:
1031 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1034 case Dali::DevelWindow::NOTIFICATION:
1036 windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1039 case Dali::DevelWindow::UTILITY:
1041 windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1044 case Dali::DevelWindow::DIALOG:
1046 windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1051 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1056 ecore_wl_window_type_set( mEventHandler->mEcoreWindow, windowType );
1062 Dali::DevelWindow::Type Window::GetType() const
1067 bool Window::SetNotificationLevel( Dali::DevelWindow::NotificationLevel::Type level )
1069 if( mType != Dali::DevelWindow::NOTIFICATION )
1071 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
1075 while( !mEventHandler->mTizenPolicy )
1077 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1080 int notificationLevel;
1084 case Dali::DevelWindow::NotificationLevel::NONE:
1086 notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1089 case Dali::DevelWindow::NotificationLevel::BASE:
1091 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1094 case Dali::DevelWindow::NotificationLevel::MEDIUM:
1096 notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1099 case Dali::DevelWindow::NotificationLevel::HIGH:
1101 notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1104 case Dali::DevelWindow::NotificationLevel::TOP:
1106 notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1111 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: invalid level [%d]\n", level );
1112 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1117 mEventHandler->mNotificationLevelChangeDone = false;
1118 mEventHandler->mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1120 tizen_policy_set_notification_level( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), notificationLevel );
1124 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1127 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1131 if( !mEventHandler->mNotificationLevelChangeDone )
1133 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mEventHandler->mNotificationChangeState );
1136 else if( mEventHandler->mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1138 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Permission denied! [%d]\n", level );
1142 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level is changed [%d]\n", mEventHandler->mNotificationLevel );
1147 Dali::DevelWindow::NotificationLevel::Type Window::GetNotificationLevel()
1149 if( mType != Dali::DevelWindow::NOTIFICATION )
1151 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
1152 return Dali::DevelWindow::NotificationLevel::NONE;
1155 while( !mEventHandler->mTizenPolicy )
1157 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1162 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1165 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1169 if( !mEventHandler->mNotificationLevelChangeDone )
1171 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Error! [%d]\n", mEventHandler->mNotificationChangeState );
1172 return Dali::DevelWindow::NotificationLevel::NONE;
1175 Dali::DevelWindow::NotificationLevel::Type level;
1177 switch( mEventHandler->mNotificationLevel )
1179 case TIZEN_POLICY_LEVEL_NONE:
1181 level = Dali::DevelWindow::NotificationLevel::NONE;
1184 case TIZEN_POLICY_LEVEL_DEFAULT:
1186 level = Dali::DevelWindow::NotificationLevel::BASE;
1189 case TIZEN_POLICY_LEVEL_MEDIUM:
1191 level = Dali::DevelWindow::NotificationLevel::MEDIUM;
1194 case TIZEN_POLICY_LEVEL_HIGH:
1196 level = Dali::DevelWindow::NotificationLevel::HIGH;
1199 case TIZEN_POLICY_LEVEL_TOP:
1201 level = Dali::DevelWindow::NotificationLevel::TOP;
1206 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: invalid level [%d]\n", mEventHandler->mNotificationLevel );
1207 level = Dali::DevelWindow::NotificationLevel::NONE;
1212 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: level [%d]\n", mEventHandler->mNotificationLevel );
1217 void Window::SetOpaqueState( bool opaque )
1219 while( !mEventHandler->mTizenPolicy )
1221 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1224 tizen_policy_set_opaque_state( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), ( opaque ? 1 : 0 ) );
1226 mOpaqueState = opaque;
1228 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
1231 bool Window::IsOpaqueState()
1233 return mOpaqueState;
1236 bool Window::SetScreenMode( Dali::DevelWindow::ScreenMode::Type screenMode )
1238 while( !mEventHandler->mTizenPolicy )
1240 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1243 mEventHandler->mScreenModeChangeDone = false;
1244 mEventHandler->mScreenModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1246 unsigned int mode = 0;
1248 switch( screenMode )
1250 case Dali::DevelWindow::ScreenMode::DEFAULT:
1255 case Dali::DevelWindow::ScreenMode::ALWAYS_ON:
1262 tizen_policy_set_window_screen_mode( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), mode );
1266 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1269 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1273 if( !mEventHandler->mScreenModeChangeDone )
1275 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode change is failed [%d, %d]\n", screenMode, mEventHandler->mScreenModeChangeState );
1278 else if( mEventHandler->mScreenModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1280 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Permission denied! [%d]\n", screenMode );
1284 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode is changed [%d]\n", mEventHandler->mScreenMode );
1289 Dali::DevelWindow::ScreenMode::Type Window::GetScreenMode()
1291 while( !mEventHandler->mTizenPolicy )
1293 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1298 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1301 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1305 if( !mEventHandler->mScreenModeChangeDone )
1307 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: Error! [%d]\n", mEventHandler->mScreenModeChangeState );
1308 return Dali::DevelWindow::ScreenMode::DEFAULT;
1311 Dali::DevelWindow::ScreenMode::Type screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1313 switch( mEventHandler->mScreenMode )
1317 screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1322 screenMode = Dali::DevelWindow::ScreenMode::ALWAYS_ON;
1327 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: screen mode [%d]\n", mEventHandler->mScreenMode );
1332 bool Window::SetBrightness( int brightness )
1334 if( brightness < 0 || brightness > 100 )
1336 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
1340 while( !mEventHandler->mTizenDisplayPolicy )
1342 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1345 mEventHandler->mBrightnessChangeDone = false;
1346 mEventHandler->mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1348 tizen_display_policy_set_window_brightness( mEventHandler->mTizenDisplayPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), brightness );
1352 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1355 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1359 if( !mEventHandler->mBrightnessChangeDone )
1361 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mEventHandler->mBrightnessChangeState );
1364 else if( mEventHandler->mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1366 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Permission denied! [%d]\n", brightness );
1370 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness is changed [%d]\n", mEventHandler->mBrightness );
1375 int Window::GetBrightness()
1377 while( !mEventHandler->mTizenDisplayPolicy )
1379 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1384 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1387 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1391 if( !mEventHandler->mBrightnessChangeDone )
1393 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Error! [%d]\n", mEventHandler->mBrightnessChangeState );
1397 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Brightness [%d]\n", mEventHandler->mBrightness );
1399 return mEventHandler->mBrightness;
1402 void Window::SetSize( Dali::DevelWindow::WindowSize size )
1404 if( !mResizeEnabled )
1406 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
1407 mResizeEnabled = true;
1410 PositionSize positionSize = mSurface->GetPositionSize();
1412 if( positionSize.width != size.GetWidth() || positionSize.height != size.GetHeight() )
1414 positionSize.width = size.GetWidth();
1415 positionSize.height = size.GetHeight();
1417 mSurface->MoveResize( positionSize );
1419 mAdaptor->SurfaceResizePrepare( Dali::Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
1422 mResizedSignal.Emit( Dali::DevelWindow::WindowSize( positionSize.width, positionSize.height ) );
1424 mAdaptor->SurfaceResizeComplete( Dali::Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
1428 Dali::DevelWindow::WindowSize Window::GetSize()
1430 PositionSize positionSize = mSurface->GetPositionSize();
1432 return Dali::DevelWindow::WindowSize( positionSize.width, positionSize.height );
1435 void Window::SetPosition( Dali::DevelWindow::WindowPosition position )
1437 if( !mResizeEnabled )
1439 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
1440 mResizeEnabled = true;
1443 PositionSize positionSize = mSurface->GetPositionSize();
1445 if( positionSize.x != position.GetX() || positionSize.y != position.GetY() )
1447 positionSize.x = position.GetX();
1448 positionSize.y = position.GetY();
1450 mSurface->MoveResize( positionSize );
1454 Dali::DevelWindow::WindowPosition Window::GetPosition()
1456 PositionSize positionSize = mSurface->GetPositionSize();
1458 return Dali::DevelWindow::WindowPosition( positionSize.x, positionSize.y );
1461 void Window::SetTransparency( bool transparent )
1463 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
1464 wlSurface->SetTransparency( transparent );
1473 #pragma GCC diagnostic pop