2 * Copyright (c) 2014 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>
25 #include <dali/integration-api/core.h>
26 #include <dali/integration-api/system-overlay.h>
27 #include <dali/public-api/render-tasks/render-task.h>
28 #include <dali/public-api/render-tasks/render-task-list.h>
29 #include <orientation.h>
32 #include <window-render-surface.h>
33 #include <drag-and-drop-detector-impl.h>
34 #include <ecore-indicator-impl.h>
35 #include <window-visibility-observer.h>
36 #include <orientation-impl.h>
39 const float INDICATOR_ANIMATION_DURATION( 0.18f ); // 180 milli seconds
40 const float INDICATOR_SHOW_Y_POSITION( 0.0f );
41 const float INDICATOR_HIDE_Y_POSITION( -52.0f );
50 #if defined(DEBUG_ENABLED)
51 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_WINDOW");
55 * TODO: Abstract Window class out and move this into a window implementation for Ecore
57 struct Window::EventHandler
61 * @param[in] window A pointer to the window class.
63 EventHandler( Window* window )
65 mWindowPropertyHandler( NULL ),
66 mClientMessageHandler( NULL ),
69 // store ecore window handle
70 ECore::WindowRenderSurface* wlWindow( dynamic_cast< ECore::WindowRenderSurface * >( mWindow->mSurface ) );
73 mEcoreWindow = wlWindow->GetWlWindow();
75 DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no ecore Wl window");
83 if ( mWindowPropertyHandler )
85 ecore_event_handler_del( mWindowPropertyHandler );
87 if ( mClientMessageHandler )
89 ecore_event_handler_del( mClientMessageHandler );
95 /// Called when the window properties are changed.
96 static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
101 /// Called when the window properties are changed.
102 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
109 Ecore_Event_Handler* mWindowPropertyHandler;
110 Ecore_Event_Handler* mClientMessageHandler;
111 Ecore_Wl_Window* mEcoreWindow;
115 Window* Window::New(const PositionSize& posSize, const std::string& name, const std::string& className, bool isTransparent)
117 Window* window = new Window();
118 window->mIsTransparent = isTransparent;
119 window->Initialize(posSize, name, className);
123 void Window::SetAdaptor(Dali::Adaptor& adaptor)
125 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
128 // Only create one overlay per window
129 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
130 Integration::Core& core = adaptorImpl.GetCore();
131 mOverlay = &core.GetSystemOverlay();
133 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
134 taskList.CreateTask();
136 mAdaptor = &adaptorImpl;
137 mAdaptor->AddObserver( *this );
139 // Can only create the detector when we know the Core has been instantiated.
140 mDragAndDropDetector = DragAndDropDetector::New();
141 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
145 mOrientation->SetAdaptor(adaptor);
148 if( mIndicator != NULL )
150 mIndicator->SetAdaptor(mAdaptor);
154 RenderSurface* Window::GetSurface()
159 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
161 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
162 DALI_ASSERT_DEBUG(mOverlay);
164 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
165 DALI_ASSERT_DEBUG(wlSurface);
166 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
168 mIndicatorVisible = visibleMode;
170 if ( mIndicatorVisible == Dali::Window::VISIBLE )
172 // when the indicator is visible, set proper mode for indicator server according to bg mode
173 if ( mIndicatorOpacityMode == Dali::Window::OPAQUE )
175 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
177 else if ( mIndicatorOpacityMode == Dali::Window::TRANSLUCENT )
179 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSLUCENT);
181 else if ( mIndicatorOpacityMode == Dali::Window::TRANSPARENT )
183 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_OPAQUE);
188 // when the indicator is not visible, set TRANSPARENT mode for indicator server
189 ecore_wl_window_indicator_opacity_set(wlWindow, ECORE_WL_INDICATOR_TRANSPARENT); // it means hidden indicator
192 DoShowIndicator( mIndicatorOrientation );
195 void Window::RotateIndicator(Dali::Window::WindowOrientation orientation)
197 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
199 DoRotateIndicator( orientation );
202 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
204 mIndicatorOpacityMode = opacityMode;
206 if( mIndicator != NULL )
208 mIndicator->SetOpacityMode( opacityMode );
212 void Window::SetClass(std::string name, std::string klass)
214 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
218 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
219 ecore_wl_window_title_set( wlWindow, name.c_str() );
220 ecore_wl_window_class_name_set( wlWindow, klass.c_str() );
224 DALI_LOG_INFO( gWindowLogFilter, Debug::General, "Window has no surface\n" );
230 mIndicatorVisible(Dali::Window::VISIBLE),
231 mIndicatorIsShown(false),
232 mShowRotatedIndicatorOnClose(false),
234 mIsTransparent(false),
235 mWMRotationAppSet(false),
236 mEcoreEventHander(true),
238 mIndicatorOrientation(Dali::Window::PORTRAIT),
239 mNextIndicatorOrientation(Dali::Window::PORTRAIT),
240 mIndicatorOpacityMode(Dali::Window::OPAQUE),
244 mPreferredOrientation(Dali::Window::PORTRAIT)
250 delete mEventHandler;
260 mAdaptor->RemoveObserver( *this );
261 mAdaptor->SetDragAndDropDetector( NULL );
268 void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
270 // create an Wayland window by default
272 ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
274 mSurface = windowSurface;
275 SetClass( name, className );
276 windowSurface->Map();
278 mOrientation = Orientation::New(this);
280 // create event handler for Wayland window
281 mEventHandler = new EventHandler( this );
284 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
286 if( mIndicator == NULL )
288 if( mIndicatorVisible != Dali::Window::INVISIBLE )
290 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
291 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
292 Dali::Actor actor = mIndicator->GetActor();
293 SetIndicatorActorRotation();
294 mOverlay->Add(actor);
296 // else don't create a hidden indicator
298 else // Already have indicator
300 if( mIndicatorVisible == Dali::Window::VISIBLE )
302 // If we are resuming, and rotation has changed,
303 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
305 // then close current indicator and open new one
306 mShowRotatedIndicatorOnClose = true;
307 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
308 // Don't show actor - will contain indicator for old orientation.
313 // set indicator visible mode
314 if( mIndicator != NULL )
316 mIndicator->SetVisible( mIndicatorVisible );
319 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
320 SetIndicatorProperties( show, lastOrientation );
321 mIndicatorIsShown = show;
324 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
326 if( mIndicatorIsShown )
328 mShowRotatedIndicatorOnClose = true;
329 mNextIndicatorOrientation = orientation;
330 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
334 // Save orientation for when the indicator is next shown
335 mShowRotatedIndicatorOnClose = false;
336 mNextIndicatorOrientation = orientation;
340 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
342 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
346 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
349 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_ON);
353 ecore_wl_window_indicator_state_set(wlWindow, ECORE_WL_INDICATOR_STATE_OFF);
358 void Window::IndicatorTypeChanged(Indicator::Type type)
360 #if defined(DALI_PROFILE_MOBILE)
361 ECore::WindowRenderSurface* wlSurface( dynamic_cast< ECore::WindowRenderSurface * >( mSurface ) );
365 Ecore_Wl_Window* wlWindow = wlSurface->GetWlWindow();
368 case Indicator::INDICATOR_TYPE_1:
369 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_SHOWN);
372 case Indicator::INDICATOR_TYPE_2:
373 ecore_wl_indicator_visible_type_set(wlWindow, ECORE_WL_INDICATOR_VISIBLE_TYPE_HIDDEN);
376 case Indicator::INDICATOR_TYPE_UNKNOWN:
384 void Window::IndicatorClosed( IndicatorInterface* indicator )
386 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
388 if( mShowRotatedIndicatorOnClose )
390 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
391 mIndicator->Open(mNextIndicatorOrientation);
392 mIndicatorOrientation = mNextIndicatorOrientation;
393 SetIndicatorActorRotation();
394 DoShowIndicator(currentOrientation);
398 void Window::IndicatorVisibilityChanged(bool isVisible)
400 mIndicatorVisibilityChangedSignal.Emit(isVisible);
403 void Window::SetIndicatorActorRotation()
405 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
406 DALI_ASSERT_DEBUG( mIndicator != NULL );
408 Dali::Actor actor = mIndicator->GetActor();
409 switch( mIndicatorOrientation )
411 case Dali::Window::PORTRAIT:
412 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
413 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
414 actor.SetOrientation( Degree(0), Vector3::ZAXIS );
416 case Dali::Window::PORTRAIT_INVERSE:
417 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
418 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
419 actor.SetOrientation( Degree(180), Vector3::ZAXIS );
421 case Dali::Window::LANDSCAPE:
422 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
423 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
424 actor.SetOrientation( Degree(270), Vector3::ZAXIS );
426 case Dali::Window::LANDSCAPE_INVERSE:
427 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
428 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
429 actor.SetOrientation( Degree(90), Vector3::ZAXIS );
442 void Window::Activate()
446 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
448 return mDragAndDropDetector;
451 Dali::Any Window::GetNativeHandle() const
455 return mEventHandler->mEcoreWindow;
463 void Window::OnStart()
465 DoShowIndicator( mIndicatorOrientation );
468 void Window::OnPause()
472 void Window::OnResume()
474 // resume indicator status
475 if( mIndicator != NULL )
477 // Restore own indicator opacity
478 // Send opacity mode to indicator service when app resumed
479 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
483 void Window::OnStop()
494 void Window::OnDestroy()
499 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
503 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
505 if(mAvailableOrientations[i] == orientation)
514 mAvailableOrientations.push_back(orientation);
515 SetAvailableOrientations( mAvailableOrientations );
519 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
521 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
522 iter != mAvailableOrientations.end(); ++iter )
524 if( *iter == orientation )
526 mAvailableOrientations.erase( iter );
530 SetAvailableOrientations( mAvailableOrientations );
533 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
535 DALI_ASSERT_ALWAYS( mAvailableOrientations.size() <= 4 && "Incorrect number of available orientations" );
538 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
540 return mAvailableOrientations;
543 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
545 mPreferredOrientation = orientation;
548 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
550 return mPreferredOrientation;
553 void Window::RotationDone( int orientation, int width, int height )