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::SetIndicatorStyle( Dali::Window::IndicatorStyle style )
153 mIndicatorStyle = style;
156 void Window::ShowIndicator( bool show )
158 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "%s\n", show?"SHOW":"HIDE" );
159 DALI_ASSERT_DEBUG(mOverlay);
163 mIndicatorVisible = Dali::Window::VISIBLE;
167 mIndicatorVisible = Dali::Window::INVISIBLE;
170 DoShowIndicator( mIndicatorOrientation );
173 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
175 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "visible : %d\n", visibleMode );
176 DALI_ASSERT_DEBUG(mOverlay);
178 DoShowIndicator( mIndicatorOrientation );
181 void Window::RotateIndicator(Dali::Window::WindowOrientation orientation)
183 DALI_LOG_TRACE_METHOD_FMT( gWindowLogFilter, "Orientation: %d\n", orientation );
185 DoRotateIndicator( orientation );
188 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
190 mIndicatorOpacityMode = opacityMode;
192 if( mIndicator != NULL )
194 mIndicator->SetOpacityMode( opacityMode );
198 void Window::SetClass(std::string name, std::string klass)
204 mIndicatorStyle(Dali::Window::CHANGEABLE_COLOR),
205 mIndicatorVisible(Dali::Window::VISIBLE),
206 mIndicatorIsShown(false),
207 mShowRotatedIndicatorOnClose(false),
209 mIsTransparent(false),
210 mWMRotationAppSet(false),
212 mIndicatorOrientation(Dali::Window::PORTRAIT),
213 mNextIndicatorOrientation(Dali::Window::PORTRAIT),
214 mIndicatorOpacityMode(Dali::Window::OPAQUE),
222 delete mEventHandler;
226 mAdaptor->RemoveObserver( *this );
227 mAdaptor->SetDragAndDropDetector( NULL );
234 void Window::Initialize(const PositionSize& windowPosition, const std::string& name)
236 // create an Wayland window by default
239 mSurface = new ECore::WindowRenderSurface( windowPosition, surface, display, name, mIsTransparent );
240 mOrientation = Orientation::New(this);
242 // create event handler for Wayland window
243 mEventHandler = new EventHandler( this );
246 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
248 if( mIndicator == NULL )
250 if( mIndicatorVisible != Dali::Window::INVISIBLE )
252 mIndicator = new Indicator( mAdaptor, mIndicatorOrientation, mIndicatorStyle, this );
253 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
254 Dali::Actor actor = mIndicator->GetActor();
255 SetIndicatorActorRotation();
256 mOverlay->Add(actor);
258 // else don't create a hidden indicator
260 else // Already have indicator
262 if( mIndicatorVisible == Dali::Window::VISIBLE )
264 // If we are resuming, and rotation has changed,
265 if( mIndicatorIsShown == false && mIndicatorOrientation != mNextIndicatorOrientation )
267 // then close current indicator and open new one
268 mShowRotatedIndicatorOnClose = true;
269 mIndicator->Close(); // May synchronously call IndicatorClosed() callback & 1 level of recursion
270 // Don't show actor - will contain indicator for old orientation.
275 // set indicator visible mode
276 if( mIndicator != NULL )
278 mIndicator->SetVisible( mIndicatorVisible );
281 bool show = (mIndicatorVisible != Dali::Window::INVISIBLE );
282 SetIndicatorProperties( show, lastOrientation );
283 mIndicatorIsShown = show;
286 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
288 if( mIndicatorIsShown )
290 mShowRotatedIndicatorOnClose = true;
291 mNextIndicatorOrientation = orientation;
292 mIndicator->Close(); // May synchronously call IndicatorClosed() callback
296 // Save orientation for when the indicator is next shown
297 mShowRotatedIndicatorOnClose = false;
298 mNextIndicatorOrientation = orientation;
302 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
306 void Window::IndicatorTypeChanged(Indicator::Type type)
310 void Window::IndicatorClosed( Indicator* indicator )
312 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
314 if( mShowRotatedIndicatorOnClose )
316 Dali::Window::WindowOrientation currentOrientation = mIndicatorOrientation;
317 mIndicator->Open(mNextIndicatorOrientation);
318 mIndicatorOrientation = mNextIndicatorOrientation;
319 SetIndicatorActorRotation();
320 DoShowIndicator(currentOrientation);
324 void Window::SetIndicatorActorRotation()
326 DALI_LOG_TRACE_METHOD( gWindowLogFilter );
327 DALI_ASSERT_DEBUG( mIndicator != NULL );
329 Dali::Actor actor = mIndicator->GetActor();
330 switch( mIndicatorOrientation )
332 case Dali::Window::PORTRAIT:
333 actor.SetParentOrigin( ParentOrigin::TOP_CENTER );
334 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
335 actor.SetRotation( Degree(0), Vector3::ZAXIS );
337 case Dali::Window::PORTRAIT_INVERSE:
338 actor.SetParentOrigin( ParentOrigin::BOTTOM_CENTER );
339 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
340 actor.SetRotation( Degree(180), Vector3::ZAXIS );
342 case Dali::Window::LANDSCAPE:
343 actor.SetParentOrigin( ParentOrigin::CENTER_LEFT );
344 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
345 actor.SetRotation( Degree(270), Vector3::ZAXIS );
347 case Dali::Window::LANDSCAPE_INVERSE:
348 actor.SetParentOrigin( ParentOrigin::CENTER_RIGHT );
349 actor.SetAnchorPoint( AnchorPoint::TOP_CENTER );
350 actor.SetRotation( Degree(90), Vector3::ZAXIS );
363 void Window::Activate()
367 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
369 return mDragAndDropDetector;
372 void Window::OnStart()
374 DoShowIndicator( mIndicatorOrientation );
377 void Window::OnPause()
381 void Window::OnResume()
383 // resume indicator status
384 if( mIndicator != NULL )
386 // Restore own indicator opacity
387 // Send opacity mode to indicator service when app resumed
388 mIndicator->SetOpacityMode( mIndicatorOpacityMode );
392 void Window::OnStop()
403 void Window::OnDestroy()
408 OrientationPtr Window::GetOrientation()
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 )