1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
5 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <dali/public-api/actors/layer.h>
23 #include <dali/public-api/adaptor-framework/window-enumerations.h>
24 #include <dali/public-api/object/base-object.h>
25 #include <dali/public-api/object/property-array.h>
26 #include <dali/public-api/object/ref-object.h>
27 #include <dali/public-api/render-tasks/render-task-list.h>
30 #include <dali/devel-api/adaptor-framework/window-devel.h>
31 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
32 #include <dali/internal/adaptor/common/adaptor-impl.h>
33 #include <dali/internal/window-system/common/event-handler.h>
34 #include <dali/public-api/adaptor-framework/key-grab.h>
35 #include <dali/public-api/adaptor-framework/window.h>
41 class RenderSurfaceInterface;
48 class WindowRenderSurface;
52 using WindowPtr = IntrusivePtr<Window>;
53 using OrientationPtr = IntrusivePtr<Orientation>;
54 using EventHandlerPtr = IntrusivePtr<EventHandler>;
57 * Window provides a surface to render onto with orientation & indicator properties.
59 class Window : public Dali::Internal::Adaptor::SceneHolder, public EventHandler::Observer, public ConnectionTracker
62 typedef Dali::Window::FocusChangeSignalType FocusChangeSignalType;
63 typedef Dali::Window::ResizeSignalType ResizeSignalType;
64 typedef Dali::DevelWindow::VisibilityChangedSignalType VisibilityChangedSignalType;
65 typedef Dali::DevelWindow::TransitionEffectEventSignalType TransitionEffectEventSignalType;
66 typedef Dali::DevelWindow::KeyboardRepeatSettingsChangedSignalType KeyboardRepeatSettingsChangedSignalType;
67 typedef Signal<void()> SignalType;
70 * @brief Create a new Window. This should only be called once by the Application class
71 * @param[in] positionSize The position and size of the window
72 * @param[in] name The window title
73 * @param[in] className The window class name
74 * @param[in] type Window type.
75 * @param[in] isTransparent Whether window is transparent
76 * @return A newly allocated Window
78 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
81 * @brief Create a new Window. This should only be called once by the Application class
82 * @param[in] surface The surface used to render on.
83 * @param[in] positionSize The position and size of the window
84 * @param[in] name The window title
85 * @param[in] className The window class name
86 * @param[in] type Window type.
87 * @param[in] isTransparent Whether window is transparent
88 * @return A newly allocated Window
90 static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
93 * @copydoc Dali::Window::SetClass()
95 void SetClass(std::string name, std::string className);
98 * @brief Gets the window class name.
99 * @return The class of the window
101 std::string GetClassName() const;
104 * @copydoc Dali::Window::Raise()
109 * @copydoc Dali::Window::Lower()
114 * @copydoc Dali::Window::Activate()
119 * @copydoc Dali::Window::GetLayerCount()
121 uint32_t GetLayerCount() const;
124 * @copydoc Dali::Window::GetLayer()
126 Dali::Layer GetLayer(uint32_t depth) const;
129 * @copydoc Dali::DevelWindow::GetRenderTaskList()
131 Dali::RenderTaskList GetRenderTaskList() const;
134 * @copydoc Dali::Window::AddAvailableOrientation()
136 void AddAvailableOrientation(WindowOrientation orientation);
139 * @copydoc Dali::Window::RemoveAvailableOrientation()
141 void RemoveAvailableOrientation(WindowOrientation orientation);
144 * @copydoc Dali::Window::SetPreferredOrientation()
146 void SetPreferredOrientation(WindowOrientation orientation);
149 * @copydoc Dali::Window::GetPreferredOrientation()
151 WindowOrientation GetPreferredOrientation();
154 * @copydoc Dali::Window::SetAcceptFocus()
156 void SetAcceptFocus(bool accept);
159 * @copydoc Dali::Window::IsFocusAcceptable()
161 bool IsFocusAcceptable() const;
164 * @copydoc Dali::Window::Show()
169 * @copydoc Dali::Window::Hide()
174 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
176 unsigned int GetSupportedAuxiliaryHintCount() const;
179 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
181 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
184 * @copydoc Dali::Window::AddAuxiliaryHint()
186 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
189 * @copydoc Dali::Window::RemoveAuxiliaryHint()
191 bool RemoveAuxiliaryHint(unsigned int id);
194 * @copydoc Dali::Window::SetAuxiliaryHintValue()
196 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
199 * @copydoc Dali::Window::GetAuxiliaryHintValue()
201 std::string GetAuxiliaryHintValue(unsigned int id) const;
204 * @copydoc Dali::Window::GetAuxiliaryHintId()
206 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
209 * @copydoc Dali::Window::SetInputRegion()
211 void SetInputRegion(const Rect<int>& inputRegion);
214 * @copydoc Dali::Window::SetType()
216 void SetType(WindowType type);
219 * @copydoc Dali::Window::GetType() const
221 WindowType GetType() const;
224 * @copydoc Dali::Window::SetNotificationLevel()
226 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
229 * @copydoc Dali::Window::GetNotificationLevel()
231 WindowNotificationLevel GetNotificationLevel() const;
234 * @copydoc Dali::Window::SetOpaqueState()
236 void SetOpaqueState(bool opaque);
239 * @copydoc Dali::Window::IsOpaqueState()
241 bool IsOpaqueState() const;
244 * @copydoc Dali::Window::SetScreenOffMode()
246 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
249 * @copydoc Dali::Window::GetScreenOffMode()
251 WindowScreenOffMode GetScreenOffMode() const;
254 * @copydoc Dali::Window::SetBrightness()
256 WindowOperationResult SetBrightness(int brightness);
259 * @copydoc Dali::Window::GetBrightness()
261 int GetBrightness() const;
264 * @copydoc Dali::Window::SetSize()
266 void SetSize(Dali::Window::WindowSize size);
269 * @copydoc Dali::Window::GetSize()
271 Dali::Window::WindowSize GetSize() const;
274 * @copydoc Dali::Window::SetPosition()
276 void SetPosition(Dali::Window::WindowPosition position);
279 * @copydoc Dali::Window::GetPosition()
281 Dali::Window::WindowPosition GetPosition() const;
284 * @copydoc Dali::DevelWindow::SetPositionSize()
286 void SetPositionSize(PositionSize positionSize);
289 * @copydoc Dali::DevelWindow::GetPositionSize()
291 PositionSize GetPositionSize() const;
294 * @copydoc Dali::Window::GetRootLayer()
296 Dali::Layer GetRootLayer() const;
299 * @copydoc Dali::Window::SetTransparency()
301 void SetTransparency(bool transparent);
304 * @copydoc Dali::KeyGrab::GrabKey()
306 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
309 * @copydoc Dali::KeyGrab::UngrabKey()
311 bool UngrabKey(Dali::KEY key);
314 * @copydoc Dali::KeyGrab::GrabKeyList()
316 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
319 * @copydoc Dali::KeyGrab::UngrabKeyList()
321 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
324 * @copydoc Dali::DevelWindow::Get()
326 static Dali::Window Get(Dali::Actor actor);
329 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
331 void SetParent(Dali::Window& parent);
334 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
336 void SetParent(Dali::Window& parent, bool belowParent);
339 * @copydoc Dali::DevelWindow::Unparent()
344 * @copydoc Dali::DevelWindow::GetParent()
346 Dali::Window GetParent();
349 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
351 WindowOrientation GetCurrentOrientation() const;
354 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
356 int GetPhysicalOrientation() const;
359 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
361 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
364 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
366 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
368 public: // Dali::Internal::Adaptor::SceneHolder
370 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
372 Dali::Any GetNativeHandle() const override;
375 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
377 bool IsVisible() const override;
380 * @copydoc Dali::DevelWindow::GetNativeId()
382 int32_t GetNativeId() const;
385 * @copydoc Dali::DevelWindow::RequestMoveToServer()
387 void RequestMoveToServer();
390 * @copydoc Dali::DevelWindow::RequestResizeToServer()
392 void RequestResizeToServer(WindowResizeDirection direction);
395 * @copydoc Dali::DevelWindow::EnableFloatingMode()
397 void EnableFloatingMode(bool enable);
400 * @copydoc Dali::DevelWindow::IncludeInputRegion()
402 void IncludeInputRegion(const Rect<int>& inputRegion);
405 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
407 void ExcludeInputRegion(const Rect<int>& inputRegion);
411 * @brief Enumeration for orietation mode.
412 * The Orientation Mode is related to screen size.
413 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
414 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
416 enum class OrientationMode
423 * Private constructor.
434 * Second stage initialization
436 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
439 * Called when the window becomes iconified or deiconified.
441 void OnIconifyChanged(bool iconified);
444 * Called when the window focus is changed.
446 void OnFocusChanged(bool focusIn);
449 * Called when the output is transformed.
451 void OnOutputTransformed();
454 * Called when the window receives a delete request.
456 void OnDeleteRequest();
459 * Called when the window receives a Transition effect-start/end event.
461 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
464 * @brief Called when window receives a keyboard repeat event.
466 void OnKeyboardRepeatSettingsChanged();
469 * @brief Called when the window redraw is requested.
471 void OnWindowRedrawRequest();
474 * @brief Called when the window is resized or moved by display server.
476 * @param positionSize the updated window's position and size.
478 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
481 * @brief Set available orientation to window base.
483 void SetAvailableAnlges(const std::vector<int>& angles);
486 * @brief Convert from window orientation to angle using OrientationMode.
488 int ConvertToAngle(WindowOrientation orientation);
491 * @brief Convert from angle to window orientation using OrientationMode.
493 WindowOrientation ConvertToOrientation(int angle) const;
496 * @brief Check available window orientation for Available orientation.
498 bool IsOrientationAvailable(WindowOrientation orientation) const;
500 private: // Dali::Internal::Adaptor::SceneHolder
502 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
504 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
507 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
509 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
512 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
514 void OnPause() override;
517 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
519 void OnResume() override;
522 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
524 void RecalculateTouchPosition(Integration::Point& point) override;
526 private: // Dali::Internal::Adaptor::EventHandler::Observer
528 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
530 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
533 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
535 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
538 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
540 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
543 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
545 void OnRotation(const RotationEvent& rotation) override;
549 * @copydoc Dali::Window::FocusChangeSignal()
551 FocusChangeSignalType& FocusChangeSignal()
553 return mFocusChangeSignal;
557 * @copydoc Dali::Window::ResizedSignal()
559 ResizeSignalType& ResizeSignal()
561 return mResizeSignal;
565 * This signal is emitted when the window is requesting to be deleted
567 SignalType& DeleteRequestSignal()
569 return mDeleteRequestSignal;
573 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
575 VisibilityChangedSignalType& VisibilityChangedSignal()
577 return mVisibilityChangedSignal;
581 * @copydoc Dali::Window::SignalEventProcessingFinished()
583 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
585 return mScene.EventProcessingFinishedSignal();
589 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
591 TransitionEffectEventSignalType& TransitionEffectEventSignal()
593 return mTransitionEffectEventSignal;
597 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
599 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
601 return mKeyboardRepeatSettingsChangedSignal;
605 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
606 WindowBase* mWindowBase;
608 std::string mClassName;
609 bool mIsTransparent : 1;
610 bool mIsFocusAcceptable : 1;
612 bool mOpaqueState : 1;
613 Dali::Window mParentWindow;
615 OrientationPtr mOrientation;
616 std::vector<int> mAvailableAngles;
619 int mRotationAngle; ///< The angle of the rotation
620 int mWindowWidth; ///< The width of the window
621 int mWindowHeight; ///< The height of the window
623 EventHandlerPtr mEventHandler; ///< The window events handler
625 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
627 int mNativeWindowId; ///< The Native Window Id
630 SignalType mDeleteRequestSignal;
631 FocusChangeSignalType mFocusChangeSignal;
632 ResizeSignalType mResizeSignal;
633 VisibilityChangedSignalType mVisibilityChangedSignal;
634 TransitionEffectEventSignalType mTransitionEffectEventSignal;
635 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
638 } // namespace Adaptor
639 } // namespace Internal
641 // Helpers for public-api forwarding methods
643 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
645 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
646 BaseObject& object = window.GetBaseObject();
647 return static_cast<Internal::Adaptor::Window&>(object);
650 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
652 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
653 const BaseObject& object = window.GetBaseObject();
654 return static_cast<const Internal::Adaptor::Window&>(object);
659 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H