1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
5 * Copyright (c) 2022 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 Signal<void()> SignalType;
73 * @brief Create a new Window. This should only be called once by the Application class
74 * @param[in] positionSize The position and size of the window
75 * @param[in] name The window title
76 * @param[in] className The window class name
77 * @param[in] type Window type.
78 * @param[in] isTransparent Whether window is transparent
79 * @return A newly allocated Window
81 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
84 * @brief Create a new Window. This should only be called once by the Application class
85 * @param[in] surface The surface used to render on.
86 * @param[in] positionSize The position and size of the window
87 * @param[in] name The window title
88 * @param[in] className The window class name
89 * @param[in] type Window type.
90 * @param[in] isTransparent Whether window is transparent
91 * @return A newly allocated Window
93 static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
96 * @copydoc Dali::Window::SetClass()
98 void SetClass(std::string name, std::string className);
101 * @brief Gets the window class name.
102 * @return The class of the window
104 std::string GetClassName() const;
107 * @copydoc Dali::Window::Raise()
112 * @copydoc Dali::Window::Lower()
117 * @copydoc Dali::Window::Activate()
122 * @copydoc Dali::DevelWindow::Maximize()
124 void Maximize(bool maximize);
127 * @copydoc Dali::DevelWindow::IsMaximized()
129 bool IsMaximized() const;
132 * @copydoc Dali::DevelWindow::SetMaximumSize()
134 void SetMaximumSize(Dali::Window::WindowSize size);
137 * @copydoc Dali::DevelWindow::Minimize()
139 void Minimize(bool minimize);
142 * @copydoc Dali::DevelWindow::IsMinimized()
144 bool IsMinimized() const;
147 * @copydoc Dali::DevelWindow::SetMimimumSize()
149 void SetMimimumSize(Dali::Window::WindowSize size);
152 * @copydoc Dali::Window::GetLayerCount()
154 uint32_t GetLayerCount() const;
157 * @copydoc Dali::Window::GetLayer()
159 Dali::Layer GetLayer(uint32_t depth) const;
162 * @copydoc Dali::DevelWindow::GetRenderTaskList()
164 Dali::RenderTaskList GetRenderTaskList() const;
167 * @brief Get window resource ID assigned by window manager
168 * @return The resource ID of the window
170 std::string GetNativeResourceId() const;
173 * @copydoc Dali::Window::AddAvailableOrientation()
175 void AddAvailableOrientation(WindowOrientation orientation);
178 * @copydoc Dali::Window::RemoveAvailableOrientation()
180 void RemoveAvailableOrientation(WindowOrientation orientation);
183 * @copydoc Dali::Window::SetPreferredOrientation()
185 void SetPreferredOrientation(WindowOrientation orientation);
188 * @copydoc Dali::Window::GetPreferredOrientation()
190 WindowOrientation GetPreferredOrientation();
193 * @copydoc Dali::Window::SetAcceptFocus()
195 void SetAcceptFocus(bool accept);
198 * @copydoc Dali::Window::IsFocusAcceptable()
200 bool IsFocusAcceptable() const;
203 * @copydoc Dali::Window::Show()
208 * @copydoc Dali::Window::Hide()
213 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
215 unsigned int GetSupportedAuxiliaryHintCount() const;
218 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
220 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
223 * @copydoc Dali::Window::AddAuxiliaryHint()
225 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
228 * @copydoc Dali::Window::RemoveAuxiliaryHint()
230 bool RemoveAuxiliaryHint(unsigned int id);
233 * @copydoc Dali::Window::SetAuxiliaryHintValue()
235 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
238 * @copydoc Dali::Window::GetAuxiliaryHintValue()
240 std::string GetAuxiliaryHintValue(unsigned int id) const;
243 * @copydoc Dali::Window::GetAuxiliaryHintId()
245 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
248 * @copydoc Dali::Window::SetInputRegion()
250 void SetInputRegion(const Rect<int>& inputRegion);
253 * @copydoc Dali::Window::SetType()
255 void SetType(WindowType type);
258 * @copydoc Dali::Window::GetType() const
260 WindowType GetType() const;
263 * @copydoc Dali::Window::SetNotificationLevel()
265 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
268 * @copydoc Dali::Window::GetNotificationLevel()
270 WindowNotificationLevel GetNotificationLevel() const;
273 * @copydoc Dali::Window::SetOpaqueState()
275 void SetOpaqueState(bool opaque);
278 * @copydoc Dali::Window::IsOpaqueState()
280 bool IsOpaqueState() const;
283 * @copydoc Dali::Window::SetScreenOffMode()
285 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
288 * @copydoc Dali::Window::GetScreenOffMode()
290 WindowScreenOffMode GetScreenOffMode() const;
293 * @copydoc Dali::Window::SetBrightness()
295 WindowOperationResult SetBrightness(int brightness);
298 * @copydoc Dali::Window::GetBrightness()
300 int GetBrightness() const;
303 * @copydoc Dali::Window::SetSize()
305 void SetSize(Dali::Window::WindowSize size);
308 * @copydoc Dali::Window::GetSize()
310 Dali::Window::WindowSize GetSize() const;
313 * @copydoc Dali::Window::SetPosition()
315 void SetPosition(Dali::Window::WindowPosition position);
318 * @copydoc Dali::Window::GetPosition()
320 Dali::Window::WindowPosition GetPosition() const;
323 * @copydoc Dali::DevelWindow::SetPositionSize()
325 void SetPositionSize(PositionSize positionSize);
328 * @copydoc Dali::DevelWindow::GetPositionSize()
330 PositionSize GetPositionSize() const;
333 * @copydoc Dali::Window::GetRootLayer()
335 Dali::Layer GetRootLayer() const;
338 * @copydoc Dali::Window::SetTransparency()
340 void SetTransparency(bool transparent);
343 * @copydoc Dali::KeyGrab::GrabKey()
345 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
348 * @copydoc Dali::KeyGrab::UngrabKey()
350 bool UngrabKey(Dali::KEY key);
353 * @copydoc Dali::KeyGrab::GrabKeyList()
355 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
358 * @copydoc Dali::KeyGrab::UngrabKeyList()
360 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
363 * @copydoc Dali::DevelWindow::Get()
365 static Dali::Window Get(Dali::Actor actor);
368 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
370 void SetParent(Dali::Window& parent);
373 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
375 void SetParent(Dali::Window& parent, bool belowParent);
378 * @copydoc Dali::DevelWindow::Unparent()
383 * @copydoc Dali::DevelWindow::GetParent()
385 Dali::Window GetParent();
388 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
390 WindowOrientation GetCurrentOrientation() const;
393 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
395 int GetPhysicalOrientation() const;
398 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
400 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
403 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
405 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
408 * @brief Emit the accessibility highlight signal.
409 * The highlight indicates that it is an object to interact with the user regardless of focus.
410 * After setting the highlight on the object, you can do things that the object can do, such as
411 * giving or losing focus.
413 * @param[in] highlight If window needs to grab or clear highlight.
415 void EmitAccessibilityHighlightSignal(bool highlight);
417 public: // Dali::Internal::Adaptor::SceneHolder
419 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
421 Dali::Any GetNativeHandle() const override;
424 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
426 bool IsVisible() const override;
429 * @copydoc Dali::DevelWindow::GetNativeId()
431 int32_t GetNativeId() const;
434 * @copydoc Dali::DevelWindow::RequestMoveToServer()
436 void RequestMoveToServer();
439 * @copydoc Dali::DevelWindow::RequestResizeToServer()
441 void RequestResizeToServer(WindowResizeDirection direction);
444 * @copydoc Dali::DevelWindow::EnableFloatingMode()
446 void EnableFloatingMode(bool enable);
449 * @copydoc Dali::DevelWindow::IncludeInputRegion()
451 void IncludeInputRegion(const Rect<int>& inputRegion);
454 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
456 void ExcludeInputRegion(const Rect<int>& inputRegion);
459 * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
461 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
464 * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
466 void SendRotationCompletedAcknowledgement();
469 * @copydoc Dali::DevelWindow::IsWindowRotating()
471 bool IsWindowRotating() const;
474 * @copydoc Dali::DevelWindow::GetLastKeyEvent()
476 const Dali::KeyEvent& GetLastKeyEvent() const;
479 * @copydoc Dali::DevelWindow::GetLastTouchEvent()
481 const Dali::TouchEvent& GetLastTouchEvent() const;
485 * @brief Enumeration for orietation mode.
486 * The Orientation Mode is related to screen size.
487 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
488 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
490 enum class OrientationMode
497 * Private constructor.
508 * Second stage initialization
510 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
513 * Called when the window becomes iconified or deiconified.
515 void OnIconifyChanged(bool iconified);
518 * Called when the window focus is changed.
520 void OnFocusChanged(bool focusIn);
523 * Called when the output is transformed.
525 void OnOutputTransformed();
528 * Called when the window receives a delete request.
530 void OnDeleteRequest();
533 * Called when the window receives a Transition effect-start/end event.
535 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
538 * @brief Called when window receives a keyboard repeat event.
540 void OnKeyboardRepeatSettingsChanged();
543 * @brief Called when the window redraw is requested.
545 void OnWindowRedrawRequest();
548 * @brief Called when the window is resized or moved by display server.
550 * @param[in] positionSize the updated window's position and size.
552 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
555 * @brief Called when display server sent the auxiliary message.
557 * @param[in] key the auxiliary message's key.
558 * @param[in] value the auxiliary message's value.
559 * @param[in] options the auxiliary message's options. This is the list of string.
561 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
564 * @brief Called when Accessibility is enabled.
566 * This method is to register the window to accessibility bridge.
568 void OnAccessibilityEnabled();
571 * @brief Called when Accessibility is disabled.
573 * This method is to remove the window from accessibility bridge.
575 void OnAccessibilityDisabled();
578 * @brief Set available orientation to window base.
580 void SetAvailableAnlges(const std::vector<int>& angles);
583 * @brief Convert from window orientation to angle using OrientationMode.
585 int ConvertToAngle(WindowOrientation orientation);
588 * @brief Convert from angle to window orientation using OrientationMode.
590 WindowOrientation ConvertToOrientation(int angle) const;
593 * @brief Check available window orientation for Available orientation.
595 bool IsOrientationAvailable(WindowOrientation orientation) const;
598 * @brief Return the rect value to recalulate with the default system coordinates.
600 * Some native window APIs work the geometry value based on the default system coordinates.
601 * IncludeInputRegion() and ExcludeInputRegion() are one of them.
602 * When the window is rotated, current window's geometry already were set with the rotated angle.
603 * If IncludeInputRegion() or ExcludeInputRegion() are called with rotated angle by application,
604 * the rect's area should be re-calcuated on the default system coordinates.
606 * @param[in] rect the window's current position and size with current window rotation angle.
607 * @return the re-calculated rect on the default system coordinates.
609 Rect<int> RecalculateRect(const Rect<int>& rect);
611 private: // Dali::Internal::Adaptor::SceneHolder
613 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
615 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
618 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
620 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
623 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
625 void OnPause() override;
628 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
630 void OnResume() override;
633 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
635 void RecalculateTouchPosition(Integration::Point& point) override;
637 private: // Dali::Internal::Adaptor::EventHandler::Observer
639 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
641 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
644 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
646 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
649 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
651 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
654 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
656 void OnRotation(const RotationEvent& rotation) override;
660 * @copydoc Dali::Window::FocusChangeSignal()
662 FocusChangeSignalType& FocusChangeSignal()
664 return mFocusChangeSignal;
668 * @copydoc Dali::Window::ResizedSignal()
670 ResizeSignalType& ResizeSignal()
672 return mResizeSignal;
676 * This signal is emitted when the window is requesting to be deleted
678 SignalType& DeleteRequestSignal()
680 return mDeleteRequestSignal;
684 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
686 VisibilityChangedSignalType& VisibilityChangedSignal()
688 return mVisibilityChangedSignal;
692 * @copydoc Dali::Window::SignalEventProcessingFinished()
694 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
696 return mScene.EventProcessingFinishedSignal();
700 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
702 TransitionEffectEventSignalType& TransitionEffectEventSignal()
704 return mTransitionEffectEventSignal;
708 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
710 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
712 return mKeyboardRepeatSettingsChangedSignal;
716 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
718 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
720 return mAuxiliaryMessageSignal;
724 * @copydoc Dali::DevelWindow::AccessibilityHighlightSignal()
726 AccessibilityHighlightSignalType& AccessibilityHighlightSignal()
728 return mAccessibilityHighlightSignal;
732 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
733 WindowBase* mWindowBase;
735 std::string mClassName;
736 Dali::Window mParentWindow;
738 OrientationPtr mOrientation;
739 std::vector<int> mAvailableAngles;
742 int mRotationAngle; ///< The angle of the rotation
743 int mWindowWidth; ///< The width of the window
744 int mWindowHeight; ///< The height of the window
745 int mNativeWindowId; ///< The Native Window Id
747 EventHandlerPtr mEventHandler; ///< The window events handler
748 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
751 SignalType mDeleteRequestSignal;
752 FocusChangeSignalType mFocusChangeSignal;
753 ResizeSignalType mResizeSignal;
754 VisibilityChangedSignalType mVisibilityChangedSignal;
755 TransitionEffectEventSignalType mTransitionEffectEventSignal;
756 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
757 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
758 AccessibilityHighlightSignalType mAccessibilityHighlightSignal;
760 Dali::KeyEvent mLastKeyEvent;
761 Dali::TouchEvent mLastTouchEvent;
763 bool mIsTransparent : 1;
764 bool mIsFocusAcceptable : 1;
766 bool mOpaqueState : 1;
767 bool mWindowRotationAcknowledgement : 1;
771 } // namespace Adaptor
772 } // namespace Internal
774 // Helpers for public-api forwarding methods
776 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
778 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
779 BaseObject& object = window.GetBaseObject();
780 return static_cast<Internal::Adaptor::Window&>(object);
783 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
785 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
786 const BaseObject& object = window.GetBaseObject();
787 return static_cast<const Internal::Adaptor::Window&>(object);
792 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H