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 // store ecore window handle
85 ECore::WindowRenderSurface* wlWindow( dynamic_cast< ECore::WindowRenderSurface * >( mWindow->mSurface ) );
88 mEcoreWindow = wlWindow->GetWlWindow();
90 DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no ecore Wl window");
92 if( mWindow->mEcoreEventHander )
94 mWindowIconifyStateHandler = ecore_event_handler_add( ECORE_WL_EVENT_WINDOW_ICONIFY_STATE_CHANGE, EcoreEventWindowIconifyStateChanged, this );
95 mWindowFocusInHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_IN, EcoreEventWindowFocusIn, this );
96 mWindowFocusOutHandler = ecore_event_handler_add( ECORE_WL_EVENT_FOCUS_OUT, EcoreEventWindowFocusOut, this );
99 mDisplay = ecore_wl_display_get();
103 wl_display* displayWrapper = static_cast< wl_display* >( wl_proxy_create_wrapper( mDisplay ) );
106 mEventQueue = wl_display_create_queue( mDisplay );
109 wl_proxy_set_queue( reinterpret_cast< wl_proxy* >( displayWrapper ), mEventQueue );
111 wl_registry* registry = wl_display_get_registry( displayWrapper );
112 wl_registry_add_listener( registry, &mRegistryListener, this );
115 wl_proxy_wrapper_destroy( displayWrapper );
125 if ( mWindowPropertyHandler )
127 ecore_event_handler_del( mWindowPropertyHandler );
129 if ( mWindowIconifyStateHandler )
131 ecore_event_handler_del( mWindowIconifyStateHandler );
133 if( mWindowFocusInHandler )
135 ecore_event_handler_del( mWindowFocusInHandler );
137 if( mWindowFocusOutHandler )
139 ecore_event_handler_del( mWindowFocusOutHandler );
143 wl_event_queue_destroy( mEventQueue );
149 /// Called when the window properties are changed.
150 static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
155 /// Called when the window iconify state is changed.
156 static Eina_Bool EcoreEventWindowIconifyStateChanged( void* data, int type, void* event )
158 Ecore_Wl_Event_Window_Iconify_State_Change* iconifyChangedEvent( static_cast< Ecore_Wl_Event_Window_Iconify_State_Change* >( event ) );
159 EventHandler* handler( static_cast< EventHandler* >( data ) );
160 Eina_Bool handled( ECORE_CALLBACK_PASS_ON );
162 if ( handler && handler->mWindow )
164 WindowVisibilityObserver* observer( handler->mWindow->mAdaptor );
165 if ( observer && ( iconifyChangedEvent->win == static_cast< unsigned int> ( ecore_wl_window_id_get( handler->mEcoreWindow ) ) ) )
167 if( iconifyChangedEvent->iconified == EINA_TRUE )
169 observer->OnWindowHidden();
170 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Iconfied\n", handler->mEcoreWindow );
174 observer->OnWindowShown();
175 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window (%d) Shown\n", handler->mEcoreWindow );
177 handled = ECORE_CALLBACK_DONE;
184 /// Called when the window gains focus
185 static Eina_Bool EcoreEventWindowFocusIn( void* data, int type, void* event )
187 Ecore_Wl_Event_Focus_In* focusInEvent( static_cast< Ecore_Wl_Event_Focus_In* >( event ) );
188 EventHandler* handler( static_cast< EventHandler* >( data ) );
190 if ( handler && handler->mWindow && focusInEvent->win == static_cast< unsigned int >( ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
192 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusIn\n" );
194 handler->mWindow->mFocusChangedSignal.Emit( true );
197 return ECORE_CALLBACK_PASS_ON;
200 /// Called when the window loses focus
201 static Eina_Bool EcoreEventWindowFocusOut( void* data, int type, void* event )
203 Ecore_Wl_Event_Focus_Out* focusOutEvent( static_cast< Ecore_Wl_Event_Focus_Out* >( event ) );
204 EventHandler* handler( static_cast< EventHandler* >( data ) );
206 if ( handler && handler->mWindow && focusOutEvent->win == static_cast< unsigned int >(ecore_wl_window_id_get( handler->mEcoreWindow ) ) )
208 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window EcoreEventWindowFocusOut\n" );
210 handler->mWindow->mFocusChangedSignal.Emit( false );
213 return ECORE_CALLBACK_PASS_ON;
216 static void RegistryGlobalCallback( void* data, struct wl_registry *registry, uint32_t name, const char* interface, uint32_t version )
218 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
220 if( strcmp( interface, tizen_policy_interface.name ) == 0 )
222 eventHandler->mTizenPolicy = static_cast< tizen_policy* >( wl_registry_bind( registry, name, &tizen_policy_interface, version ) );
223 if( !eventHandler->mTizenPolicy )
225 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_policy_interface) is failed.\n" );
229 tizen_policy_add_listener( eventHandler->mTizenPolicy, &eventHandler->mTizenPolicyListener, data );
231 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_policy_add_listener is called.\n" );
233 else if( strcmp( interface, tizen_display_policy_interface.name ) == 0 )
235 eventHandler->mTizenDisplayPolicy = static_cast< tizen_display_policy* >( wl_registry_bind( registry, name, &tizen_display_policy_interface, version ) );
236 if( !eventHandler->mTizenDisplayPolicy )
238 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: wl_registry_bind(tizen_display_policy_interface) is failed.\n" );
242 tizen_display_policy_add_listener( eventHandler->mTizenDisplayPolicy, &eventHandler->mTizenDisplayPolicyListener, data );
244 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::RegistryGlobalCallback: tizen_display_policy_add_listener is called.\n" );
248 static void RegistryGlobalCallbackRemove( void* data, struct wl_registry* registry, uint32_t id )
250 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
251 eventHandler->mTizenPolicy = NULL;
252 eventHandler->mTizenDisplayPolicy = NULL;
255 static void TizenPolicyNotificationChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, int32_t level, uint32_t state )
257 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
259 eventHandler->mNotificationLevel = level;
260 eventHandler->mNotificationChangeState = state;
261 eventHandler->mNotificationLevelChangeDone = true;
263 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyNotificationChangeDone: level = %d, state = %d\n", level, state );
266 static void TizenPolicyScreenModeChangeDone(void* data, struct tizen_policy* tizenPolicy, struct wl_surface* surface, uint32_t mode, uint32_t state )
268 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
270 eventHandler->mScreenMode = mode;
271 eventHandler->mScreenModeChangeState = state;
272 eventHandler->mScreenModeChangeDone = true;
274 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::TizenPolicyScreenModeChangeDone: mode = %d, state = %d\n", mode, state );
277 static void DisplayPolicyBrightnessChangeDone(void* data, struct tizen_display_policy *displayPolicy, struct wl_surface* surface, int32_t brightness, uint32_t state )
279 Window::EventHandler* eventHandler = static_cast< Window::EventHandler* >( data );
281 eventHandler->mBrightness = brightness;
282 eventHandler->mBrightnessChangeState = state;
283 eventHandler->mBrightnessChangeDone = true;
285 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window::EventHandler::DisplayPolicyBrightnessChangeDone: brightness = %d, state = %d\n", brightness, state );
288 const struct wl_registry_listener mRegistryListener =
290 RegistryGlobalCallback,
291 RegistryGlobalCallbackRemove
294 const struct tizen_policy_listener mTizenPolicyListener =
298 TizenPolicyNotificationChangeDone,
300 TizenPolicyScreenModeChangeDone,
307 const struct tizen_display_policy_listener mTizenDisplayPolicyListener =
309 DisplayPolicyBrightnessChangeDone
314 Ecore_Event_Handler* mWindowPropertyHandler;
315 Ecore_Event_Handler* mWindowIconifyStateHandler;
316 Ecore_Event_Handler* mWindowFocusInHandler;
317 Ecore_Event_Handler* mWindowFocusOutHandler;
318 Ecore_Wl_Window* mEcoreWindow;
320 wl_display* mDisplay;
321 wl_event_queue* mEventQueue;
322 tizen_policy* mTizenPolicy;
323 tizen_display_policy* mTizenDisplayPolicy;
325 int mNotificationLevel;
326 uint32_t mNotificationChangeState;
327 bool mNotificationLevelChangeDone;
330 uint32_t mScreenModeChangeState;
331 bool mScreenModeChangeDone;
334 uint32_t mBrightnessChangeState;
335 bool mBrightnessChangeDone;
338 Window* Window::New(const PositionSize& posSize, const std::string& name, const std::string& className, bool isTransparent)
340 Window* window = new Window();
341 window->mIsTransparent = isTransparent;
342 window->Initialize(posSize, name, className);
346 void Window::SetAdaptor(Dali::Adaptor& adaptor)
348 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
351 // Only create one overlay per window
352 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
353 Integration::Core& core = adaptorImpl.GetCore();
354 mOverlay = &core.GetSystemOverlay();
356 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
357 taskList.CreateTask();
359 mAdaptor = &adaptorImpl;
360 mAdaptor->AddObserver( *this );
362 // Can only create the detector when we know the Core has been instantiated.
363 mDragAndDropDetector = DragAndDropDetector::New();
364 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
368 mOrientation->SetAdaptor(adaptor);
371 if( mIndicator != NULL )
373 mIndicator->SetAdaptor(mAdaptor);
377 RenderSurface* Window::GetSurface()
382 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
384 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
385 DALI_ASSERT_DEBUG(mOverlay);
387 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
388 DALI_ASSERT_DEBUG(wlSurface);
392 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
394 mIndicatorVisible = visibleMode;
396 if ( mIndicatorVisible == Dali::Window::VISIBLE )
398 // when the indicator is visible, set proper mode for indicator server according to bg mode
399 if ( mIndicatorOpacityMode == Dali::Window::OPAQUE )
401 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
403 else if ( mIndicatorOpacityMode == Dali::Window::TRANSLUCENT )
405 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSLUCENT);
407 else if ( mIndicatorOpacityMode == Dali::Window::TRANSPARENT )
409 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
414 // when the indicator is not visible, set TRANSPARENT mode for indicator server
415 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSPARENT); // it means hidden indicator
419 DoShowIndicator( mIndicatorOrientation );
422 void Window::RotateIndicator( Dali::Window::WindowOrientation orientation )
424 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
426 DoRotateIndicator( orientation );
429 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
431 mIndicatorOpacityMode = opacityMode;
433 if( mIndicator != NULL )
435 mIndicator->SetOpacityMode( opacityMode );
439 void Window::SetClass(std::string name, std::string klass)
441 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
445 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
446 ecore_wl_window_title_set( wlWindow, name.c_str() );
447 ecore_wl_window_class_name_set( wlWindow, klass.c_str() );
451 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window has no surface\n" );
457 mIndicatorVisible( Dali::Window::VISIBLE ),
458 mIndicatorIsShown( false ),
459 mShowRotatedIndicatorOnClose( false ),
461 mIsTransparent( false ),
462 mWMRotationAppSet( false ),
463 mEcoreEventHander( true ),
464 mIsFocusAcceptable( true ),
466 mOpaqueState( false ),
468 mIndicatorOrientation( Dali::Window::PORTRAIT ),
469 mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
470 mIndicatorOpacityMode( Dali::Window::OPAQUE ),
473 mType( Dali::DevelWindow::NORMAL ),
474 mEventHandler( NULL ),
475 mPreferredOrientation( Dali::Window::PORTRAIT ),
476 mSupportedAuxiliaryHints(),
483 delete mEventHandler;
493 mAdaptor->RemoveObserver( *this );
494 mAdaptor->SetDragAndDropDetector( NULL );
500 mSupportedAuxiliaryHints.clear();
501 mAuxiliaryHints.clear();
504 void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
506 // create an Wayland window by default
508 ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
510 mSurface = windowSurface;
511 SetClass( name, className );
512 windowSurface->Map();
514 mOrientation = Orientation::New(this);
516 // create event handler for Wayland window
517 mEventHandler = new EventHandler( this );
519 // get auxiliary hint
520 Eina_List* hints = ecore_wl_window_aux_hints_supported_get( mEventHandler->mEcoreWindow );
526 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) ) ) )
528 mSupportedAuxiliaryHints.push_back( hint );
530 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::Initialize: %s\n", hint );
535 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
537 if( mIndicator == NULL )
539 if( mIndicatorVisible != Dali::Window::INVISIBLE )
541 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
542 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
543 Dali::Actor actor = mIndicator->GetActor();
544 SetIndicatorActorRotation();
545 mOverlay->Add(actor);
547 // else don't create a hidden indicator
549 else // Already have indicator
551 if( mIndicatorVisible == Dali::Window::VISIBLE )
553 // If we are resuming, and rotation has changed,
554 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
556 // then close current indicator and open new one
557 mShowRotatedIndicatorOnClose = true;
558 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
559 // Don't show actor - will contain indicator for old orientation.
564 // set indicator visible mode
565 if( mIndicator != NULL )
567 mIndicator->SetVisible( mIndicatorVisible );
570 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
571 SetIndicatorProperties( show, lastOrientation );
572 mIndicatorIsShown = show;
575 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
577 if( mIndicatorIsShown )
579 mShowRotatedIndicatorOnClose = true;
580 mNextIndicatorOrientation = orientation;
581 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
585 // Save orientation for when the indicator is next shown
586 mShowRotatedIndicatorOnClose = false;
587 mNextIndicatorOrientation = orientation;
591 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
593 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
597 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
600 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_ON);
604 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_OFF);
609 void Window::IndicatorTypeChanged(Indicator::Type type)
611 #if defined(DALI_PROFILE_MOBILE)
612 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
616 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
619 case Indicator::INDICATOR_TYPE_1:
620 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
623 case Indicator::INDICATOR_TYPE_2:
624 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_HIDDEN);
627 case Indicator::INDICATOR_TYPE_UNKNOWN:
635 void Window::IndicatorClosed( IndicatorInterface* indicator )
637 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
639 if( mShowRotatedIndicatorOnClose )
641 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
642 mIndicator->Open(mNextIndicatorOrientation);
643 mIndicatorOrientation = mNextIndicatorOrientation;
644 SetIndicatorActorRotation();
645 DoShowIndicator(currentOrientation);
649 void Window::IndicatorVisibilityChanged(bool isVisible)
651 mIndicatorVisibilityChangedSignal.Emit(isVisible);
654 void Window::SetIndicatorActorRotation()
656 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
657 DALI_ASSERT_DEBUG( mIndicator != NULL );
659 Dali::Actor actor = mIndicator->GetActor();
660 switch( mIndicatorOrientation )
662 case Dali::Window::PORTRAIT:
663 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
664 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
665 actor.SetOrientation( Degree(0), Vector3::ZAXIS );
667 case Dali::Window::PORTRAIT_INVERSE:
668 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
669 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
670 actor.SetOrientation( Degree(180), Vector3::ZAXIS );
672 case Dali::Window::LANDSCAPE:
673 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
674 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
675 actor.SetOrientation( Degree(270), Vector3::ZAXIS );
677 case Dali::Window::LANDSCAPE_INVERSE:
678 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
679 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
680 actor.SetOrientation( Degree(90), Vector3::ZAXIS );
687 ecore_wl_window_raise( mEventHandler->mEcoreWindow );
692 ecore_wl_window_lower( mEventHandler->mEcoreWindow );
695 void Window::Activate()
697 ecore_wl_window_activate( mEventHandler->mEcoreWindow );
700 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
702 return mDragAndDropDetector;
705 Dali::Any Window::GetNativeHandle() const
709 return mEventHandler->mEcoreWindow;
717 void Window::OnStart()
719 DoShowIndicator( mIndicatorOrientation );
722 void Window::OnPause()
726 void Window::OnResume()
728 // resume indicator status
729 if( mIndicator != NULL )
731 // Restore own indicator opacity
732 // Send opacity mode to indicator service when app resumed
733 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
737 void Window::OnStop()
748 void Window::OnDestroy()
753 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
757 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
759 if(mAvailableOrientations[i] == orientation)
768 mAvailableOrientations.push_back(orientation);
769 SetAvailableOrientations( mAvailableOrientations );
773 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
775 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
776 iter != mAvailableOrientations.end(); ++iter )
778 if( *iter == orientation )
780 mAvailableOrientations.erase( iter );
784 SetAvailableOrientations( mAvailableOrientations );
787 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
790 for( std::size_t i = 0; i < mAvailableOrientations.size(); ++i )
792 rotations[i] = static_cast< int >( mAvailableOrientations[i] );
794 ecore_wl_window_rotation_available_rotations_set( mEventHandler->mEcoreWindow, rotations, mAvailableOrientations.size() );
797 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
799 return mAvailableOrientations;
802 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
804 mPreferredOrientation = orientation;
806 ecore_wl_window_rotation_preferred_rotation_set( mEventHandler->mEcoreWindow, orientation );
809 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
811 return mPreferredOrientation;
814 void Window::SetAcceptFocus( bool accept )
816 mIsFocusAcceptable = accept;
818 ecore_wl_window_focus_skip_set( mEventHandler->mEcoreWindow, !accept );
821 bool Window::IsFocusAcceptable()
823 return mIsFocusAcceptable;
829 ecore_wl_window_show( mEventHandler->mEcoreWindow );
831 // Need an update request
834 mAdaptor->RequestUpdateOnce();
841 ecore_wl_window_hide( mEventHandler->mEcoreWindow );
844 bool Window::IsVisible() const
849 void Window::RotationDone( int orientation, int width, int height )
851 ecore_wl_window_rotation_change_done_send( mEventHandler->mEcoreWindow );
854 unsigned int Window::GetSupportedAuxiliaryHintCount()
856 return mSupportedAuxiliaryHints.size();
859 std::string Window::GetSupportedAuxiliaryHint( unsigned int index )
861 if( index >= GetSupportedAuxiliaryHintCount() )
863 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetSupportedAuxiliaryHint: Invalid index! [%d]\n", index );
866 return mSupportedAuxiliaryHints[index];
869 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
871 bool supported = false;
873 // Check if the hint is suppported
874 for( std::vector< std::string >::iterator iter = mSupportedAuxiliaryHints.begin(); iter != mSupportedAuxiliaryHints.end(); ++iter )
885 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::AddAuxiliaryHint: Not supported auxiliary hint [%s]\n", hint.c_str() );
889 // Check if the hint is already added
890 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
892 if( mAuxiliaryHints[i].first == hint )
894 // Just change the value
895 mAuxiliaryHints[i].second = value;
897 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: Change! hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), i + 1 );
899 return i + 1; // id is index + 1
904 mAuxiliaryHints.push_back( std::pair< std::string, std::string >( hint, value ) );
906 unsigned int id = mAuxiliaryHints.size();
908 ecore_wl_window_aux_hint_add( mEventHandler->mEcoreWindow, static_cast< int >( id ), hint.c_str(), value.c_str() );
910 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::AddAuxiliaryHint: hint = %s, value = %s, id = %d\n", hint.c_str(), value.c_str(), id );
915 bool Window::RemoveAuxiliaryHint( unsigned int id )
917 if( id == 0 || id > mAuxiliaryHints.size() )
919 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::RemoveAuxiliaryHint: Invalid id [%d]\n", id );
923 mAuxiliaryHints[id - 1].second = std::string();
925 ecore_wl_window_aux_hint_del( mEventHandler->mEcoreWindow, static_cast< int >( id ) );
927 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::RemoveAuxiliaryHint: id = %d, hint = %s\n", id, mAuxiliaryHints[id - 1].first.c_str() );
932 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
934 if( id == 0 || id > mAuxiliaryHints.size() )
936 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::SetAuxiliaryHintValue: Invalid id [%d]\n", id );
940 mAuxiliaryHints[id - 1].second = value;
942 ecore_wl_window_aux_hint_change( mEventHandler->mEcoreWindow, static_cast< int >( id ), value.c_str() );
944 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() );
949 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
951 if( id == 0 || id > mAuxiliaryHints.size() )
953 DALI_LOG_INFO( gWindowLogFilter, Debug::Concise, "Window::GetAuxiliaryHintValue: Invalid id [%d]\n", id );
954 return std::string();
957 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() );
959 return mAuxiliaryHints[id - 1].second;
962 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
964 for( unsigned int i = 0; i < mAuxiliaryHints.size(); i++ )
966 if( mAuxiliaryHints[i].first == hint )
968 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: hint = %s, id = %d\n", hint.c_str(), i + 1 );
973 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetAuxiliaryHintId: Invalid hint! [%s]\n", hint.c_str() );
978 void Window::SetInputRegion( const Rect< int >& inputRegion )
980 ecore_wl_window_input_region_set( mEventHandler->mEcoreWindow, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height );
982 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 );
985 void Window::SetType( Dali::DevelWindow::Type type )
987 Ecore_Wl_Window_Type windowType;
993 case Dali::DevelWindow::NORMAL:
995 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
998 case Dali::DevelWindow::NOTIFICATION:
1000 windowType = ECORE_WL_WINDOW_TYPE_NOTIFICATION;
1003 case Dali::DevelWindow::UTILITY:
1005 windowType = ECORE_WL_WINDOW_TYPE_UTILITY;
1008 case Dali::DevelWindow::DIALOG:
1010 windowType = ECORE_WL_WINDOW_TYPE_DIALOG;
1015 windowType = ECORE_WL_WINDOW_TYPE_TOPLEVEL;
1020 ecore_wl_window_type_set( mEventHandler->mEcoreWindow, windowType );
1026 Dali::DevelWindow::Type Window::GetType() const
1031 bool Window::SetNotificationLevel( Dali::DevelWindow::NotificationLevel::Type level )
1033 if( mType != Dali::DevelWindow::NOTIFICATION )
1035 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", mType );
1039 while( !mEventHandler->mTizenPolicy )
1041 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1044 int notificationLevel;
1048 case Dali::DevelWindow::NotificationLevel::NONE:
1050 notificationLevel = TIZEN_POLICY_LEVEL_NONE;
1053 case Dali::DevelWindow::NotificationLevel::BASE:
1055 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1058 case Dali::DevelWindow::NotificationLevel::MEDIUM:
1060 notificationLevel = TIZEN_POLICY_LEVEL_MEDIUM;
1063 case Dali::DevelWindow::NotificationLevel::HIGH:
1065 notificationLevel = TIZEN_POLICY_LEVEL_HIGH;
1068 case Dali::DevelWindow::NotificationLevel::TOP:
1070 notificationLevel = TIZEN_POLICY_LEVEL_TOP;
1075 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: invalid level [%d]\n", level );
1076 notificationLevel = TIZEN_POLICY_LEVEL_DEFAULT;
1081 mEventHandler->mNotificationLevelChangeDone = false;
1082 mEventHandler->mNotificationChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1084 tizen_policy_set_notification_level( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), notificationLevel );
1088 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1091 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1095 if( !mEventHandler->mNotificationLevelChangeDone )
1097 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level change is failed [%d, %d]\n", level, mEventHandler->mNotificationChangeState );
1100 else if( mEventHandler->mNotificationChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1102 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Permission denied! [%d]\n", level );
1106 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Level is changed [%d]\n", mEventHandler->mNotificationLevel );
1111 Dali::DevelWindow::NotificationLevel::Type Window::GetNotificationLevel()
1113 if( mType != Dali::DevelWindow::NOTIFICATION )
1115 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", mType );
1116 return Dali::DevelWindow::NotificationLevel::NONE;
1119 while( !mEventHandler->mTizenPolicy )
1121 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1126 while( !mEventHandler->mNotificationLevelChangeDone && count < 3 )
1129 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1133 if( !mEventHandler->mNotificationLevelChangeDone )
1135 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Error! [%d]\n", mEventHandler->mNotificationChangeState );
1136 return Dali::DevelWindow::NotificationLevel::NONE;
1139 Dali::DevelWindow::NotificationLevel::Type level;
1141 switch( mEventHandler->mNotificationLevel )
1143 case TIZEN_POLICY_LEVEL_NONE:
1145 level = Dali::DevelWindow::NotificationLevel::NONE;
1148 case TIZEN_POLICY_LEVEL_DEFAULT:
1150 level = Dali::DevelWindow::NotificationLevel::BASE;
1153 case TIZEN_POLICY_LEVEL_MEDIUM:
1155 level = Dali::DevelWindow::NotificationLevel::MEDIUM;
1158 case TIZEN_POLICY_LEVEL_HIGH:
1160 level = Dali::DevelWindow::NotificationLevel::HIGH;
1163 case TIZEN_POLICY_LEVEL_TOP:
1165 level = Dali::DevelWindow::NotificationLevel::TOP;
1170 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: invalid level [%d]\n", mEventHandler->mNotificationLevel );
1171 level = Dali::DevelWindow::NotificationLevel::NONE;
1176 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: level [%d]\n", mEventHandler->mNotificationLevel );
1181 void Window::SetOpaqueState( bool opaque )
1183 while( !mEventHandler->mTizenPolicy )
1185 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1188 tizen_policy_set_opaque_state( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), ( opaque ? 1 : 0 ) );
1190 mOpaqueState = opaque;
1192 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque );
1195 bool Window::IsOpaqueState()
1197 return mOpaqueState;
1200 bool Window::SetScreenMode( Dali::DevelWindow::ScreenMode::Type screenMode )
1202 while( !mEventHandler->mTizenPolicy )
1204 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1207 mEventHandler->mScreenModeChangeDone = false;
1208 mEventHandler->mScreenModeChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1210 unsigned int mode = 0;
1212 switch( screenMode )
1214 case Dali::DevelWindow::ScreenMode::DEFAULT:
1219 case Dali::DevelWindow::ScreenMode::ALWAYS_ON:
1226 tizen_policy_set_window_screen_mode( mEventHandler->mTizenPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), mode );
1230 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1233 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1237 if( !mEventHandler->mScreenModeChangeDone )
1239 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode change is failed [%d, %d]\n", screenMode, mEventHandler->mScreenModeChangeState );
1242 else if( mEventHandler->mScreenModeChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1244 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Permission denied! [%d]\n", screenMode );
1248 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetScreenMode: Screen mode is changed [%d]\n", mEventHandler->mScreenMode );
1253 Dali::DevelWindow::ScreenMode::Type Window::GetScreenMode()
1255 while( !mEventHandler->mTizenPolicy )
1257 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1262 while( !mEventHandler->mScreenModeChangeDone && count < 3 )
1265 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1269 if( !mEventHandler->mScreenModeChangeDone )
1271 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: Error! [%d]\n", mEventHandler->mScreenModeChangeState );
1272 return Dali::DevelWindow::ScreenMode::DEFAULT;
1275 Dali::DevelWindow::ScreenMode::Type screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1277 switch( mEventHandler->mScreenMode )
1281 screenMode = Dali::DevelWindow::ScreenMode::DEFAULT;
1286 screenMode = Dali::DevelWindow::ScreenMode::ALWAYS_ON;
1291 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetScreenMode: screen mode [%d]\n", mEventHandler->mScreenMode );
1296 bool Window::SetBrightness( int brightness )
1298 if( brightness < 0 || brightness > 100 )
1300 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness );
1304 while( !mEventHandler->mTizenDisplayPolicy )
1306 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1309 mEventHandler->mBrightnessChangeDone = false;
1310 mEventHandler->mBrightnessChangeState = TIZEN_POLICY_ERROR_STATE_NONE;
1312 tizen_display_policy_set_window_brightness( mEventHandler->mTizenDisplayPolicy, ecore_wl_window_surface_get( mEventHandler->mEcoreWindow ), brightness );
1316 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1319 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1323 if( !mEventHandler->mBrightnessChangeDone )
1325 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness change is failed [%d, %d]\n", brightness, mEventHandler->mBrightnessChangeState );
1328 else if( mEventHandler->mBrightnessChangeState == TIZEN_POLICY_ERROR_STATE_PERMISSION_DENIED )
1330 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Permission denied! [%d]\n", brightness );
1334 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Brightness is changed [%d]\n", mEventHandler->mBrightness );
1339 int Window::GetBrightness()
1341 while( !mEventHandler->mTizenDisplayPolicy )
1343 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1348 while( !mEventHandler->mBrightnessChangeDone && count < 3 )
1351 wl_display_dispatch_queue( mEventHandler->mDisplay, mEventHandler->mEventQueue );
1355 if( !mEventHandler->mBrightnessChangeDone )
1357 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Error! [%d]\n", mEventHandler->mBrightnessChangeState );
1361 DALI_LOG_INFO( gWindowLogFilter, Debug::Verbose, "Window::GetBrightness: Brightness [%d]\n", mEventHandler->mBrightness );
1363 return mEventHandler->mBrightness;
1366 void* Window::GetNativeWindowHandler()
1368 return mEventHandler->mEcoreWindow;