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 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 Signal<void()> SignalType;
75 * @brief Create a new Window. This should only be called once by the Application class
76 * @param[in] positionSize The position and size of the window
77 * @param[in] name The window title
78 * @param[in] className The window class name
79 * @param[in] type Window type.
80 * @param[in] isTransparent Whether window is transparent
81 * @return A newly allocated Window
83 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
86 * @brief Create a new Window. This should only be called once by the Application class
87 * @param[in] surface The surface used to render on.
88 * @param[in] positionSize The position and size of the window
89 * @param[in] name The window title
90 * @param[in] className The window class name
91 * @param[in] type Window type.
92 * @param[in] isTransparent Whether window is transparent
93 * @return A newly allocated Window
95 static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
98 * @copydoc Dali::Window::SetClass()
100 void SetClass(std::string name, std::string className);
103 * @brief Gets the window class name.
104 * @return The class of the window
106 std::string GetClassName() const;
109 * @copydoc Dali::Window::Raise()
114 * @copydoc Dali::Window::Lower()
119 * @copydoc Dali::Window::Activate()
124 * @copydoc Dali::DevelWindow::Maximize()
126 void Maximize(bool maximize);
129 * @copydoc Dali::DevelWindow::IsMaximized()
131 bool IsMaximized() const;
134 * @copydoc Dali::DevelWindow::SetMaximumSize()
136 void SetMaximumSize(Dali::Window::WindowSize size);
139 * @copydoc Dali::DevelWindow::Minimize()
141 void Minimize(bool minimize);
144 * @copydoc Dali::DevelWindow::IsMinimized()
146 bool IsMinimized() const;
149 * @copydoc Dali::DevelWindow::SetMimimumSize()
151 void SetMimimumSize(Dali::Window::WindowSize size);
154 * @copydoc Dali::Window::GetLayerCount()
156 uint32_t GetLayerCount() const;
159 * @copydoc Dali::Window::GetLayer()
161 Dali::Layer GetLayer(uint32_t depth) const;
164 * @copydoc Dali::DevelWindow::GetRenderTaskList()
166 Dali::RenderTaskList GetRenderTaskList() const;
169 * @brief Get window resource ID assigned by window manager
170 * @return The resource ID of the window
172 std::string GetNativeResourceId() const;
175 * @copydoc Dali::Window::AddAvailableOrientation()
177 void AddAvailableOrientation(WindowOrientation orientation);
180 * @copydoc Dali::Window::RemoveAvailableOrientation()
182 void RemoveAvailableOrientation(WindowOrientation orientation);
185 * @copydoc Dali::Window::SetPreferredOrientation()
187 void SetPreferredOrientation(WindowOrientation orientation);
190 * @copydoc Dali::Window::GetPreferredOrientation()
192 WindowOrientation GetPreferredOrientation();
195 * @copydoc Dali::Window::SetAcceptFocus()
197 void SetAcceptFocus(bool accept);
200 * @copydoc Dali::Window::IsFocusAcceptable()
202 bool IsFocusAcceptable() const;
205 * @copydoc Dali::Window::Show()
210 * @copydoc Dali::Window::Hide()
215 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
217 unsigned int GetSupportedAuxiliaryHintCount() const;
220 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
222 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
225 * @copydoc Dali::Window::AddAuxiliaryHint()
227 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
230 * @copydoc Dali::Window::RemoveAuxiliaryHint()
232 bool RemoveAuxiliaryHint(unsigned int id);
235 * @copydoc Dali::Window::SetAuxiliaryHintValue()
237 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
240 * @copydoc Dali::Window::GetAuxiliaryHintValue()
242 std::string GetAuxiliaryHintValue(unsigned int id) const;
245 * @copydoc Dali::Window::GetAuxiliaryHintId()
247 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
250 * @copydoc Dali::Window::SetInputRegion()
252 void SetInputRegion(const Rect<int>& inputRegion);
255 * @copydoc Dali::Window::SetType()
257 void SetType(WindowType type);
260 * @copydoc Dali::Window::GetType() const
262 WindowType GetType() const;
265 * @copydoc Dali::Window::SetNotificationLevel()
267 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
270 * @copydoc Dali::Window::GetNotificationLevel()
272 WindowNotificationLevel GetNotificationLevel() const;
275 * @copydoc Dali::Window::SetOpaqueState()
277 void SetOpaqueState(bool opaque);
280 * @copydoc Dali::Window::IsOpaqueState()
282 bool IsOpaqueState() const;
285 * @copydoc Dali::Window::SetScreenOffMode()
287 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
290 * @copydoc Dali::Window::GetScreenOffMode()
292 WindowScreenOffMode GetScreenOffMode() const;
295 * @copydoc Dali::Window::SetBrightness()
297 WindowOperationResult SetBrightness(int brightness);
300 * @copydoc Dali::Window::GetBrightness()
302 int GetBrightness() const;
305 * @copydoc Dali::Window::SetSize()
307 void SetSize(Dali::Window::WindowSize size);
310 * @copydoc Dali::Window::GetSize()
312 Dali::Window::WindowSize GetSize() const;
315 * @copydoc Dali::Window::SetPosition()
317 void SetPosition(Dali::Window::WindowPosition position);
320 * @copydoc Dali::Window::GetPosition()
322 Dali::Window::WindowPosition GetPosition() const;
325 * @copydoc Dali::DevelWindow::SetPositionSize()
327 void SetPositionSize(PositionSize positionSize);
330 * @copydoc Dali::DevelWindow::GetPositionSize()
332 PositionSize GetPositionSize() const;
335 * @copydoc Dali::Window::GetRootLayer()
337 Dali::Layer GetRootLayer() const;
340 * @copydoc Dali::Window::SetTransparency()
342 void SetTransparency(bool transparent);
345 * @copydoc Dali::KeyGrab::GrabKey()
347 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
350 * @copydoc Dali::KeyGrab::UngrabKey()
352 bool UngrabKey(Dali::KEY key);
355 * @copydoc Dali::KeyGrab::GrabKeyList()
357 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
360 * @copydoc Dali::KeyGrab::UngrabKeyList()
362 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
365 * @copydoc Dali::DevelWindow::Get()
367 static Dali::Window Get(Dali::Actor actor);
370 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
372 void SetParent(Dali::Window& parent);
375 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
377 void SetParent(Dali::Window& parent, bool belowParent);
380 * @copydoc Dali::DevelWindow::Unparent()
385 * @copydoc Dali::DevelWindow::GetParent()
387 Dali::Window GetParent();
390 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
392 WindowOrientation GetCurrentOrientation() const;
395 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
397 int GetPhysicalOrientation() const;
400 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
402 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
405 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
407 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
410 * @brief Emit the accessibility highlight signal.
411 * The highlight indicates that it is an object to interact with the user regardless of focus.
412 * After setting the highlight on the object, you can do things that the object can do, such as
413 * giving or losing focus.
415 * @param[in] highlight If window needs to grab or clear highlight.
417 void EmitAccessibilityHighlightSignal(bool highlight);
420 * @brief Sets the render notification trigger to call when render thread is completed a frame
422 * @param[in] renderNotification to use
424 void SetRenderNotification(TriggerEventInterface *renderNotification);
426 public: // Dali::Internal::Adaptor::SceneHolder
428 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
430 Dali::Any GetNativeHandle() const override;
433 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
435 bool IsVisible() const override;
438 * @copydoc Dali::DevelWindow::GetNativeId()
440 int32_t GetNativeId() const;
443 * @copydoc Dali::DevelWindow::RequestMoveToServer()
445 void RequestMoveToServer();
448 * @copydoc Dali::DevelWindow::RequestResizeToServer()
450 void RequestResizeToServer(WindowResizeDirection direction);
453 * @copydoc Dali::DevelWindow::EnableFloatingMode()
455 void EnableFloatingMode(bool enable);
458 * @copydoc Dali::DevelWindow::IncludeInputRegion()
460 void IncludeInputRegion(const Rect<int>& inputRegion);
463 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
465 void ExcludeInputRegion(const Rect<int>& inputRegion);
468 * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
470 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
473 * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
475 void SendRotationCompletedAcknowledgement();
478 * @copydoc Dali::DevelWindow::IsWindowRotating()
480 bool IsWindowRotating() const;
483 * @copydoc Dali::DevelWindow::GetLastKeyEvent()
485 const Dali::KeyEvent& GetLastKeyEvent() const;
488 * @copydoc Dali::DevelWindow::GetLastTouchEvent()
490 const Dali::TouchEvent& GetLastTouchEvent() const;
494 * @brief Enumeration for orietation mode.
495 * The Orientation Mode is related to screen size.
496 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
497 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
499 enum class OrientationMode
506 * Private constructor.
517 * Second stage initialization
519 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
522 * Called when the window becomes iconified or deiconified.
524 void OnIconifyChanged(bool iconified);
527 * Called when the window becomes maximized or unmaximized.
529 void OnMaximizeChanged(bool maximized);
532 * Called when the window focus is changed.
534 void OnFocusChanged(bool focusIn);
537 * Called when the output is transformed.
539 void OnOutputTransformed();
542 * Called when the window receives a delete request.
544 void OnDeleteRequest();
547 * Called when the window receives a Transition effect-start/end event.
549 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
552 * @brief Called when window receives a keyboard repeat event.
554 void OnKeyboardRepeatSettingsChanged();
557 * @brief Called when the window redraw is requested.
559 void OnWindowRedrawRequest();
562 * @brief Called when the window is resized or moved by display server.
564 * @param[in] positionSize the updated window's position and size.
566 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
569 * @brief Called when display server sent the auxiliary message.
571 * @param[in] key the auxiliary message's key.
572 * @param[in] value the auxiliary message's value.
573 * @param[in] options the auxiliary message's options. This is the list of string.
575 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
578 * @brief Called when Accessibility is enabled.
580 * This method is to register the window to accessibility bridge.
582 void OnAccessibilityEnabled();
585 * @brief Called when Accessibility is disabled.
587 * This method is to remove the window from accessibility bridge.
589 void OnAccessibilityDisabled();
592 * Called when the window rotation is finished.
594 * This signal is emmit when window rotation is finisehd and WindowRotationCompleted() is called.
596 void OnRotationFinished();
599 * @brief Set available orientation to window base.
601 void SetAvailableAnlges(const std::vector<int>& angles);
604 * @brief Convert from window orientation to angle using OrientationMode.
606 int ConvertToAngle(WindowOrientation orientation);
609 * @brief Convert from angle to window orientation using OrientationMode.
611 WindowOrientation ConvertToOrientation(int angle) const;
614 * @brief Check available window orientation for Available orientation.
616 bool IsOrientationAvailable(WindowOrientation orientation) const;
619 * @brief Return the rect value to recalulate with the default system coordinates.
621 * Some native window APIs work the geometry value based on the default system coordinates.
622 * IncludeInputRegion() and ExcludeInputRegion() are one of them.
623 * When the window is rotated, current window's geometry already were set with the rotated angle.
624 * If IncludeInputRegion() or ExcludeInputRegion() are called with rotated angle by application,
625 * the rect's area should be re-calcuated on the default system coordinates.
627 * @param[in] rect the window's current position and size with current window rotation angle.
628 * @return the re-calculated rect on the default system coordinates.
630 Rect<int> RecalculateRect(const Rect<int>& rect);
632 private: // Dali::Internal::Adaptor::SceneHolder
634 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
636 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
639 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
641 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
644 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
646 void OnPause() override;
649 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
651 void OnResume() override;
654 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculatePosition
656 Vector2 RecalculatePosition(const Vector2& position) override;
658 private: // Dali::Internal::Adaptor::EventHandler::Observer
660 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
662 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
665 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
667 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
670 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
672 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
675 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
677 void OnRotation(const RotationEvent& rotation) override;
681 * @copydoc Dali::Window::FocusChangeSignal()
683 FocusChangeSignalType& FocusChangeSignal()
685 return mFocusChangeSignal;
689 * @copydoc Dali::Window::ResizedSignal()
691 ResizeSignalType& ResizeSignal()
693 return mResizeSignal;
697 * This signal is emitted when the window is requesting to be deleted
699 SignalType& DeleteRequestSignal()
701 return mDeleteRequestSignal;
705 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
707 VisibilityChangedSignalType& VisibilityChangedSignal()
709 return mVisibilityChangedSignal;
713 * @copydoc Dali::Window::SignalEventProcessingFinished()
715 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
717 return mScene.EventProcessingFinishedSignal();
721 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
723 TransitionEffectEventSignalType& TransitionEffectEventSignal()
725 return mTransitionEffectEventSignal;
729 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
731 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
733 return mKeyboardRepeatSettingsChangedSignal;
737 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
739 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
741 return mAuxiliaryMessageSignal;
745 * @copydoc Dali::DevelWindow::AccessibilityHighlightSignal()
747 AccessibilityHighlightSignalType& AccessibilityHighlightSignal()
749 return mAccessibilityHighlightSignal;
753 * @copydoc Dali::DevelWindow::MovedSignal()
755 MovedSignalType& MovedSignal()
761 * @copydoc Dali::DevelWindow::OrientationChangedSignal()
763 OrientationChangedSignalType& OrientationChangedSignal()
765 return mOrientationChangedSignal;
769 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
770 WindowBase* mWindowBase;
772 std::string mClassName;
773 Dali::Window mParentWindow;
775 OrientationPtr mOrientation;
776 std::vector<int> mAvailableAngles;
779 int mRotationAngle; ///< The angle of the rotation
780 int mWindowWidth; ///< The width of the window
781 int mWindowHeight; ///< The height of the window
782 int mNativeWindowId; ///< The Native Window Id
784 EventHandlerPtr mEventHandler; ///< The window events handler
785 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
788 SignalType mDeleteRequestSignal;
789 FocusChangeSignalType mFocusChangeSignal;
790 ResizeSignalType mResizeSignal;
791 VisibilityChangedSignalType mVisibilityChangedSignal;
792 TransitionEffectEventSignalType mTransitionEffectEventSignal;
793 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
794 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
795 AccessibilityHighlightSignalType mAccessibilityHighlightSignal;
796 MovedSignalType mMovedSignal;
797 OrientationChangedSignalType mOrientationChangedSignal;
799 Dali::KeyEvent mLastKeyEvent;
800 Dali::TouchEvent mLastTouchEvent;
802 bool mIsTransparent : 1;
803 bool mIsFocusAcceptable : 1;
806 bool mOpaqueState : 1;
807 bool mWindowRotationAcknowledgement : 1;
809 bool mIsWindowRotating : 1; ///< The window rotating flag.
812 } // namespace Adaptor
813 } // namespace Internal
815 // Helpers for public-api forwarding methods
817 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
819 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
820 BaseObject& object = window.GetBaseObject();
821 return static_cast<Internal::Adaptor::Window&>(object);
824 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
826 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
827 const BaseObject& object = window.GetBaseObject();
828 return static_cast<const Internal::Adaptor::Window&>(object);
833 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H