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/object/base-object.h>
25 #include <dali/public-api/object/property-array.h>
26 #include <dali/public-api/object/ref-object.h>
27 #include <dali/public-api/render-tasks/render-task-list.h>
30 #include <dali/devel-api/adaptor-framework/window-devel.h>
31 #include <dali/integration-api/adaptor-framework/scene-holder-impl.h>
32 #include <dali/internal/adaptor/common/adaptor-impl.h>
33 #include <dali/internal/window-system/common/event-handler.h>
34 #include <dali/public-api/adaptor-framework/key-grab.h>
35 #include <dali/public-api/adaptor-framework/window.h>
41 class RenderSurfaceInterface;
48 class WindowRenderSurface;
52 using WindowPtr = IntrusivePtr<Window>;
53 using OrientationPtr = IntrusivePtr<Orientation>;
54 using EventHandlerPtr = IntrusivePtr<EventHandler>;
57 * Window provides a surface to render onto with orientation & indicator properties.
59 class Window : public Dali::Internal::Adaptor::SceneHolder, public EventHandler::Observer, public ConnectionTracker
62 typedef Dali::Window::FocusChangeSignalType FocusChangeSignalType;
63 typedef Dali::Window::ResizeSignalType ResizeSignalType;
64 typedef Dali::DevelWindow::VisibilityChangedSignalType VisibilityChangedSignalType;
65 typedef Dali::DevelWindow::TransitionEffectEventSignalType TransitionEffectEventSignalType;
66 typedef Dali::DevelWindow::KeyboardRepeatSettingsChangedSignalType KeyboardRepeatSettingsChangedSignalType;
67 typedef Dali::DevelWindow::AuxiliaryMessageSignalType AuxiliaryMessageSignalType;
68 typedef Dali::DevelWindow::AccessibilityHighlightSignalType AccessibilityHighlightSignalType;
69 typedef Signal<void()> SignalType;
72 * @brief Create a new Window. This should only be called once by the Application class
73 * @param[in] positionSize The position and size of the window
74 * @param[in] name The window title
75 * @param[in] className The window class name
76 * @param[in] type Window type.
77 * @param[in] isTransparent Whether window is transparent
78 * @return A newly allocated Window
80 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
83 * @brief Create a new Window. This should only be called once by the Application class
84 * @param[in] surface The surface used to render on.
85 * @param[in] positionSize The position and size of the window
86 * @param[in] name The window title
87 * @param[in] className The window class name
88 * @param[in] type Window type.
89 * @param[in] isTransparent Whether window is transparent
90 * @return A newly allocated Window
92 static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
95 * @copydoc Dali::Window::SetClass()
97 void SetClass(std::string name, std::string className);
100 * @brief Gets the window class name.
101 * @return The class of the window
103 std::string GetClassName() const;
106 * @copydoc Dali::Window::Raise()
111 * @copydoc Dali::Window::Lower()
116 * @copydoc Dali::Window::Activate()
121 * @copydoc Dali::DevelWindow::Maximize()
123 void Maximize(bool maximize);
126 * @copydoc Dali::DevelWindow::IsMaximized()
128 bool IsMaximized() const;
131 * @copydoc Dali::DevelWindow::Minimize()
133 void Minimize(bool minimize);
136 * @copydoc Dali::DevelWindow::IsMinimized()
138 bool IsMinimized() const;
141 * @copydoc Dali::Window::GetLayerCount()
143 uint32_t GetLayerCount() const;
146 * @copydoc Dali::Window::GetLayer()
148 Dali::Layer GetLayer(uint32_t depth) const;
151 * @copydoc Dali::DevelWindow::GetRenderTaskList()
153 Dali::RenderTaskList GetRenderTaskList() const;
156 * @brief Get window resource ID assigned by window manager
157 * @return The resource ID of the window
159 std::string GetNativeResourceId() const;
162 * @copydoc Dali::Window::AddAvailableOrientation()
164 void AddAvailableOrientation(WindowOrientation orientation);
167 * @copydoc Dali::Window::RemoveAvailableOrientation()
169 void RemoveAvailableOrientation(WindowOrientation orientation);
172 * @copydoc Dali::Window::SetPreferredOrientation()
174 void SetPreferredOrientation(WindowOrientation orientation);
177 * @copydoc Dali::Window::GetPreferredOrientation()
179 WindowOrientation GetPreferredOrientation();
182 * @copydoc Dali::Window::SetAcceptFocus()
184 void SetAcceptFocus(bool accept);
187 * @copydoc Dali::Window::IsFocusAcceptable()
189 bool IsFocusAcceptable() const;
192 * @copydoc Dali::Window::Show()
197 * @copydoc Dali::Window::Hide()
202 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
204 unsigned int GetSupportedAuxiliaryHintCount() const;
207 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
209 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
212 * @copydoc Dali::Window::AddAuxiliaryHint()
214 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
217 * @copydoc Dali::Window::RemoveAuxiliaryHint()
219 bool RemoveAuxiliaryHint(unsigned int id);
222 * @copydoc Dali::Window::SetAuxiliaryHintValue()
224 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
227 * @copydoc Dali::Window::GetAuxiliaryHintValue()
229 std::string GetAuxiliaryHintValue(unsigned int id) const;
232 * @copydoc Dali::Window::GetAuxiliaryHintId()
234 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
237 * @copydoc Dali::Window::SetInputRegion()
239 void SetInputRegion(const Rect<int>& inputRegion);
242 * @copydoc Dali::Window::SetType()
244 void SetType(WindowType type);
247 * @copydoc Dali::Window::GetType() const
249 WindowType GetType() const;
252 * @copydoc Dali::Window::SetNotificationLevel()
254 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
257 * @copydoc Dali::Window::GetNotificationLevel()
259 WindowNotificationLevel GetNotificationLevel() const;
262 * @copydoc Dali::Window::SetOpaqueState()
264 void SetOpaqueState(bool opaque);
267 * @copydoc Dali::Window::IsOpaqueState()
269 bool IsOpaqueState() const;
272 * @copydoc Dali::Window::SetScreenOffMode()
274 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
277 * @copydoc Dali::Window::GetScreenOffMode()
279 WindowScreenOffMode GetScreenOffMode() const;
282 * @copydoc Dali::Window::SetBrightness()
284 WindowOperationResult SetBrightness(int brightness);
287 * @copydoc Dali::Window::GetBrightness()
289 int GetBrightness() const;
292 * @copydoc Dali::Window::SetSize()
294 void SetSize(Dali::Window::WindowSize size);
297 * @copydoc Dali::Window::GetSize()
299 Dali::Window::WindowSize GetSize() const;
302 * @copydoc Dali::Window::SetPosition()
304 void SetPosition(Dali::Window::WindowPosition position);
307 * @copydoc Dali::Window::GetPosition()
309 Dali::Window::WindowPosition GetPosition() const;
312 * @copydoc Dali::DevelWindow::SetPositionSize()
314 void SetPositionSize(PositionSize positionSize);
317 * @copydoc Dali::DevelWindow::GetPositionSize()
319 PositionSize GetPositionSize() const;
322 * @copydoc Dali::Window::GetRootLayer()
324 Dali::Layer GetRootLayer() const;
327 * @copydoc Dali::Window::SetTransparency()
329 void SetTransparency(bool transparent);
332 * @copydoc Dali::KeyGrab::GrabKey()
334 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
337 * @copydoc Dali::KeyGrab::UngrabKey()
339 bool UngrabKey(Dali::KEY key);
342 * @copydoc Dali::KeyGrab::GrabKeyList()
344 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
347 * @copydoc Dali::KeyGrab::UngrabKeyList()
349 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
352 * @copydoc Dali::DevelWindow::Get()
354 static Dali::Window Get(Dali::Actor actor);
357 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
359 void SetParent(Dali::Window& parent);
362 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
364 void SetParent(Dali::Window& parent, bool belowParent);
367 * @copydoc Dali::DevelWindow::Unparent()
372 * @copydoc Dali::DevelWindow::GetParent()
374 Dali::Window GetParent();
377 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
379 WindowOrientation GetCurrentOrientation() const;
382 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
384 int GetPhysicalOrientation() const;
387 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
389 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
392 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
394 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
397 * @brief Emit the accessibility highlight signal.
398 * The highlight indicates that it is an object to interact with the user regardless of focus.
399 * After setting the highlight on the object, you can do things that the object can do, such as
400 * giving or losing focus.
402 * @param[in] highlight If window needs to grab or clear highlight.
404 void EmitAccessibilityHighlightSignal(bool highlight);
406 public: // Dali::Internal::Adaptor::SceneHolder
408 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
410 Dali::Any GetNativeHandle() const override;
413 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
415 bool IsVisible() const override;
418 * @copydoc Dali::DevelWindow::GetNativeId()
420 int32_t GetNativeId() const;
423 * @copydoc Dali::DevelWindow::RequestMoveToServer()
425 void RequestMoveToServer();
428 * @copydoc Dali::DevelWindow::RequestResizeToServer()
430 void RequestResizeToServer(WindowResizeDirection direction);
433 * @copydoc Dali::DevelWindow::EnableFloatingMode()
435 void EnableFloatingMode(bool enable);
438 * @copydoc Dali::DevelWindow::IncludeInputRegion()
440 void IncludeInputRegion(const Rect<int>& inputRegion);
443 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
445 void ExcludeInputRegion(const Rect<int>& inputRegion);
448 * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
450 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
453 * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
455 void SendRotationCompletedAcknowledgement();
459 * @brief Enumeration for orietation mode.
460 * The Orientation Mode is related to screen size.
461 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
462 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
464 enum class OrientationMode
471 * Private constructor.
482 * Second stage initialization
484 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
487 * Called when the window becomes iconified or deiconified.
489 void OnIconifyChanged(bool iconified);
492 * Called when the window focus is changed.
494 void OnFocusChanged(bool focusIn);
497 * Called when the output is transformed.
499 void OnOutputTransformed();
502 * Called when the window receives a delete request.
504 void OnDeleteRequest();
507 * Called when the window receives a Transition effect-start/end event.
509 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
512 * @brief Called when window receives a keyboard repeat event.
514 void OnKeyboardRepeatSettingsChanged();
517 * @brief Called when the window redraw is requested.
519 void OnWindowRedrawRequest();
522 * @brief Called when the window is resized or moved by display server.
524 * @param[in] positionSize the updated window's position and size.
526 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
529 * @brief Called when display server sent the auxiliary message.
531 * @param[in] key the auxiliary message's key.
532 * @param[in] value the auxiliary message's value.
533 * @param[in] options the auxiliary message's options. This is the list of string.
535 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
538 * @brief Called when Accessibility is enabled.
540 * This method is to register the window to accessibility bridge.
542 void OnAccessibilityEnabled();
545 * @brief Called when Accessibility is disabled.
547 * This method is to remove the window from accessibility bridge.
549 void OnAccessibilityDisabled();
552 * @brief Set available orientation to window base.
554 void SetAvailableAnlges(const std::vector<int>& angles);
557 * @brief Convert from window orientation to angle using OrientationMode.
559 int ConvertToAngle(WindowOrientation orientation);
562 * @brief Convert from angle to window orientation using OrientationMode.
564 WindowOrientation ConvertToOrientation(int angle) const;
567 * @brief Check available window orientation for Available orientation.
569 bool IsOrientationAvailable(WindowOrientation orientation) const;
572 * @brief Return the rect value to recalulate with the default system coordinates.
574 * Some native window APIs work the geometry value based on the default system coordinates.
575 * IncludeInputRegion() and ExcludeInputRegion() are one of them.
576 * When the window is rotated, current window's geometry already were set with the rotated angle.
577 * If IncludeInputRegion() or ExcludeInputRegion() are called with rotated angle by application,
578 * the rect's area should be re-calcuated on the default system coordinates.
580 * @param[in] rect the window's current position and size with current window rotation angle.
581 * @return the re-calculated rect on the default system coordinates.
583 Rect<int> RecalculateRect(const Rect<int>& rect);
585 private: // Dali::Internal::Adaptor::SceneHolder
587 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
589 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
592 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
594 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
597 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
599 void OnPause() override;
602 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
604 void OnResume() override;
607 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
609 void RecalculateTouchPosition(Integration::Point& point) override;
611 private: // Dali::Internal::Adaptor::EventHandler::Observer
613 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
615 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
618 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
620 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
623 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
625 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
628 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
630 void OnRotation(const RotationEvent& rotation) override;
634 * @copydoc Dali::Window::FocusChangeSignal()
636 FocusChangeSignalType& FocusChangeSignal()
638 return mFocusChangeSignal;
642 * @copydoc Dali::Window::ResizedSignal()
644 ResizeSignalType& ResizeSignal()
646 return mResizeSignal;
650 * This signal is emitted when the window is requesting to be deleted
652 SignalType& DeleteRequestSignal()
654 return mDeleteRequestSignal;
658 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
660 VisibilityChangedSignalType& VisibilityChangedSignal()
662 return mVisibilityChangedSignal;
666 * @copydoc Dali::Window::SignalEventProcessingFinished()
668 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
670 return mScene.EventProcessingFinishedSignal();
674 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
676 TransitionEffectEventSignalType& TransitionEffectEventSignal()
678 return mTransitionEffectEventSignal;
682 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
684 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
686 return mKeyboardRepeatSettingsChangedSignal;
690 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
692 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
694 return mAuxiliaryMessageSignal;
698 * @copydoc Dali::DevelWindow::AccessibilityHighlightSignal()
700 AccessibilityHighlightSignalType& AccessibilityHighlightSignal()
702 return mAccessibilityHighlightSignal;
706 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
707 WindowBase* mWindowBase;
709 std::string mClassName;
710 bool mIsTransparent : 1;
711 bool mIsFocusAcceptable : 1;
713 bool mOpaqueState : 1;
714 bool mWindowRotationAcknowledgement : 1;
716 Dali::Window mParentWindow;
718 OrientationPtr mOrientation;
719 std::vector<int> mAvailableAngles;
722 int mRotationAngle; ///< The angle of the rotation
723 int mWindowWidth; ///< The width of the window
724 int mWindowHeight; ///< The height of the window
726 EventHandlerPtr mEventHandler; ///< The window events handler
728 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
730 int mNativeWindowId; ///< The Native Window Id
733 SignalType mDeleteRequestSignal;
734 FocusChangeSignalType mFocusChangeSignal;
735 ResizeSignalType mResizeSignal;
736 VisibilityChangedSignalType mVisibilityChangedSignal;
737 TransitionEffectEventSignalType mTransitionEffectEventSignal;
738 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
739 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
740 AccessibilityHighlightSignalType mAccessibilityHighlightSignal;
743 } // namespace Adaptor
744 } // namespace Internal
746 // Helpers for public-api forwarding methods
748 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
750 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
751 BaseObject& object = window.GetBaseObject();
752 return static_cast<Internal::Adaptor::Window&>(object);
755 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
757 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
758 const BaseObject& object = window.GetBaseObject();
759 return static_cast<const Internal::Adaptor::Window&>(object);
764 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H