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 )
68 // store ecore window handle
69 ECore::WindowRenderSurface* wlWindow( dynamic_cast< ECore::WindowRenderSurface * >( mWindow->mSurface ) );
72 mEcoreWindow = wlWindow->GetWlWindow();
74 DALI_ASSERT_ALWAYS( mEcoreWindow != 0 && "There is no ecore wl window");
82 if ( mWindowPropertyHandler )
84 ecore_event_handler_del( mWindowPropertyHandler );
86 if ( mClientMessagehandler )
88 ecore_event_handler_del( mClientMessagehandler );
94 /// Called when the window properties are changed.
95 static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
100 /// Called when the window properties are changed.
101 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
108 Ecore_Event_Handler* mWindowPropertyHandler;
109 Ecore_Event_Handler* mClientMessagehandler;
110 Ecore_Wl_Window* mEcoreWindow;
114 Window* Window::New(const PositionSize& posSize, const std::string& name, bool isTransparent)
116 Window* window = new Window();
117 window->mIsTransparent = isTransparent;
118 window->Initialize(posSize, name);
122 void Window::SetAdaptor(Dali::Adaptor& adaptor)
124 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
127 // Only create one overlay per window
128 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
129 Integration::Core& core = adaptorImpl.GetCore();
130 mOverlay = &core.GetSystemOverlay();
132 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
133 taskList.CreateTask();
135 mAdaptor = &adaptorImpl;
136 mAdaptor->AddObserver( *this );
138 // Can only create the detector when we know the Core has been instantiated.
139 mDragAndDropDetector = DragAndDropDetector::New();
140 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
144 mOrientation->SetAdaptor(adaptor);
147 if( mIndicator != NULL )
149 mIndicator->SetAdaptor(mAdaptor);
153 RenderSurface* Window::GetSurface()
158 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
160 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
161 DALI_ASSERT_DEBUG(mOverlay);
163 DoShowIndicator( mIndicatorOrientation );
166 void Window::RotateIndicator(Dali::Window::WindowOrientation orientation)
168 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
170 DoRotateIndicator( orientation );
173 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
175 mIndicatorOpacityMode = opacityMode;
177 if( mIndicator != NULL )
179 mIndicator->SetOpacityMode( opacityMode );
183 void Window::SetClass(std::string name, std::string klass)
189 mIndicatorVisible(Dali::Window::VISIBLE),
190 mIndicatorIsShown(false),
191 mShowRotatedIndicatorOnClose(false),
193 mIsTransparent(false),
194 mWMRotationAppSet(false),
196 mIndicatorOrientation(Dali::Window::PORTRAIT),
197 mNextIndicatorOrientation(Dali::Window::PORTRAIT),
198 mIndicatorOpacityMode(Dali::Window::OPAQUE),
206 delete mEventHandler;
216 mAdaptor->RemoveObserver( *this );
217 mAdaptor->SetDragAndDropDetector( NULL );
224 void Window::Initialize(const PositionSize& windowPosition, const std::string& name)
226 // create an Wayland window by default
228 ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
229 windowSurface->Map();
231 mSurface = windowSurface;
233 mOrientation = Orientation::New(this);
235 // create event handler for Wayland window
236 mEventHandler = new EventHandler( this );
239 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
241 if( mIndicator == NULL )
243 if( mIndicatorVisible != Dali::Window::INVISIBLE )
245 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
246 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
247 Dali::Actor actor = mIndicator->GetActor();
248 SetIndicatorActorRotation();
249 mOverlay->Add(actor);
251 // else don't create a hidden indicator
253 else // Already have indicator
255 if( mIndicatorVisible == Dali::Window::VISIBLE )
257 // If we are resuming, and rotation has changed,
258 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
260 // then close current indicator and open new one
261 mShowRotatedIndicatorOnClose = true;
262 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
263 // Don't show actor - will contain indicator for old orientation.
268 // set indicator visible mode
269 if( mIndicator != NULL )
271 mIndicator->SetVisible( mIndicatorVisible );
274 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
275 SetIndicatorProperties( show, lastOrientation );
276 mIndicatorIsShown = show;
279 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
281 if( mIndicatorIsShown )
283 mShowRotatedIndicatorOnClose = true;
284 mNextIndicatorOrientation = orientation;
285 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
289 // Save orientation for when the indicator is next shown
290 mShowRotatedIndicatorOnClose = false;
291 mNextIndicatorOrientation = orientation;
295 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
299 void Window::IndicatorTypeChanged(Indicator::Type type)
303 void Window::IndicatorClosed( Indicator* indicator )
305 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
307 if( mShowRotatedIndicatorOnClose )
309 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
310 mIndicator->Open(mNextIndicatorOrientation);
311 mIndicatorOrientation = mNextIndicatorOrientation;
312 SetIndicatorActorRotation();
313 DoShowIndicator(currentOrientation);
317 void Window::IndicatorVisibilityChanged(bool isVisible)
319 mIndicatorVisibilityChangedSignal.Emit(isVisible);
322 void Window::SetIndicatorActorRotation()
324 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
325 DALI_ASSERT_DEBUG( mIndicator != NULL );
327 Dali::Actor actor = mIndicator->GetActor();
328 switch( mIndicatorOrientation )
330 case Dali::Window::PORTRAIT:
331 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
332 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
333 actor.SetOrientation( Degree(0), Vector3::ZAXIS );
335 case Dali::Window::PORTRAIT_INVERSE:
336 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
337 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
338 actor.SetOrientation( Degree(180), Vector3::ZAXIS );
340 case Dali::Window::LANDSCAPE:
341 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
342 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
343 actor.SetOrientation( Degree(270), Vector3::ZAXIS );
345 case Dali::Window::LANDSCAPE_INVERSE:
346 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
347 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
348 actor.SetOrientation( Degree(90), Vector3::ZAXIS );
361 void Window::Activate()
365 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
367 return mDragAndDropDetector;
370 Dali::Any Window::GetNativeHandle() const
374 return mEventHandler->mEcoreWindow;
382 void Window::OnStart()
384 DoShowIndicator( mIndicatorOrientation );
387 void Window::OnPause()
391 void Window::OnResume()
393 // resume indicator status
394 if( mIndicator != NULL )
396 // Restore own indicator opacity
397 // Send opacity mode to indicator service when app resumed
398 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
402 void Window::OnStop()
413 void Window::OnDestroy()
418 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
422 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
424 if(mAvailableOrientations[i] == orientation)
433 mAvailableOrientations.push_back(orientation);
434 SetAvailableOrientations( mAvailableOrientations );
438 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
440 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
441 iter != mAvailableOrientations.end(); ++iter )
443 if( *iter == orientation )
445 mAvailableOrientations.erase( iter );
449 SetAvailableOrientations( mAvailableOrientations );
452 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
454 DALI_ASSERT_ALWAYS( mAvailableOrientations.size() <= 4 && "Incorrect number of available orientations" );
457 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
459 return mAvailableOrientations;
462 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
464 mPreferredOrientation = orientation;
467 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
469 return mPreferredOrientation;
472 void Window::RotationDone( int orientation, int width, int height )