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::Minimize()
134 void Minimize(bool minimize);
137 * @copydoc Dali::DevelWindow::IsMinimized()
139 bool IsMinimized() const;
142 * @copydoc Dali::Window::GetLayerCount()
144 uint32_t GetLayerCount() const;
147 * @copydoc Dali::Window::GetLayer()
149 Dali::Layer GetLayer(uint32_t depth) const;
152 * @copydoc Dali::DevelWindow::GetRenderTaskList()
154 Dali::RenderTaskList GetRenderTaskList() const;
157 * @brief Get window resource ID assigned by window manager
158 * @return The resource ID of the window
160 std::string GetNativeResourceId() const;
163 * @copydoc Dali::Window::AddAvailableOrientation()
165 void AddAvailableOrientation(WindowOrientation orientation);
168 * @copydoc Dali::Window::RemoveAvailableOrientation()
170 void RemoveAvailableOrientation(WindowOrientation orientation);
173 * @copydoc Dali::Window::SetPreferredOrientation()
175 void SetPreferredOrientation(WindowOrientation orientation);
178 * @copydoc Dali::Window::GetPreferredOrientation()
180 WindowOrientation GetPreferredOrientation();
183 * @copydoc Dali::Window::SetAcceptFocus()
185 void SetAcceptFocus(bool accept);
188 * @copydoc Dali::Window::IsFocusAcceptable()
190 bool IsFocusAcceptable() const;
193 * @copydoc Dali::Window::Show()
198 * @copydoc Dali::Window::Hide()
203 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
205 unsigned int GetSupportedAuxiliaryHintCount() const;
208 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
210 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
213 * @copydoc Dali::Window::AddAuxiliaryHint()
215 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
218 * @copydoc Dali::Window::RemoveAuxiliaryHint()
220 bool RemoveAuxiliaryHint(unsigned int id);
223 * @copydoc Dali::Window::SetAuxiliaryHintValue()
225 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
228 * @copydoc Dali::Window::GetAuxiliaryHintValue()
230 std::string GetAuxiliaryHintValue(unsigned int id) const;
233 * @copydoc Dali::Window::GetAuxiliaryHintId()
235 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
238 * @copydoc Dali::Window::SetInputRegion()
240 void SetInputRegion(const Rect<int>& inputRegion);
243 * @copydoc Dali::Window::SetType()
245 void SetType(WindowType type);
248 * @copydoc Dali::Window::GetType() const
250 WindowType GetType() const;
253 * @copydoc Dali::Window::SetNotificationLevel()
255 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
258 * @copydoc Dali::Window::GetNotificationLevel()
260 WindowNotificationLevel GetNotificationLevel() const;
263 * @copydoc Dali::Window::SetOpaqueState()
265 void SetOpaqueState(bool opaque);
268 * @copydoc Dali::Window::IsOpaqueState()
270 bool IsOpaqueState() const;
273 * @copydoc Dali::Window::SetScreenOffMode()
275 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
278 * @copydoc Dali::Window::GetScreenOffMode()
280 WindowScreenOffMode GetScreenOffMode() const;
283 * @copydoc Dali::Window::SetBrightness()
285 WindowOperationResult SetBrightness(int brightness);
288 * @copydoc Dali::Window::GetBrightness()
290 int GetBrightness() const;
293 * @copydoc Dali::Window::SetSize()
295 void SetSize(Dali::Window::WindowSize size);
298 * @copydoc Dali::Window::GetSize()
300 Dali::Window::WindowSize GetSize() const;
303 * @copydoc Dali::Window::SetPosition()
305 void SetPosition(Dali::Window::WindowPosition position);
308 * @copydoc Dali::Window::GetPosition()
310 Dali::Window::WindowPosition GetPosition() const;
313 * @copydoc Dali::DevelWindow::SetPositionSize()
315 void SetPositionSize(PositionSize positionSize);
318 * @copydoc Dali::DevelWindow::GetPositionSize()
320 PositionSize GetPositionSize() const;
323 * @copydoc Dali::Window::GetRootLayer()
325 Dali::Layer GetRootLayer() const;
328 * @copydoc Dali::Window::SetTransparency()
330 void SetTransparency(bool transparent);
333 * @copydoc Dali::KeyGrab::GrabKey()
335 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
338 * @copydoc Dali::KeyGrab::UngrabKey()
340 bool UngrabKey(Dali::KEY key);
343 * @copydoc Dali::KeyGrab::GrabKeyList()
345 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
348 * @copydoc Dali::KeyGrab::UngrabKeyList()
350 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
353 * @copydoc Dali::DevelWindow::Get()
355 static Dali::Window Get(Dali::Actor actor);
358 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
360 void SetParent(Dali::Window& parent);
363 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
365 void SetParent(Dali::Window& parent, bool belowParent);
368 * @copydoc Dali::DevelWindow::Unparent()
373 * @copydoc Dali::DevelWindow::GetParent()
375 Dali::Window GetParent();
378 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
380 WindowOrientation GetCurrentOrientation() const;
383 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
385 int GetPhysicalOrientation() const;
388 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
390 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
393 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
395 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
398 * @brief Emit the accessibility highlight signal.
399 * The highlight indicates that it is an object to interact with the user regardless of focus.
400 * After setting the highlight on the object, you can do things that the object can do, such as
401 * giving or losing focus.
403 * @param[in] highlight If window needs to grab or clear highlight.
405 void EmitAccessibilityHighlightSignal(bool highlight);
407 public: // Dali::Internal::Adaptor::SceneHolder
409 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
411 Dali::Any GetNativeHandle() const override;
414 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
416 bool IsVisible() const override;
419 * @copydoc Dali::DevelWindow::GetNativeId()
421 int32_t GetNativeId() const;
424 * @copydoc Dali::DevelWindow::RequestMoveToServer()
426 void RequestMoveToServer();
429 * @copydoc Dali::DevelWindow::RequestResizeToServer()
431 void RequestResizeToServer(WindowResizeDirection direction);
434 * @copydoc Dali::DevelWindow::EnableFloatingMode()
436 void EnableFloatingMode(bool enable);
439 * @copydoc Dali::DevelWindow::IncludeInputRegion()
441 void IncludeInputRegion(const Rect<int>& inputRegion);
444 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
446 void ExcludeInputRegion(const Rect<int>& inputRegion);
449 * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
451 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
454 * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
456 void SendRotationCompletedAcknowledgement();
459 * @copydoc Dali::DevelWindow::IsWindowRotating()
461 bool IsWindowRotating() const;
464 * @copydoc Dali::DevelWindow::GetLastKeyEvent()
466 const Dali::KeyEvent& GetLastKeyEvent() const;
469 * @copydoc Dali::DevelWindow::GetLastTouchEvent()
471 const Dali::TouchEvent& GetLastTouchEvent() const;
475 * @brief Enumeration for orietation mode.
476 * The Orientation Mode is related to screen size.
477 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
478 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
480 enum class OrientationMode
487 * Private constructor.
498 * Second stage initialization
500 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
503 * Called when the window becomes iconified or deiconified.
505 void OnIconifyChanged(bool iconified);
508 * Called when the window focus is changed.
510 void OnFocusChanged(bool focusIn);
513 * Called when the output is transformed.
515 void OnOutputTransformed();
518 * Called when the window receives a delete request.
520 void OnDeleteRequest();
523 * Called when the window receives a Transition effect-start/end event.
525 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
528 * @brief Called when window receives a keyboard repeat event.
530 void OnKeyboardRepeatSettingsChanged();
533 * @brief Called when the window redraw is requested.
535 void OnWindowRedrawRequest();
538 * @brief Called when the window is resized or moved by display server.
540 * @param[in] positionSize the updated window's position and size.
542 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
545 * @brief Called when display server sent the auxiliary message.
547 * @param[in] key the auxiliary message's key.
548 * @param[in] value the auxiliary message's value.
549 * @param[in] options the auxiliary message's options. This is the list of string.
551 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
554 * @brief Called when Accessibility is enabled.
556 * This method is to register the window to accessibility bridge.
558 void OnAccessibilityEnabled();
561 * @brief Called when Accessibility is disabled.
563 * This method is to remove the window from accessibility bridge.
565 void OnAccessibilityDisabled();
568 * @brief Set available orientation to window base.
570 void SetAvailableAnlges(const std::vector<int>& angles);
573 * @brief Convert from window orientation to angle using OrientationMode.
575 int ConvertToAngle(WindowOrientation orientation);
578 * @brief Convert from angle to window orientation using OrientationMode.
580 WindowOrientation ConvertToOrientation(int angle) const;
583 * @brief Check available window orientation for Available orientation.
585 bool IsOrientationAvailable(WindowOrientation orientation) const;
588 * @brief Return the rect value to recalulate with the default system coordinates.
590 * Some native window APIs work the geometry value based on the default system coordinates.
591 * IncludeInputRegion() and ExcludeInputRegion() are one of them.
592 * When the window is rotated, current window's geometry already were set with the rotated angle.
593 * If IncludeInputRegion() or ExcludeInputRegion() are called with rotated angle by application,
594 * the rect's area should be re-calcuated on the default system coordinates.
596 * @param[in] rect the window's current position and size with current window rotation angle.
597 * @return the re-calculated rect on the default system coordinates.
599 Rect<int> RecalculateRect(const Rect<int>& rect);
601 private: // Dali::Internal::Adaptor::SceneHolder
603 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
605 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
608 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
610 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
613 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
615 void OnPause() override;
618 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
620 void OnResume() override;
623 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
625 void RecalculateTouchPosition(Integration::Point& point) override;
627 private: // Dali::Internal::Adaptor::EventHandler::Observer
629 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
631 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
634 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
636 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
639 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
641 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
644 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
646 void OnRotation(const RotationEvent& rotation) override;
650 * @copydoc Dali::Window::FocusChangeSignal()
652 FocusChangeSignalType& FocusChangeSignal()
654 return mFocusChangeSignal;
658 * @copydoc Dali::Window::ResizedSignal()
660 ResizeSignalType& ResizeSignal()
662 return mResizeSignal;
666 * This signal is emitted when the window is requesting to be deleted
668 SignalType& DeleteRequestSignal()
670 return mDeleteRequestSignal;
674 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
676 VisibilityChangedSignalType& VisibilityChangedSignal()
678 return mVisibilityChangedSignal;
682 * @copydoc Dali::Window::SignalEventProcessingFinished()
684 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
686 return mScene.EventProcessingFinishedSignal();
690 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
692 TransitionEffectEventSignalType& TransitionEffectEventSignal()
694 return mTransitionEffectEventSignal;
698 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
700 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
702 return mKeyboardRepeatSettingsChangedSignal;
706 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
708 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
710 return mAuxiliaryMessageSignal;
714 * @copydoc Dali::DevelWindow::AccessibilityHighlightSignal()
716 AccessibilityHighlightSignalType& AccessibilityHighlightSignal()
718 return mAccessibilityHighlightSignal;
722 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
723 WindowBase* mWindowBase;
725 std::string mClassName;
726 Dali::Window mParentWindow;
728 OrientationPtr mOrientation;
729 std::vector<int> mAvailableAngles;
732 int mRotationAngle; ///< The angle of the rotation
733 int mWindowWidth; ///< The width of the window
734 int mWindowHeight; ///< The height of the window
735 int mNativeWindowId; ///< The Native Window Id
737 EventHandlerPtr mEventHandler; ///< The window events handler
738 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
741 SignalType mDeleteRequestSignal;
742 FocusChangeSignalType mFocusChangeSignal;
743 ResizeSignalType mResizeSignal;
744 VisibilityChangedSignalType mVisibilityChangedSignal;
745 TransitionEffectEventSignalType mTransitionEffectEventSignal;
746 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
747 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
748 AccessibilityHighlightSignalType mAccessibilityHighlightSignal;
750 Dali::KeyEvent mLastKeyEvent;
751 Dali::TouchEvent mLastTouchEvent;
753 bool mIsTransparent : 1;
754 bool mIsFocusAcceptable : 1;
756 bool mOpaqueState : 1;
757 bool mWindowRotationAcknowledgement : 1;
761 } // namespace Adaptor
762 } // namespace Internal
764 // Helpers for public-api forwarding methods
766 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
768 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
769 BaseObject& object = window.GetBaseObject();
770 return static_cast<Internal::Adaptor::Window&>(object);
773 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
775 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
776 const BaseObject& object = window.GetBaseObject();
777 return static_cast<const Internal::Adaptor::Window&>(object);
782 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H