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>
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 MouseInOutEventPtr = IntrusivePtr<Dali::DevelWindow::MouseInOutEvent>;
55 using EventHandlerPtr = IntrusivePtr<EventHandler>;
58 * Window provides a surface to render onto with orientation & indicator properties.
60 class Window : public Dali::Internal::Adaptor::SceneHolder, public EventHandler::Observer, public ConnectionTracker
63 typedef Dali::Window::FocusChangeSignalType FocusChangeSignalType;
64 typedef Dali::Window::ResizeSignalType ResizeSignalType;
65 typedef Dali::DevelWindow::VisibilityChangedSignalType VisibilityChangedSignalType;
66 typedef Dali::DevelWindow::TransitionEffectEventSignalType TransitionEffectEventSignalType;
67 typedef Dali::DevelWindow::KeyboardRepeatSettingsChangedSignalType KeyboardRepeatSettingsChangedSignalType;
68 typedef Dali::DevelWindow::AuxiliaryMessageSignalType AuxiliaryMessageSignalType;
69 typedef Dali::DevelWindow::AccessibilityHighlightSignalType AccessibilityHighlightSignalType;
70 typedef Dali::DevelWindow::MovedSignalType MovedSignalType;
71 typedef Dali::DevelWindow::OrientationChangedSignalType OrientationChangedSignalType;
72 typedef Dali::DevelWindow::MouseInOutEventSignalType MouseInOutEventSignalType;
73 typedef Dali::DevelWindow::MoveCompletedSignalType MoveCompletedSignalType;
74 typedef Dali::DevelWindow::ResizeCompletedSignalType ResizeCompletedSignalType;
75 typedef Dali::DevelWindow::InsetsChangedSignalType InsetsChangedSignalType;
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 * @brief Get window resource ID assigned by window manager
169 * @return The resource ID of the window
171 std::string GetNativeResourceId() const;
174 * @copydoc Dali::Window::AddAvailableOrientation()
176 void AddAvailableOrientation(WindowOrientation orientation);
179 * @copydoc Dali::Window::RemoveAvailableOrientation()
181 void RemoveAvailableOrientation(WindowOrientation orientation);
184 * @copydoc Dali::Window::SetPreferredOrientation()
186 void SetPreferredOrientation(WindowOrientation orientation);
189 * @copydoc Dali::Window::GetPreferredOrientation()
191 WindowOrientation GetPreferredOrientation();
194 * @copydoc Dali::Window::SetAcceptFocus()
196 void SetAcceptFocus(bool accept);
199 * @copydoc Dali::Window::IsFocusAcceptable()
201 bool IsFocusAcceptable() const;
204 * @copydoc Dali::Window::Show()
209 * @copydoc Dali::Window::Hide()
214 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
216 unsigned int GetSupportedAuxiliaryHintCount() const;
219 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
221 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
224 * @copydoc Dali::Window::AddAuxiliaryHint()
226 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
229 * @copydoc Dali::Window::RemoveAuxiliaryHint()
231 bool RemoveAuxiliaryHint(unsigned int id);
234 * @copydoc Dali::Window::SetAuxiliaryHintValue()
236 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
239 * @copydoc Dali::Window::GetAuxiliaryHintValue()
241 std::string GetAuxiliaryHintValue(unsigned int id) const;
244 * @copydoc Dali::Window::GetAuxiliaryHintId()
246 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
249 * @copydoc Dali::Window::SetInputRegion()
251 void SetInputRegion(const Rect<int>& inputRegion);
254 * @copydoc Dali::Window::SetType()
256 void SetType(WindowType type);
259 * @copydoc Dali::Window::GetType() const
261 WindowType GetType() const;
264 * @copydoc Dali::Window::SetNotificationLevel()
266 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
269 * @copydoc Dali::Window::GetNotificationLevel()
271 WindowNotificationLevel GetNotificationLevel() const;
274 * @copydoc Dali::Window::SetOpaqueState()
276 void SetOpaqueState(bool opaque);
279 * @copydoc Dali::Window::IsOpaqueState()
281 bool IsOpaqueState() const;
284 * @copydoc Dali::Window::SetScreenOffMode()
286 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
289 * @copydoc Dali::Window::GetScreenOffMode()
291 WindowScreenOffMode GetScreenOffMode() const;
294 * @copydoc Dali::Window::SetBrightness()
296 WindowOperationResult SetBrightness(int brightness);
299 * @copydoc Dali::Window::GetBrightness()
301 int GetBrightness() const;
304 * @copydoc Dali::Window::SetSize()
306 void SetSize(Dali::Window::WindowSize size);
309 * @copydoc Dali::Window::GetSize()
311 Dali::Window::WindowSize GetSize() const;
314 * @copydoc Dali::Window::SetPosition()
316 void SetPosition(Dali::Window::WindowPosition position);
319 * @copydoc Dali::Window::GetPosition()
321 Dali::Window::WindowPosition GetPosition() const;
324 * @copydoc Dali::DevelWindow::SetPositionSize()
326 void SetPositionSize(PositionSize positionSize);
329 * @copydoc Dali::DevelWindow::GetPositionSize()
331 PositionSize GetPositionSize() const;
334 * @copydoc Dali::Window::SetLayout()
336 void SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan);
339 * @copydoc Dali::Window::GetRootLayer()
341 Dali::Layer GetRootLayer() const;
344 * @copydoc Dali::Window::SetTransparency()
346 void SetTransparency(bool transparent);
349 * @copydoc Dali::KeyGrab::GrabKey()
351 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
354 * @copydoc Dali::KeyGrab::UngrabKey()
356 bool UngrabKey(Dali::KEY key);
359 * @copydoc Dali::KeyGrab::GrabKeyList()
361 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
364 * @copydoc Dali::KeyGrab::UngrabKeyList()
366 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
369 * @copydoc Dali::DevelWindow::Get()
371 static Dali::Window Get(Dali::Actor actor);
374 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
376 void SetParent(Dali::Window& parent);
379 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
381 void SetParent(Dali::Window& parent, bool belowParent);
384 * @copydoc Dali::DevelWindow::Unparent()
389 * @copydoc Dali::DevelWindow::GetParent()
391 Dali::Window GetParent();
394 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
396 WindowOrientation GetCurrentOrientation() const;
399 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
401 int GetPhysicalOrientation() const;
404 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
406 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
409 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
411 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
414 * @brief Emit the accessibility highlight signal.
415 * The highlight indicates that it is an object to interact with the user regardless of focus.
416 * After setting the highlight on the object, you can do things that the object can do, such as
417 * giving or losing focus.
419 * @param[in] highlight If window needs to grab or clear highlight.
421 void EmitAccessibilityHighlightSignal(bool highlight);
424 * @brief Sets the render notification trigger to call when render thread is completed a frame
426 * @param[in] renderNotification to use
428 void SetRenderNotification(TriggerEventInterface* renderNotification);
430 public: // Dali::Internal::Adaptor::SceneHolder
432 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
434 Dali::Any GetNativeHandle() const override;
437 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
439 bool IsVisible() const override;
442 * @copydoc Dali::DevelWindow::GetNativeId()
444 int32_t GetNativeId() const;
447 * @copydoc Dali::DevelWindow::RequestMoveToServer()
449 void RequestMoveToServer();
452 * @copydoc Dali::DevelWindow::RequestResizeToServer()
454 void RequestResizeToServer(WindowResizeDirection direction);
457 * @copydoc Dali::DevelWindow::EnableFloatingMode()
459 void EnableFloatingMode(bool enable);
462 * @copydoc Dali::DevelWindow::IsFloatingModeEnabled()
464 bool IsFloatingModeEnabled();
467 * @copydoc Dali::DevelWindow::IncludeInputRegion()
469 void IncludeInputRegion(const Rect<int>& inputRegion);
472 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
474 void ExcludeInputRegion(const Rect<int>& inputRegion);
477 * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
479 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
482 * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
484 void SendRotationCompletedAcknowledgement();
487 * @copydoc Dali::DevelWindow::IsWindowRotating()
489 bool IsWindowRotating() const;
492 * @copydoc Dali::DevelWindow::GetLastKeyEvent()
494 const Dali::KeyEvent& GetLastKeyEvent() const;
497 * @copydoc Dali::DevelWindow::GetLastTouchEvent()
499 const Dali::TouchEvent& GetLastTouchEvent() const;
503 * @brief Enumeration for orietation mode.
504 * The Orientation Mode is related to screen size.
505 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
506 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
508 enum class OrientationMode
515 * Private constructor.
526 * Second stage initialization
528 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
531 * Called when the window becomes iconified or deiconified.
533 void OnIconifyChanged(bool iconified);
536 * Called when the window focus is changed.
538 void OnFocusChanged(bool focusIn);
541 * Called when the output is transformed.
543 void OnOutputTransformed();
546 * Called when the window receives a delete request.
548 void OnDeleteRequest();
551 * Called when the window receives a Transition effect-start/end event.
553 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
556 * @brief Called when window receives a keyboard repeat event.
558 void OnKeyboardRepeatSettingsChanged();
561 * @brief Called when the window redraw is requested.
563 void OnWindowRedrawRequest();
566 * @brief Called when the window's geometry data is changed by display server or client.
567 * It is based on configure noification event.
569 * @param[in] positionSize the updated window's position and size.
571 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
574 * @brief Called when display server sent the auxiliary message.
576 * @param[in] key the auxiliary message's key.
577 * @param[in] value the auxiliary message's value.
578 * @param[in] options the auxiliary message's options. This is the list of string.
580 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
583 * @brief Called when Accessibility is enabled.
585 * This method is to register the window to accessibility bridge.
587 void OnAccessibilityEnabled();
590 * @brief Called when Accessibility is disabled.
592 * This method is to remove the window from accessibility bridge.
594 void OnAccessibilityDisabled();
597 * Called when the window rotation is finished.
599 * This signal is emmit when window rotation is finisehd and WindowRotationCompleted() is called.
601 void OnRotationFinished();
604 * @brief Called when the mouse in or out event is received.
605 * @param[in] mouseInOutEvent the mouse event
607 void OnMouseInOutEvent(const Dali::DevelWindow::MouseInOutEvent& mouseInOutEvent);
610 * @brief Called when the window is moved by display server.
612 * @param[in] position the moved window's position.
614 void OnMoveCompleted(Dali::Window::WindowPosition& position);
617 * @brief Called when the window is resized by display server.
619 * @param[in] positionSize the resized window's size.
621 void OnResizeCompleted(Dali::Window::WindowSize& size);
624 * @brief Set available orientation to window base.
626 void SetAvailableAnlges(const std::vector<int>& angles);
629 * @brief Convert from window orientation to angle using OrientationMode.
631 int ConvertToAngle(WindowOrientation orientation);
634 * @brief Convert from angle to window orientation using OrientationMode.
636 WindowOrientation ConvertToOrientation(int angle) const;
639 * @brief Check available window orientation for Available orientation.
641 bool IsOrientationAvailable(WindowOrientation orientation) const;
644 * @brief Called when window insets are changed by appearing or disappearing indicator, virtual keyboard, or clipboard.
646 * @param[in] partType the type of the part that occurs the window insets change.
647 * @param[in] partState the state of the part that occurs the window insets change.
648 * @param[in] insets the extents value of window insets.
650 void OnInsetsChanged(WindowInsetsPartType partType, WindowInsetsPartState partState, const Extents& insets);
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 * @copydoc Dali::DevelWindow::InsetsChangedSignal()
816 InsetsChangedSignalType& InsetsChangedSignal()
818 return mInsetsChangedSignal;
822 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
823 WindowBase* mWindowBase;
825 std::string mClassName;
826 Dali::Window mParentWindow;
828 OrientationPtr mOrientation;
829 std::vector<int> mAvailableAngles;
832 int mRotationAngle; ///< The angle of the rotation
833 int mWindowWidth; ///< The width of the window
834 int mWindowHeight; ///< The height of the window
835 int mNativeWindowId; ///< The Native Window Id
837 EventHandlerPtr mEventHandler; ///< The window events handler
838 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
841 SignalType mDeleteRequestSignal;
842 FocusChangeSignalType mFocusChangeSignal;
843 ResizeSignalType mResizeSignal;
844 VisibilityChangedSignalType mVisibilityChangedSignal;
845 TransitionEffectEventSignalType mTransitionEffectEventSignal;
846 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
847 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
848 AccessibilityHighlightSignalType mAccessibilityHighlightSignal;
849 MovedSignalType mMovedSignal;
850 OrientationChangedSignalType mOrientationChangedSignal;
851 MouseInOutEventSignalType mMouseInOutEventSignal;
852 MoveCompletedSignalType mMoveCompletedSignal;
853 ResizeCompletedSignalType mResizeCompletedSignal;
854 InsetsChangedSignalType mInsetsChangedSignal;
856 Dali::KeyEvent mLastKeyEvent;
857 Dali::TouchEvent mLastTouchEvent;
859 bool mIsTransparent : 1;
860 bool mIsFocusAcceptable : 1;
862 bool mOpaqueState : 1;
863 bool mWindowRotationAcknowledgement : 1;
865 bool mIsWindowRotating : 1; ///< The window rotating flag.
868 } // namespace Adaptor
869 } // namespace Internal
871 // Helpers for public-api forwarding methods
873 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
875 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
876 BaseObject& object = window.GetBaseObject();
877 return static_cast<Internal::Adaptor::Window&>(object);
880 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
882 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
883 const BaseObject& object = window.GetBaseObject();
884 return static_cast<const Internal::Adaptor::Window&>(object);
889 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H