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();
458 * @copydoc Dali::DevelWindow::IsWindowRotating()
460 bool IsWindowRotating() const;
464 * @brief Enumeration for orietation mode.
465 * The Orientation Mode is related to screen size.
466 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
467 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
469 enum class OrientationMode
476 * Private constructor.
487 * Second stage initialization
489 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
492 * Called when the window becomes iconified or deiconified.
494 void OnIconifyChanged(bool iconified);
497 * Called when the window focus is changed.
499 void OnFocusChanged(bool focusIn);
502 * Called when the output is transformed.
504 void OnOutputTransformed();
507 * Called when the window receives a delete request.
509 void OnDeleteRequest();
512 * Called when the window receives a Transition effect-start/end event.
514 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
517 * @brief Called when window receives a keyboard repeat event.
519 void OnKeyboardRepeatSettingsChanged();
522 * @brief Called when the window redraw is requested.
524 void OnWindowRedrawRequest();
527 * @brief Called when the window is resized or moved by display server.
529 * @param[in] positionSize the updated window's position and size.
531 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
534 * @brief Called when display server sent the auxiliary message.
536 * @param[in] key the auxiliary message's key.
537 * @param[in] value the auxiliary message's value.
538 * @param[in] options the auxiliary message's options. This is the list of string.
540 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
543 * @brief Called when Accessibility is enabled.
545 * This method is to register the window to accessibility bridge.
547 void OnAccessibilityEnabled();
550 * @brief Called when Accessibility is disabled.
552 * This method is to remove the window from accessibility bridge.
554 void OnAccessibilityDisabled();
557 * @brief Set available orientation to window base.
559 void SetAvailableAnlges(const std::vector<int>& angles);
562 * @brief Convert from window orientation to angle using OrientationMode.
564 int ConvertToAngle(WindowOrientation orientation);
567 * @brief Convert from angle to window orientation using OrientationMode.
569 WindowOrientation ConvertToOrientation(int angle) const;
572 * @brief Check available window orientation for Available orientation.
574 bool IsOrientationAvailable(WindowOrientation orientation) const;
577 * @brief Return the rect value to recalulate with the default system coordinates.
579 * Some native window APIs work the geometry value based on the default system coordinates.
580 * IncludeInputRegion() and ExcludeInputRegion() are one of them.
581 * When the window is rotated, current window's geometry already were set with the rotated angle.
582 * If IncludeInputRegion() or ExcludeInputRegion() are called with rotated angle by application,
583 * the rect's area should be re-calcuated on the default system coordinates.
585 * @param[in] rect the window's current position and size with current window rotation angle.
586 * @return the re-calculated rect on the default system coordinates.
588 Rect<int> RecalculateRect(const Rect<int>& rect);
590 private: // Dali::Internal::Adaptor::SceneHolder
592 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
594 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
597 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
599 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
602 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
604 void OnPause() override;
607 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
609 void OnResume() override;
612 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
614 void RecalculateTouchPosition(Integration::Point& point) override;
616 private: // Dali::Internal::Adaptor::EventHandler::Observer
618 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
620 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
623 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
625 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
628 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
630 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
633 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
635 void OnRotation(const RotationEvent& rotation) override;
639 * @copydoc Dali::Window::FocusChangeSignal()
641 FocusChangeSignalType& FocusChangeSignal()
643 return mFocusChangeSignal;
647 * @copydoc Dali::Window::ResizedSignal()
649 ResizeSignalType& ResizeSignal()
651 return mResizeSignal;
655 * This signal is emitted when the window is requesting to be deleted
657 SignalType& DeleteRequestSignal()
659 return mDeleteRequestSignal;
663 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
665 VisibilityChangedSignalType& VisibilityChangedSignal()
667 return mVisibilityChangedSignal;
671 * @copydoc Dali::Window::SignalEventProcessingFinished()
673 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
675 return mScene.EventProcessingFinishedSignal();
679 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
681 TransitionEffectEventSignalType& TransitionEffectEventSignal()
683 return mTransitionEffectEventSignal;
687 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
689 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
691 return mKeyboardRepeatSettingsChangedSignal;
695 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
697 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
699 return mAuxiliaryMessageSignal;
703 * @copydoc Dali::DevelWindow::AccessibilityHighlightSignal()
705 AccessibilityHighlightSignalType& AccessibilityHighlightSignal()
707 return mAccessibilityHighlightSignal;
711 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
712 WindowBase* mWindowBase;
714 std::string mClassName;
715 bool mIsTransparent : 1;
716 bool mIsFocusAcceptable : 1;
718 bool mOpaqueState : 1;
719 bool mWindowRotationAcknowledgement : 1;
721 Dali::Window mParentWindow;
723 OrientationPtr mOrientation;
724 std::vector<int> mAvailableAngles;
727 int mRotationAngle; ///< The angle of the rotation
728 int mWindowWidth; ///< The width of the window
729 int mWindowHeight; ///< The height of the window
731 EventHandlerPtr mEventHandler; ///< The window events handler
733 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
735 int mNativeWindowId; ///< The Native Window Id
738 SignalType mDeleteRequestSignal;
739 FocusChangeSignalType mFocusChangeSignal;
740 ResizeSignalType mResizeSignal;
741 VisibilityChangedSignalType mVisibilityChangedSignal;
742 TransitionEffectEventSignalType mTransitionEffectEventSignal;
743 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
744 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
745 AccessibilityHighlightSignalType mAccessibilityHighlightSignal;
748 } // namespace Adaptor
749 } // namespace Internal
751 // Helpers for public-api forwarding methods
753 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
755 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
756 BaseObject& object = window.GetBaseObject();
757 return static_cast<Internal::Adaptor::Window&>(object);
760 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
762 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
763 const BaseObject& object = window.GetBaseObject();
764 return static_cast<const Internal::Adaptor::Window&>(object);
769 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H