2 * Copyright (c) 2017 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"
22 #include <dali/integration-api/core.h>
23 #include <dali/integration-api/system-overlay.h>
24 #include <dali/public-api/render-tasks/render-task.h>
25 #include <dali/public-api/render-tasks/render-task-list.h>
26 #include <orientation.h>
29 #include "render-surface/render-surface-wl.h"
30 #include <drag-and-drop-detector-impl.h>
31 #include <window-visibility-observer.h>
32 #include <orientation-impl.h>
42 #if defined(DEBUG_ENABLED)
43 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::Concise, false, "LOG_WINDOW");
46 struct Window::EventHandler
51 Window* Window::New( const PositionSize& positionSize, const std::string& name, const std::string& className, bool isTransparent )
53 Window* window = new Window();
54 window->mIsTransparent = isTransparent;
55 window->Initialize( positionSize, name, className );
59 void Window::SetAdaptor(Dali::Adaptor& adaptor)
61 DALI_ASSERT_ALWAYS( !mStarted && "Adaptor already started" );
64 // Only create one overlay per window
65 Internal::Adaptor::Adaptor& adaptorImpl = Internal::Adaptor::Adaptor::GetImplementation(adaptor);
66 Integration::Core& core = adaptorImpl.GetCore();
67 mOverlay = &core.GetSystemOverlay();
69 Dali::RenderTaskList taskList = mOverlay->GetOverlayRenderTasks();
70 taskList.CreateTask();
72 mAdaptor = &adaptorImpl;
73 mAdaptor->AddObserver( *this );
75 // Can only create the detector when we know the Core has been instantiated.
76 mDragAndDropDetector = DragAndDropDetector::New();
77 mAdaptor->SetDragAndDropDetector( &GetImplementation( mDragAndDropDetector ) );
82 RenderSurface* Window::GetSurface()
87 void Window::ShowIndicator( Dali::Window::IndicatorVisibleMode visibleMode )
92 void Window::RotateIndicator(Dali::Window::WindowOrientation orientation)
96 void Window::SetIndicatorBgOpacity( Dali::Window::IndicatorBgOpacity opacityMode )
100 void Window::SetClass(std::string name, std::string klass)
106 mIndicatorVisible( Dali::Window::VISIBLE ),
107 mIndicatorIsShown( false ),
108 mShowRotatedIndicatorOnClose( false ),
110 mIsTransparent( false ),
111 mWMRotationAppSet( false ),
112 mIsFocusAcceptable( true ),
115 mOpaqueState( false ),
116 mResizeEnabled( true ),
118 mIndicatorOrientation( Dali::Window::PORTRAIT ),
119 mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
120 mIndicatorOpacityMode( Dali::Window::OPAQUE ),
123 mType( Dali::Window::NORMAL ),
124 mPreferredOrientation( Dali::Window::PORTRAIT ),
125 mSupportedAuxiliaryHints(),
127 mIndicatorVisibilityChangedSignal(),
128 mFocusChangedSignal(),
130 mDeleteRequestSignal()
132 mEventHandler = NULL;
137 delete mEventHandler;
141 mAdaptor->RemoveObserver( *this );
142 mAdaptor->SetDragAndDropDetector( NULL );
149 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
151 // create an Wayland window by default
153 Wayland::RenderSurface* windowSurface = new Wayland::RenderSurface( positionSize, surface, name, mIsTransparent );
155 mSurface = windowSurface;
157 mOrientation = Orientation::New(this);
160 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
165 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
170 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
174 void Window::IndicatorTypeChanged(IndicatorInterface::Type type)
178 void Window::IndicatorClosed( IndicatorInterface* indicator )
183 void Window::IndicatorVisibilityChanged(bool isVisible)
188 void Window::SetIndicatorActorRotation()
201 void Window::Activate()
205 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
207 return mDragAndDropDetector;
210 Dali::Any Window::GetNativeHandle() const
212 Wayland::RenderSurface* surface = static_cast< Wayland::RenderSurface* >( mSurface );
214 return surface->GetWindow();
217 void Window::OnStart()
221 void Window::OnPause()
225 void Window::OnResume()
229 void Window::OnStop()
233 void Window::OnDestroy()
238 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
242 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
244 if(mAvailableOrientations[i] == orientation)
253 mAvailableOrientations.push_back(orientation);
254 SetAvailableOrientations( mAvailableOrientations );
258 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
260 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
261 iter != mAvailableOrientations.end(); ++iter )
263 if( *iter == orientation )
265 mAvailableOrientations.erase( iter );
269 SetAvailableOrientations( mAvailableOrientations );
272 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
274 DALI_ASSERT_ALWAYS( mAvailableOrientations.size() <= 4 && "Incorrect number of available orientations" );
277 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
279 return mAvailableOrientations;
282 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
284 mPreferredOrientation = orientation;
287 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
289 return mPreferredOrientation;
292 void Window::SetAcceptFocus( bool accept )
294 mIsFocusAcceptable = accept;
297 bool Window::IsFocusAcceptable() const
299 return mIsFocusAcceptable;
312 bool Window::IsVisible() const
318 void Window::RotationDone( int orientation, int width, int height )
322 void Window::SetIndicatorVisibleMode( Dali::Window::IndicatorVisibleMode mode )
324 mIndicatorVisible = mode;
327 unsigned int Window::GetSupportedAuxiliaryHintCount() const
332 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
334 return std::string();
337 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
342 bool Window::RemoveAuxiliaryHint( unsigned int id )
347 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
352 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
354 return std::string();
357 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
362 void Window::SetInputRegion( const Rect< int >& inputRegion )
366 void Window::SetType( Dali::Window::Type type )
371 Dali::Window::Type Window::GetType() const
376 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
381 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
383 return Dali::Window::NotificationLevel::NONE;
386 void Window::SetOpaqueState( bool opaque )
388 mOpaqueState = opaque;
391 bool Window::IsOpaqueState() const
396 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
401 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
403 return Dali::Window::ScreenOffMode::TIMEOUT;
406 bool Window::SetBrightness( int brightness )
411 int Window::GetBrightness() const
416 void Window::SetSize( Dali::Window::WindowSize size )
418 PositionSize positionSize = mSurface->GetPositionSize();
420 if( positionSize.width != size.GetWidth() || positionSize.height != size.GetHeight() )
422 positionSize.width = size.GetWidth();
423 positionSize.height = size.GetHeight();
425 mSurface->MoveResize( positionSize );
427 mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
430 mResizedSignal.Emit( Dali::Window::WindowSize( positionSize.width, positionSize.height ) );
432 mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
436 Dali::Window::WindowSize Window::GetSize() const
438 PositionSize positionSize = mSurface->GetPositionSize();
440 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
443 void Window::SetPosition( Dali::Window::WindowPosition position )
445 PositionSize positionSize = mSurface->GetPositionSize();
447 if( positionSize.x != position.GetX() || positionSize.y != position.GetY() )
449 positionSize.x = position.GetX();
450 positionSize.y = position.GetY();
452 mSurface->MoveResize( positionSize );
456 Dali::Window::WindowPosition Window::GetPosition() const
458 PositionSize positionSize = mSurface->GetPositionSize();
460 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
463 void Window::SetTransparency( bool transparent )