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 Dali::DevelWindow::MovedSignalType MovedSignalType;
71 typedef Signal<void()> SignalType;
74 * @brief Create a new Window. This should only be called once by the Application class
75 * @param[in] positionSize The position and size of the window
76 * @param[in] name The window title
77 * @param[in] className The window class name
78 * @param[in] type Window type.
79 * @param[in] isTransparent Whether window is transparent
80 * @return A newly allocated Window
82 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
85 * @brief Create a new Window. This should only be called once by the Application class
86 * @param[in] surface The surface used to render on.
87 * @param[in] positionSize The position and size of the window
88 * @param[in] name The window title
89 * @param[in] className The window class name
90 * @param[in] type Window type.
91 * @param[in] isTransparent Whether window is transparent
92 * @return A newly allocated Window
94 static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
97 * @copydoc Dali::Window::SetClass()
99 void SetClass(std::string name, std::string className);
102 * @brief Gets the window class name.
103 * @return The class of the window
105 std::string GetClassName() const;
108 * @copydoc Dali::Window::Raise()
113 * @copydoc Dali::Window::Lower()
118 * @copydoc Dali::Window::Activate()
123 * @copydoc Dali::DevelWindow::Maximize()
125 void Maximize(bool maximize);
128 * @copydoc Dali::DevelWindow::IsMaximized()
130 bool IsMaximized() const;
133 * @copydoc Dali::DevelWindow::SetMaximumSize()
135 void SetMaximumSize(Dali::Window::WindowSize size);
138 * @copydoc Dali::DevelWindow::Minimize()
140 void Minimize(bool minimize);
143 * @copydoc Dali::DevelWindow::IsMinimized()
145 bool IsMinimized() const;
148 * @copydoc Dali::DevelWindow::SetMimimumSize()
150 void SetMimimumSize(Dali::Window::WindowSize size);
153 * @copydoc Dali::Window::GetLayerCount()
155 uint32_t GetLayerCount() const;
158 * @copydoc Dali::Window::GetLayer()
160 Dali::Layer GetLayer(uint32_t depth) const;
163 * @copydoc Dali::DevelWindow::GetRenderTaskList()
165 Dali::RenderTaskList GetRenderTaskList() const;
168 * @brief Get window resource ID assigned by window manager
169 * @return The resource ID of the window
171 std::string GetNativeResourceId() const;
174 * @copydoc Dali::Window::AddAvailableOrientation()
176 void AddAvailableOrientation(WindowOrientation orientation);
179 * @copydoc Dali::Window::RemoveAvailableOrientation()
181 void RemoveAvailableOrientation(WindowOrientation orientation);
184 * @copydoc Dali::Window::SetPreferredOrientation()
186 void SetPreferredOrientation(WindowOrientation orientation);
189 * @copydoc Dali::Window::GetPreferredOrientation()
191 WindowOrientation GetPreferredOrientation();
194 * @copydoc Dali::Window::SetAcceptFocus()
196 void SetAcceptFocus(bool accept);
199 * @copydoc Dali::Window::IsFocusAcceptable()
201 bool IsFocusAcceptable() const;
204 * @copydoc Dali::Window::Show()
209 * @copydoc Dali::Window::Hide()
214 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
216 unsigned int GetSupportedAuxiliaryHintCount() const;
219 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
221 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
224 * @copydoc Dali::Window::AddAuxiliaryHint()
226 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
229 * @copydoc Dali::Window::RemoveAuxiliaryHint()
231 bool RemoveAuxiliaryHint(unsigned int id);
234 * @copydoc Dali::Window::SetAuxiliaryHintValue()
236 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
239 * @copydoc Dali::Window::GetAuxiliaryHintValue()
241 std::string GetAuxiliaryHintValue(unsigned int id) const;
244 * @copydoc Dali::Window::GetAuxiliaryHintId()
246 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
249 * @copydoc Dali::Window::SetInputRegion()
251 void SetInputRegion(const Rect<int>& inputRegion);
254 * @copydoc Dali::Window::SetType()
256 void SetType(WindowType type);
259 * @copydoc Dali::Window::GetType() const
261 WindowType GetType() const;
264 * @copydoc Dali::Window::SetNotificationLevel()
266 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
269 * @copydoc Dali::Window::GetNotificationLevel()
271 WindowNotificationLevel GetNotificationLevel() const;
274 * @copydoc Dali::Window::SetOpaqueState()
276 void SetOpaqueState(bool opaque);
279 * @copydoc Dali::Window::IsOpaqueState()
281 bool IsOpaqueState() const;
284 * @copydoc Dali::Window::SetScreenOffMode()
286 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
289 * @copydoc Dali::Window::GetScreenOffMode()
291 WindowScreenOffMode GetScreenOffMode() const;
294 * @copydoc Dali::Window::SetBrightness()
296 WindowOperationResult SetBrightness(int brightness);
299 * @copydoc Dali::Window::GetBrightness()
301 int GetBrightness() const;
304 * @copydoc Dali::Window::SetSize()
306 void SetSize(Dali::Window::WindowSize size);
309 * @copydoc Dali::Window::GetSize()
311 Dali::Window::WindowSize GetSize() const;
314 * @copydoc Dali::Window::SetPosition()
316 void SetPosition(Dali::Window::WindowPosition position);
319 * @copydoc Dali::Window::GetPosition()
321 Dali::Window::WindowPosition GetPosition() const;
324 * @copydoc Dali::DevelWindow::SetPositionSize()
326 void SetPositionSize(PositionSize positionSize);
329 * @copydoc Dali::DevelWindow::GetPositionSize()
331 PositionSize GetPositionSize() const;
334 * @copydoc Dali::Window::GetRootLayer()
336 Dali::Layer GetRootLayer() const;
339 * @copydoc Dali::Window::SetTransparency()
341 void SetTransparency(bool transparent);
344 * @copydoc Dali::KeyGrab::GrabKey()
346 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
349 * @copydoc Dali::KeyGrab::UngrabKey()
351 bool UngrabKey(Dali::KEY key);
354 * @copydoc Dali::KeyGrab::GrabKeyList()
356 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
359 * @copydoc Dali::KeyGrab::UngrabKeyList()
361 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
364 * @copydoc Dali::DevelWindow::Get()
366 static Dali::Window Get(Dali::Actor actor);
369 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
371 void SetParent(Dali::Window& parent);
374 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
376 void SetParent(Dali::Window& parent, bool belowParent);
379 * @copydoc Dali::DevelWindow::Unparent()
384 * @copydoc Dali::DevelWindow::GetParent()
386 Dali::Window GetParent();
389 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
391 WindowOrientation GetCurrentOrientation() const;
394 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
396 int GetPhysicalOrientation() const;
399 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
401 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
404 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
406 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
409 * @brief Emit the accessibility highlight signal.
410 * The highlight indicates that it is an object to interact with the user regardless of focus.
411 * After setting the highlight on the object, you can do things that the object can do, such as
412 * giving or losing focus.
414 * @param[in] highlight If window needs to grab or clear highlight.
416 void EmitAccessibilityHighlightSignal(bool highlight);
418 public: // Dali::Internal::Adaptor::SceneHolder
420 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
422 Dali::Any GetNativeHandle() const override;
425 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
427 bool IsVisible() const override;
430 * @copydoc Dali::DevelWindow::GetNativeId()
432 int32_t GetNativeId() const;
435 * @copydoc Dali::DevelWindow::RequestMoveToServer()
437 void RequestMoveToServer();
440 * @copydoc Dali::DevelWindow::RequestResizeToServer()
442 void RequestResizeToServer(WindowResizeDirection direction);
445 * @copydoc Dali::DevelWindow::EnableFloatingMode()
447 void EnableFloatingMode(bool enable);
450 * @copydoc Dali::DevelWindow::IncludeInputRegion()
452 void IncludeInputRegion(const Rect<int>& inputRegion);
455 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
457 void ExcludeInputRegion(const Rect<int>& inputRegion);
460 * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
462 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
465 * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
467 void SendRotationCompletedAcknowledgement();
470 * @copydoc Dali::DevelWindow::IsWindowRotating()
472 bool IsWindowRotating() const;
475 * @copydoc Dali::DevelWindow::GetLastKeyEvent()
477 const Dali::KeyEvent& GetLastKeyEvent() const;
480 * @copydoc Dali::DevelWindow::GetLastTouchEvent()
482 const Dali::TouchEvent& GetLastTouchEvent() const;
486 * @brief Enumeration for orietation mode.
487 * The Orientation Mode is related to screen size.
488 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
489 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
491 enum class OrientationMode
498 * Private constructor.
509 * Second stage initialization
511 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
514 * Called when the window becomes iconified or deiconified.
516 void OnIconifyChanged(bool iconified);
519 * Called when the window focus is changed.
521 void OnFocusChanged(bool focusIn);
524 * Called when the output is transformed.
526 void OnOutputTransformed();
529 * Called when the window receives a delete request.
531 void OnDeleteRequest();
534 * Called when the window receives a Transition effect-start/end event.
536 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
539 * @brief Called when window receives a keyboard repeat event.
541 void OnKeyboardRepeatSettingsChanged();
544 * @brief Called when the window redraw is requested.
546 void OnWindowRedrawRequest();
549 * @brief Called when the window is resized or moved by display server.
551 * @param[in] positionSize the updated window's position and size.
553 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
556 * @brief Called when display server sent the auxiliary message.
558 * @param[in] key the auxiliary message's key.
559 * @param[in] value the auxiliary message's value.
560 * @param[in] options the auxiliary message's options. This is the list of string.
562 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
565 * @brief Called when Accessibility is enabled.
567 * This method is to register the window to accessibility bridge.
569 void OnAccessibilityEnabled();
572 * @brief Called when Accessibility is disabled.
574 * This method is to remove the window from accessibility bridge.
576 void OnAccessibilityDisabled();
579 * Called when the window rotation is finished.
581 * This signal is emmit when window rotation is finisehd and WindowRotationCompleted() is called.
583 void OnRotationFinished();
586 * @brief Set available orientation to window base.
588 void SetAvailableAnlges(const std::vector<int>& angles);
591 * @brief Convert from window orientation to angle using OrientationMode.
593 int ConvertToAngle(WindowOrientation orientation);
596 * @brief Convert from angle to window orientation using OrientationMode.
598 WindowOrientation ConvertToOrientation(int angle) const;
601 * @brief Check available window orientation for Available orientation.
603 bool IsOrientationAvailable(WindowOrientation orientation) const;
606 * @brief Return the rect value to recalulate with the default system coordinates.
608 * Some native window APIs work the geometry value based on the default system coordinates.
609 * IncludeInputRegion() and ExcludeInputRegion() are one of them.
610 * When the window is rotated, current window's geometry already were set with the rotated angle.
611 * If IncludeInputRegion() or ExcludeInputRegion() are called with rotated angle by application,
612 * the rect's area should be re-calcuated on the default system coordinates.
614 * @param[in] rect the window's current position and size with current window rotation angle.
615 * @return the re-calculated rect on the default system coordinates.
617 Rect<int> RecalculateRect(const Rect<int>& rect);
619 private: // Dali::Internal::Adaptor::SceneHolder
621 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
623 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
626 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
628 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
631 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
633 void OnPause() override;
636 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
638 void OnResume() override;
641 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
643 void RecalculateTouchPosition(Integration::Point& point) override;
645 private: // Dali::Internal::Adaptor::EventHandler::Observer
647 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
649 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
652 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
654 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
657 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
659 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
662 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
664 void OnRotation(const RotationEvent& rotation) override;
668 * @copydoc Dali::Window::FocusChangeSignal()
670 FocusChangeSignalType& FocusChangeSignal()
672 return mFocusChangeSignal;
676 * @copydoc Dali::Window::ResizedSignal()
678 ResizeSignalType& ResizeSignal()
680 return mResizeSignal;
684 * This signal is emitted when the window is requesting to be deleted
686 SignalType& DeleteRequestSignal()
688 return mDeleteRequestSignal;
692 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
694 VisibilityChangedSignalType& VisibilityChangedSignal()
696 return mVisibilityChangedSignal;
700 * @copydoc Dali::Window::SignalEventProcessingFinished()
702 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
704 return mScene.EventProcessingFinishedSignal();
708 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
710 TransitionEffectEventSignalType& TransitionEffectEventSignal()
712 return mTransitionEffectEventSignal;
716 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
718 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
720 return mKeyboardRepeatSettingsChangedSignal;
724 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
726 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
728 return mAuxiliaryMessageSignal;
732 * @copydoc Dali::DevelWindow::AccessibilityHighlightSignal()
734 AccessibilityHighlightSignalType& AccessibilityHighlightSignal()
736 return mAccessibilityHighlightSignal;
740 * @copydoc Dali::DevelWindow::MovedSignal()
742 MovedSignalType& MovedSignal()
748 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
749 WindowBase* mWindowBase;
751 std::string mClassName;
752 Dali::Window mParentWindow;
754 OrientationPtr mOrientation;
755 std::vector<int> mAvailableAngles;
758 int mRotationAngle; ///< The angle of the rotation
759 int mWindowWidth; ///< The width of the window
760 int mWindowHeight; ///< The height of the window
761 int mNativeWindowId; ///< The Native Window Id
763 EventHandlerPtr mEventHandler; ///< The window events handler
764 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
767 SignalType mDeleteRequestSignal;
768 FocusChangeSignalType mFocusChangeSignal;
769 ResizeSignalType mResizeSignal;
770 VisibilityChangedSignalType mVisibilityChangedSignal;
771 TransitionEffectEventSignalType mTransitionEffectEventSignal;
772 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
773 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
774 AccessibilityHighlightSignalType mAccessibilityHighlightSignal;
775 MovedSignalType mMovedSignal;
777 Dali::KeyEvent mLastKeyEvent;
778 Dali::TouchEvent mLastTouchEvent;
780 bool mIsTransparent : 1;
781 bool mIsFocusAcceptable : 1;
783 bool mOpaqueState : 1;
784 bool mWindowRotationAcknowledgement : 1;
786 bool mIsWindowRotating : 1; ///< The window rotating flag.
789 } // namespace Adaptor
790 } // namespace Internal
792 // Helpers for public-api forwarding methods
794 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
796 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
797 BaseObject& object = window.GetBaseObject();
798 return static_cast<Internal::Adaptor::Window&>(object);
801 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
803 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
804 const BaseObject& object = window.GetBaseObject();
805 return static_cast<const Internal::Adaptor::Window&>(object);
810 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H