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 ),
114 mOpaqueState( false ),
115 mResizeEnabled( true ),
117 mIndicatorOrientation( Dali::Window::PORTRAIT ),
118 mNextIndicatorOrientation( Dali::Window::PORTRAIT ),
119 mIndicatorOpacityMode( Dali::Window::OPAQUE ),
122 mType( Dali::Window::NORMAL ),
123 mPreferredOrientation( Dali::Window::PORTRAIT ),
124 mSupportedAuxiliaryHints(),
126 mIndicatorVisibilityChangedSignal(),
127 mFocusChangedSignal(),
129 mDeleteRequestSignal()
131 mEventHandler = NULL;
136 delete mEventHandler;
140 mAdaptor->RemoveObserver( *this );
141 mAdaptor->SetDragAndDropDetector( NULL );
148 void Window::Initialize(const PositionSize& positionSize, const std::string& name, const std::string& className)
150 // create an Wayland window by default
152 Wayland::RenderSurface* windowSurface = new Wayland::RenderSurface( positionSize, surface, name, mIsTransparent );
154 mSurface = windowSurface;
156 mOrientation = Orientation::New(this);
159 void Window::DoShowIndicator( Dali::Window::WindowOrientation lastOrientation )
164 void Window::DoRotateIndicator( Dali::Window::WindowOrientation orientation )
169 void Window::SetIndicatorProperties( bool isShow, Dali::Window::WindowOrientation lastOrientation )
173 void Window::IndicatorTypeChanged(IndicatorInterface::Type type)
177 void Window::IndicatorClosed( IndicatorInterface* indicator )
182 void Window::IndicatorVisibilityChanged(bool isVisible)
187 void Window::SetIndicatorActorRotation()
200 void Window::Activate()
204 Dali::DragAndDropDetector Window::GetDragAndDropDetector() const
206 return mDragAndDropDetector;
209 Dali::Any Window::GetNativeHandle() const
211 Wayland::RenderSurface* surface = static_cast< Wayland::RenderSurface* >( mSurface );
213 return surface->GetWindow();
216 void Window::OnStart()
220 void Window::OnPause()
224 void Window::OnResume()
228 void Window::OnStop()
232 void Window::OnDestroy()
237 void Window::AddAvailableOrientation(Dali::Window::WindowOrientation orientation)
241 for( std::size_t i=0; i<mAvailableOrientations.size(); i++ )
243 if(mAvailableOrientations[i] == orientation)
252 mAvailableOrientations.push_back(orientation);
253 SetAvailableOrientations( mAvailableOrientations );
257 void Window::RemoveAvailableOrientation(Dali::Window::WindowOrientation orientation)
259 for( std::vector<Dali::Window::WindowOrientation>::iterator iter = mAvailableOrientations.begin();
260 iter != mAvailableOrientations.end(); ++iter )
262 if( *iter == orientation )
264 mAvailableOrientations.erase( iter );
268 SetAvailableOrientations( mAvailableOrientations );
271 void Window::SetAvailableOrientations(const std::vector<Dali::Window::WindowOrientation>& orientations)
273 DALI_ASSERT_ALWAYS( mAvailableOrientations.size() <= 4 && "Incorrect number of available orientations" );
276 const std::vector<Dali::Window::WindowOrientation>& Window::GetAvailableOrientations()
278 return mAvailableOrientations;
281 void Window::SetPreferredOrientation(Dali::Window::WindowOrientation orientation)
283 mPreferredOrientation = orientation;
286 Dali::Window::WindowOrientation Window::GetPreferredOrientation()
288 return mPreferredOrientation;
291 void Window::SetAcceptFocus( bool accept )
293 mIsFocusAcceptable = accept;
296 bool Window::IsFocusAcceptable() const
298 return mIsFocusAcceptable;
311 bool Window::IsVisible() const
317 void Window::RotationDone( int orientation, int width, int height )
321 void Window::SetIndicatorVisibleMode( Dali::Window::IndicatorVisibleMode mode )
323 mIndicatorVisible = mode;
326 unsigned int Window::GetSupportedAuxiliaryHintCount() const
331 std::string Window::GetSupportedAuxiliaryHint( unsigned int index ) const
333 return std::string();
336 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
341 bool Window::RemoveAuxiliaryHint( unsigned int id )
346 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
351 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
353 return std::string();
356 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
361 void Window::SetInputRegion( const Rect< int >& inputRegion )
365 void Window::SetType( Dali::Window::Type type )
370 Dali::Window::Type Window::GetType() const
375 bool Window::SetNotificationLevel( Dali::Window::NotificationLevel::Type level )
380 Dali::Window::NotificationLevel::Type Window::GetNotificationLevel() const
382 return Dali::Window::NotificationLevel::NONE;
385 void Window::SetOpaqueState( bool opaque )
387 mOpaqueState = opaque;
390 bool Window::IsOpaqueState() const
395 bool Window::SetScreenOffMode(Dali::Window::ScreenOffMode::Type screenOffMode)
400 Dali::Window::ScreenOffMode::Type Window::GetScreenOffMode() const
402 return Dali::Window::ScreenOffMode::TIMEOUT;
405 bool Window::SetBrightness( int brightness )
410 int Window::GetBrightness() const
415 void Window::SetSize( Dali::Window::WindowSize size )
417 PositionSize positionSize = mSurface->GetPositionSize();
419 if( positionSize.width != size.GetWidth() || positionSize.height != size.GetHeight() )
421 positionSize.width = size.GetWidth();
422 positionSize.height = size.GetHeight();
424 mSurface->MoveResize( positionSize );
426 mAdaptor->SurfaceResizePrepare( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
429 mResizedSignal.Emit( Dali::Window::WindowSize( positionSize.width, positionSize.height ) );
431 mAdaptor->SurfaceResizeComplete( Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
435 Dali::Window::WindowSize Window::GetSize() const
437 PositionSize positionSize = mSurface->GetPositionSize();
439 return Dali::Window::WindowSize( positionSize.width, positionSize.height );
442 void Window::SetPosition( Dali::Window::WindowPosition position )
444 PositionSize positionSize = mSurface->GetPositionSize();
446 if( positionSize.x != position.GetX() || positionSize.y != position.GetY() )
448 positionSize.x = position.GetX();
449 positionSize.y = position.GetY();
451 mSurface->MoveResize( positionSize );
455 Dali::Window::WindowPosition Window::GetPosition() const
457 PositionSize positionSize = mSurface->GetPositionSize();
459 return Dali::Window::WindowPosition( positionSize.x, positionSize.y );
462 void Window::SetTransparency( bool transparent )