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 Signal<void()> SignalType;
71 * @brief Create a new Window. This should only be called once by the Application class
72 * @param[in] positionSize The position and size of the window
73 * @param[in] name The window title
74 * @param[in] className The window class name
75 * @param[in] type Window type.
76 * @param[in] isTransparent Whether window is transparent
77 * @return A newly allocated Window
79 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
82 * @brief Create a new Window. This should only be called once by the Application class
83 * @param[in] surface The surface used to render on.
84 * @param[in] positionSize The position and size of the window
85 * @param[in] name The window title
86 * @param[in] className The window class name
87 * @param[in] type Window type.
88 * @param[in] isTransparent Whether window is transparent
89 * @return A newly allocated Window
91 static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
94 * @copydoc Dali::Window::SetClass()
96 void SetClass(std::string name, std::string className);
99 * @brief Gets the window class name.
100 * @return The class of the window
102 std::string GetClassName() const;
105 * @copydoc Dali::Window::Raise()
110 * @copydoc Dali::Window::Lower()
115 * @copydoc Dali::Window::Activate()
120 * @copydoc Dali::DevelWindow::Maximize()
122 void Maximize(bool maximize);
125 * @copydoc Dali::DevelWindow::IsMaximized()
127 bool IsMaximized() const;
130 * @copydoc Dali::DevelWindow::Minimize()
132 void Minimize(bool minimize);
135 * @copydoc Dali::DevelWindow::IsMinimized()
137 bool IsMinimized() const;
140 * @copydoc Dali::Window::GetLayerCount()
142 uint32_t GetLayerCount() const;
145 * @copydoc Dali::Window::GetLayer()
147 Dali::Layer GetLayer(uint32_t depth) const;
150 * @copydoc Dali::DevelWindow::GetRenderTaskList()
152 Dali::RenderTaskList GetRenderTaskList() const;
155 * @brief Get window resource ID assigned by window manager
156 * @return The resource ID of the window
158 std::string GetNativeResourceId() const;
161 * @copydoc Dali::Window::AddAvailableOrientation()
163 void AddAvailableOrientation(WindowOrientation orientation);
166 * @copydoc Dali::Window::RemoveAvailableOrientation()
168 void RemoveAvailableOrientation(WindowOrientation orientation);
171 * @copydoc Dali::Window::SetPreferredOrientation()
173 void SetPreferredOrientation(WindowOrientation orientation);
176 * @copydoc Dali::Window::GetPreferredOrientation()
178 WindowOrientation GetPreferredOrientation();
181 * @copydoc Dali::Window::SetAcceptFocus()
183 void SetAcceptFocus(bool accept);
186 * @copydoc Dali::Window::IsFocusAcceptable()
188 bool IsFocusAcceptable() const;
191 * @copydoc Dali::Window::Show()
196 * @copydoc Dali::Window::Hide()
201 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
203 unsigned int GetSupportedAuxiliaryHintCount() const;
206 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
208 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
211 * @copydoc Dali::Window::AddAuxiliaryHint()
213 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
216 * @copydoc Dali::Window::RemoveAuxiliaryHint()
218 bool RemoveAuxiliaryHint(unsigned int id);
221 * @copydoc Dali::Window::SetAuxiliaryHintValue()
223 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
226 * @copydoc Dali::Window::GetAuxiliaryHintValue()
228 std::string GetAuxiliaryHintValue(unsigned int id) const;
231 * @copydoc Dali::Window::GetAuxiliaryHintId()
233 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
236 * @copydoc Dali::Window::SetInputRegion()
238 void SetInputRegion(const Rect<int>& inputRegion);
241 * @copydoc Dali::Window::SetType()
243 void SetType(WindowType type);
246 * @copydoc Dali::Window::GetType() const
248 WindowType GetType() const;
251 * @copydoc Dali::Window::SetNotificationLevel()
253 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
256 * @copydoc Dali::Window::GetNotificationLevel()
258 WindowNotificationLevel GetNotificationLevel() const;
261 * @copydoc Dali::Window::SetOpaqueState()
263 void SetOpaqueState(bool opaque);
266 * @copydoc Dali::Window::IsOpaqueState()
268 bool IsOpaqueState() const;
271 * @copydoc Dali::Window::SetScreenOffMode()
273 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
276 * @copydoc Dali::Window::GetScreenOffMode()
278 WindowScreenOffMode GetScreenOffMode() const;
281 * @copydoc Dali::Window::SetBrightness()
283 WindowOperationResult SetBrightness(int brightness);
286 * @copydoc Dali::Window::GetBrightness()
288 int GetBrightness() const;
291 * @copydoc Dali::Window::SetSize()
293 void SetSize(Dali::Window::WindowSize size);
296 * @copydoc Dali::Window::GetSize()
298 Dali::Window::WindowSize GetSize() const;
301 * @copydoc Dali::Window::SetPosition()
303 void SetPosition(Dali::Window::WindowPosition position);
306 * @copydoc Dali::Window::GetPosition()
308 Dali::Window::WindowPosition GetPosition() const;
311 * @copydoc Dali::DevelWindow::SetPositionSize()
313 void SetPositionSize(PositionSize positionSize);
316 * @copydoc Dali::DevelWindow::GetPositionSize()
318 PositionSize GetPositionSize() const;
321 * @copydoc Dali::Window::GetRootLayer()
323 Dali::Layer GetRootLayer() const;
326 * @copydoc Dali::Window::SetTransparency()
328 void SetTransparency(bool transparent);
331 * @copydoc Dali::KeyGrab::GrabKey()
333 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
336 * @copydoc Dali::KeyGrab::UngrabKey()
338 bool UngrabKey(Dali::KEY key);
341 * @copydoc Dali::KeyGrab::GrabKeyList()
343 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
346 * @copydoc Dali::KeyGrab::UngrabKeyList()
348 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
351 * @copydoc Dali::DevelWindow::Get()
353 static Dali::Window Get(Dali::Actor actor);
356 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
358 void SetParent(Dali::Window& parent);
361 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
363 void SetParent(Dali::Window& parent, bool belowParent);
366 * @copydoc Dali::DevelWindow::Unparent()
371 * @copydoc Dali::DevelWindow::GetParent()
373 Dali::Window GetParent();
376 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
378 WindowOrientation GetCurrentOrientation() const;
381 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
383 int GetPhysicalOrientation() const;
386 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
388 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
391 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
393 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
395 public: // Dali::Internal::Adaptor::SceneHolder
397 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
399 Dali::Any GetNativeHandle() const override;
402 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
404 bool IsVisible() const override;
407 * @copydoc Dali::DevelWindow::GetNativeId()
409 int32_t GetNativeId() const;
412 * @copydoc Dali::DevelWindow::RequestMoveToServer()
414 void RequestMoveToServer();
417 * @copydoc Dali::DevelWindow::RequestResizeToServer()
419 void RequestResizeToServer(WindowResizeDirection direction);
422 * @copydoc Dali::DevelWindow::EnableFloatingMode()
424 void EnableFloatingMode(bool enable);
427 * @copydoc Dali::DevelWindow::IncludeInputRegion()
429 void IncludeInputRegion(const Rect<int>& inputRegion);
432 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
434 void ExcludeInputRegion(const Rect<int>& inputRegion);
437 * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
439 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
442 * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
444 void SendRotationCompletedAcknowledgement();
448 * @brief Enumeration for orietation mode.
449 * The Orientation Mode is related to screen size.
450 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
451 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
453 enum class OrientationMode
460 * Private constructor.
471 * Second stage initialization
473 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
476 * Called when the window becomes iconified or deiconified.
478 void OnIconifyChanged(bool iconified);
481 * Called when the window focus is changed.
483 void OnFocusChanged(bool focusIn);
486 * Called when the output is transformed.
488 void OnOutputTransformed();
491 * Called when the window receives a delete request.
493 void OnDeleteRequest();
496 * Called when the window receives a Transition effect-start/end event.
498 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
501 * @brief Called when window receives a keyboard repeat event.
503 void OnKeyboardRepeatSettingsChanged();
506 * @brief Called when the window redraw is requested.
508 void OnWindowRedrawRequest();
511 * @brief Called when the window is resized or moved by display server.
513 * @param[in] positionSize the updated window's position and size.
515 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
518 * @brief Called when display server sent the auxiliary message.
520 * @param[in] key the auxiliary message's key.
521 * @param[in] value the auxiliary message's value.
522 * @param[in] options the auxiliary message's options. This is the list of string.
524 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
527 * @brief Called when Accessibility is enabled.
529 * This method is to register the window to accessibility bridge.
531 void OnAccessibilityEnabled();
534 * @brief Called when Accessibility is disabled.
536 * This method is to remove the window from accessibility bridge.
538 void OnAccessibilityDisabled();
541 * @brief Set available orientation to window base.
543 void SetAvailableAnlges(const std::vector<int>& angles);
546 * @brief Convert from window orientation to angle using OrientationMode.
548 int ConvertToAngle(WindowOrientation orientation);
551 * @brief Convert from angle to window orientation using OrientationMode.
553 WindowOrientation ConvertToOrientation(int angle) const;
556 * @brief Check available window orientation for Available orientation.
558 bool IsOrientationAvailable(WindowOrientation orientation) const;
561 * @brief Return the rect value to recalulate with the default system coordinates.
563 * Some native window APIs work the geometry value based on the default system coordinates.
564 * IncludeInputRegion() and ExcludeInputRegion() are one of them.
565 * When the window is rotated, current window's geometry already were set with the rotated angle.
566 * If IncludeInputRegion() or ExcludeInputRegion() are called with rotated angle by application,
567 * the rect's area should be re-calcuated on the default system coordinates.
569 * @param[in] rect the window's current position and size with current window rotation angle.
570 * @return the re-calculated rect on the default system coordinates.
572 Rect<int> RecalculateRect(const Rect<int>& rect);
574 private: // Dali::Internal::Adaptor::SceneHolder
576 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
578 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
581 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
583 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
586 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
588 void OnPause() override;
591 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
593 void OnResume() override;
596 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
598 void RecalculateTouchPosition(Integration::Point& point) override;
600 private: // Dali::Internal::Adaptor::EventHandler::Observer
602 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
604 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
607 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
609 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
612 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
614 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
617 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
619 void OnRotation(const RotationEvent& rotation) override;
623 * @copydoc Dali::Window::FocusChangeSignal()
625 FocusChangeSignalType& FocusChangeSignal()
627 return mFocusChangeSignal;
631 * @copydoc Dali::Window::ResizedSignal()
633 ResizeSignalType& ResizeSignal()
635 return mResizeSignal;
639 * This signal is emitted when the window is requesting to be deleted
641 SignalType& DeleteRequestSignal()
643 return mDeleteRequestSignal;
647 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
649 VisibilityChangedSignalType& VisibilityChangedSignal()
651 return mVisibilityChangedSignal;
655 * @copydoc Dali::Window::SignalEventProcessingFinished()
657 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
659 return mScene.EventProcessingFinishedSignal();
663 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
665 TransitionEffectEventSignalType& TransitionEffectEventSignal()
667 return mTransitionEffectEventSignal;
671 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
673 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
675 return mKeyboardRepeatSettingsChangedSignal;
679 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
681 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
683 return mAuxiliaryMessageSignal;
687 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
688 WindowBase* mWindowBase;
690 std::string mClassName;
691 bool mIsTransparent : 1;
692 bool mIsFocusAcceptable : 1;
694 bool mOpaqueState : 1;
695 bool mWindowRotationAcknowledgement : 1;
696 Dali::Window mParentWindow;
698 OrientationPtr mOrientation;
699 std::vector<int> mAvailableAngles;
702 int mRotationAngle; ///< The angle of the rotation
703 int mWindowWidth; ///< The width of the window
704 int mWindowHeight; ///< The height of the window
706 EventHandlerPtr mEventHandler; ///< The window events handler
708 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
710 int mNativeWindowId; ///< The Native Window Id
713 SignalType mDeleteRequestSignal;
714 FocusChangeSignalType mFocusChangeSignal;
715 ResizeSignalType mResizeSignal;
716 VisibilityChangedSignalType mVisibilityChangedSignal;
717 TransitionEffectEventSignalType mTransitionEffectEventSignal;
718 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
719 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
722 } // namespace Adaptor
723 } // namespace Internal
725 // Helpers for public-api forwarding methods
727 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
729 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
730 BaseObject& object = window.GetBaseObject();
731 return static_cast<Internal::Adaptor::Window&>(object);
734 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
736 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
737 const BaseObject& object = window.GetBaseObject();
738 return static_cast<const Internal::Adaptor::Window&>(object);
743 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H