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 ),
77 if ( mWindowPropertyHandler )
79 ecore_event_handler_del( mWindowPropertyHandler );
81 if ( mClientMessagehandler )
83 ecore_event_handler_del( mClientMessagehandler );
89 /// Called when the window properties are changed.
90 static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
95 /// Called when the window properties are changed.
96 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
103 Ecore_Event_Handler* mWindowPropertyHandler;
104 Ecore_Event_Handler* mClientMessagehandler;
105 Ecore_Wl_Window* mEcoreWindow;
109 Window* Window::New(const PositionSize& posSize, const std::string& name, bool isTransparent)
111 Window* window = new Window();
112 window->mIsTransparent = isTransparent;
113 window->Initialize(posSize, name);
117 void Window::SetAdaptor(Dali::Adaptor& adaptor)
119 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
122 // Only create one overlay per window
123 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
124 Integration::Core& core = adaptorImpl.GetCore();
125 mOverlay = &core.GetSystemOverlay();
127 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
128 taskList.CreateTask();
130 mAdaptor = &adaptorImpl;
131 mAdaptor->AddObserver( *this );
133 // Can only create the detector when we know the Core has been instantiated.
134 mDragAndDropDetector = DragAndDropDetector::New();
135 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
139 mOrientation->SetAdaptor(adaptor);
142 if( mIndicator != NULL )
144 mIndicator->SetAdaptor(mAdaptor);
148 RenderSurface* Window::GetSurface()
153 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
155 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
156 DALI_ASSERT_DEBUG(mOverlay);
158 DoShowIndicator( mIndicatorOrientation );
161 void Window::RotateIndicator(Dali::Window::WindowOrientation orientation)
163 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
165 DoRotateIndicator( orientation );
168 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
170 mIndicatorOpacityMode = opacityMode;
172 if( mIndicator != NULL )
174 mIndicator->SetOpacityMode( opacityMode );
178 void Window::SetClass(std::string name, std::string klass)
184 mIndicatorVisible(Dali::Window::VISIBLE),
185 mIndicatorIsShown(false),
186 mShowRotatedIndicatorOnClose(false),
188 mIsTransparent(false),
189 mWMRotationAppSet(false),
191 mIndicatorOrientation(Dali::Window::PORTRAIT),
192 mNextIndicatorOrientation(Dali::Window::PORTRAIT),
193 mIndicatorOpacityMode(Dali::Window::OPAQUE),
201 delete mEventHandler;
211 mAdaptor->RemoveObserver( *this );
212 mAdaptor->SetDragAndDropDetector( NULL );
219 void Window::Initialize(const PositionSize& windowPosition, const std::string& name)
221 // create an Wayland window by default
223 ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
224 windowSurface->Map();
226 mSurface = windowSurface;
228 mOrientation = Orientation::New(this);
230 // create event handler for Wayland window
231 mEventHandler = new EventHandler( this );
234 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
236 if( mIndicator == NULL )
238 if( mIndicatorVisible != Dali::Window::INVISIBLE )
240 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
241 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
242 Dali::Actor actor = mIndicator->GetActor();
243 SetIndicatorActorRotation();
244 mOverlay->Add(actor);
246 // else don't create a hidden indicator
248 else // Already have indicator
250 if( mIndicatorVisible == Dali::Window::VISIBLE )
252 // If we are resuming, and rotation has changed,
253 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
255 // then close current indicator and open new one
256 mShowRotatedIndicatorOnClose = true;
257 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
258 // Don't show actor - will contain indicator for old orientation.
263 // set indicator visible mode
264 if( mIndicator != NULL )
266 mIndicator->SetVisible( mIndicatorVisible );
269 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
270 SetIndicatorProperties( show, lastOrientation );
271 mIndicatorIsShown = show;
274 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
276 if( mIndicatorIsShown )
278 mShowRotatedIndicatorOnClose = true;
279 mNextIndicatorOrientation = orientation;
280 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
284 // Save orientation for when the indicator is next shown
285 mShowRotatedIndicatorOnClose = false;
286 mNextIndicatorOrientation = orientation;
290 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
294 void Window::IndicatorTypeChanged(Indicator::Type type)
298 void Window::IndicatorClosed( Indicator* indicator )
300 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
302 if( mShowRotatedIndicatorOnClose )
304 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
305 mIndicator->Open(mNextIndicatorOrientation);
306 mIndicatorOrientation = mNextIndicatorOrientation;
307 SetIndicatorActorRotation();
308 DoShowIndicator(currentOrientation);
312 void Window::IndicatorVisibilityChanged(bool isVisible)
314 mIndicatorVisibilityChangedSignal.Emit(isVisible);
317 void Window::SetIndicatorActorRotation()
319 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
320 DALI_ASSERT_DEBUG( mIndicator != NULL );
322 Dali::Actor actor = mIndicator->GetActor();
323 switch( mIndicatorOrientation )
325 case Dali::Window::PORTRAIT:
326 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
327 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
328 actor.SetOrientation( Degree(0), Vector3::ZAXIS );
330 case Dali::Window::PORTRAIT_INVERSE:
331 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
332 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
333 actor.SetOrientation( Degree(180), Vector3::ZAXIS );
335 case Dali::Window::LANDSCAPE:
336 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
337 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
338 actor.SetOrientation( Degree(270), Vector3::ZAXIS );
340 case Dali::Window::LANDSCAPE_INVERSE:
341 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
342 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
343 actor.SetOrientation( Degree(90), Vector3::ZAXIS );
356 void Window::Activate()
360 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
362 return mDragAndDropDetector;
365 Dali::Any Window::GetNativeHandle() const
369 return mEventHandler->mEcoreWindow;
377 void Window::OnStart()
379 DoShowIndicator( mIndicatorOrientation );
382 void Window::OnPause()
386 void Window::OnResume()
388 // resume indicator status
389 if( mIndicator != NULL )
391 // Restore own indicator opacity
392 // Send opacity mode to indicator service when app resumed
393 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
397 void Window::OnStop()
408 void Window::OnDestroy()
413 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
417 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
419 if(mAvailableOrientations[i] == orientation)
428 mAvailableOrientations.push_back(orientation);
429 SetAvailableOrientations( mAvailableOrientations );
433 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
435 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
436 iter != mAvailableOrientations.end(); ++iter )
438 if( *iter == orientation )
440 mAvailableOrientations.erase( iter );
444 SetAvailableOrientations( mAvailableOrientations );
447 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
449 DALI_ASSERT_ALWAYS( mAvailableOrientations.size() <= 4 && "Incorrect number of available orientations" );
452 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
454 return mAvailableOrientations;
457 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
459 mPreferredOrientation = orientation;
462 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
464 return mPreferredOrientation;
467 void Window::RotationDone( int orientation, int width, int height )