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::DevelWindow::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()
298 return mIsFocusAcceptable;
311 bool Window::IsVisible() const
317 void Window::RotationDone( int orientation, int width, int height )
321 unsigned int Window::GetSupportedAuxiliaryHintCount()
326 std::string Window::GetSupportedAuxiliaryHint( unsigned int index )
328 return std::string();
331 unsigned int Window::AddAuxiliaryHint( const std::string& hint, const std::string& value )
336 bool Window::RemoveAuxiliaryHint( unsigned int id )
341 bool Window::SetAuxiliaryHintValue( unsigned int id, const std::string& value )
346 std::string Window::GetAuxiliaryHintValue( unsigned int id ) const
348 return std::string();
351 unsigned int Window::GetAuxiliaryHintId( const std::string& hint ) const
356 void Window::SetInputRegion( const Rect< int >& inputRegion )
360 void Window::SetType( Dali::DevelWindow::Type type )
365 Dali::DevelWindow::Type Window::GetType() const
370 bool Window::SetNotificationLevel( Dali::DevelWindow::NotificationLevel::Type level )
375 Dali::DevelWindow::NotificationLevel::Type Window::GetNotificationLevel()
377 return Dali::DevelWindow::NotificationLevel::NONE;
380 void Window::SetOpaqueState( bool opaque )
382 mOpaqueState = opaque;
385 bool Window::IsOpaqueState()
390 bool Window::SetScreenMode( Dali::DevelWindow::ScreenMode::Type screenMode )
395 Dali::DevelWindow::ScreenMode::Type Window::GetScreenMode()
397 return Dali::DevelWindow::ScreenMode::DEFAULT;
400 bool Window::SetBrightness( int brightness )
405 int Window::GetBrightness()
410 void Window::SetSize( Dali::DevelWindow::WindowSize size )
412 PositionSize positionSize = mSurface->GetPositionSize();
414 if( positionSize.width != size.GetWidth() || positionSize.height != size.GetHeight() )
416 positionSize.width = size.GetWidth();
417 positionSize.height = size.GetHeight();
419 mSurface->MoveResize( positionSize );
421 mAdaptor->SurfaceSizeChanged( Dali::Adaptor::SurfaceSize( positionSize.width, positionSize.height ) );
424 mResizedSignal.Emit( Dali::DevelWindow::WindowSize( positionSize.width, positionSize.height ) );
428 Dali::DevelWindow::WindowSize Window::GetSize()
430 PositionSize positionSize = mSurface->GetPositionSize();
432 return Dali::DevelWindow::WindowSize( positionSize.width, positionSize.height );
435 void Window::SetPosition( Dali::DevelWindow::WindowPosition position )
437 PositionSize positionSize = mSurface->GetPositionSize();
439 if( positionSize.x != position.GetX() || positionSize.y != position.GetY() )
441 positionSize.x = position.GetX();
442 positionSize.y = position.GetY();
444 mSurface->MoveResize( positionSize );
448 Dali::DevelWindow::WindowPosition Window::GetPosition()
450 PositionSize positionSize = mSurface->GetPositionSize();
452 return Dali::DevelWindow::WindowPosition( positionSize.x, positionSize.y );
455 void Window::SetTransparency( bool transparent )