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::DevelWindow::GetRenderTaskList()
170 Dali::RenderTaskList GetRenderTaskList() const;
173 * @brief Get window resource ID assigned by window manager
174 * @return The resource ID of the window
176 std::string GetNativeResourceId() const;
179 * @copydoc Dali::Window::AddAvailableOrientation()
181 void AddAvailableOrientation(WindowOrientation orientation);
184 * @copydoc Dali::Window::RemoveAvailableOrientation()
186 void RemoveAvailableOrientation(WindowOrientation orientation);
189 * @copydoc Dali::Window::SetPreferredOrientation()
191 void SetPreferredOrientation(WindowOrientation orientation);
194 * @copydoc Dali::Window::GetPreferredOrientation()
196 WindowOrientation GetPreferredOrientation();
199 * @copydoc Dali::Window::SetAcceptFocus()
201 void SetAcceptFocus(bool accept);
204 * @copydoc Dali::Window::IsFocusAcceptable()
206 bool IsFocusAcceptable() const;
209 * @copydoc Dali::Window::Show()
214 * @copydoc Dali::Window::Hide()
219 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
221 unsigned int GetSupportedAuxiliaryHintCount() const;
224 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
226 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
229 * @copydoc Dali::Window::AddAuxiliaryHint()
231 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
234 * @copydoc Dali::Window::RemoveAuxiliaryHint()
236 bool RemoveAuxiliaryHint(unsigned int id);
239 * @copydoc Dali::Window::SetAuxiliaryHintValue()
241 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
244 * @copydoc Dali::Window::GetAuxiliaryHintValue()
246 std::string GetAuxiliaryHintValue(unsigned int id) const;
249 * @copydoc Dali::Window::GetAuxiliaryHintId()
251 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
254 * @copydoc Dali::Window::SetInputRegion()
256 void SetInputRegion(const Rect<int>& inputRegion);
259 * @copydoc Dali::Window::SetType()
261 void SetType(WindowType type);
264 * @copydoc Dali::Window::GetType() const
266 WindowType GetType() const;
269 * @copydoc Dali::Window::SetNotificationLevel()
271 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
274 * @copydoc Dali::Window::GetNotificationLevel()
276 WindowNotificationLevel GetNotificationLevel() const;
279 * @copydoc Dali::Window::SetOpaqueState()
281 void SetOpaqueState(bool opaque);
284 * @copydoc Dali::Window::IsOpaqueState()
286 bool IsOpaqueState() const;
289 * @copydoc Dali::Window::SetScreenOffMode()
291 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
294 * @copydoc Dali::Window::GetScreenOffMode()
296 WindowScreenOffMode GetScreenOffMode() const;
299 * @copydoc Dali::Window::SetBrightness()
301 WindowOperationResult SetBrightness(int brightness);
304 * @copydoc Dali::Window::GetBrightness()
306 int GetBrightness() const;
309 * @copydoc Dali::Window::SetSize()
311 void SetSize(Dali::Window::WindowSize size);
314 * @copydoc Dali::Window::GetSize()
316 Dali::Window::WindowSize GetSize() const;
319 * @copydoc Dali::Window::SetPosition()
321 void SetPosition(Dali::Window::WindowPosition position);
324 * @copydoc Dali::Window::GetPosition()
326 Dali::Window::WindowPosition GetPosition() const;
329 * @copydoc Dali::DevelWindow::SetPositionSize()
331 void SetPositionSize(PositionSize positionSize);
334 * @copydoc Dali::DevelWindow::GetPositionSize()
336 PositionSize GetPositionSize() const;
339 * @copydoc Dali::Window::SetLayout()
341 void SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan);
344 * @copydoc Dali::Window::GetRootLayer()
346 Dali::Layer GetRootLayer() const;
349 * @copydoc Dali::Window::SetTransparency()
351 void SetTransparency(bool transparent);
354 * @copydoc Dali::KeyGrab::GrabKey()
356 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
359 * @copydoc Dali::KeyGrab::UngrabKey()
361 bool UngrabKey(Dali::KEY key);
364 * @copydoc Dali::KeyGrab::GrabKeyList()
366 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
369 * @copydoc Dali::KeyGrab::UngrabKeyList()
371 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
374 * @copydoc Dali::DevelWindow::Get()
376 static Dali::Window Get(Dali::Actor actor);
379 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
381 void SetParent(Dali::Window& parent);
384 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
386 void SetParent(Dali::Window& parent, bool belowParent);
389 * @copydoc Dali::DevelWindow::Unparent()
394 * @copydoc Dali::DevelWindow::GetParent()
396 Dali::Window GetParent();
399 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
401 WindowOrientation GetCurrentOrientation() const;
404 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
406 int GetPhysicalOrientation() const;
409 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
411 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
414 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
416 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
419 * @brief Emit the accessibility highlight signal.
420 * The highlight indicates that it is an object to interact with the user regardless of focus.
421 * After setting the highlight on the object, you can do things that the object can do, such as
422 * giving or losing focus.
424 * @param[in] highlight If window needs to grab or clear highlight.
426 void EmitAccessibilityHighlightSignal(bool highlight);
429 * @brief Sets the render notification trigger to call when render thread is completed a frame
431 * @param[in] renderNotification to use
433 void SetRenderNotification(TriggerEventInterface* renderNotification);
435 public: // Dali::Internal::Adaptor::SceneHolder
437 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
439 Dali::Any GetNativeHandle() const override;
442 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
444 bool IsVisible() const override;
447 * @copydoc Dali::DevelWindow::GetNativeId()
449 int32_t GetNativeId() const;
452 * @copydoc Dali::DevelWindow::RequestMoveToServer()
454 void RequestMoveToServer();
457 * @copydoc Dali::DevelWindow::RequestResizeToServer()
459 void RequestResizeToServer(WindowResizeDirection direction);
462 * @copydoc Dali::DevelWindow::EnableFloatingMode()
464 void EnableFloatingMode(bool enable);
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;
643 private: // Dali::Internal::Adaptor::SceneHolder
645 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
647 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
650 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
652 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
655 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
657 void OnPause() override;
660 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
662 void OnResume() override;
665 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculatePosition
667 Vector2 RecalculatePosition(const Vector2& position) override;
669 private: // Dali::Internal::Adaptor::EventHandler::Observer
671 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
673 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
676 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
678 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
681 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
683 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
686 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
688 void OnRotation(const RotationEvent& rotation) override;
692 * @copydoc Dali::Window::FocusChangeSignal()
694 FocusChangeSignalType& FocusChangeSignal()
696 return mFocusChangeSignal;
700 * @copydoc Dali::Window::ResizedSignal()
702 ResizeSignalType& ResizeSignal()
704 return mResizeSignal;
708 * This signal is emitted when the window is requesting to be deleted
710 SignalType& DeleteRequestSignal()
712 return mDeleteRequestSignal;
716 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
718 VisibilityChangedSignalType& VisibilityChangedSignal()
720 return mVisibilityChangedSignal;
724 * @copydoc Dali::Window::SignalEventProcessingFinished()
726 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
728 return mScene.EventProcessingFinishedSignal();
732 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
734 TransitionEffectEventSignalType& TransitionEffectEventSignal()
736 return mTransitionEffectEventSignal;
740 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
742 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
744 return mKeyboardRepeatSettingsChangedSignal;
748 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
750 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
752 return mAuxiliaryMessageSignal;
756 * @copydoc Dali::DevelWindow::AccessibilityHighlightSignal()
758 AccessibilityHighlightSignalType& AccessibilityHighlightSignal()
760 return mAccessibilityHighlightSignal;
764 * @copydoc Dali::DevelWindow::MovedSignal()
766 MovedSignalType& MovedSignal()
772 * @copydoc Dali::DevelWindow::OrientationChangedSignal()
774 OrientationChangedSignalType& OrientationChangedSignal()
776 return mOrientationChangedSignal;
780 * @copydoc Dali::DevelWindow::MouseInOutEventSignal()
782 MouseInOutEventSignalType& MouseInOutEventSignal()
784 return mMouseInOutEventSignal;
788 * @copydoc Dali::DevelWindow::MoveCompletedSignal()
790 MoveCompletedSignalType& MoveCompletedSignal()
792 return mMoveCompletedSignal;
796 * @copydoc Dali::DevelWindow::ResizeCompletedSignal()
798 ResizeCompletedSignalType& ResizeCompletedSignal()
800 return mResizeCompletedSignal;
804 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
805 WindowBase* mWindowBase;
807 std::string mClassName;
808 Dali::Window mParentWindow;
810 OrientationPtr mOrientation;
811 std::vector<int> mAvailableAngles;
814 int mRotationAngle; ///< The angle of the rotation
815 int mWindowWidth; ///< The width of the window
816 int mWindowHeight; ///< The height of the window
817 int mNativeWindowId; ///< The Native Window Id
819 EventHandlerPtr mEventHandler; ///< The window events handler
820 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
823 SignalType mDeleteRequestSignal;
824 FocusChangeSignalType mFocusChangeSignal;
825 ResizeSignalType mResizeSignal;
826 VisibilityChangedSignalType mVisibilityChangedSignal;
827 TransitionEffectEventSignalType mTransitionEffectEventSignal;
828 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
829 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
830 AccessibilityHighlightSignalType mAccessibilityHighlightSignal;
831 MovedSignalType mMovedSignal;
832 OrientationChangedSignalType mOrientationChangedSignal;
833 MouseInOutEventSignalType mMouseInOutEventSignal;
834 MoveCompletedSignalType mMoveCompletedSignal;
835 ResizeCompletedSignalType mResizeCompletedSignal;
837 Dali::KeyEvent mLastKeyEvent;
838 Dali::TouchEvent mLastTouchEvent;
840 bool mIsTransparent : 1;
841 bool mIsFocusAcceptable : 1;
843 bool mOpaqueState : 1;
844 bool mWindowRotationAcknowledgement : 1;
846 bool mIsWindowRotating : 1; ///< The window rotating flag.
849 } // namespace Adaptor
850 } // namespace Internal
852 // Helpers for public-api forwarding methods
854 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
856 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
857 BaseObject& object = window.GetBaseObject();
858 return static_cast<Internal::Adaptor::Window&>(object);
861 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
863 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
864 const BaseObject& object = window.GetBaseObject();
865 return static_cast<const Internal::Adaptor::Window&>(object);
870 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H