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 Signal<void()> SignalType;
77 * @brief Create a new Window. This should only be called once by the Application class
78 * @param[in] positionSize The position and size of the window
79 * @param[in] name The window title
80 * @param[in] className The window class name
81 * @param[in] type Window type.
82 * @param[in] isTransparent Whether window is transparent
83 * @return A newly allocated Window
85 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
88 * @brief Create a new Window. This should only be called once by the Application class
89 * @param[in] surface The surface used to render on.
90 * @param[in] positionSize The position and size of the window
91 * @param[in] name The window title
92 * @param[in] className The window class name
93 * @param[in] type Window type.
94 * @param[in] isTransparent Whether window is transparent
95 * @return A newly allocated Window
97 static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
100 * @copydoc Dali::Window::SetClass()
102 void SetClass(std::string name, std::string className);
105 * @brief Gets the window class name.
106 * @return The class of the window
108 std::string GetClassName() const;
111 * @copydoc Dali::Window::Raise()
116 * @copydoc Dali::Window::Lower()
121 * @copydoc Dali::Window::Activate()
126 * @copydoc Dali::DevelWindow::Maximize()
128 void Maximize(bool maximize);
131 * @copydoc Dali::DevelWindow::IsMaximized()
133 bool IsMaximized() const;
136 * @copydoc Dali::DevelWindow::SetMaximumSize()
138 void SetMaximumSize(Dali::Window::WindowSize size);
141 * @copydoc Dali::DevelWindow::Minimize()
143 void Minimize(bool minimize);
146 * @copydoc Dali::DevelWindow::IsMinimized()
148 bool IsMinimized() const;
151 * @copydoc Dali::DevelWindow::SetMimimumSize()
153 void SetMimimumSize(Dali::Window::WindowSize size);
156 * @copydoc Dali::Window::GetLayerCount()
158 uint32_t GetLayerCount() const;
161 * @copydoc Dali::Window::GetLayer()
163 Dali::Layer GetLayer(uint32_t depth) const;
166 * @copydoc Dali::DevelWindow::GetRenderTaskList()
168 Dali::RenderTaskList GetRenderTaskList() const;
171 * @brief Get window resource ID assigned by window manager
172 * @return The resource ID of the window
174 std::string GetNativeResourceId() const;
177 * @copydoc Dali::Window::AddAvailableOrientation()
179 void AddAvailableOrientation(WindowOrientation orientation);
182 * @copydoc Dali::Window::RemoveAvailableOrientation()
184 void RemoveAvailableOrientation(WindowOrientation orientation);
187 * @copydoc Dali::Window::SetPreferredOrientation()
189 void SetPreferredOrientation(WindowOrientation orientation);
192 * @copydoc Dali::Window::GetPreferredOrientation()
194 WindowOrientation GetPreferredOrientation();
197 * @copydoc Dali::Window::SetAcceptFocus()
199 void SetAcceptFocus(bool accept);
202 * @copydoc Dali::Window::IsFocusAcceptable()
204 bool IsFocusAcceptable() const;
207 * @copydoc Dali::Window::Show()
212 * @copydoc Dali::Window::Hide()
217 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
219 unsigned int GetSupportedAuxiliaryHintCount() const;
222 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
224 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
227 * @copydoc Dali::Window::AddAuxiliaryHint()
229 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
232 * @copydoc Dali::Window::RemoveAuxiliaryHint()
234 bool RemoveAuxiliaryHint(unsigned int id);
237 * @copydoc Dali::Window::SetAuxiliaryHintValue()
239 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
242 * @copydoc Dali::Window::GetAuxiliaryHintValue()
244 std::string GetAuxiliaryHintValue(unsigned int id) const;
247 * @copydoc Dali::Window::GetAuxiliaryHintId()
249 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
252 * @copydoc Dali::Window::SetInputRegion()
254 void SetInputRegion(const Rect<int>& inputRegion);
257 * @copydoc Dali::Window::SetType()
259 void SetType(WindowType type);
262 * @copydoc Dali::Window::GetType() const
264 WindowType GetType() const;
267 * @copydoc Dali::Window::SetNotificationLevel()
269 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
272 * @copydoc Dali::Window::GetNotificationLevel()
274 WindowNotificationLevel GetNotificationLevel() const;
277 * @copydoc Dali::Window::SetOpaqueState()
279 void SetOpaqueState(bool opaque);
282 * @copydoc Dali::Window::IsOpaqueState()
284 bool IsOpaqueState() const;
287 * @copydoc Dali::Window::SetScreenOffMode()
289 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
292 * @copydoc Dali::Window::GetScreenOffMode()
294 WindowScreenOffMode GetScreenOffMode() const;
297 * @copydoc Dali::Window::SetBrightness()
299 WindowOperationResult SetBrightness(int brightness);
302 * @copydoc Dali::Window::GetBrightness()
304 int GetBrightness() const;
307 * @copydoc Dali::Window::SetSize()
309 void SetSize(Dali::Window::WindowSize size);
312 * @copydoc Dali::Window::GetSize()
314 Dali::Window::WindowSize GetSize() const;
317 * @copydoc Dali::Window::SetPosition()
319 void SetPosition(Dali::Window::WindowPosition position);
322 * @copydoc Dali::Window::GetPosition()
324 Dali::Window::WindowPosition GetPosition() const;
327 * @copydoc Dali::DevelWindow::SetPositionSize()
329 void SetPositionSize(PositionSize positionSize);
332 * @copydoc Dali::DevelWindow::GetPositionSize()
334 PositionSize GetPositionSize() const;
337 * @copydoc Dali::Window::SetLayout()
339 void SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan);
342 * @copydoc Dali::Window::GetRootLayer()
344 Dali::Layer GetRootLayer() const;
347 * @copydoc Dali::Window::SetTransparency()
349 void SetTransparency(bool transparent);
352 * @copydoc Dali::KeyGrab::GrabKey()
354 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
357 * @copydoc Dali::KeyGrab::UngrabKey()
359 bool UngrabKey(Dali::KEY key);
362 * @copydoc Dali::KeyGrab::GrabKeyList()
364 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
367 * @copydoc Dali::KeyGrab::UngrabKeyList()
369 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
372 * @copydoc Dali::DevelWindow::Get()
374 static Dali::Window Get(Dali::Actor actor);
377 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
379 void SetParent(Dali::Window& parent);
382 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
384 void SetParent(Dali::Window& parent, bool belowParent);
387 * @copydoc Dali::DevelWindow::Unparent()
392 * @copydoc Dali::DevelWindow::GetParent()
394 Dali::Window GetParent();
397 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
399 WindowOrientation GetCurrentOrientation() const;
402 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
404 int GetPhysicalOrientation() const;
407 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
409 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
412 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
414 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
417 * @brief Emit the accessibility highlight signal.
418 * The highlight indicates that it is an object to interact with the user regardless of focus.
419 * After setting the highlight on the object, you can do things that the object can do, such as
420 * giving or losing focus.
422 * @param[in] highlight If window needs to grab or clear highlight.
424 void EmitAccessibilityHighlightSignal(bool highlight);
427 * @brief Sets the render notification trigger to call when render thread is completed a frame
429 * @param[in] renderNotification to use
431 void SetRenderNotification(TriggerEventInterface* renderNotification);
433 public: // Dali::Internal::Adaptor::SceneHolder
435 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
437 Dali::Any GetNativeHandle() const override;
440 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
442 bool IsVisible() const override;
445 * @copydoc Dali::DevelWindow::GetNativeId()
447 int32_t GetNativeId() const;
450 * @copydoc Dali::DevelWindow::RequestMoveToServer()
452 void RequestMoveToServer();
455 * @copydoc Dali::DevelWindow::RequestResizeToServer()
457 void RequestResizeToServer(WindowResizeDirection direction);
460 * @copydoc Dali::DevelWindow::EnableFloatingMode()
462 void EnableFloatingMode(bool enable);
465 * @copydoc Dali::DevelWindow::IncludeInputRegion()
467 void IncludeInputRegion(const Rect<int>& inputRegion);
470 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
472 void ExcludeInputRegion(const Rect<int>& inputRegion);
475 * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
477 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
480 * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
482 void SendRotationCompletedAcknowledgement();
485 * @copydoc Dali::DevelWindow::IsWindowRotating()
487 bool IsWindowRotating() const;
490 * @copydoc Dali::DevelWindow::GetLastKeyEvent()
492 const Dali::KeyEvent& GetLastKeyEvent() const;
495 * @copydoc Dali::DevelWindow::GetLastTouchEvent()
497 const Dali::TouchEvent& GetLastTouchEvent() const;
501 * @brief Enumeration for orietation mode.
502 * The Orientation Mode is related to screen size.
503 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
504 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
506 enum class OrientationMode
513 * Private constructor.
524 * Second stage initialization
526 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
529 * Called when the window becomes iconified or deiconified.
531 void OnIconifyChanged(bool iconified);
534 * Called when the window becomes maximized or unmaximized.
536 void OnMaximizeChanged(bool maximized);
539 * Called when the window focus is changed.
541 void OnFocusChanged(bool focusIn);
544 * Called when the output is transformed.
546 void OnOutputTransformed();
549 * Called when the window receives a delete request.
551 void OnDeleteRequest();
554 * Called when the window receives a Transition effect-start/end event.
556 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
559 * @brief Called when window receives a keyboard repeat event.
561 void OnKeyboardRepeatSettingsChanged();
564 * @brief Called when the window redraw is requested.
566 void OnWindowRedrawRequest();
569 * @brief Called when the window is resized or moved by display server.
571 * @param[in] positionSize the updated window's position and size.
573 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
576 * @brief Called when display server sent the auxiliary message.
578 * @param[in] key the auxiliary message's key.
579 * @param[in] value the auxiliary message's value.
580 * @param[in] options the auxiliary message's options. This is the list of string.
582 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
585 * @brief Called when Accessibility is enabled.
587 * This method is to register the window to accessibility bridge.
589 void OnAccessibilityEnabled();
592 * @brief Called when Accessibility is disabled.
594 * This method is to remove the window from accessibility bridge.
596 void OnAccessibilityDisabled();
599 * Called when the window rotation is finished.
601 * This signal is emmit when window rotation is finisehd and WindowRotationCompleted() is called.
603 void OnRotationFinished();
606 * @brief Called when the mouse in or out event is received.
607 * @param[in] mouseInOutEvent the mouse event
609 void OnMouseInOutEvent(const Dali::DevelWindow::MouseInOutEvent& mouseInOutEvent);
612 * @brief Set available orientation to window base.
614 void SetAvailableAnlges(const std::vector<int>& angles);
617 * @brief Convert from window orientation to angle using OrientationMode.
619 int ConvertToAngle(WindowOrientation orientation);
622 * @brief Convert from angle to window orientation using OrientationMode.
624 WindowOrientation ConvertToOrientation(int angle) const;
627 * @brief Check available window orientation for Available orientation.
629 bool IsOrientationAvailable(WindowOrientation orientation) const;
631 private: // Dali::Internal::Adaptor::SceneHolder
633 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
635 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
638 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
640 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
643 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
645 void OnPause() override;
648 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
650 void OnResume() override;
653 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculatePosition
655 Vector2 RecalculatePosition(const Vector2& position) override;
657 private: // Dali::Internal::Adaptor::EventHandler::Observer
659 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
661 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
664 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
666 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
669 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
671 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
674 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
676 void OnRotation(const RotationEvent& rotation) override;
680 * @copydoc Dali::Window::FocusChangeSignal()
682 FocusChangeSignalType& FocusChangeSignal()
684 return mFocusChangeSignal;
688 * @copydoc Dali::Window::ResizedSignal()
690 ResizeSignalType& ResizeSignal()
692 return mResizeSignal;
696 * This signal is emitted when the window is requesting to be deleted
698 SignalType& DeleteRequestSignal()
700 return mDeleteRequestSignal;
704 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
706 VisibilityChangedSignalType& VisibilityChangedSignal()
708 return mVisibilityChangedSignal;
712 * @copydoc Dali::Window::SignalEventProcessingFinished()
714 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
716 return mScene.EventProcessingFinishedSignal();
720 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
722 TransitionEffectEventSignalType& TransitionEffectEventSignal()
724 return mTransitionEffectEventSignal;
728 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
730 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
732 return mKeyboardRepeatSettingsChangedSignal;
736 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
738 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
740 return mAuxiliaryMessageSignal;
744 * @copydoc Dali::DevelWindow::AccessibilityHighlightSignal()
746 AccessibilityHighlightSignalType& AccessibilityHighlightSignal()
748 return mAccessibilityHighlightSignal;
752 * @copydoc Dali::DevelWindow::MovedSignal()
754 MovedSignalType& MovedSignal()
760 * @copydoc Dali::DevelWindow::OrientationChangedSignal()
762 OrientationChangedSignalType& OrientationChangedSignal()
764 return mOrientationChangedSignal;
768 * @copydoc Dali::DevelWindow::MouseInOutEventSignal()
770 MouseInOutEventSignalType& MouseInOutEventSignal()
772 return mMouseInOutEventSignal;
776 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
777 WindowBase* mWindowBase;
779 std::string mClassName;
780 Dali::Window mParentWindow;
782 OrientationPtr mOrientation;
783 std::vector<int> mAvailableAngles;
786 int mRotationAngle; ///< The angle of the rotation
787 int mWindowWidth; ///< The width of the window
788 int mWindowHeight; ///< The height of the window
789 int mNativeWindowId; ///< The Native Window Id
791 EventHandlerPtr mEventHandler; ///< The window events handler
792 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
795 SignalType mDeleteRequestSignal;
796 FocusChangeSignalType mFocusChangeSignal;
797 ResizeSignalType mResizeSignal;
798 VisibilityChangedSignalType mVisibilityChangedSignal;
799 TransitionEffectEventSignalType mTransitionEffectEventSignal;
800 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
801 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
802 AccessibilityHighlightSignalType mAccessibilityHighlightSignal;
803 MovedSignalType mMovedSignal;
804 OrientationChangedSignalType mOrientationChangedSignal;
805 MouseInOutEventSignalType mMouseInOutEventSignal;
807 Dali::KeyEvent mLastKeyEvent;
808 Dali::TouchEvent mLastTouchEvent;
810 bool mIsTransparent : 1;
811 bool mIsFocusAcceptable : 1;
814 bool mOpaqueState : 1;
815 bool mWindowRotationAcknowledgement : 1;
817 bool mIsWindowRotating : 1; ///< The window rotating flag.
820 } // namespace Adaptor
821 } // namespace Internal
823 // Helpers for public-api forwarding methods
825 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
827 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
828 BaseObject& object = window.GetBaseObject();
829 return static_cast<Internal::Adaptor::Window&>(object);
832 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
834 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
835 const BaseObject& object = window.GetBaseObject();
836 return static_cast<const Internal::Adaptor::Window&>(object);
841 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H