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 mWindowVisibilityStateHandler( NULL ),
71 mWindowFocusInHandler( NULL ),
72 mWindowFocusOutHandler( NULL ),
77 mTizenDisplayPolicy( NULL ),
78 mNotificationLevel( -1 ),
79 mNotificationChangeState( 0 ),
80 mNotificationLevelChangeDone( true ),
82 mScreenModeChangeState( 0 ),
83 mScreenModeChangeDone( true ),
85 mBrightnessChangeState( 0 ),
86 mBrightnessChangeDone( true )
88 // store ecore window handle
89 ECore::WindowRenderSurface* wlWindow( dynamic_cast< ECore::WindowRenderSurface * >( mWindow->mSurface ) );
92 mEcoreWindow = wlWindow->GetWlWindow();
94 DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no ecore Wl window");
96 if( mWindow->mEcoreEventHander )
98 mWindowIconifyStateHandler = ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this );
99 mWindowVisibilityStateHandler = ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_VISIBILITY_CHANGE, EcoreEventWindowVisibilityChanged, this );
100 mWindowFocusInHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this );
101 mWindowFocusOutHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, 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 if ( mWindowPropertyHandler )
132 ecore_event_handler_del( mWindowPropertyHandler );
135 if ( mWindowIconifyStateHandler )
137 ecore_event_handler_del( mWindowIconifyStateHandler );
140 if ( mWindowVisibilityStateHandler )
142 ecore_event_handler_del( mWindowVisibilityStateHandler );
145 if( mWindowFocusInHandler )
147 ecore_event_handler_del( mWindowFocusInHandler );
150 if( mWindowFocusOutHandler )
152 ecore_event_handler_del( mWindowFocusOutHandler );
157 wl_event_queue_destroy( mEventQueue );
163 /// Called when the window properties are changed.
164 static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
169 /// Called when the window iconify state is changed.
170 static Eina_Bool EcoreEventWindowIconifyStateChanged( void* data, int type, void* event )
172 Ecore_Wl_Event_Window_Iconify_State_Change* iconifyChangedEvent( static_cast< Ecore_Wl_Event_Window_Iconify_State_Change* >( event ) );
173 EventHandler* handler( static_cast< EventHandler* >( data ) );
174 Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
176 if ( handler && handler->mWindow )
178 WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
179 if ( observer && ( iconifyChangedEvent->win == static_cast< unsigned int> ( ecore_wl_window_id_get( handler->mEcoreWindow ) ) ) )
181 if( iconifyChangedEvent->iconified == EINA_TRUE )
183 observer->OnWindowHidden();
184 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Iconfied\n", handler->mEcoreWindow );
188 observer->OnWindowShown();
189 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Shown\n", handler->mEcoreWindow );
191 handled = ECORE_CALLBACK_DONE;
198 /// Called when the window visibility is changed.
199 static Eina_Bool EcoreEventWindowVisibilityChanged( void* data, int type, void* event )
201 Ecore_Wl_Event_Window_Visibility_Change* visibilityChangedEvent( static_cast< Ecore_Wl_Event_Window_Visibility_Change* >( event ) );
202 EventHandler* handler( static_cast< EventHandler* >( data ) );
203 Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
205 if ( handler && handler->mWindow )
207 WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
208 if ( observer && ( visibilityChangedEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( handler->mEcoreWindow ) ) ) )
210 if( visibilityChangedEvent->fully_obscured == 1 )
212 observer->OnWindowHidden();
213 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) full obscured\n", handler->mEcoreWindow );
217 observer->OnWindowShown();
218 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Shown\n", handler->mEcoreWindow );
220 handled = ECORE_CALLBACK_DONE;
227 /// Called when the window gains focus
228 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
230 Ecore_Wl_Event_Focus_In* focusInEvent( static_cast< Ecore_Wl_Event_Focus_In* >( event ) );
231 EventHandler* handler( static_cast< EventHandler* >( data ) );
233 if ( handler && handler->mWindow && focusInEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
235 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n" );
237 handler->mWindow->mFocusChangedSignal.Emit( true );
240 return ECORE_CALLBACK_PASS_ON;
243 /// Called when the window loses focus
244 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
246 Ecore_Wl_Event_Focus_Out* focusOutEvent( static_cast< Ecore_Wl_Event_Focus_Out* >( event ) );
247 EventHandler* handler( static_cast< EventHandler* >( data ) );
249 if ( handler && handler->mWindow && focusOutEvent->win == static_cast< unsigned int >(ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
251 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n" );
253 handler->mWindow->mFocusChangedSignal.Emit( false );
256 return ECORE_CALLBACK_PASS_ON;
259 static void RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
261 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
263 if( strcmp( interface, tizen_policy_interface.name ) == 0 )
265 eventHandler->mTizenPolicy = static_cast< tizen_policy* >( wl_registry_bind( registry, name, &tizen_policy_interface, version ) );
266 if( !eventHandler->mTizenPolicy )
268 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n" );
272 tizen_policy_add_listener( eventHandler->mTizenPolicy, &eventHandler->mTizenPolicyListener, data );
274 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_policy_add_listener is called.\n" );
276 else if( strcmp( interface, tizen_display_policy_interface.name ) == 0 )
278 eventHandler->mTizenDisplayPolicy = static_cast< tizen_display_policy* >( wl_registry_bind( registry, name, &tizen_display_policy_interface, version ) );
279 if( !eventHandler->mTizenDisplayPolicy )
281 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n" );
285 tizen_display_policy_add_listener( eventHandler->mTizenDisplayPolicy, &eventHandler->mTizenDisplayPolicyListener, data );
287 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n" );
291 static void RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
293 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
294 eventHandler->mTizenPolicy = NULL;
295 eventHandler->mTizenDisplayPolicy = NULL;
298 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
300 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
302 eventHandler->mNotificationLevel = level;
303 eventHandler->mNotificationChangeState = state;
304 eventHandler->mNotificationLevelChangeDone = true;
306 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state );
309 static void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
311 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
313 eventHandler->mScreenMode = mode;
314 eventHandler->mScreenModeChangeState = state;
315 eventHandler->mScreenModeChangeDone = true;
317 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state );
320 static void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
322 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
324 eventHandler->mBrightness = brightness;
325 eventHandler->mBrightnessChangeState = state;
326 eventHandler->mBrightnessChangeDone = true;
328 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state );
331 const struct wl_registry_listener mRegistryListener =
333 RegistryGlobalCallback,
334 RegistryGlobalCallbackRemove
337 const struct tizen_policy_listener mTizenPolicyListener =
341 TizenPolicyNotificationChangeDone,
343 TizenPolicyScreenModeChangeDone,
350 const struct tizen_display_policy_listener mTizenDisplayPolicyListener =
352 DisplayPolicyBrightnessChangeDone
357 Ecore_Event_Handler* mWindowPropertyHandler;
358 Ecore_Event_Handler* mWindowIconifyStateHandler;
359 Ecore_Event_Handler* mWindowVisibilityStateHandler;
360 Ecore_Event_Handler* mWindowFocusInHandler;
361 Ecore_Event_Handler* mWindowFocusOutHandler;
362 Ecore_Wl_Window* mEcoreWindow;
364 wl_display* mDisplay;
365 wl_event_queue* mEventQueue;
366 tizen_policy* mTizenPolicy;
367 tizen_display_policy* mTizenDisplayPolicy;
369 int mNotificationLevel;
370 uint32_t mNotificationChangeState;
371 bool mNotificationLevelChangeDone;
374 uint32_t mScreenModeChangeState;
375 bool mScreenModeChangeDone;
378 uint32_t mBrightnessChangeState;
379 bool mBrightnessChangeDone;
382 Window* Window::New(const PositionSize& posSize, const std::string& name, const std::string& className, bool isTransparent)
384 Window* window = new Window();
385 window->mIsTransparent = isTransparent;
386 window->Initialize(posSize, name, className);
390 void Window::SetAdaptor(Dali::Adaptor& adaptor)
392 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
395 // Only create one overlay per window
396 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
397 Integration::Core& core = adaptorImpl.GetCore();
398 mOverlay = &core.GetSystemOverlay();
400 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
401 taskList.CreateTask();
403 mAdaptor = &adaptorImpl;
404 mAdaptor->AddObserver( *this );
406 // Can only create the detector when we know the Core has been instantiated.
407 mDragAndDropDetector = DragAndDropDetector::New();
408 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
412 mOrientation->SetAdaptor(adaptor);
415 if( mIndicator != NULL )
417 mIndicator->SetAdaptor(mAdaptor);
421 RenderSurface* Window::GetSurface()
426 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
428 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
429 DALI_ASSERT_DEBUG(mOverlay);
431 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
432 DALI_ASSERT_DEBUG(wlSurface);
436 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
438 mIndicatorVisible = visibleMode;
440 if ( mIndicatorVisible == Dali::Window::VISIBLE )
442 // when the indicator is visible, set proper mode for indicator server according to bg mode
443 if ( mIndicatorOpacityMode == Dali::Window::OPAQUE )
445 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
447 else if ( mIndicatorOpacityMode == Dali::Window::TRANSLUCENT )
449 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSLUCENT);
451 else if ( mIndicatorOpacityMode == Dali::Window::TRANSPARENT )
453 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
458 // when the indicator is not visible, set TRANSPARENT mode for indicator server
459 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSPARENT); // it means hidden indicator
463 DoShowIndicator( mIndicatorOrientation );
466 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
468 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
470 DoRotateIndicator( orientation );
473 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
475 mIndicatorOpacityMode = opacityMode;
477 if( mIndicator != NULL )
479 mIndicator->SetOpacityMode( opacityMode );
483 void Window::SetClass(std::string name, std::string klass)
485 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
489 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
490 ecore_wl_window_title_set( wlWindow, name.c_str() );
491 ecore_wl_window_class_name_set( wlWindow, klass.c_str() );
495 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window has no surface\n" );
501 mIndicatorVisible( Dali::Window::VISIBLE ),
502 mIndicatorIsShown( false ),
503 mShowRotatedIndicatorOnClose( false ),
505 mIsTransparent( false ),
506 mWMRotationAppSet( false ),
507 mEcoreEventHander( true ),
508 mIsFocusAcceptable( true ),
510 mOpaqueState( false ),
512 mIndicatorOrientation( Dali::Window::PORTRAIT ),
513 mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
514 mIndicatorOpacityMode( Dali::Window::OPAQUE ),
517 mType( Dali::DevelWindow::NORMAL ),
518 mEventHandler( NULL ),
519 mPreferredOrientation( Dali::Window::PORTRAIT ),
520 mSupportedAuxiliaryHints(),
527 delete mEventHandler;
537 mAdaptor->RemoveObserver( *this );
538 mAdaptor->SetDragAndDropDetector( NULL );
544 mSupportedAuxiliaryHints.clear();
545 mAuxiliaryHints.clear();
548 void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
550 // create an Wayland window by default
552 ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
554 mSurface = windowSurface;
555 SetClass( name, className );
556 windowSurface->Map();
558 mOrientation = Orientation::New(this);
560 // create event handler for Wayland window
561 mEventHandler = new EventHandler( this );
563 // get auxiliary hint
564 Eina_List* hints = ecore_wl_window_aux_hints_supported_get( mEventHandler->mEcoreWindow );
570 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) ) ) )
572 mSupportedAuxiliaryHints.push_back( hint );
574 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::Initialize: %s\n", hint );
579 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
581 if( mIndicator == NULL )
583 if( mIndicatorVisible != Dali::Window::INVISIBLE )
585 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
586 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
587 Dali::Actor actor = mIndicator->GetActor();
588 SetIndicatorActorRotation();
589 mOverlay->Add(actor);
591 // else don't create a hidden indicator
593 else // Already have indicator
595 if( mIndicatorVisible == Dali::Window::VISIBLE )
597 // If we are resuming, and rotation has changed,
598 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
600 // then close current indicator and open new one
601 mShowRotatedIndicatorOnClose = true;
602 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
603 // Don't show actor - will contain indicator for old orientation.
608 // set indicator visible mode
609 if( mIndicator != NULL )
611 mIndicator->SetVisible( mIndicatorVisible );
614 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
615 SetIndicatorProperties( show, lastOrientation );
616 mIndicatorIsShown = show;
619 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
621 if( mIndicatorIsShown )
623 mShowRotatedIndicatorOnClose = true;
624 mNextIndicatorOrientation = orientation;
625 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
629 // Save orientation for when the indicator is next shown
630 mShowRotatedIndicatorOnClose = false;
631 mNextIndicatorOrientation = orientation;
635 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
637 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
641 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
644 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_ON);
648 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_OFF);
653 void Window::IndicatorTypeChanged(Indicator::Type type)
655 #if defined(DALI_PROFILE_MOBILE)
656 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
660 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
663 case Indicator::INDICATOR_TYPE_1:
664 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
667 case Indicator::INDICATOR_TYPE_2:
668 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_HIDDEN);
671 case Indicator::INDICATOR_TYPE_UNKNOWN:
679 void Window::IndicatorClosed( IndicatorInterface* indicator )
681 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
683 if( mShowRotatedIndicatorOnClose )
685 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
686 mIndicator->Open(mNextIndicatorOrientation);
687 mIndicatorOrientation = mNextIndicatorOrientation;
688 SetIndicatorActorRotation();
689 DoShowIndicator(currentOrientation);
693 void Window::IndicatorVisibilityChanged(bool isVisible)
695 mIndicatorVisibilityChangedSignal.Emit(isVisible);
698 void Window::SetIndicatorActorRotation()
700 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
701 DALI_ASSERT_DEBUG( mIndicator != NULL );
703 Dali::Actor actor = mIndicator->GetActor();
704 switch( mIndicatorOrientation )
706 case Dali::Window::PORTRAIT:
707 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
708 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
709 actor.SetOrientation( Degree(0), Vector3::ZAXIS );
711 case Dali::Window::PORTRAIT_INVERSE:
712 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
713 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
714 actor.SetOrientation( Degree(180), Vector3::ZAXIS );
716 case Dali::Window::LANDSCAPE:
717 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
718 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
719 actor.SetOrientation( Degree(270), Vector3::ZAXIS );
721 case Dali::Window::LANDSCAPE_INVERSE:
722 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
723 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
724 actor.SetOrientation( Degree(90), Vector3::ZAXIS );
731 ecore_wl_window_raise( mEventHandler->mEcoreWindow );
736 ecore_wl_window_lower( mEventHandler->mEcoreWindow );
739 void Window::Activate()
741 ecore_wl_window_activate( mEventHandler->mEcoreWindow );
744 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
746 return mDragAndDropDetector;
749 Dali::Any Window::GetNativeHandle() const
753 return mEventHandler->mEcoreWindow;
761 void Window::OnStart()
763 DoShowIndicator( mIndicatorOrientation );
766 void Window::OnPause()
770 void Window::OnResume()
772 // resume indicator status
773 if( mIndicator != NULL )
775 // Restore own indicator opacity
776 // Send opacity mode to indicator service when app resumed
777 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
781 void Window::OnStop()
792 void Window::OnDestroy()
797 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
801 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
803 if(mAvailableOrientations[i] == orientation)
812 mAvailableOrientations.push_back(orientation);
813 SetAvailableOrientations( mAvailableOrientations );
817 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
819 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
820 iter != mAvailableOrientations.end(); ++iter )
822 if( *iter == orientation )
824 mAvailableOrientations.erase( iter );
828 SetAvailableOrientations( mAvailableOrientations );
831 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
834 for( std::size_t i = 0; i < mAvailableOrientations.size(); ++i )
836 rotations[i] = static_cast< int >( mAvailableOrientations[i] );
838 ecore_wl_window_rotation_available_rotations_set( mEventHandler->mEcoreWindow, rotations, mAvailableOrientations.size() );
841 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
843 return mAvailableOrientations;
846 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
848 mPreferredOrientation = orientation;
850 ecore_wl_window_rotation_preferred_rotation_set( mEventHandler->mEcoreWindow, orientation );
853 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
855 return mPreferredOrientation;
858 void Window::SetAcceptFocus( bool accept )
860 mIsFocusAcceptable = accept;
862 ecore_wl_window_focus_skip_set( mEventHandler->mEcoreWindow, !accept );
865 bool Window::IsFocusAcceptable()
867 return mIsFocusAcceptable;
873 ecore_wl_window_show( mEventHandler->mEcoreWindow );
875 // Need an update request
878 mAdaptor->RequestUpdateOnce();
885 ecore_wl_window_hide( mEventHandler->mEcoreWindow );
888 bool Window::IsVisible() const
893 void Window::RotationDone( int orientation, int width, int height )
895 ecore_wl_window_rotation_change_done_send( mEventHandler->mEcoreWindow );
898 unsigned int Window::GetSupportedAuxiliaryHintCount()
900 return mSupportedAuxiliaryHints.size();
903 std::string Window::GetSupportedAuxiliaryHint( unsigned int index )
905 if( index >= GetSupportedAuxiliaryHintCount() )
907 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
910 return mSupportedAuxiliaryHints[index];
913 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
915 bool supported = false;
917 // Check if the hint is suppported
918 for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
929 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
933 // Check if the hint is already added
934 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
936 if( mAuxiliaryHints[i].first == hint )
938 // Just change the value
939 mAuxiliaryHints[i].second = value;
941 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
943 return i + 1; // id is index + 1
948 mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
950 unsigned int id = mAuxiliaryHints.size();
952 ecore_wl_window_aux_hint_add( mEventHandler->mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
954 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
959 bool Window::RemoveAuxiliaryHint( unsigned int id )
961 if( id == 0 || id > mAuxiliaryHints.size() )
963 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
967 mAuxiliaryHints[id - 1].second = std::string();
969 ecore_wl_window_aux_hint_del( mEventHandler->mEcoreWindow, static_cast< int >( id ) );
971 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
976 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
978 if( id == 0 || id > mAuxiliaryHints.size() )
980 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
984 mAuxiliaryHints[id - 1].second = value;
986 ecore_wl_window_aux_hint_change( mEventHandler->mEcoreWindow, static_cast< int >( id ), value.c_str() );
988 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() );
993 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
995 if( id == 0 || id > mAuxiliaryHints.size() )
997 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
998 return std::string();
1001 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() );
1003 return mAuxiliaryHints[id - 1].second;
1006 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
1008 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
1010 if( mAuxiliaryHints[i].first == hint )
1012 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
1017 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
1022 void Window::SetInputRegion( const Rect< int >& inputRegion )
1024 ecore_wl_window_input_region_set( mEventHandler->mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
1026 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 );
1029 void Window::SetType( Dali::DevelWindow::Type type )
1031 Ecore_Wl_Window_Type windowType;
1037 case Dali::DevelWindow::NORMAL:
1039 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1042 case Dali::DevelWindow::NOTIFICATION:
1044 windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1047 case Dali::DevelWindow::UTILITY:
1049 windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1052 case Dali::DevelWindow::DIALOG:
1054 windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1059 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1064 ecore_wl_window_type_set( mEventHandler->mEcoreWindow, windowType );
1070 Dali::DevelWindow::Type Window::GetType() const
1075 bool Window::SetNotificationLevel( Dali::DevelWindow::NotificationLevel::Type level )
1077 if( mType != Dali::DevelWindow::NOTIFICATION )
1079 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
1083 while( !mEventHandler->mTizenPolicy )
1085 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1088 int notificationLevel;
1092 case Dali::DevelWindow::NotificationLevel::NONE:
1094 notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1097 case Dali::DevelWindow::NotificationLevel::BASE:
1099 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1102 case Dali::DevelWindow::NotificationLevel::MEDIUM:
1104 notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1107 case Dali::DevelWindow::NotificationLevel::HIGH:
1109 notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1112 case Dali::DevelWindow::NotificationLevel::TOP:
1114 notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1119 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: invalid level [%d]\n", level );
1120 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1125 mEventHandler->mNotificationLevelChangeDone = false;
1126 mEventHandler->mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1128 tizen_policy_set_notification_level( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), notificationLevel );
1132 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1135 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1139 if( !mEventHandler->mNotificationLevelChangeDone )
1141 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mEventHandler->mNotificationChangeState );
1144 else if( mEventHandler->mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1146 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Permission denied! [%d]\n", level );
1150 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level is changed [%d]\n", mEventHandler->mNotificationLevel );
1155 Dali::DevelWindow::NotificationLevel::Type Window::GetNotificationLevel()
1157 if( mType != Dali::DevelWindow::NOTIFICATION )
1159 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
1160 return Dali::DevelWindow::NotificationLevel::NONE;
1163 while( !mEventHandler->mTizenPolicy )
1165 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1170 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1173 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1177 if( !mEventHandler->mNotificationLevelChangeDone )
1179 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Error! [%d]\n", mEventHandler->mNotificationChangeState );
1180 return Dali::DevelWindow::NotificationLevel::NONE;
1183 Dali::DevelWindow::NotificationLevel::Type level;
1185 switch( mEventHandler->mNotificationLevel )
1187 case TIZEN_POLICY_LEVEL_NONE:
1189 level = Dali::DevelWindow::NotificationLevel::NONE;
1192 case TIZEN_POLICY_LEVEL_DEFAULT:
1194 level = Dali::DevelWindow::NotificationLevel::BASE;
1197 case TIZEN_POLICY_LEVEL_MEDIUM:
1199 level = Dali::DevelWindow::NotificationLevel::MEDIUM;
1202 case TIZEN_POLICY_LEVEL_HIGH:
1204 level = Dali::DevelWindow::NotificationLevel::HIGH;
1207 case TIZEN_POLICY_LEVEL_TOP:
1209 level = Dali::DevelWindow::NotificationLevel::TOP;
1214 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: invalid level [%d]\n", mEventHandler->mNotificationLevel );
1215 level = Dali::DevelWindow::NotificationLevel::NONE;
1220 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: level [%d]\n", mEventHandler->mNotificationLevel );
1225 void Window::SetOpaqueState( bool opaque )
1227 while( !mEventHandler->mTizenPolicy )
1229 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1232 tizen_policy_set_opaque_state( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), ( opaque ? 1 : 0 ) );
1234 mOpaqueState = opaque;
1236 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
1239 bool Window::IsOpaqueState()
1241 return mOpaqueState;
1244 bool Window::SetScreenMode( Dali::DevelWindow::ScreenMode::Type screenMode )
1246 while( !mEventHandler->mTizenPolicy )
1248 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1251 mEventHandler->mScreenModeChangeDone = false;
1252 mEventHandler->mScreenModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1254 unsigned int mode = 0;
1256 switch( screenMode )
1258 case Dali::DevelWindow::ScreenMode::DEFAULT:
1263 case Dali::DevelWindow::ScreenMode::ALWAYS_ON:
1270 tizen_policy_set_window_screen_mode( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), mode );
1274 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1277 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1281 if( !mEventHandler->mScreenModeChangeDone )
1283 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode change is failed [%d, %d]\n", screenMode, mEventHandler->mScreenModeChangeState );
1286 else if( mEventHandler->mScreenModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1288 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Permission denied! [%d]\n", screenMode );
1292 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode is changed [%d]\n", mEventHandler->mScreenMode );
1297 Dali::DevelWindow::ScreenMode::Type Window::GetScreenMode()
1299 while( !mEventHandler->mTizenPolicy )
1301 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1306 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1309 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1313 if( !mEventHandler->mScreenModeChangeDone )
1315 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: Error! [%d]\n", mEventHandler->mScreenModeChangeState );
1316 return Dali::DevelWindow::ScreenMode::DEFAULT;
1319 Dali::DevelWindow::ScreenMode::Type screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1321 switch( mEventHandler->mScreenMode )
1325 screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1330 screenMode = Dali::DevelWindow::ScreenMode::ALWAYS_ON;
1335 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: screen mode [%d]\n", mEventHandler->mScreenMode );
1340 bool Window::SetBrightness( int brightness )
1342 if( brightness < 0 || brightness > 100 )
1344 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
1348 while( !mEventHandler->mTizenDisplayPolicy )
1350 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1353 mEventHandler->mBrightnessChangeDone = false;
1354 mEventHandler->mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1356 tizen_display_policy_set_window_brightness( mEventHandler->mTizenDisplayPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), brightness );
1360 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1363 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1367 if( !mEventHandler->mBrightnessChangeDone )
1369 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mEventHandler->mBrightnessChangeState );
1372 else if( mEventHandler->mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1374 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Permission denied! [%d]\n", brightness );
1378 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness is changed [%d]\n", mEventHandler->mBrightness );
1383 int Window::GetBrightness()
1385 while( !mEventHandler->mTizenDisplayPolicy )
1387 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1392 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1395 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1399 if( !mEventHandler->mBrightnessChangeDone )
1401 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Error! [%d]\n", mEventHandler->mBrightnessChangeState );
1405 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Brightness [%d]\n", mEventHandler->mBrightness );
1407 return mEventHandler->mBrightness;