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] name The window title
80 * @param[in] className The window class name
81 * @param[in] windowData The window data
82 * @return A newly allocated Window
84 static Window* New(const std::string& name, const std::string& className, const WindowData& windowData);
87 * @brief Create a new Window. This should only be called once by the Application class
88 * @param[in] surface The surface used to render on.
89 * @param[in] name The window title
90 * @param[in] className The window class name
91 * @param[in] windowData The window data
92 * @return A newly allocated Window
94 static Window* New(Any surface, const std::string& name, const std::string& className, const WindowData& windowData);
97 * @copydoc Dali::Window::SetClass()
99 void SetClass(std::string name, std::string className);
102 * @brief Gets the window class name.
103 * @return The class of the window
105 std::string GetClassName() const;
108 * @copydoc Dali::Window::Raise()
113 * @copydoc Dali::Window::Lower()
118 * @copydoc Dali::Window::Activate()
123 * @copydoc Dali::DevelWindow::Maximize()
125 void Maximize(bool maximize);
128 * @copydoc Dali::DevelWindow::IsMaximized()
130 bool IsMaximized() const;
133 * @copydoc Dali::DevelWindow::SetMaximumSize()
135 void SetMaximumSize(Dali::Window::WindowSize size);
138 * @copydoc Dali::DevelWindow::Minimize()
140 void Minimize(bool minimize);
143 * @copydoc Dali::DevelWindow::IsMinimized()
145 bool IsMinimized() const;
148 * @copydoc Dali::DevelWindow::SetMimimumSize()
150 void SetMimimumSize(Dali::Window::WindowSize size);
153 * @copydoc Dali::Window::GetLayerCount()
155 uint32_t GetLayerCount() const;
158 * @copydoc Dali::Window::GetLayer()
160 Dali::Layer GetLayer(uint32_t depth) const;
163 * @copydoc Dali::Window::KeepRendering()
165 void KeepRendering(float durationSeconds);
168 * @copydoc Dali::Window::SetPartialUpdateEnabled()
170 void SetPartialUpdateEnabled(bool enabled);
173 * @copydoc Dali::Window::IsPartialUpdateEnabled()
175 bool IsPartialUpdateEnabled() const;
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;
654 * @brief Sets user geometry flag when window's geometry is changed.
655 * Window is created with screen size or not.
656 * If window is created with screen size or the geometry is changed by user,
657 * client should inform to server setting user.geometry flag
659 void SetUserGeometryPolicy();
661 private: // Dali::Internal::Adaptor::SceneHolder
663 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
665 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
668 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
670 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
673 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
675 void OnPause() override;
678 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
680 void OnResume() override;
683 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculatePosition
685 Vector2 RecalculatePosition(const Vector2& position) override;
687 private: // Dali::Internal::Adaptor::EventHandler::Observer
689 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
691 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
694 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
696 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
699 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
701 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
704 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
706 void OnRotation(const RotationEvent& rotation) override;
710 * @copydoc Dali::Window::FocusChangeSignal()
712 FocusChangeSignalType& FocusChangeSignal()
714 return mFocusChangeSignal;
718 * @copydoc Dali::Window::ResizedSignal()
720 ResizeSignalType& ResizeSignal()
722 return mResizeSignal;
726 * This signal is emitted when the window is requesting to be deleted
728 SignalType& DeleteRequestSignal()
730 return mDeleteRequestSignal;
734 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
736 VisibilityChangedSignalType& VisibilityChangedSignal()
738 return mVisibilityChangedSignal;
742 * @copydoc Dali::Window::SignalEventProcessingFinished()
744 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
746 return mScene.EventProcessingFinishedSignal();
750 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
752 TransitionEffectEventSignalType& TransitionEffectEventSignal()
754 return mTransitionEffectEventSignal;
758 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
760 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
762 return mKeyboardRepeatSettingsChangedSignal;
766 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
768 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
770 return mAuxiliaryMessageSignal;
774 * @copydoc Dali::DevelWindow::AccessibilityHighlightSignal()
776 AccessibilityHighlightSignalType& AccessibilityHighlightSignal()
778 return mAccessibilityHighlightSignal;
782 * @copydoc Dali::DevelWindow::MovedSignal()
784 MovedSignalType& MovedSignal()
790 * @copydoc Dali::DevelWindow::OrientationChangedSignal()
792 OrientationChangedSignalType& OrientationChangedSignal()
794 return mOrientationChangedSignal;
798 * @copydoc Dali::DevelWindow::MouseInOutEventSignal()
800 MouseInOutEventSignalType& MouseInOutEventSignal()
802 return mMouseInOutEventSignal;
806 * @copydoc Dali::DevelWindow::MoveCompletedSignal()
808 MoveCompletedSignalType& MoveCompletedSignal()
810 return mMoveCompletedSignal;
814 * @copydoc Dali::DevelWindow::ResizeCompletedSignal()
816 ResizeCompletedSignalType& ResizeCompletedSignal()
818 return mResizeCompletedSignal;
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;
855 Dali::KeyEvent mLastKeyEvent;
856 Dali::TouchEvent mLastTouchEvent;
858 bool mIsTransparent : 1;
859 bool mIsFocusAcceptable : 1;
862 bool mOpaqueState : 1;
863 bool mWindowRotationAcknowledgement : 1;
865 bool mIsWindowRotating : 1; ///< The window rotating flag.
866 bool mIsEnabledUserGeometry : 1; ///< The user geometry enable flag.
869 } // namespace Adaptor
870 } // namespace Internal
872 // Helpers for public-api forwarding methods
874 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
876 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
877 BaseObject& object = window.GetBaseObject();
878 return static_cast<Internal::Adaptor::Window&>(object);
881 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
883 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
884 const BaseObject& object = window.GetBaseObject();
885 return static_cast<const Internal::Adaptor::Window&>(object);
890 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H