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 mScreenOffModeChangeState( 0 ),
82 mScreenOffModeChangeDone( 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 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) EcoreEventOutputTransform\n", handler->mEcoreWindow );
215 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( handler->mWindow->mSurface ) );
218 wlSurface->OutputTransformed();
220 PositionSize positionSize = wlSurface->GetPositionSize();
221 handler->mWindow->mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
222 handler->mWindow->mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
226 return ECORE_CALLBACK_PASS_ON;
229 /// Called when the output transform should be ignored
230 static Eina_Bool EcoreEventIgnoreOutputTransform( void* data, int type, void* event )
232 Ecore_Wl_Event_Ignore_Output_Transform* ignoreTransformEvent( static_cast< Ecore_Wl_Event_Ignore_Output_Transform* >( event ) );
233 EventHandler* handler( static_cast< EventHandler* >( data ) );
235 if ( handler && handler->mWindow && ignoreTransformEvent->win == handler->mEcoreWindow )
237 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) EcoreEventIgnoreOutputTransform\n", handler->mEcoreWindow );
239 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( handler->mWindow->mSurface ) );
242 wlSurface->OutputTransformed();
244 PositionSize positionSize = wlSurface->GetPositionSize();
245 handler->mWindow->mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
246 handler->mWindow->mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
250 return ECORE_CALLBACK_PASS_ON;
253 static void RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
255 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
257 if( strcmp( interface, tizen_policy_interface.name ) == 0 )
259 eventHandler->mTizenPolicy = static_cast< tizen_policy* >( wl_registry_bind( registry, name, &tizen_policy_interface, version ) );
260 if( !eventHandler->mTizenPolicy )
262 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n" );
266 tizen_policy_add_listener( eventHandler->mTizenPolicy, &eventHandler->mTizenPolicyListener, data );
268 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_policy_add_listener is called.\n" );
270 else if( strcmp( interface, tizen_display_policy_interface.name ) == 0 )
272 eventHandler->mTizenDisplayPolicy = static_cast< tizen_display_policy* >( wl_registry_bind( registry, name, &tizen_display_policy_interface, version ) );
273 if( !eventHandler->mTizenDisplayPolicy )
275 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n" );
279 tizen_display_policy_add_listener( eventHandler->mTizenDisplayPolicy, &eventHandler->mTizenDisplayPolicyListener, data );
281 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n" );
285 static void RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
287 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
288 eventHandler->mTizenPolicy = NULL;
289 eventHandler->mTizenDisplayPolicy = NULL;
292 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
294 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
296 eventHandler->mNotificationLevel = level;
297 eventHandler->mNotificationChangeState = state;
298 eventHandler->mNotificationLevelChangeDone = true;
300 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state );
303 static void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
305 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
307 eventHandler->mScreenOffMode = mode;
308 eventHandler->mScreenOffModeChangeState = state;
309 eventHandler->mScreenOffModeChangeDone = true;
311 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state );
314 static void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
316 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
318 eventHandler->mBrightness = brightness;
319 eventHandler->mBrightnessChangeState = state;
320 eventHandler->mBrightnessChangeDone = true;
322 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state );
325 const struct wl_registry_listener mRegistryListener =
327 RegistryGlobalCallback,
328 RegistryGlobalCallbackRemove
331 const struct tizen_policy_listener mTizenPolicyListener =
335 TizenPolicyNotificationChangeDone,
337 TizenPolicyScreenModeChangeDone,
344 const struct tizen_display_policy_listener mTizenDisplayPolicyListener =
346 DisplayPolicyBrightnessChangeDone
351 Dali::Vector< Ecore_Event_Handler* > mEcoreEventHandler;
352 Ecore_Wl_Window* mEcoreWindow;
354 wl_display* mDisplay;
355 wl_event_queue* mEventQueue;
356 tizen_policy* mTizenPolicy;
357 tizen_display_policy* mTizenDisplayPolicy;
359 int mNotificationLevel;
360 uint32_t mNotificationChangeState;
361 bool mNotificationLevelChangeDone;
364 uint32_t mScreenOffModeChangeState;
365 bool mScreenOffModeChangeDone;
368 uint32_t mBrightnessChangeState;
369 bool mBrightnessChangeDone;
372 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
374 Window* window = new Window();
375 window->mIsTransparent = isTransparent;
376 window->Initialize( positionSize, name, className );
380 void Window::SetAdaptor(Dali::Adaptor& adaptor)
382 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
385 // Only create one overlay per window
386 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
387 Integration::Core& core = adaptorImpl.GetCore();
388 mOverlay = &core.GetSystemOverlay();
390 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
391 taskList.CreateTask();
393 mAdaptor = &adaptorImpl;
394 mAdaptor->AddObserver( *this );
396 // Can only create the detector when we know the Core has been instantiated.
397 mDragAndDropDetector = DragAndDropDetector::New();
398 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
402 mOrientation->SetAdaptor(adaptor);
405 if( mIndicator != NULL )
407 mIndicator->SetAdaptor(mAdaptor);
411 RenderSurface* Window::GetSurface()
416 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
418 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
419 DALI_ASSERT_DEBUG(mOverlay);
421 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
422 DALI_ASSERT_DEBUG(wlSurface);
426 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
428 mIndicatorVisible = visibleMode;
430 if ( mIndicatorVisible == Dali::Window::VISIBLE )
432 // when the indicator is visible, set proper mode for indicator server according to bg mode
433 if ( mIndicatorOpacityMode == Dali::Window::OPAQUE )
435 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
437 else if ( mIndicatorOpacityMode == Dali::Window::TRANSLUCENT )
439 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSLUCENT);
441 else if ( mIndicatorOpacityMode == Dali::Window::TRANSPARENT )
443 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
448 // when the indicator is not visible, set TRANSPARENT mode for indicator server
449 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSPARENT); // it means hidden indicator
453 DoShowIndicator( mIndicatorOrientation );
456 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
458 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
460 DoRotateIndicator( orientation );
463 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
465 mIndicatorOpacityMode = opacityMode;
467 if( mIndicator != NULL )
469 mIndicator->SetOpacityMode( opacityMode );
473 void Window::SetClass(std::string name, std::string klass)
475 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
479 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
480 ecore_wl_window_title_set( wlWindow, name.c_str() );
481 ecore_wl_window_class_name_set( wlWindow, klass.c_str() );
485 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window has no surface\n" );
491 mIndicatorVisible( Dali::Window::VISIBLE ),
492 mIndicatorIsShown( false ),
493 mShowRotatedIndicatorOnClose( false ),
495 mIsTransparent( false ),
496 mWMRotationAppSet( false ),
497 mEcoreEventHander( true ),
498 mIsFocusAcceptable( true ),
500 mOpaqueState( false ),
501 mResizeEnabled( false ),
503 mIndicatorOrientation( Dali::Window::PORTRAIT ),
504 mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
505 mIndicatorOpacityMode( Dali::Window::OPAQUE ),
508 mType( Dali::Window::NORMAL ),
509 mEventHandler( NULL ),
510 mPreferredOrientation( Dali::Window::PORTRAIT ),
511 mSupportedAuxiliaryHints(),
513 mIndicatorVisibilityChangedSignal(),
514 mFocusChangedSignal(),
516 mDeleteRequestSignal()
522 delete mEventHandler;
532 mAdaptor->RemoveObserver( *this );
533 mAdaptor->SetDragAndDropDetector( NULL );
539 mSupportedAuxiliaryHints.clear();
540 mAuxiliaryHints.clear();
543 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
545 // create an Wayland window by default
547 ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( positionSize, surface, name, mIsTransparent );
549 mSurface = windowSurface;
551 // create event handler for Wayland window
552 mEventHandler = new EventHandler( this );
554 // get auxiliary hint
555 Eina_List* hints = ecore_wl_window_aux_hints_supported_get( mEventHandler->mEcoreWindow );
561 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) ) ) )
563 mSupportedAuxiliaryHints.push_back( hint );
565 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::Initialize: %s\n", hint );
569 if( !positionSize.IsEmpty() )
571 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
572 mResizeEnabled = true;
575 SetClass( name, className );
576 windowSurface->Map();
578 mOrientation = Orientation::New(this);
581 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
583 if( mIndicator == NULL )
585 if( mIndicatorVisible != Dali::Window::INVISIBLE )
587 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
588 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
589 Dali::Actor actor = mIndicator->GetActor();
590 SetIndicatorActorRotation();
591 mOverlay->Add(actor);
593 // else don't create a hidden indicator
595 else // Already have indicator
597 if( mIndicatorVisible == Dali::Window::VISIBLE )
599 // If we are resuming, and rotation has changed,
600 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
602 // then close current indicator and open new one
603 mShowRotatedIndicatorOnClose = true;
604 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
605 // Don't show actor - will contain indicator for old orientation.
610 // set indicator visible mode
611 if( mIndicator != NULL )
613 mIndicator->SetVisible( mIndicatorVisible );
616 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
617 SetIndicatorProperties( show, lastOrientation );
618 mIndicatorIsShown = show;
621 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
623 if( mIndicatorIsShown )
625 mShowRotatedIndicatorOnClose = true;
626 mNextIndicatorOrientation = orientation;
627 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
631 // Save orientation for when the indicator is next shown
632 mShowRotatedIndicatorOnClose = false;
633 mNextIndicatorOrientation = orientation;
637 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
639 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
643 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
646 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_ON);
650 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_OFF);
655 void Window::IndicatorTypeChanged(Indicator::Type type)
657 #if defined(DALI_PROFILE_MOBILE)
658 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
662 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
665 case Indicator::INDICATOR_TYPE_1:
666 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
669 case Indicator::INDICATOR_TYPE_2:
670 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_HIDDEN);
673 case Indicator::INDICATOR_TYPE_UNKNOWN:
681 void Window::IndicatorClosed( IndicatorInterface* indicator )
683 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
685 if( mShowRotatedIndicatorOnClose )
687 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
688 mIndicator->Open(mNextIndicatorOrientation);
689 mIndicatorOrientation = mNextIndicatorOrientation;
690 SetIndicatorActorRotation();
691 DoShowIndicator(currentOrientation);
695 void Window::IndicatorVisibilityChanged(bool isVisible)
697 mIndicatorVisibilityChangedSignal.Emit(isVisible);
700 void Window::SetIndicatorActorRotation()
702 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
703 DALI_ASSERT_DEBUG( mIndicator != NULL );
705 Dali::Actor actor = mIndicator->GetActor();
706 switch( mIndicatorOrientation )
708 case Dali::Window::PORTRAIT:
709 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
710 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
711 actor.SetOrientation( Degree(0), Vector3::ZAXIS );
713 case Dali::Window::PORTRAIT_INVERSE:
714 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
715 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
716 actor.SetOrientation( Degree(180), Vector3::ZAXIS );
718 case Dali::Window::LANDSCAPE:
719 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
720 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
721 actor.SetOrientation( Degree(270), Vector3::ZAXIS );
723 case Dali::Window::LANDSCAPE_INVERSE:
724 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
725 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
726 actor.SetOrientation( Degree(90), Vector3::ZAXIS );
733 // Use ecore_wl_window_activate to prevent the window shown without rendering
734 ecore_wl_window_activate( 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() const
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::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
901 wlSurface->RequestRotation( orientation, width, height );
904 mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( width, height ) );
907 mResizedSignal.Emit( Dali::Window::WindowSize( width, height ) );
909 mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( width, height ) );
912 void Window::SetIndicatorVisibleMode( Dali::Window::IndicatorVisibleMode mode )
914 mIndicatorVisible = mode;
917 unsigned int Window::GetSupportedAuxiliaryHintCount() const
919 return mSupportedAuxiliaryHints.size();
922 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
924 if( index >= GetSupportedAuxiliaryHintCount() )
926 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
929 return mSupportedAuxiliaryHints[index];
932 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
934 bool supported = false;
936 // Check if the hint is suppported
937 for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
948 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
952 // Check if the hint is already added
953 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
955 if( mAuxiliaryHints[i].first == hint )
957 // Just change the value
958 mAuxiliaryHints[i].second = value;
960 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
962 return i + 1; // id is index + 1
967 mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
969 unsigned int id = mAuxiliaryHints.size();
971 ecore_wl_window_aux_hint_add( mEventHandler->mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
973 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
978 bool Window::RemoveAuxiliaryHint( unsigned int id )
980 if( id == 0 || id > mAuxiliaryHints.size() )
982 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
986 mAuxiliaryHints[id - 1].second = std::string();
988 ecore_wl_window_aux_hint_del( mEventHandler->mEcoreWindow, static_cast< int >( id ) );
990 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
995 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
997 if( id == 0 || id > mAuxiliaryHints.size() )
999 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
1003 mAuxiliaryHints[id - 1].second = value;
1005 ecore_wl_window_aux_hint_change( mEventHandler->mEcoreWindow, static_cast< int >( id ), value.c_str() );
1007 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() );
1012 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
1014 if( id == 0 || id > mAuxiliaryHints.size() )
1016 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
1017 return std::string();
1020 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() );
1022 return mAuxiliaryHints[id - 1].second;
1025 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
1027 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
1029 if( mAuxiliaryHints[i].first == hint )
1031 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
1036 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
1041 void Window::SetInputRegion( const Rect< int >& inputRegion )
1043 ecore_wl_window_input_region_set( mEventHandler->mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
1045 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 );
1048 void Window::SetType( Dali::Window::Type type )
1050 Ecore_Wl_Window_Type windowType;
1056 case Dali::Window::NORMAL:
1058 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1061 case Dali::Window::NOTIFICATION:
1063 windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1066 case Dali::Window::UTILITY:
1068 windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1071 case Dali::Window::DIALOG:
1073 windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1078 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1083 ecore_wl_window_type_set( mEventHandler->mEcoreWindow, windowType );
1089 Dali::Window::Type Window::GetType() const
1094 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
1096 if( mType != Dali::Window::NOTIFICATION )
1098 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
1102 while( !mEventHandler->mTizenPolicy )
1104 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1107 int notificationLevel;
1111 case Dali::Window::NotificationLevel::NONE:
1113 notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1116 case Dali::Window::NotificationLevel::BASE:
1118 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1121 case Dali::Window::NotificationLevel::MEDIUM:
1123 notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1126 case Dali::Window::NotificationLevel::HIGH:
1128 notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1131 case Dali::Window::NotificationLevel::TOP:
1133 notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1138 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: invalid level [%d]\n", level );
1139 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1144 mEventHandler->mNotificationLevelChangeDone = false;
1145 mEventHandler->mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1147 tizen_policy_set_notification_level( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), notificationLevel );
1151 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1154 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1158 if( !mEventHandler->mNotificationLevelChangeDone )
1160 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mEventHandler->mNotificationChangeState );
1163 else if( mEventHandler->mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1165 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Permission denied! [%d]\n", level );
1169 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level is changed [%d]\n", mEventHandler->mNotificationLevel );
1174 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
1176 if( mType != Dali::Window::NOTIFICATION )
1178 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
1179 return Dali::Window::NotificationLevel::NONE;
1182 while( !mEventHandler->mTizenPolicy )
1184 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1189 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1192 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1196 if( !mEventHandler->mNotificationLevelChangeDone )
1198 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Error! [%d]\n", mEventHandler->mNotificationChangeState );
1199 return Dali::Window::NotificationLevel::NONE;
1202 Dali::Window::NotificationLevel::Type level;
1204 switch( mEventHandler->mNotificationLevel )
1206 case TIZEN_POLICY_LEVEL_NONE:
1208 level = Dali::Window::NotificationLevel::NONE;
1211 case TIZEN_POLICY_LEVEL_DEFAULT:
1213 level = Dali::Window::NotificationLevel::BASE;
1216 case TIZEN_POLICY_LEVEL_MEDIUM:
1218 level = Dali::Window::NotificationLevel::MEDIUM;
1221 case TIZEN_POLICY_LEVEL_HIGH:
1223 level = Dali::Window::NotificationLevel::HIGH;
1226 case TIZEN_POLICY_LEVEL_TOP:
1228 level = Dali::Window::NotificationLevel::TOP;
1233 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: invalid level [%d]\n", mEventHandler->mNotificationLevel );
1234 level = Dali::Window::NotificationLevel::NONE;
1239 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: level [%d]\n", mEventHandler->mNotificationLevel );
1244 void Window::SetOpaqueState( bool opaque )
1246 while( !mEventHandler->mTizenPolicy )
1248 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1251 tizen_policy_set_opaque_state( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), ( opaque ? 1 : 0 ) );
1253 mOpaqueState = opaque;
1255 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
1258 bool Window::IsOpaqueState() const
1260 return mOpaqueState;
1263 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
1265 while( !mEventHandler->mTizenPolicy )
1267 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1270 mEventHandler->mScreenOffModeChangeDone = false;
1271 mEventHandler->mScreenOffModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1273 unsigned int mode = 0;
1275 switch( screenOffMode )
1277 case Dali::Window::ScreenOffMode::TIMEOUT:
1282 case Dali::Window::ScreenOffMode::NEVER:
1289 tizen_policy_set_window_screen_mode( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), mode );
1293 while( !mEventHandler->mScreenOffModeChangeDone && count < 3 )
1296 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1300 if( !mEventHandler->mScreenOffModeChangeDone )
1302 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenOffMode: Screen mode change is failed [%d, %d]\n", screenOffMode, mEventHandler->mScreenOffModeChangeState );
1305 else if( mEventHandler->mScreenOffModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1307 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenOffMode: Permission denied! [%d]\n", screenOffMode );
1311 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenOffMode: Screen mode is changed [%d]\n", mEventHandler->mScreenOffMode );
1316 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
1318 while( !mEventHandler->mTizenPolicy )
1320 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1325 while( !mEventHandler->mScreenOffModeChangeDone && count < 3 )
1328 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1332 if( !mEventHandler->mScreenOffModeChangeDone )
1334 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenOffMode: Error! [%d]\n", mEventHandler->mScreenOffModeChangeState );
1335 return Dali::Window::ScreenOffMode::TIMEOUT;
1338 Dali::Window::ScreenOffMode::Type screenMode = Dali::Window::ScreenOffMode::TIMEOUT;
1340 switch( mEventHandler->mScreenOffMode )
1344 screenMode = Dali::Window::ScreenOffMode::TIMEOUT;
1349 screenMode = Dali::Window::ScreenOffMode::NEVER;
1354 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenOffMode: screen mode [%d]\n", mEventHandler->mScreenOffMode );
1359 bool Window::SetBrightness( int brightness )
1361 if( brightness < 0 || brightness > 100 )
1363 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
1367 while( !mEventHandler->mTizenDisplayPolicy )
1369 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1372 mEventHandler->mBrightnessChangeDone = false;
1373 mEventHandler->mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1375 tizen_display_policy_set_window_brightness( mEventHandler->mTizenDisplayPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), brightness );
1379 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1382 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1386 if( !mEventHandler->mBrightnessChangeDone )
1388 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mEventHandler->mBrightnessChangeState );
1391 else if( mEventHandler->mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1393 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Permission denied! [%d]\n", brightness );
1397 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness is changed [%d]\n", mEventHandler->mBrightness );
1402 int Window::GetBrightness() const
1404 while( !mEventHandler->mTizenDisplayPolicy )
1406 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1411 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1414 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1418 if( !mEventHandler->mBrightnessChangeDone )
1420 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Error! [%d]\n", mEventHandler->mBrightnessChangeState );
1424 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Brightness [%d]\n", mEventHandler->mBrightness );
1426 return mEventHandler->mBrightness;
1429 void Window::SetSize( Dali::Window::WindowSize size )
1431 if( !mResizeEnabled )
1433 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
1434 mResizeEnabled = true;
1437 PositionSize positionSize = mSurface->GetPositionSize();
1439 if( positionSize.width != size.GetWidth() || positionSize.height != size.GetHeight() )
1441 positionSize.width = size.GetWidth();
1442 positionSize.height = size.GetHeight();
1444 mSurface->MoveResize( positionSize );
1446 mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
1449 mResizedSignal.Emit( Dali::Window::WindowSize( positionSize.width, positionSize.height ) );
1451 mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
1455 Dali::Window::WindowSize Window::GetSize() const
1457 PositionSize positionSize = mSurface->GetPositionSize();
1459 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
1462 void Window::SetPosition( Dali::Window::WindowPosition position )
1464 if( !mResizeEnabled )
1466 AddAuxiliaryHint( "wm.policy.win.user.geometry", "1" );
1467 mResizeEnabled = true;
1470 PositionSize positionSize = mSurface->GetPositionSize();
1472 if( positionSize.x != position.GetX() || positionSize.y != position.GetY() )
1474 positionSize.x = position.GetX();
1475 positionSize.y = position.GetY();
1477 mSurface->MoveResize( positionSize );
1481 Dali::Window::WindowPosition Window::GetPosition() const
1483 PositionSize positionSize = mSurface->GetPositionSize();
1485 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
1488 void Window::SetTransparency( bool transparent )
1490 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
1493 wlSurface->SetTransparency( transparent );
1503 #pragma GCC diagnostic pop