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 )
75 if ( mWindowPropertyHandler )
77 ecore_event_handler_del( mWindowPropertyHandler );
79 if ( mClientMessagehandler )
81 ecore_event_handler_del( mClientMessagehandler );
87 /// Called when the window properties are changed.
88 static Eina_Bool EcoreEventWindowPropertyChanged( void* data, int type, void* event )
93 /// Called when the window properties are changed.
94 static Eina_Bool EcoreEventClientMessage( void* data, int type, void* event )
101 Ecore_Event_Handler* mWindowPropertyHandler;
102 Ecore_Event_Handler* mClientMessagehandler;
103 Ecore_Wl_Window* mEcoreWindow;
107 Window* Window::New(const PositionSize& posSize, const std::string& name, bool isTransparent)
109 Window* window = new Window();
110 window->mIsTransparent = isTransparent;
111 window->Initialize(posSize, name);
115 void Window::SetAdaptor(Dali::Adaptor& adaptor)
117 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
120 // Only create one overlay per window
121 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
122 Integration::Core& core = adaptorImpl.GetCore();
123 mOverlay = &core.GetSystemOverlay();
125 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
126 taskList.CreateTask();
128 mAdaptor = &adaptorImpl;
129 mAdaptor->AddObserver( *this );
131 // Can only create the detector when we know the Core has been instantiated.
132 mDragAndDropDetector = DragAndDropDetector::New();
133 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
137 mOrientation->SetAdaptor(adaptor);
140 if( mIndicator != NULL )
142 mIndicator->SetAdaptor(mAdaptor);
146 RenderSurface* Window::GetSurface()
151 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
153 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
154 DALI_ASSERT_DEBUG(mOverlay);
156 DoShowIndicator( mIndicatorOrientation );
159 void Window::RotateIndicator(Dali::Window::WindowOrientation orientation)
161 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
163 DoRotateIndicator( orientation );
166 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
168 mIndicatorOpacityMode = opacityMode;
170 if( mIndicator != NULL )
172 mIndicator->SetOpacityMode( opacityMode );
176 void Window::SetClass(std::string name, std::string klass)
182 mIndicatorVisible(Dali::Window::VISIBLE),
183 mIndicatorIsShown(false),
184 mShowRotatedIndicatorOnClose(false),
186 mIsTransparent(false),
187 mWMRotationAppSet(false),
189 mIndicatorOrientation(Dali::Window::PORTRAIT),
190 mNextIndicatorOrientation(Dali::Window::PORTRAIT),
191 mIndicatorOpacityMode(Dali::Window::OPAQUE),
199 delete mEventHandler;
209 mAdaptor->RemoveObserver( *this );
210 mAdaptor->SetDragAndDropDetector( NULL );
217 void Window::Initialize(const PositionSize& windowPosition, const std::string& name)
219 // create an Wayland window by default
221 ECore::WindowRenderSurface* windowSurface = new ECore::WindowRenderSurface( windowPosition, surface, name, mIsTransparent );
222 windowSurface->Map();
224 mSurface = windowSurface;
226 mOrientation = Orientation::New(this);
228 // create event handler for Wayland window
229 mEventHandler = new EventHandler( this );
232 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
234 if( mIndicator == NULL )
236 if( mIndicatorVisible != Dali::Window::INVISIBLE )
238 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, this );
239 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
240 Dali::Actor actor = mIndicator->GetActor();
241 SetIndicatorActorRotation();
242 mOverlay->Add(actor);
244 // else don't create a hidden indicator
246 else // Already have indicator
248 if( mIndicatorVisible == Dali::Window::VISIBLE )
250 // If we are resuming, and rotation has changed,
251 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
253 // then close current indicator and open new one
254 mShowRotatedIndicatorOnClose = true;
255 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
256 // Don't show actor - will contain indicator for old orientation.
261 // set indicator visible mode
262 if( mIndicator != NULL )
264 mIndicator->SetVisible( mIndicatorVisible );
267 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
268 SetIndicatorProperties( show, lastOrientation );
269 mIndicatorIsShown = show;
272 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
274 if( mIndicatorIsShown )
276 mShowRotatedIndicatorOnClose = true;
277 mNextIndicatorOrientation = orientation;
278 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
282 // Save orientation for when the indicator is next shown
283 mShowRotatedIndicatorOnClose = false;
284 mNextIndicatorOrientation = orientation;
288 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
292 void Window::IndicatorTypeChanged(Indicator::Type type)
296 void Window::IndicatorClosed( Indicator* indicator )
298 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
300 if( mShowRotatedIndicatorOnClose )
302 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
303 mIndicator->Open(mNextIndicatorOrientation);
304 mIndicatorOrientation = mNextIndicatorOrientation;
305 SetIndicatorActorRotation();
306 DoShowIndicator(currentOrientation);
310 void Window::IndicatorVisibilityChanged(bool isVisible)
312 mIndicatorVisibilityChangedSignal.Emit(isVisible);
315 void Window::SetIndicatorActorRotation()
317 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
318 DALI_ASSERT_DEBUG( mIndicator != NULL );
320 Dali::Actor actor = mIndicator->GetActor();
321 switch( mIndicatorOrientation )
323 case Dali::Window::PORTRAIT:
324 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
325 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
326 actor.SetOrientation( Degree(0), Vector3::ZAXIS );
328 case Dali::Window::PORTRAIT_INVERSE:
329 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
330 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
331 actor.SetOrientation( Degree(180), Vector3::ZAXIS );
333 case Dali::Window::LANDSCAPE:
334 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
335 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
336 actor.SetOrientation( Degree(270), Vector3::ZAXIS );
338 case Dali::Window::LANDSCAPE_INVERSE:
339 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
340 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
341 actor.SetOrientation( Degree(90), Vector3::ZAXIS );
354 void Window::Activate()
358 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
360 return mDragAndDropDetector;
363 Dali::Any Window::GetNativeHandle() const
367 return mEventHandler->mEcoreWindow;
375 void Window::OnStart()
377 DoShowIndicator( mIndicatorOrientation );
380 void Window::OnPause()
384 void Window::OnResume()
386 // resume indicator status
387 if( mIndicator != NULL )
389 // Restore own indicator opacity
390 // Send opacity mode to indicator service when app resumed
391 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
395 void Window::OnStop()
406 void Window::OnDestroy()
411 OrientationPtr Window::GetOrientation()
416 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
420 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
422 if(mAvailableOrientations[i] == orientation)
431 mAvailableOrientations.push_back(orientation);
432 SetAvailableOrientations( mAvailableOrientations );
436 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
438 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
439 iter != mAvailableOrientations.end(); ++iter )
441 if( *iter == orientation )
443 mAvailableOrientations.erase( iter );
447 SetAvailableOrientations( mAvailableOrientations );
450 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
452 DALI_ASSERT_ALWAYS( mAvailableOrientations.size() <= 4 && "Incorrect number of available orientations" );
455 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
457 return mAvailableOrientations;
460 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
462 mPreferredOrientation = orientation;
465 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
467 return mPreferredOrientation;
470 void Window::RotationDone( int orientation, int width, int height )