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 Signal<void()> SignalType;
78 * @brief Create a new Window. This should only be called once by the Application class
79 * @param[in] positionSize The position and size of the window
80 * @param[in] name The window title
81 * @param[in] className The window class name
82 * @param[in] type Window type.
83 * @param[in] isTransparent Whether window is transparent
84 * @return A newly allocated Window
86 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
89 * @brief Create a new Window. This should only be called once by the Application class
90 * @param[in] surface The surface used to render on.
91 * @param[in] positionSize The position and size of the window
92 * @param[in] name The window title
93 * @param[in] className The window class name
94 * @param[in] type Window type.
95 * @param[in] isTransparent Whether window is transparent
96 * @return A newly allocated Window
98 static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
101 * @copydoc Dali::Window::SetClass()
103 void SetClass(std::string name, std::string className);
106 * @brief Gets the window class name.
107 * @return The class of the window
109 std::string GetClassName() const;
112 * @copydoc Dali::Window::Raise()
117 * @copydoc Dali::Window::Lower()
122 * @copydoc Dali::Window::Activate()
127 * @copydoc Dali::DevelWindow::Maximize()
129 void Maximize(bool maximize);
132 * @copydoc Dali::DevelWindow::IsMaximized()
134 bool IsMaximized() const;
137 * @copydoc Dali::DevelWindow::SetMaximumSize()
139 void SetMaximumSize(Dali::Window::WindowSize size);
142 * @copydoc Dali::DevelWindow::Minimize()
144 void Minimize(bool minimize);
147 * @copydoc Dali::DevelWindow::IsMinimized()
149 bool IsMinimized() const;
152 * @copydoc Dali::DevelWindow::SetMimimumSize()
154 void SetMimimumSize(Dali::Window::WindowSize size);
157 * @copydoc Dali::Window::GetLayerCount()
159 uint32_t GetLayerCount() const;
162 * @copydoc Dali::Window::GetLayer()
164 Dali::Layer GetLayer(uint32_t depth) const;
167 * @copydoc Dali::Window::KeepRendering()
169 void KeepRendering(float durationSeconds);
172 * @brief Get window resource ID assigned by window manager
173 * @return The resource ID of the window
175 std::string GetNativeResourceId() const;
178 * @copydoc Dali::Window::AddAvailableOrientation()
180 void AddAvailableOrientation(WindowOrientation orientation);
183 * @copydoc Dali::Window::RemoveAvailableOrientation()
185 void RemoveAvailableOrientation(WindowOrientation orientation);
188 * @copydoc Dali::Window::SetPreferredOrientation()
190 void SetPreferredOrientation(WindowOrientation orientation);
193 * @copydoc Dali::Window::GetPreferredOrientation()
195 WindowOrientation GetPreferredOrientation();
198 * @copydoc Dali::Window::SetAcceptFocus()
200 void SetAcceptFocus(bool accept);
203 * @copydoc Dali::Window::IsFocusAcceptable()
205 bool IsFocusAcceptable() const;
208 * @copydoc Dali::Window::Show()
213 * @copydoc Dali::Window::Hide()
218 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
220 unsigned int GetSupportedAuxiliaryHintCount() const;
223 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
225 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
228 * @copydoc Dali::Window::AddAuxiliaryHint()
230 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
233 * @copydoc Dali::Window::RemoveAuxiliaryHint()
235 bool RemoveAuxiliaryHint(unsigned int id);
238 * @copydoc Dali::Window::SetAuxiliaryHintValue()
240 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
243 * @copydoc Dali::Window::GetAuxiliaryHintValue()
245 std::string GetAuxiliaryHintValue(unsigned int id) const;
248 * @copydoc Dali::Window::GetAuxiliaryHintId()
250 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
253 * @copydoc Dali::Window::SetInputRegion()
255 void SetInputRegion(const Rect<int>& inputRegion);
258 * @copydoc Dali::Window::SetType()
260 void SetType(WindowType type);
263 * @copydoc Dali::Window::GetType() const
265 WindowType GetType() const;
268 * @copydoc Dali::Window::SetNotificationLevel()
270 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
273 * @copydoc Dali::Window::GetNotificationLevel()
275 WindowNotificationLevel GetNotificationLevel() const;
278 * @copydoc Dali::Window::SetOpaqueState()
280 void SetOpaqueState(bool opaque);
283 * @copydoc Dali::Window::IsOpaqueState()
285 bool IsOpaqueState() const;
288 * @copydoc Dali::Window::SetScreenOffMode()
290 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
293 * @copydoc Dali::Window::GetScreenOffMode()
295 WindowScreenOffMode GetScreenOffMode() const;
298 * @copydoc Dali::Window::SetBrightness()
300 WindowOperationResult SetBrightness(int brightness);
303 * @copydoc Dali::Window::GetBrightness()
305 int GetBrightness() const;
308 * @copydoc Dali::Window::SetSize()
310 void SetSize(Dali::Window::WindowSize size);
313 * @copydoc Dali::Window::GetSize()
315 Dali::Window::WindowSize GetSize() const;
318 * @copydoc Dali::Window::SetPosition()
320 void SetPosition(Dali::Window::WindowPosition position);
323 * @copydoc Dali::Window::GetPosition()
325 Dali::Window::WindowPosition GetPosition() const;
328 * @copydoc Dali::DevelWindow::SetPositionSize()
330 void SetPositionSize(PositionSize positionSize);
333 * @copydoc Dali::DevelWindow::GetPositionSize()
335 PositionSize GetPositionSize() const;
338 * @copydoc Dali::Window::SetLayout()
340 void SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan);
343 * @copydoc Dali::Window::GetRootLayer()
345 Dali::Layer GetRootLayer() const;
348 * @copydoc Dali::Window::SetTransparency()
350 void SetTransparency(bool transparent);
353 * @copydoc Dali::KeyGrab::GrabKey()
355 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
358 * @copydoc Dali::KeyGrab::UngrabKey()
360 bool UngrabKey(Dali::KEY key);
363 * @copydoc Dali::KeyGrab::GrabKeyList()
365 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
368 * @copydoc Dali::KeyGrab::UngrabKeyList()
370 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
373 * @copydoc Dali::DevelWindow::Get()
375 static Dali::Window Get(Dali::Actor actor);
378 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
380 void SetParent(Dali::Window& parent);
383 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
385 void SetParent(Dali::Window& parent, bool belowParent);
388 * @copydoc Dali::DevelWindow::Unparent()
393 * @copydoc Dali::DevelWindow::GetParent()
395 Dali::Window GetParent();
398 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
400 WindowOrientation GetCurrentOrientation() const;
403 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
405 int GetPhysicalOrientation() const;
408 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
410 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
413 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
415 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
418 * @brief Emit the accessibility highlight signal.
419 * The highlight indicates that it is an object to interact with the user regardless of focus.
420 * After setting the highlight on the object, you can do things that the object can do, such as
421 * giving or losing focus.
423 * @param[in] highlight If window needs to grab or clear highlight.
425 void EmitAccessibilityHighlightSignal(bool highlight);
428 * @brief Sets the render notification trigger to call when render thread is completed a frame
430 * @param[in] renderNotification to use
432 void SetRenderNotification(TriggerEventInterface* renderNotification);
434 public: // Dali::Internal::Adaptor::SceneHolder
436 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
438 Dali::Any GetNativeHandle() const override;
441 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
443 bool IsVisible() const override;
446 * @copydoc Dali::DevelWindow::GetNativeId()
448 int32_t GetNativeId() const;
451 * @copydoc Dali::DevelWindow::RequestMoveToServer()
453 void RequestMoveToServer();
456 * @copydoc Dali::DevelWindow::RequestResizeToServer()
458 void RequestResizeToServer(WindowResizeDirection direction);
461 * @copydoc Dali::DevelWindow::EnableFloatingMode()
463 void EnableFloatingMode(bool enable);
466 * @copydoc Dali::DevelWindow::IncludeInputRegion()
468 void IncludeInputRegion(const Rect<int>& inputRegion);
471 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
473 void ExcludeInputRegion(const Rect<int>& inputRegion);
476 * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
478 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
481 * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
483 void SendRotationCompletedAcknowledgement();
486 * @copydoc Dali::DevelWindow::IsWindowRotating()
488 bool IsWindowRotating() const;
491 * @copydoc Dali::DevelWindow::GetLastKeyEvent()
493 const Dali::KeyEvent& GetLastKeyEvent() const;
496 * @copydoc Dali::DevelWindow::GetLastTouchEvent()
498 const Dali::TouchEvent& GetLastTouchEvent() const;
502 * @brief Enumeration for orietation mode.
503 * The Orientation Mode is related to screen size.
504 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
505 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
507 enum class OrientationMode
514 * Private constructor.
525 * Second stage initialization
527 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
530 * Called when the window becomes iconified or deiconified.
532 void OnIconifyChanged(bool iconified);
535 * Called when the window becomes maximized or unmaximized.
537 void OnMaximizeChanged(bool maximized);
540 * Called when the window focus is changed.
542 void OnFocusChanged(bool focusIn);
545 * Called when the output is transformed.
547 void OnOutputTransformed();
550 * Called when the window receives a delete request.
552 void OnDeleteRequest();
555 * Called when the window receives a Transition effect-start/end event.
557 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
560 * @brief Called when window receives a keyboard repeat event.
562 void OnKeyboardRepeatSettingsChanged();
565 * @brief Called when the window redraw is requested.
567 void OnWindowRedrawRequest();
570 * @brief Called when the window's geometry data is changed by display server or client.
571 * It is based on configure noification event.
573 * @param[in] positionSize the updated window's position and size.
575 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
578 * @brief Called when display server sent the auxiliary message.
580 * @param[in] key the auxiliary message's key.
581 * @param[in] value the auxiliary message's value.
582 * @param[in] options the auxiliary message's options. This is the list of string.
584 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
587 * @brief Called when Accessibility is enabled.
589 * This method is to register the window to accessibility bridge.
591 void OnAccessibilityEnabled();
594 * @brief Called when Accessibility is disabled.
596 * This method is to remove the window from accessibility bridge.
598 void OnAccessibilityDisabled();
601 * Called when the window rotation is finished.
603 * This signal is emmit when window rotation is finisehd and WindowRotationCompleted() is called.
605 void OnRotationFinished();
608 * @brief Called when the mouse in or out event is received.
609 * @param[in] mouseInOutEvent the mouse event
611 void OnMouseInOutEvent(const Dali::DevelWindow::MouseInOutEvent& mouseInOutEvent);
614 * @brief Called when the window is moved by display server.
616 * @param[in] position the moved window's position.
618 void OnMoveCompleted(Dali::Window::WindowPosition& position);
621 * @brief Called when the window is resized by display server.
623 * @param[in] positionSize the resized window's size.
625 void OnResizeCompleted(Dali::Window::WindowSize& size);
628 * @brief Set available orientation to window base.
630 void SetAvailableAnlges(const std::vector<int>& angles);
633 * @brief Convert from window orientation to angle using OrientationMode.
635 int ConvertToAngle(WindowOrientation orientation);
638 * @brief Convert from angle to window orientation using OrientationMode.
640 WindowOrientation ConvertToOrientation(int angle) const;
643 * @brief Check available window orientation for Available orientation.
645 bool IsOrientationAvailable(WindowOrientation orientation) const;
648 * @brief Sets user geometry flag when window's geometry is changed.
649 * Window is created with screen size or not.
650 * If window is created with screen size or the geometry is changed by user,
651 * client should inform to server setting user.geometry flag
653 void SetUserGeometryPolicy();
655 private: // Dali::Internal::Adaptor::SceneHolder
657 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
659 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
662 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
664 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
667 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
669 void OnPause() override;
672 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
674 void OnResume() override;
677 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculatePosition
679 Vector2 RecalculatePosition(const Vector2& position) override;
681 private: // Dali::Internal::Adaptor::EventHandler::Observer
683 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
685 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
688 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
690 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
693 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
695 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
698 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
700 void OnRotation(const RotationEvent& rotation) override;
704 * @copydoc Dali::Window::FocusChangeSignal()
706 FocusChangeSignalType& FocusChangeSignal()
708 return mFocusChangeSignal;
712 * @copydoc Dali::Window::ResizedSignal()
714 ResizeSignalType& ResizeSignal()
716 return mResizeSignal;
720 * This signal is emitted when the window is requesting to be deleted
722 SignalType& DeleteRequestSignal()
724 return mDeleteRequestSignal;
728 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
730 VisibilityChangedSignalType& VisibilityChangedSignal()
732 return mVisibilityChangedSignal;
736 * @copydoc Dali::Window::SignalEventProcessingFinished()
738 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
740 return mScene.EventProcessingFinishedSignal();
744 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
746 TransitionEffectEventSignalType& TransitionEffectEventSignal()
748 return mTransitionEffectEventSignal;
752 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
754 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
756 return mKeyboardRepeatSettingsChangedSignal;
760 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
762 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
764 return mAuxiliaryMessageSignal;
768 * @copydoc Dali::DevelWindow::AccessibilityHighlightSignal()
770 AccessibilityHighlightSignalType& AccessibilityHighlightSignal()
772 return mAccessibilityHighlightSignal;
776 * @copydoc Dali::DevelWindow::MovedSignal()
778 MovedSignalType& MovedSignal()
784 * @copydoc Dali::DevelWindow::OrientationChangedSignal()
786 OrientationChangedSignalType& OrientationChangedSignal()
788 return mOrientationChangedSignal;
792 * @copydoc Dali::DevelWindow::MouseInOutEventSignal()
794 MouseInOutEventSignalType& MouseInOutEventSignal()
796 return mMouseInOutEventSignal;
800 * @copydoc Dali::DevelWindow::MoveCompletedSignal()
802 MoveCompletedSignalType& MoveCompletedSignal()
804 return mMoveCompletedSignal;
808 * @copydoc Dali::DevelWindow::ResizeCompletedSignal()
810 ResizeCompletedSignalType& ResizeCompletedSignal()
812 return mResizeCompletedSignal;
816 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
817 WindowBase* mWindowBase;
819 std::string mClassName;
820 Dali::Window mParentWindow;
822 OrientationPtr mOrientation;
823 std::vector<int> mAvailableAngles;
826 int mRotationAngle; ///< The angle of the rotation
827 int mWindowWidth; ///< The width of the window
828 int mWindowHeight; ///< The height of the window
829 int mNativeWindowId; ///< The Native Window Id
831 EventHandlerPtr mEventHandler; ///< The window events handler
832 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
835 SignalType mDeleteRequestSignal;
836 FocusChangeSignalType mFocusChangeSignal;
837 ResizeSignalType mResizeSignal;
838 VisibilityChangedSignalType mVisibilityChangedSignal;
839 TransitionEffectEventSignalType mTransitionEffectEventSignal;
840 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
841 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
842 AccessibilityHighlightSignalType mAccessibilityHighlightSignal;
843 MovedSignalType mMovedSignal;
844 OrientationChangedSignalType mOrientationChangedSignal;
845 MouseInOutEventSignalType mMouseInOutEventSignal;
846 MoveCompletedSignalType mMoveCompletedSignal;
847 ResizeCompletedSignalType mResizeCompletedSignal;
849 Dali::KeyEvent mLastKeyEvent;
850 Dali::TouchEvent mLastTouchEvent;
852 bool mIsTransparent : 1;
853 bool mIsFocusAcceptable : 1;
856 bool mOpaqueState : 1;
857 bool mWindowRotationAcknowledgement : 1;
859 bool mIsWindowRotating : 1; ///< The window rotating flag.
860 bool mIsEnabledUserGeometry : 1; ///< The user geometry enable flag.
863 } // namespace Adaptor
864 } // namespace Internal
866 // Helpers for public-api forwarding methods
868 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
870 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
871 BaseObject& object = window.GetBaseObject();
872 return static_cast<Internal::Adaptor::Window&>(object);
875 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
877 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
878 const BaseObject& object = window.GetBaseObject();
879 return static_cast<const Internal::Adaptor::Window&>(object);
884 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H