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 <indicator-impl.h>
35 #include <window-visibility-observer.h>
36 #include <orientation-impl.h>
40 const float INDICATOR_ANIMATION_DURATION( 0.18f ); // 180 milli seconds
41 const float INDICATOR_SHOW_Y_POSITION( 0.0f );
42 const float INDICATOR_HIDE_Y_POSITION( -52.0f );
51 #if defined(DEBUG_ENABLED)
52 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_WINDOW");
56 * TODO: Abstract Window class out and move this into a window implementation for Ecore
58 struct Window::EventHandler
62 * @param[in] window A pointer to the window class.
64 EventHandler( Window* window )
66 mWindowPropertyHandler( NULL ),
67 mClientMessagehandler( NULL ),
70 // store ecore window handle
71 ECore::WindowRenderSurface* wlWindow( dynamic_cast< ECore::WindowRenderSurface * >( mWindow->mSurface ) );
74 mEcoreWindow = wlWindow->GetWlWindow();
76 DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no ecore wl window");
84 if ( mWindowPropertyHandler )
86 ecore_event_handler_del( mWindowPropertyHandler );
88 if ( mClientMessagehandler )
90 ecore_event_handler_del( mClientMessagehandler );
96 /// Called when the window properties are changed.
97 static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
102 /// Called when the window properties are changed.
103 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
110 Ecore_Event_Handler* mWindowPropertyHandler;
111 Ecore_Event_Handler* mClientMessagehandler;
112 Ecore_Wl_Window* mEcoreWindow;
116 Window* Window::New(const PositionSize& posSize, const std::string& name, const std::string& className, bool isTransparent)
118 Window* window = new Window();
119 window->mIsTransparent = isTransparent;
120 window->Initialize(posSize, name, className);
124 void Window::SetAdaptor(Dali::Adaptor& adaptor)
126 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
129 // Only create one overlay per window
130 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
131 Integration::Core& core = adaptorImpl.GetCore();
132 mOverlay = &core.GetSystemOverlay();
134 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
135 taskList.CreateTask();
137 mAdaptor = &adaptorImpl;
138 mAdaptor->AddObserver( *this );
140 // Can only create the detector when we know the Core has been instantiated.
141 mDragAndDropDetector = DragAndDropDetector::New();
142 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
146 mOrientation->SetAdaptor(adaptor);
149 if( mIndicator != NULL )
151 mIndicator->SetAdaptor(mAdaptor);
155 RenderSurface* Window::GetSurface()
160 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
162 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
163 DALI_ASSERT_DEBUG(mOverlay);
165 DoShowIndicator( mIndicatorOrientation );
168 void Window::RotateIndicator(Dali::Window::WindowOrientation orientation)
170 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
172 DoRotateIndicator( orientation );
175 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
177 mIndicatorOpacityMode = opacityMode;
179 if( mIndicator != NULL )
181 mIndicator->SetOpacityMode( opacityMode );
185 void Window::SetClass(std::string name, std::string klass)
191 mIndicatorVisible(Dali::Window::VISIBLE),
192 mIndicatorIsShown(false),
193 mShowRotatedIndicatorOnClose(false),
195 mIsTransparent(false),
196 mWMRotationAppSet(false),
198 mIndicatorOrientation(Dali::Window::PORTRAIT),
199 mNextIndicatorOrientation(Dali::Window::PORTRAIT),
200 mIndicatorOpacityMode(Dali::Window::OPAQUE),
208 delete mEventHandler;
218 mAdaptor->RemoveObserver( *this );
219 mAdaptor->SetDragAndDropDetector( NULL );
226 void Window::Initialize(const PositionSize& windowPosition, const std::string& name, const std::string& className)
228 // create an Wayland window by default
230 ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
231 SetClass( name, className );
232 windowSurface->Map();
234 mSurface = windowSurface;
236 mOrientation = Orientation::New(this);
238 // create event handler for Wayland window
239 mEventHandler = new EventHandler( this );
242 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
244 if( mIndicator == NULL )
246 if( mIndicatorVisible != Dali::Window::INVISIBLE )
248 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
249 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
250 Dali::Actor actor = mIndicator->GetActor();
251 SetIndicatorActorRotation();
252 mOverlay->Add(actor);
254 // else don't create a hidden indicator
256 else // Already have indicator
258 if( mIndicatorVisible == Dali::Window::VISIBLE )
260 // If we are resuming, and rotation has changed,
261 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
263 // then close current indicator and open new one
264 mShowRotatedIndicatorOnClose = true;
265 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
266 // Don't show actor - will contain indicator for old orientation.
271 // set indicator visible mode
272 if( mIndicator != NULL )
274 mIndicator->SetVisible( mIndicatorVisible );
277 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
278 SetIndicatorProperties( show, lastOrientation );
279 mIndicatorIsShown = show;
282 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
284 if( mIndicatorIsShown )
286 mShowRotatedIndicatorOnClose = true;
287 mNextIndicatorOrientation = orientation;
288 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
292 // Save orientation for when the indicator is next shown
293 mShowRotatedIndicatorOnClose = false;
294 mNextIndicatorOrientation = orientation;
298 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
302 void Window::IndicatorTypeChanged(Indicator::Type type)
306 void Window::IndicatorClosed( Indicator* indicator )
308 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
310 if( mShowRotatedIndicatorOnClose )
312 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
313 mIndicator->Open(mNextIndicatorOrientation);
314 mIndicatorOrientation = mNextIndicatorOrientation;
315 SetIndicatorActorRotation();
316 DoShowIndicator(currentOrientation);
320 void Window::IndicatorVisibilityChanged(bool isVisible)
322 mIndicatorVisibilityChangedSignal.Emit(isVisible);
325 void Window::SetIndicatorActorRotation()
327 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
328 DALI_ASSERT_DEBUG( mIndicator != NULL );
330 Dali::Actor actor = mIndicator->GetActor();
331 switch( mIndicatorOrientation )
333 case Dali::Window::PORTRAIT:
334 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
335 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
336 actor.SetOrientation( Degree(0), Vector3::ZAXIS );
338 case Dali::Window::PORTRAIT_INVERSE:
339 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
340 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
341 actor.SetOrientation( Degree(180), Vector3::ZAXIS );
343 case Dali::Window::LANDSCAPE:
344 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
345 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
346 actor.SetOrientation( Degree(270), Vector3::ZAXIS );
348 case Dali::Window::LANDSCAPE_INVERSE:
349 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
350 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
351 actor.SetOrientation( Degree(90), Vector3::ZAXIS );
364 void Window::Activate()
368 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
370 return mDragAndDropDetector;
373 Dali::Any Window::GetNativeHandle() const
377 return mEventHandler->mEcoreWindow;
385 void Window::OnStart()
387 DoShowIndicator( mIndicatorOrientation );
390 void Window::OnPause()
394 void Window::OnResume()
396 // resume indicator status
397 if( mIndicator != NULL )
399 // Restore own indicator opacity
400 // Send opacity mode to indicator service when app resumed
401 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
405 void Window::OnStop()
416 void Window::OnDestroy()
421 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
425 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
427 if(mAvailableOrientations[i] == orientation)
436 mAvailableOrientations.push_back(orientation);
437 SetAvailableOrientations( mAvailableOrientations );
441 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
443 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
444 iter != mAvailableOrientations.end(); ++iter )
446 if( *iter == orientation )
448 mAvailableOrientations.erase( iter );
452 SetAvailableOrientations( mAvailableOrientations );
455 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
457 DALI_ASSERT_ALWAYS( mAvailableOrientations.size() <= 4 && "Incorrect number of available orientations" );
460 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
462 return mAvailableOrientations;
465 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
467 mPreferredOrientation = orientation;
470 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
472 return mPreferredOrientation;
475 void Window::RotationDone( int orientation, int width, int height )