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 focus is changed.
536 void OnFocusChanged(bool focusIn);
539 * Called when the output is transformed.
541 void OnOutputTransformed();
544 * Called when the window receives a delete request.
546 void OnDeleteRequest();
549 * Called when the window receives a Transition effect-start/end event.
551 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
554 * @brief Called when window receives a keyboard repeat event.
556 void OnKeyboardRepeatSettingsChanged();
559 * @brief Called when the window redraw is requested.
561 void OnWindowRedrawRequest();
564 * @brief Called when the window is resized or moved by display server.
566 * @param[in] positionSize the updated window's position and size.
568 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
571 * @brief Called when display server sent the auxiliary message.
573 * @param[in] key the auxiliary message's key.
574 * @param[in] value the auxiliary message's value.
575 * @param[in] options the auxiliary message's options. This is the list of string.
577 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
580 * @brief Called when Accessibility is enabled.
582 * This method is to register the window to accessibility bridge.
584 void OnAccessibilityEnabled();
587 * @brief Called when Accessibility is disabled.
589 * This method is to remove the window from accessibility bridge.
591 void OnAccessibilityDisabled();
594 * Called when the window rotation is finished.
596 * This signal is emmit when window rotation is finisehd and WindowRotationCompleted() is called.
598 void OnRotationFinished();
601 * @brief Called when the mouse in or out event is received.
602 * @param[in] mouseInOutEvent the mouse event
604 void OnMouseInOutEvent(const Dali::DevelWindow::MouseInOutEvent& mouseInOutEvent);
607 * @brief Set available orientation to window base.
609 void SetAvailableAnlges(const std::vector<int>& angles);
612 * @brief Convert from window orientation to angle using OrientationMode.
614 int ConvertToAngle(WindowOrientation orientation);
617 * @brief Convert from angle to window orientation using OrientationMode.
619 WindowOrientation ConvertToOrientation(int angle) const;
622 * @brief Check available window orientation for Available orientation.
624 bool IsOrientationAvailable(WindowOrientation orientation) const;
626 private: // Dali::Internal::Adaptor::SceneHolder
628 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
630 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
633 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
635 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
638 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
640 void OnPause() override;
643 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
645 void OnResume() override;
648 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculatePosition
650 Vector2 RecalculatePosition(const Vector2& position) override;
652 private: // Dali::Internal::Adaptor::EventHandler::Observer
654 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
656 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
659 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
661 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
664 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
666 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
669 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
671 void OnRotation(const RotationEvent& rotation) override;
675 * @copydoc Dali::Window::FocusChangeSignal()
677 FocusChangeSignalType& FocusChangeSignal()
679 return mFocusChangeSignal;
683 * @copydoc Dali::Window::ResizedSignal()
685 ResizeSignalType& ResizeSignal()
687 return mResizeSignal;
691 * This signal is emitted when the window is requesting to be deleted
693 SignalType& DeleteRequestSignal()
695 return mDeleteRequestSignal;
699 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
701 VisibilityChangedSignalType& VisibilityChangedSignal()
703 return mVisibilityChangedSignal;
707 * @copydoc Dali::Window::SignalEventProcessingFinished()
709 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
711 return mScene.EventProcessingFinishedSignal();
715 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
717 TransitionEffectEventSignalType& TransitionEffectEventSignal()
719 return mTransitionEffectEventSignal;
723 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
725 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
727 return mKeyboardRepeatSettingsChangedSignal;
731 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
733 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
735 return mAuxiliaryMessageSignal;
739 * @copydoc Dali::DevelWindow::AccessibilityHighlightSignal()
741 AccessibilityHighlightSignalType& AccessibilityHighlightSignal()
743 return mAccessibilityHighlightSignal;
747 * @copydoc Dali::DevelWindow::MovedSignal()
749 MovedSignalType& MovedSignal()
755 * @copydoc Dali::DevelWindow::OrientationChangedSignal()
757 OrientationChangedSignalType& OrientationChangedSignal()
759 return mOrientationChangedSignal;
763 * @copydoc Dali::DevelWindow::MouseInOutEventSignal()
765 MouseInOutEventSignalType& MouseInOutEventSignal()
767 return mMouseInOutEventSignal;
771 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
772 WindowBase* mWindowBase;
774 std::string mClassName;
775 Dali::Window mParentWindow;
777 OrientationPtr mOrientation;
778 std::vector<int> mAvailableAngles;
781 int mRotationAngle; ///< The angle of the rotation
782 int mWindowWidth; ///< The width of the window
783 int mWindowHeight; ///< The height of the window
784 int mNativeWindowId; ///< The Native Window Id
786 EventHandlerPtr mEventHandler; ///< The window events handler
787 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
790 SignalType mDeleteRequestSignal;
791 FocusChangeSignalType mFocusChangeSignal;
792 ResizeSignalType mResizeSignal;
793 VisibilityChangedSignalType mVisibilityChangedSignal;
794 TransitionEffectEventSignalType mTransitionEffectEventSignal;
795 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
796 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
797 AccessibilityHighlightSignalType mAccessibilityHighlightSignal;
798 MovedSignalType mMovedSignal;
799 OrientationChangedSignalType mOrientationChangedSignal;
800 MouseInOutEventSignalType mMouseInOutEventSignal;
802 Dali::KeyEvent mLastKeyEvent;
803 Dali::TouchEvent mLastTouchEvent;
805 bool mIsTransparent : 1;
806 bool mIsFocusAcceptable : 1;
808 bool mOpaqueState : 1;
809 bool mWindowRotationAcknowledgement : 1;
811 bool mIsWindowRotating : 1; ///< The window rotating flag.
814 } // namespace Adaptor
815 } // namespace Internal
817 // Helpers for public-api forwarding methods
819 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
821 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
822 BaseObject& object = window.GetBaseObject();
823 return static_cast<Internal::Adaptor::Window&>(object);
826 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
828 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
829 const BaseObject& object = window.GetBaseObject();
830 return static_cast<const Internal::Adaptor::Window&>(object);
835 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H