1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
5 * Copyright (c) 2023 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/events/touch-event.h>
25 #include <dali/public-api/object/base-object.h>
26 #include <dali/public-api/object/property-array.h>
27 #include <dali/public-api/object/ref-object.h>
28 #include <dali/public-api/render-tasks/render-task-list.h>
31 #include <dali/devel-api/adaptor-framework/window-devel.h>
32 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
33 #include <dali/internal/adaptor/common/adaptor-impl.h>
34 #include <dali/internal/window-system/common/event-handler.h>
35 #include <dali/public-api/adaptor-framework/key-grab.h>
36 #include <dali/public-api/adaptor-framework/window.h>
42 class RenderSurfaceInterface;
49 class WindowRenderSurface;
53 using WindowPtr = IntrusivePtr<Window>;
54 using OrientationPtr = IntrusivePtr<Orientation>;
55 using MouseInOutEventPtr = IntrusivePtr<Dali::DevelWindow::MouseInOutEvent>;
56 using EventHandlerPtr = IntrusivePtr<EventHandler>;
59 * Window provides a surface to render onto with orientation & indicator properties.
61 class Window : public Dali::Internal::Adaptor::SceneHolder, public EventHandler::Observer, public ConnectionTracker
64 typedef Dali::Window::FocusChangeSignalType FocusChangeSignalType;
65 typedef Dali::Window::ResizeSignalType ResizeSignalType;
66 typedef Dali::DevelWindow::VisibilityChangedSignalType VisibilityChangedSignalType;
67 typedef Dali::DevelWindow::TransitionEffectEventSignalType TransitionEffectEventSignalType;
68 typedef Dali::DevelWindow::KeyboardRepeatSettingsChangedSignalType KeyboardRepeatSettingsChangedSignalType;
69 typedef Dali::DevelWindow::AuxiliaryMessageSignalType AuxiliaryMessageSignalType;
70 typedef Dali::DevelWindow::AccessibilityHighlightSignalType AccessibilityHighlightSignalType;
71 typedef Dali::DevelWindow::MovedSignalType MovedSignalType;
72 typedef Dali::DevelWindow::OrientationChangedSignalType OrientationChangedSignalType;
73 typedef Dali::DevelWindow::MouseInOutEventSignalType MouseInOutEventSignalType;
74 typedef Dali::DevelWindow::MoveCompletedSignalType MoveCompletedSignalType;
75 typedef Dali::DevelWindow::ResizeCompletedSignalType ResizeCompletedSignalType;
76 typedef Signal<void()> SignalType;
79 * @brief Create a new Window. This should only be called once by the Application class
80 * @param[in] positionSize The position and size of the window
81 * @param[in] name The window title
82 * @param[in] className The window class name
83 * @param[in] type Window type.
84 * @param[in] isTransparent Whether window is transparent
85 * @return A newly allocated Window
87 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
90 * @brief Create a new Window. This should only be called once by the Application class
91 * @param[in] surface The surface used to render on.
92 * @param[in] positionSize The position and size of the window
93 * @param[in] name The window title
94 * @param[in] className The window class name
95 * @param[in] type Window type.
96 * @param[in] isTransparent Whether window is transparent
97 * @return A newly allocated Window
99 static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
102 * @copydoc Dali::Window::SetClass()
104 void SetClass(std::string name, std::string className);
107 * @brief Gets the window class name.
108 * @return The class of the window
110 std::string GetClassName() const;
113 * @copydoc Dali::Window::Raise()
118 * @copydoc Dali::Window::Lower()
123 * @copydoc Dali::Window::Activate()
128 * @copydoc Dali::DevelWindow::Maximize()
130 void Maximize(bool maximize);
133 * @copydoc Dali::DevelWindow::IsMaximized()
135 bool IsMaximized() const;
138 * @copydoc Dali::DevelWindow::SetMaximumSize()
140 void SetMaximumSize(Dali::Window::WindowSize size);
143 * @copydoc Dali::DevelWindow::Minimize()
145 void Minimize(bool minimize);
148 * @copydoc Dali::DevelWindow::IsMinimized()
150 bool IsMinimized() const;
153 * @copydoc Dali::DevelWindow::SetMimimumSize()
155 void SetMimimumSize(Dali::Window::WindowSize size);
158 * @copydoc Dali::Window::GetLayerCount()
160 uint32_t GetLayerCount() const;
163 * @copydoc Dali::Window::GetLayer()
165 Dali::Layer GetLayer(uint32_t depth) const;
168 * @copydoc Dali::Window::GetRenderTaskList()
170 Dali::RenderTaskList GetRenderTaskList() const;
173 * @copydoc Dali::Window::KeepRendering()
175 void KeepRendering(float durationSeconds);
178 * @brief Get window resource ID assigned by window manager
179 * @return The resource ID of the window
181 std::string GetNativeResourceId() const;
184 * @copydoc Dali::Window::AddAvailableOrientation()
186 void AddAvailableOrientation(WindowOrientation orientation);
189 * @copydoc Dali::Window::RemoveAvailableOrientation()
191 void RemoveAvailableOrientation(WindowOrientation orientation);
194 * @copydoc Dali::Window::SetPreferredOrientation()
196 void SetPreferredOrientation(WindowOrientation orientation);
199 * @copydoc Dali::Window::GetPreferredOrientation()
201 WindowOrientation GetPreferredOrientation();
204 * @copydoc Dali::Window::SetAcceptFocus()
206 void SetAcceptFocus(bool accept);
209 * @copydoc Dali::Window::IsFocusAcceptable()
211 bool IsFocusAcceptable() const;
214 * @copydoc Dali::Window::Show()
219 * @copydoc Dali::Window::Hide()
224 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
226 unsigned int GetSupportedAuxiliaryHintCount() const;
229 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
231 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
234 * @copydoc Dali::Window::AddAuxiliaryHint()
236 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
239 * @copydoc Dali::Window::RemoveAuxiliaryHint()
241 bool RemoveAuxiliaryHint(unsigned int id);
244 * @copydoc Dali::Window::SetAuxiliaryHintValue()
246 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
249 * @copydoc Dali::Window::GetAuxiliaryHintValue()
251 std::string GetAuxiliaryHintValue(unsigned int id) const;
254 * @copydoc Dali::Window::GetAuxiliaryHintId()
256 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
259 * @copydoc Dali::Window::SetInputRegion()
261 void SetInputRegion(const Rect<int>& inputRegion);
264 * @copydoc Dali::Window::SetType()
266 void SetType(WindowType type);
269 * @copydoc Dali::Window::GetType() const
271 WindowType GetType() const;
274 * @copydoc Dali::Window::SetNotificationLevel()
276 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
279 * @copydoc Dali::Window::GetNotificationLevel()
281 WindowNotificationLevel GetNotificationLevel() const;
284 * @copydoc Dali::Window::SetOpaqueState()
286 void SetOpaqueState(bool opaque);
289 * @copydoc Dali::Window::IsOpaqueState()
291 bool IsOpaqueState() const;
294 * @copydoc Dali::Window::SetScreenOffMode()
296 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
299 * @copydoc Dali::Window::GetScreenOffMode()
301 WindowScreenOffMode GetScreenOffMode() const;
304 * @copydoc Dali::Window::SetBrightness()
306 WindowOperationResult SetBrightness(int brightness);
309 * @copydoc Dali::Window::GetBrightness()
311 int GetBrightness() const;
314 * @copydoc Dali::Window::SetSize()
316 void SetSize(Dali::Window::WindowSize size);
319 * @copydoc Dali::Window::GetSize()
321 Dali::Window::WindowSize GetSize() const;
324 * @copydoc Dali::Window::SetPosition()
326 void SetPosition(Dali::Window::WindowPosition position);
329 * @copydoc Dali::Window::GetPosition()
331 Dali::Window::WindowPosition GetPosition() const;
334 * @copydoc Dali::DevelWindow::SetPositionSize()
336 void SetPositionSize(PositionSize positionSize);
339 * @copydoc Dali::DevelWindow::GetPositionSize()
341 PositionSize GetPositionSize() const;
344 * @copydoc Dali::Window::SetLayout()
346 void SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan);
349 * @copydoc Dali::Window::GetRootLayer()
351 Dali::Layer GetRootLayer() const;
354 * @copydoc Dali::Window::SetTransparency()
356 void SetTransparency(bool transparent);
359 * @copydoc Dali::KeyGrab::GrabKey()
361 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
364 * @copydoc Dali::KeyGrab::UngrabKey()
366 bool UngrabKey(Dali::KEY key);
369 * @copydoc Dali::KeyGrab::GrabKeyList()
371 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
374 * @copydoc Dali::KeyGrab::UngrabKeyList()
376 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
379 * @copydoc Dali::DevelWindow::Get()
381 static Dali::Window Get(Dali::Actor actor);
384 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
386 void SetParent(Dali::Window& parent);
389 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
391 void SetParent(Dali::Window& parent, bool belowParent);
394 * @copydoc Dali::DevelWindow::Unparent()
399 * @copydoc Dali::DevelWindow::GetParent()
401 Dali::Window GetParent();
404 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
406 WindowOrientation GetCurrentOrientation() const;
409 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
411 int GetPhysicalOrientation() const;
414 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
416 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
419 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
421 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
424 * @brief Emit the accessibility highlight signal.
425 * The highlight indicates that it is an object to interact with the user regardless of focus.
426 * After setting the highlight on the object, you can do things that the object can do, such as
427 * giving or losing focus.
429 * @param[in] highlight If window needs to grab or clear highlight.
431 void EmitAccessibilityHighlightSignal(bool highlight);
434 * @brief Sets the render notification trigger to call when render thread is completed a frame
436 * @param[in] renderNotification to use
438 void SetRenderNotification(TriggerEventInterface* renderNotification);
440 public: // Dali::Internal::Adaptor::SceneHolder
442 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
444 Dali::Any GetNativeHandle() const override;
447 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
449 bool IsVisible() const override;
452 * @copydoc Dali::DevelWindow::GetNativeId()
454 int32_t GetNativeId() const;
457 * @copydoc Dali::DevelWindow::RequestMoveToServer()
459 void RequestMoveToServer();
462 * @copydoc Dali::DevelWindow::RequestResizeToServer()
464 void RequestResizeToServer(WindowResizeDirection direction);
467 * @copydoc Dali::DevelWindow::EnableFloatingMode()
469 void EnableFloatingMode(bool enable);
472 * @copydoc Dali::DevelWindow::IncludeInputRegion()
474 void IncludeInputRegion(const Rect<int>& inputRegion);
477 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
479 void ExcludeInputRegion(const Rect<int>& inputRegion);
482 * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
484 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
487 * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
489 void SendRotationCompletedAcknowledgement();
492 * @copydoc Dali::DevelWindow::IsWindowRotating()
494 bool IsWindowRotating() const;
497 * @copydoc Dali::DevelWindow::GetLastKeyEvent()
499 const Dali::KeyEvent& GetLastKeyEvent() const;
502 * @copydoc Dali::DevelWindow::GetLastTouchEvent()
504 const Dali::TouchEvent& GetLastTouchEvent() const;
508 * @brief Enumeration for orietation mode.
509 * The Orientation Mode is related to screen size.
510 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
511 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
513 enum class OrientationMode
520 * Private constructor.
531 * Second stage initialization
533 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
536 * Called when the window becomes iconified or deiconified.
538 void OnIconifyChanged(bool iconified);
541 * Called when the window becomes maximized or unmaximized.
543 void OnMaximizeChanged(bool maximized);
546 * Called when the window focus is changed.
548 void OnFocusChanged(bool focusIn);
551 * Called when the output is transformed.
553 void OnOutputTransformed();
556 * Called when the window receives a delete request.
558 void OnDeleteRequest();
561 * Called when the window receives a Transition effect-start/end event.
563 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
566 * @brief Called when window receives a keyboard repeat event.
568 void OnKeyboardRepeatSettingsChanged();
571 * @brief Called when the window redraw is requested.
573 void OnWindowRedrawRequest();
576 * @brief Called when the window's geometry data is changed by display server or client.
577 * It is based on configure noification event.
579 * @param[in] positionSize the updated window's position and size.
581 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
584 * @brief Called when display server sent the auxiliary message.
586 * @param[in] key the auxiliary message's key.
587 * @param[in] value the auxiliary message's value.
588 * @param[in] options the auxiliary message's options. This is the list of string.
590 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
593 * @brief Called when Accessibility is enabled.
595 * This method is to register the window to accessibility bridge.
597 void OnAccessibilityEnabled();
600 * @brief Called when Accessibility is disabled.
602 * This method is to remove the window from accessibility bridge.
604 void OnAccessibilityDisabled();
607 * Called when the window rotation is finished.
609 * This signal is emmit when window rotation is finisehd and WindowRotationCompleted() is called.
611 void OnRotationFinished();
614 * @brief Called when the mouse in or out event is received.
615 * @param[in] mouseInOutEvent the mouse event
617 void OnMouseInOutEvent(const Dali::DevelWindow::MouseInOutEvent& mouseInOutEvent);
620 * @brief Called when the window is moved by display server.
622 * @param[in] position the moved window's position.
624 void OnMoveCompleted(Dali::Window::WindowPosition& position);
627 * @brief Called when the window is resized by display server.
629 * @param[in] positionSize the resized window's size.
631 void OnResizeCompleted(Dali::Window::WindowSize& size);
634 * @brief Set available orientation to window base.
636 void SetAvailableAnlges(const std::vector<int>& angles);
639 * @brief Convert from window orientation to angle using OrientationMode.
641 int ConvertToAngle(WindowOrientation orientation);
644 * @brief Convert from angle to window orientation using OrientationMode.
646 WindowOrientation ConvertToOrientation(int angle) const;
649 * @brief Check available window orientation for Available orientation.
651 bool IsOrientationAvailable(WindowOrientation orientation) const;
653 private: // Dali::Internal::Adaptor::SceneHolder
655 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
657 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
660 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
662 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
665 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
667 void OnPause() override;
670 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
672 void OnResume() override;
675 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculatePosition
677 Vector2 RecalculatePosition(const Vector2& position) override;
679 private: // Dali::Internal::Adaptor::EventHandler::Observer
681 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
683 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
686 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
688 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
691 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
693 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
696 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
698 void OnRotation(const RotationEvent& rotation) override;
702 * @copydoc Dali::Window::FocusChangeSignal()
704 FocusChangeSignalType& FocusChangeSignal()
706 return mFocusChangeSignal;
710 * @copydoc Dali::Window::ResizedSignal()
712 ResizeSignalType& ResizeSignal()
714 return mResizeSignal;
718 * This signal is emitted when the window is requesting to be deleted
720 SignalType& DeleteRequestSignal()
722 return mDeleteRequestSignal;
726 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
728 VisibilityChangedSignalType& VisibilityChangedSignal()
730 return mVisibilityChangedSignal;
734 * @copydoc Dali::Window::SignalEventProcessingFinished()
736 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
738 return mScene.EventProcessingFinishedSignal();
742 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
744 TransitionEffectEventSignalType& TransitionEffectEventSignal()
746 return mTransitionEffectEventSignal;
750 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
752 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
754 return mKeyboardRepeatSettingsChangedSignal;
758 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
760 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
762 return mAuxiliaryMessageSignal;
766 * @copydoc Dali::DevelWindow::AccessibilityHighlightSignal()
768 AccessibilityHighlightSignalType& AccessibilityHighlightSignal()
770 return mAccessibilityHighlightSignal;
774 * @copydoc Dali::DevelWindow::MovedSignal()
776 MovedSignalType& MovedSignal()
782 * @copydoc Dali::DevelWindow::OrientationChangedSignal()
784 OrientationChangedSignalType& OrientationChangedSignal()
786 return mOrientationChangedSignal;
790 * @copydoc Dali::DevelWindow::MouseInOutEventSignal()
792 MouseInOutEventSignalType& MouseInOutEventSignal()
794 return mMouseInOutEventSignal;
798 * @copydoc Dali::DevelWindow::MoveCompletedSignal()
800 MoveCompletedSignalType& MoveCompletedSignal()
802 return mMoveCompletedSignal;
806 * @copydoc Dali::DevelWindow::ResizeCompletedSignal()
808 ResizeCompletedSignalType& ResizeCompletedSignal()
810 return mResizeCompletedSignal;
814 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
815 WindowBase* mWindowBase;
817 std::string mClassName;
818 Dali::Window mParentWindow;
820 OrientationPtr mOrientation;
821 std::vector<int> mAvailableAngles;
824 int mRotationAngle; ///< The angle of the rotation
825 int mWindowWidth; ///< The width of the window
826 int mWindowHeight; ///< The height of the window
827 int mNativeWindowId; ///< The Native Window Id
829 EventHandlerPtr mEventHandler; ///< The window events handler
830 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
833 SignalType mDeleteRequestSignal;
834 FocusChangeSignalType mFocusChangeSignal;
835 ResizeSignalType mResizeSignal;
836 VisibilityChangedSignalType mVisibilityChangedSignal;
837 TransitionEffectEventSignalType mTransitionEffectEventSignal;
838 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
839 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
840 AccessibilityHighlightSignalType mAccessibilityHighlightSignal;
841 MovedSignalType mMovedSignal;
842 OrientationChangedSignalType mOrientationChangedSignal;
843 MouseInOutEventSignalType mMouseInOutEventSignal;
844 MoveCompletedSignalType mMoveCompletedSignal;
845 ResizeCompletedSignalType mResizeCompletedSignal;
847 Dali::KeyEvent mLastKeyEvent;
848 Dali::TouchEvent mLastTouchEvent;
850 bool mIsTransparent : 1;
851 bool mIsFocusAcceptable : 1;
854 bool mOpaqueState : 1;
855 bool mWindowRotationAcknowledgement : 1;
857 bool mIsWindowRotating : 1; ///< The window rotating flag.
860 } // namespace Adaptor
861 } // namespace Internal
863 // Helpers for public-api forwarding methods
865 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
867 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
868 BaseObject& object = window.GetBaseObject();
869 return static_cast<Internal::Adaptor::Window&>(object);
872 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
874 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
875 const BaseObject& object = window.GetBaseObject();
876 return static_cast<const Internal::Adaptor::Window&>(object);
881 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H