2 * Copyright (c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <window-impl.h>
23 #include <Ecore_Wayland.h>
24 #include <tizen-extension-client-protocol.h>
26 #include <dali/integration-api/core.h>
27 #include <dali/integration-api/system-overlay.h>
28 #include <dali/public-api/render-tasks/render-task.h>
29 #include <dali/public-api/render-tasks/render-task-list.h>
30 #include <orientation.h>
33 #include <window-render-surface.h>
34 #include <drag-and-drop-detector-impl.h>
35 #include <ecore-indicator-impl.h>
36 #include <window-visibility-observer.h>
37 #include <orientation-impl.h>
41 const float INDICATOR_ANIMATION_DURATION( 0.18f ); // 180 milli seconds
42 const float INDICATOR_SHOW_Y_POSITION( 0.0f );
43 const float INDICATOR_HIDE_Y_POSITION( -52.0f );
53 #if defined(DEBUG_ENABLED)
54 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
58 * TODO: Abstract Window class out and move this into a window implementation for Ecore
60 struct Window::EventHandler
64 * @param[in] window A pointer to the window class.
66 EventHandler( Window* window )
68 mWindowPropertyHandler( NULL ),
69 mWindowIconifyStateHandler( NULL ),
70 mWindowFocusInHandler( NULL ),
71 mWindowFocusOutHandler( NULL ),
76 mTizenDisplayPolicy( NULL ),
77 mNotificationLevel( -1 ),
78 mNotificationChangeState( 0 ),
79 mNotificationLevelChangeDone( true ),
81 mScreenModeChangeState( 0 ),
82 mScreenModeChangeDone( true ),
84 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 mWindowIconifyStateHandler = ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this );
98 mWindowFocusInHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this );
99 mWindowFocusOutHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this );
102 mDisplay = ecore_wl_display_get();
106 wl_display* displayWrapper = static_cast< wl_display* >( wl_proxy_create_wrapper( mDisplay ) );
109 mEventQueue = wl_display_create_queue( mDisplay );
112 wl_proxy_set_queue( reinterpret_cast< wl_proxy* >( displayWrapper ), mEventQueue );
114 wl_registry* registry = wl_display_get_registry( displayWrapper );
115 wl_registry_add_listener( registry, &mRegistryListener, this );
118 wl_proxy_wrapper_destroy( displayWrapper );
128 if ( mWindowPropertyHandler )
130 ecore_event_handler_del( mWindowPropertyHandler );
132 if ( mWindowIconifyStateHandler )
134 ecore_event_handler_del( mWindowIconifyStateHandler );
136 if( mWindowFocusInHandler )
138 ecore_event_handler_del( mWindowFocusInHandler );
140 if( mWindowFocusOutHandler )
142 ecore_event_handler_del( mWindowFocusOutHandler );
146 wl_event_queue_destroy( mEventQueue );
152 /// Called when the window properties are changed.
153 static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
158 /// Called when the window iconify state is changed.
159 static Eina_Bool EcoreEventWindowIconifyStateChanged( void* data, int type, void* event )
161 Ecore_Wl_Event_Window_Iconify_State_Change* iconifyChangedEvent( static_cast< Ecore_Wl_Event_Window_Iconify_State_Change* >( event ) );
162 EventHandler* handler( static_cast< EventHandler* >( data ) );
163 Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
165 if ( handler && handler->mWindow )
167 WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
168 if ( observer && ( iconifyChangedEvent->win == static_cast< unsigned int> ( ecore_wl_window_id_get( handler->mEcoreWindow ) ) ) )
170 if( iconifyChangedEvent->iconified == EINA_TRUE )
172 observer->OnWindowHidden();
173 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Iconfied\n", handler->mEcoreWindow );
177 observer->OnWindowShown();
178 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Shown\n", handler->mEcoreWindow );
180 handled = ECORE_CALLBACK_DONE;
187 /// Called when the window gains focus
188 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
190 Ecore_Wl_Event_Focus_In* focusInEvent( static_cast< Ecore_Wl_Event_Focus_In* >( event ) );
191 EventHandler* handler( static_cast< EventHandler* >( data ) );
193 if ( handler && handler->mWindow && focusInEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
195 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n" );
197 handler->mWindow->mFocusChangedSignal.Emit( true );
200 return ECORE_CALLBACK_PASS_ON;
203 /// Called when the window loses focus
204 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
206 Ecore_Wl_Event_Focus_Out* focusOutEvent( static_cast< Ecore_Wl_Event_Focus_Out* >( event ) );
207 EventHandler* handler( static_cast< EventHandler* >( data ) );
209 if ( handler && handler->mWindow && focusOutEvent->win == static_cast< unsigned int >(ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
211 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n" );
213 handler->mWindow->mFocusChangedSignal.Emit( false );
216 return ECORE_CALLBACK_PASS_ON;
219 static void RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
221 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
223 if( strcmp( interface, tizen_policy_interface.name ) == 0 )
225 eventHandler->mTizenPolicy = static_cast< tizen_policy* >( wl_registry_bind( registry, name, &tizen_policy_interface, version ) );
226 if( !eventHandler->mTizenPolicy )
228 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n" );
232 tizen_policy_add_listener( eventHandler->mTizenPolicy, &eventHandler->mTizenPolicyListener, data );
234 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_policy_add_listener is called.\n" );
236 else if( strcmp( interface, tizen_display_policy_interface.name ) == 0 )
238 eventHandler->mTizenDisplayPolicy = static_cast< tizen_display_policy* >( wl_registry_bind( registry, name, &tizen_display_policy_interface, version ) );
239 if( !eventHandler->mTizenDisplayPolicy )
241 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n" );
245 tizen_display_policy_add_listener( eventHandler->mTizenDisplayPolicy, &eventHandler->mTizenDisplayPolicyListener, data );
247 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n" );
251 static void RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
253 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
254 eventHandler->mTizenPolicy = NULL;
255 eventHandler->mTizenDisplayPolicy = NULL;
258 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
260 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
262 eventHandler->mNotificationLevel = level;
263 eventHandler->mNotificationChangeState = state;
264 eventHandler->mNotificationLevelChangeDone = true;
266 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state );
269 static void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
271 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
273 eventHandler->mScreenMode = mode;
274 eventHandler->mScreenModeChangeState = state;
275 eventHandler->mScreenModeChangeDone = true;
277 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state );
280 static void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
282 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
284 eventHandler->mBrightness = brightness;
285 eventHandler->mBrightnessChangeState = state;
286 eventHandler->mBrightnessChangeDone = true;
288 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state );
291 const struct wl_registry_listener mRegistryListener =
293 RegistryGlobalCallback,
294 RegistryGlobalCallbackRemove
297 const struct tizen_policy_listener mTizenPolicyListener =
301 TizenPolicyNotificationChangeDone,
303 TizenPolicyScreenModeChangeDone,
310 const struct tizen_display_policy_listener mTizenDisplayPolicyListener =
312 DisplayPolicyBrightnessChangeDone
317 Ecore_Event_Handler* mWindowPropertyHandler;
318 Ecore_Event_Handler* mWindowIconifyStateHandler;
319 Ecore_Event_Handler* mWindowFocusInHandler;
320 Ecore_Event_Handler* mWindowFocusOutHandler;
321 Ecore_Wl_Window* mEcoreWindow;
323 wl_display* mDisplay;
324 wl_event_queue* mEventQueue;
325 tizen_policy* mTizenPolicy;
326 tizen_display_policy* mTizenDisplayPolicy;
328 int mNotificationLevel;
329 uint32_t mNotificationChangeState;
330 bool mNotificationLevelChangeDone;
333 uint32_t mScreenModeChangeState;
334 bool mScreenModeChangeDone;
337 uint32_t mBrightnessChangeState;
338 bool mBrightnessChangeDone;
341 Window* Window::New(const PositionSize& posSize, const std::string& name, const std::string& className, bool isTransparent)
343 Window* window = new Window();
344 window->mIsTransparent = isTransparent;
345 window->Initialize(posSize, name, className);
349 void Window::SetAdaptor(Dali::Adaptor& adaptor)
351 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
354 // Only create one overlay per window
355 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
356 Integration::Core& core = adaptorImpl.GetCore();
357 mOverlay = &core.GetSystemOverlay();
359 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
360 taskList.CreateTask();
362 mAdaptor = &adaptorImpl;
363 mAdaptor->AddObserver( *this );
365 // Can only create the detector when we know the Core has been instantiated.
366 mDragAndDropDetector = DragAndDropDetector::New();
367 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
371 mOrientation->SetAdaptor(adaptor);
374 if( mIndicator != NULL )
376 mIndicator->SetAdaptor(mAdaptor);
380 RenderSurface* Window::GetSurface()
385 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
387 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
388 DALI_ASSERT_DEBUG(mOverlay);
390 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
391 DALI_ASSERT_DEBUG(wlSurface);
395 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
397 mIndicatorVisible = visibleMode;
399 if ( mIndicatorVisible == Dali::Window::VISIBLE )
401 // when the indicator is visible, set proper mode for indicator server according to bg mode
402 if ( mIndicatorOpacityMode == Dali::Window::OPAQUE )
404 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
406 else if ( mIndicatorOpacityMode == Dali::Window::TRANSLUCENT )
408 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSLUCENT);
410 else if ( mIndicatorOpacityMode == Dali::Window::TRANSPARENT )
412 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
417 // when the indicator is not visible, set TRANSPARENT mode for indicator server
418 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSPARENT); // it means hidden indicator
422 DoShowIndicator( mIndicatorOrientation );
425 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
427 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
429 DoRotateIndicator( orientation );
432 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
434 mIndicatorOpacityMode = opacityMode;
436 if( mIndicator != NULL )
438 mIndicator->SetOpacityMode( opacityMode );
442 void Window::SetClass(std::string name, std::string klass)
444 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
448 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
449 ecore_wl_window_title_set( wlWindow, name.c_str() );
450 ecore_wl_window_class_name_set( wlWindow, klass.c_str() );
454 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window has no surface\n" );
460 mIndicatorVisible( Dali::Window::VISIBLE ),
461 mIndicatorIsShown( false ),
462 mShowRotatedIndicatorOnClose( false ),
464 mIsTransparent( false ),
465 mWMRotationAppSet( false ),
466 mEcoreEventHander( true ),
467 mIsFocusAcceptable( true ),
469 mOpaqueState( false ),
471 mIndicatorOrientation( Dali::Window::PORTRAIT ),
472 mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
473 mIndicatorOpacityMode( Dali::Window::OPAQUE ),
476 mType( Dali::DevelWindow::NORMAL ),
477 mEventHandler( NULL ),
478 mPreferredOrientation( Dali::Window::PORTRAIT ),
479 mSupportedAuxiliaryHints(),
486 delete mEventHandler;
496 mAdaptor->RemoveObserver( *this );
497 mAdaptor->SetDragAndDropDetector( NULL );
503 mSupportedAuxiliaryHints.clear();
504 mAuxiliaryHints.clear();
507 void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
509 // create an Wayland window by default
511 ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
513 mSurface = windowSurface;
514 SetClass( name, className );
515 windowSurface->Map();
517 mOrientation = Orientation::New(this);
519 // create event handler for Wayland window
520 mEventHandler = new EventHandler( this );
522 // get auxiliary hint
523 Eina_List* hints = ecore_wl_window_aux_hints_supported_get( mEventHandler->mEcoreWindow );
529 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) ) ) )
531 mSupportedAuxiliaryHints.push_back( hint );
533 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::Initialize: %s\n", hint );
538 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
540 if( mIndicator == NULL )
542 if( mIndicatorVisible != Dali::Window::INVISIBLE )
544 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
545 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
546 Dali::Actor actor = mIndicator->GetActor();
547 SetIndicatorActorRotation();
548 mOverlay->Add(actor);
550 // else don't create a hidden indicator
552 else // Already have indicator
554 if( mIndicatorVisible == Dali::Window::VISIBLE )
556 // If we are resuming, and rotation has changed,
557 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
559 // then close current indicator and open new one
560 mShowRotatedIndicatorOnClose = true;
561 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
562 // Don't show actor - will contain indicator for old orientation.
567 // set indicator visible mode
568 if( mIndicator != NULL )
570 mIndicator->SetVisible( mIndicatorVisible );
573 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
574 SetIndicatorProperties( show, lastOrientation );
575 mIndicatorIsShown = show;
578 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
580 if( mIndicatorIsShown )
582 mShowRotatedIndicatorOnClose = true;
583 mNextIndicatorOrientation = orientation;
584 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
588 // Save orientation for when the indicator is next shown
589 mShowRotatedIndicatorOnClose = false;
590 mNextIndicatorOrientation = orientation;
594 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
596 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
600 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
603 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_ON);
607 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_OFF);
612 void Window::IndicatorTypeChanged(Indicator::Type type)
614 #if defined(DALI_PROFILE_MOBILE)
615 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
619 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
622 case Indicator::INDICATOR_TYPE_1:
623 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
626 case Indicator::INDICATOR_TYPE_2:
627 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_HIDDEN);
630 case Indicator::INDICATOR_TYPE_UNKNOWN:
638 void Window::IndicatorClosed( IndicatorInterface* indicator )
640 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
642 if( mShowRotatedIndicatorOnClose )
644 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
645 mIndicator->Open(mNextIndicatorOrientation);
646 mIndicatorOrientation = mNextIndicatorOrientation;
647 SetIndicatorActorRotation();
648 DoShowIndicator(currentOrientation);
652 void Window::IndicatorVisibilityChanged(bool isVisible)
654 mIndicatorVisibilityChangedSignal.Emit(isVisible);
657 void Window::SetIndicatorActorRotation()
659 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
660 DALI_ASSERT_DEBUG( mIndicator != NULL );
662 Dali::Actor actor = mIndicator->GetActor();
663 switch( mIndicatorOrientation )
665 case Dali::Window::PORTRAIT:
666 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
667 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
668 actor.SetOrientation( Degree(0), Vector3::ZAXIS );
670 case Dali::Window::PORTRAIT_INVERSE:
671 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
672 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
673 actor.SetOrientation( Degree(180), Vector3::ZAXIS );
675 case Dali::Window::LANDSCAPE:
676 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
677 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
678 actor.SetOrientation( Degree(270), Vector3::ZAXIS );
680 case Dali::Window::LANDSCAPE_INVERSE:
681 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
682 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
683 actor.SetOrientation( Degree(90), Vector3::ZAXIS );
690 ecore_wl_window_raise( mEventHandler->mEcoreWindow );
695 ecore_wl_window_lower( mEventHandler->mEcoreWindow );
698 void Window::Activate()
700 ecore_wl_window_activate( mEventHandler->mEcoreWindow );
703 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
705 return mDragAndDropDetector;
708 Dali::Any Window::GetNativeHandle() const
712 return mEventHandler->mEcoreWindow;
720 void Window::OnStart()
722 DoShowIndicator( mIndicatorOrientation );
725 void Window::OnPause()
729 void Window::OnResume()
731 // resume indicator status
732 if( mIndicator != NULL )
734 // Restore own indicator opacity
735 // Send opacity mode to indicator service when app resumed
736 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
740 void Window::OnStop()
751 void Window::OnDestroy()
756 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
760 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
762 if(mAvailableOrientations[i] == orientation)
771 mAvailableOrientations.push_back(orientation);
772 SetAvailableOrientations( mAvailableOrientations );
776 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
778 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
779 iter != mAvailableOrientations.end(); ++iter )
781 if( *iter == orientation )
783 mAvailableOrientations.erase( iter );
787 SetAvailableOrientations( mAvailableOrientations );
790 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
793 for( std::size_t i = 0; i < mAvailableOrientations.size(); ++i )
795 rotations[i] = static_cast< int >( mAvailableOrientations[i] );
797 ecore_wl_window_rotation_available_rotations_set( mEventHandler->mEcoreWindow, rotations, mAvailableOrientations.size() );
800 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
802 return mAvailableOrientations;
805 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
807 mPreferredOrientation = orientation;
809 ecore_wl_window_rotation_preferred_rotation_set( mEventHandler->mEcoreWindow, orientation );
812 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
814 return mPreferredOrientation;
817 void Window::SetAcceptFocus( bool accept )
819 mIsFocusAcceptable = accept;
821 ecore_wl_window_focus_skip_set( mEventHandler->mEcoreWindow, !accept );
824 bool Window::IsFocusAcceptable()
826 return mIsFocusAcceptable;
832 ecore_wl_window_show( mEventHandler->mEcoreWindow );
834 // Need an update request
837 mAdaptor->RequestUpdateOnce();
844 ecore_wl_window_hide( mEventHandler->mEcoreWindow );
847 bool Window::IsVisible() const
852 void Window::RotationDone( int orientation, int width, int height )
854 ecore_wl_window_rotation_change_done_send( mEventHandler->mEcoreWindow );
857 unsigned int Window::GetSupportedAuxiliaryHintCount()
859 return mSupportedAuxiliaryHints.size();
862 std::string Window::GetSupportedAuxiliaryHint( unsigned int index )
864 if( index >= GetSupportedAuxiliaryHintCount() )
866 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
869 return mSupportedAuxiliaryHints[index];
872 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
874 bool supported = false;
876 // Check if the hint is suppported
877 for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
888 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
892 // Check if the hint is already added
893 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
895 if( mAuxiliaryHints[i].first == hint )
897 // Just change the value
898 mAuxiliaryHints[i].second = value;
900 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
902 return i + 1; // id is index + 1
907 mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
909 unsigned int id = mAuxiliaryHints.size();
911 ecore_wl_window_aux_hint_add( mEventHandler->mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
913 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
918 bool Window::RemoveAuxiliaryHint( unsigned int id )
920 if( id == 0 || id > mAuxiliaryHints.size() )
922 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
926 mAuxiliaryHints[id - 1].second = std::string();
928 ecore_wl_window_aux_hint_del( mEventHandler->mEcoreWindow, static_cast< int >( id ) );
930 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
935 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
937 if( id == 0 || id > mAuxiliaryHints.size() )
939 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
943 mAuxiliaryHints[id - 1].second = value;
945 ecore_wl_window_aux_hint_change( mEventHandler->mEcoreWindow, static_cast< int >( id ), value.c_str() );
947 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() );
952 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
954 if( id == 0 || id > mAuxiliaryHints.size() )
956 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
957 return std::string();
960 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() );
962 return mAuxiliaryHints[id - 1].second;
965 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
967 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
969 if( mAuxiliaryHints[i].first == hint )
971 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
976 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
981 void Window::SetInputRegion( const Rect< int >& inputRegion )
983 ecore_wl_window_input_region_set( mEventHandler->mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
985 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 );
988 void Window::SetType( Dali::DevelWindow::Type type )
990 Ecore_Wl_Window_Type windowType;
996 case Dali::DevelWindow::NORMAL:
998 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1001 case Dali::DevelWindow::NOTIFICATION:
1003 windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1006 case Dali::DevelWindow::UTILITY:
1008 windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1011 case Dali::DevelWindow::DIALOG:
1013 windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1018 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1023 ecore_wl_window_type_set( mEventHandler->mEcoreWindow, windowType );
1029 Dali::DevelWindow::Type Window::GetType() const
1034 bool Window::SetNotificationLevel( Dali::DevelWindow::NotificationLevel::Type level )
1036 if( mType != Dali::DevelWindow::NOTIFICATION )
1038 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
1042 while( !mEventHandler->mTizenPolicy )
1044 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1047 int notificationLevel;
1051 case Dali::DevelWindow::NotificationLevel::NONE:
1053 notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1056 case Dali::DevelWindow::NotificationLevel::BASE:
1058 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1061 case Dali::DevelWindow::NotificationLevel::MEDIUM:
1063 notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1066 case Dali::DevelWindow::NotificationLevel::HIGH:
1068 notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1071 case Dali::DevelWindow::NotificationLevel::TOP:
1073 notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1078 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: invalid level [%d]\n", level );
1079 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1084 mEventHandler->mNotificationLevelChangeDone = false;
1085 mEventHandler->mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1087 tizen_policy_set_notification_level( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), notificationLevel );
1091 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1094 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1098 if( !mEventHandler->mNotificationLevelChangeDone )
1100 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mEventHandler->mNotificationChangeState );
1103 else if( mEventHandler->mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1105 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Permission denied! [%d]\n", level );
1109 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level is changed [%d]\n", mEventHandler->mNotificationLevel );
1114 Dali::DevelWindow::NotificationLevel::Type Window::GetNotificationLevel()
1116 if( mType != Dali::DevelWindow::NOTIFICATION )
1118 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
1119 return Dali::DevelWindow::NotificationLevel::NONE;
1122 while( !mEventHandler->mTizenPolicy )
1124 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1129 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1132 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1136 if( !mEventHandler->mNotificationLevelChangeDone )
1138 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Error! [%d]\n", mEventHandler->mNotificationChangeState );
1139 return Dali::DevelWindow::NotificationLevel::NONE;
1142 Dali::DevelWindow::NotificationLevel::Type level;
1144 switch( mEventHandler->mNotificationLevel )
1146 case TIZEN_POLICY_LEVEL_NONE:
1148 level = Dali::DevelWindow::NotificationLevel::NONE;
1151 case TIZEN_POLICY_LEVEL_DEFAULT:
1153 level = Dali::DevelWindow::NotificationLevel::BASE;
1156 case TIZEN_POLICY_LEVEL_MEDIUM:
1158 level = Dali::DevelWindow::NotificationLevel::MEDIUM;
1161 case TIZEN_POLICY_LEVEL_HIGH:
1163 level = Dali::DevelWindow::NotificationLevel::HIGH;
1166 case TIZEN_POLICY_LEVEL_TOP:
1168 level = Dali::DevelWindow::NotificationLevel::TOP;
1173 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: invalid level [%d]\n", mEventHandler->mNotificationLevel );
1174 level = Dali::DevelWindow::NotificationLevel::NONE;
1179 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: level [%d]\n", mEventHandler->mNotificationLevel );
1184 void Window::SetOpaqueState( bool opaque )
1186 while( !mEventHandler->mTizenPolicy )
1188 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1191 tizen_policy_set_opaque_state( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), ( opaque ? 1 : 0 ) );
1193 mOpaqueState = opaque;
1195 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
1198 bool Window::IsOpaqueState()
1200 return mOpaqueState;
1203 bool Window::SetScreenMode( Dali::DevelWindow::ScreenMode::Type screenMode )
1205 while( !mEventHandler->mTizenPolicy )
1207 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1210 mEventHandler->mScreenModeChangeDone = false;
1211 mEventHandler->mScreenModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1213 unsigned int mode = 0;
1215 switch( screenMode )
1217 case Dali::DevelWindow::ScreenMode::DEFAULT:
1222 case Dali::DevelWindow::ScreenMode::ALWAYS_ON:
1229 tizen_policy_set_window_screen_mode( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), mode );
1233 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1236 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1240 if( !mEventHandler->mScreenModeChangeDone )
1242 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode change is failed [%d, %d]\n", screenMode, mEventHandler->mScreenModeChangeState );
1245 else if( mEventHandler->mScreenModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1247 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Permission denied! [%d]\n", screenMode );
1251 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode is changed [%d]\n", mEventHandler->mScreenMode );
1256 Dali::DevelWindow::ScreenMode::Type Window::GetScreenMode()
1258 while( !mEventHandler->mTizenPolicy )
1260 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1265 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1268 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1272 if( !mEventHandler->mScreenModeChangeDone )
1274 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: Error! [%d]\n", mEventHandler->mScreenModeChangeState );
1275 return Dali::DevelWindow::ScreenMode::DEFAULT;
1278 Dali::DevelWindow::ScreenMode::Type screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1280 switch( mEventHandler->mScreenMode )
1284 screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1289 screenMode = Dali::DevelWindow::ScreenMode::ALWAYS_ON;
1294 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: screen mode [%d]\n", mEventHandler->mScreenMode );
1299 bool Window::SetBrightness( int brightness )
1301 if( brightness < 0 || brightness > 100 )
1303 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
1307 while( !mEventHandler->mTizenDisplayPolicy )
1309 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1312 mEventHandler->mBrightnessChangeDone = false;
1313 mEventHandler->mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1315 tizen_display_policy_set_window_brightness( mEventHandler->mTizenDisplayPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), brightness );
1319 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1322 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1326 if( !mEventHandler->mBrightnessChangeDone )
1328 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mEventHandler->mBrightnessChangeState );
1331 else if( mEventHandler->mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1333 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Permission denied! [%d]\n", brightness );
1337 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness is changed [%d]\n", mEventHandler->mBrightness );
1342 int Window::GetBrightness()
1344 while( !mEventHandler->mTizenDisplayPolicy )
1346 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1351 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1354 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1358 if( !mEventHandler->mBrightnessChangeDone )
1360 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Error! [%d]\n", mEventHandler->mBrightnessChangeState );
1364 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Brightness [%d]\n", mEventHandler->mBrightness );
1366 return mEventHandler->mBrightness;
1369 void* Window::GetNativeWindowHandler()
1371 return mEventHandler->mEcoreWindow;