1 #ifndef DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
2 #define DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H
5 * Copyright (c) 2021 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 * @copydoc Dali::Window::AddAvailableOrientation()
157 void AddAvailableOrientation(WindowOrientation orientation);
160 * @copydoc Dali::Window::RemoveAvailableOrientation()
162 void RemoveAvailableOrientation(WindowOrientation orientation);
165 * @copydoc Dali::Window::SetPreferredOrientation()
167 void SetPreferredOrientation(WindowOrientation orientation);
170 * @copydoc Dali::Window::GetPreferredOrientation()
172 WindowOrientation GetPreferredOrientation();
175 * @copydoc Dali::Window::SetAcceptFocus()
177 void SetAcceptFocus(bool accept);
180 * @copydoc Dali::Window::IsFocusAcceptable()
182 bool IsFocusAcceptable() const;
185 * @copydoc Dali::Window::Show()
190 * @copydoc Dali::Window::Hide()
195 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
197 unsigned int GetSupportedAuxiliaryHintCount() const;
200 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
202 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
205 * @copydoc Dali::Window::AddAuxiliaryHint()
207 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
210 * @copydoc Dali::Window::RemoveAuxiliaryHint()
212 bool RemoveAuxiliaryHint(unsigned int id);
215 * @copydoc Dali::Window::SetAuxiliaryHintValue()
217 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
220 * @copydoc Dali::Window::GetAuxiliaryHintValue()
222 std::string GetAuxiliaryHintValue(unsigned int id) const;
225 * @copydoc Dali::Window::GetAuxiliaryHintId()
227 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
230 * @copydoc Dali::Window::SetInputRegion()
232 void SetInputRegion(const Rect<int>& inputRegion);
235 * @copydoc Dali::Window::SetType()
237 void SetType(WindowType type);
240 * @copydoc Dali::Window::GetType() const
242 WindowType GetType() const;
245 * @copydoc Dali::Window::SetNotificationLevel()
247 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
250 * @copydoc Dali::Window::GetNotificationLevel()
252 WindowNotificationLevel GetNotificationLevel() const;
255 * @copydoc Dali::Window::SetOpaqueState()
257 void SetOpaqueState(bool opaque);
260 * @copydoc Dali::Window::IsOpaqueState()
262 bool IsOpaqueState() const;
265 * @copydoc Dali::Window::SetScreenOffMode()
267 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
270 * @copydoc Dali::Window::GetScreenOffMode()
272 WindowScreenOffMode GetScreenOffMode() const;
275 * @copydoc Dali::Window::SetBrightness()
277 WindowOperationResult SetBrightness(int brightness);
280 * @copydoc Dali::Window::GetBrightness()
282 int GetBrightness() const;
285 * @copydoc Dali::Window::SetSize()
287 void SetSize(Dali::Window::WindowSize size);
290 * @copydoc Dali::Window::GetSize()
292 Dali::Window::WindowSize GetSize() const;
295 * @copydoc Dali::Window::SetPosition()
297 void SetPosition(Dali::Window::WindowPosition position);
300 * @copydoc Dali::Window::GetPosition()
302 Dali::Window::WindowPosition GetPosition() const;
305 * @copydoc Dali::DevelWindow::SetPositionSize()
307 void SetPositionSize(PositionSize positionSize);
310 * @copydoc Dali::DevelWindow::GetPositionSize()
312 PositionSize GetPositionSize() const;
315 * @copydoc Dali::Window::GetRootLayer()
317 Dali::Layer GetRootLayer() const;
320 * @copydoc Dali::Window::SetTransparency()
322 void SetTransparency(bool transparent);
325 * @copydoc Dali::KeyGrab::GrabKey()
327 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
330 * @copydoc Dali::KeyGrab::UngrabKey()
332 bool UngrabKey(Dali::KEY key);
335 * @copydoc Dali::KeyGrab::GrabKeyList()
337 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
340 * @copydoc Dali::KeyGrab::UngrabKeyList()
342 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
345 * @copydoc Dali::DevelWindow::Get()
347 static Dali::Window Get(Dali::Actor actor);
350 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
352 void SetParent(Dali::Window& parent);
355 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
357 void SetParent(Dali::Window& parent, bool belowParent);
360 * @copydoc Dali::DevelWindow::Unparent()
365 * @copydoc Dali::DevelWindow::GetParent()
367 Dali::Window GetParent();
370 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
372 WindowOrientation GetCurrentOrientation() const;
375 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
377 int GetPhysicalOrientation() const;
380 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
382 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
385 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
387 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
389 public: // Dali::Internal::Adaptor::SceneHolder
391 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
393 Dali::Any GetNativeHandle() const override;
396 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
398 bool IsVisible() const override;
401 * @copydoc Dali::DevelWindow::GetNativeId()
403 int32_t GetNativeId() const;
406 * @copydoc Dali::DevelWindow::RequestMoveToServer()
408 void RequestMoveToServer();
411 * @copydoc Dali::DevelWindow::RequestResizeToServer()
413 void RequestResizeToServer(WindowResizeDirection direction);
416 * @copydoc Dali::DevelWindow::EnableFloatingMode()
418 void EnableFloatingMode(bool enable);
421 * @copydoc Dali::DevelWindow::IncludeInputRegion()
423 void IncludeInputRegion(const Rect<int>& inputRegion);
426 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
428 void ExcludeInputRegion(const Rect<int>& inputRegion);
431 * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
433 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
436 * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
438 void SendRotationCompletedAcknowledgement();
442 * @brief Enumeration for orietation mode.
443 * The Orientation Mode is related to screen size.
444 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
445 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
447 enum class OrientationMode
454 * Private constructor.
465 * Second stage initialization
467 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
470 * Called when the window becomes iconified or deiconified.
472 void OnIconifyChanged(bool iconified);
475 * Called when the window focus is changed.
477 void OnFocusChanged(bool focusIn);
480 * Called when the output is transformed.
482 void OnOutputTransformed();
485 * Called when the window receives a delete request.
487 void OnDeleteRequest();
490 * Called when the window receives a Transition effect-start/end event.
492 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
495 * @brief Called when window receives a keyboard repeat event.
497 void OnKeyboardRepeatSettingsChanged();
500 * @brief Called when the window redraw is requested.
502 void OnWindowRedrawRequest();
505 * @brief Called when the window is resized or moved by display server.
507 * @param[in] positionSize the updated window's position and size.
509 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
512 * @brief Called when display server sent the auxiliary message.
514 * @param[in] key the auxiliary message's key.
515 * @param[in] value the auxiliary message's value.
516 * @param[in] options the auxiliary message's options. This is the list of string.
518 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
521 * @brief Called when Accessibility is enabled.
523 * This method is to register the window to accessibility bridge.
525 void OnAccessibilityEnabled();
528 * @brief Called when Accessibility is disabled.
530 * This method is to remove the window from accessibility bridge.
532 void OnAccessibilityDisabled();
535 * @brief Set available orientation to window base.
537 void SetAvailableAnlges(const std::vector<int>& angles);
540 * @brief Convert from window orientation to angle using OrientationMode.
542 int ConvertToAngle(WindowOrientation orientation);
545 * @brief Convert from angle to window orientation using OrientationMode.
547 WindowOrientation ConvertToOrientation(int angle) const;
550 * @brief Check available window orientation for Available orientation.
552 bool IsOrientationAvailable(WindowOrientation orientation) const;
555 * @brief Return the rect value to recalulate with the default system coordinates.
557 * Some native window APIs work the geometry value based on the default system coordinates.
558 * IncludeInputRegion() and ExcludeInputRegion() are one of them.
559 * When the window is rotated, current window's geometry already were set with the rotated angle.
560 * If IncludeInputRegion() or ExcludeInputRegion() are called with rotated angle by application,
561 * the rect's area should be re-calcuated on the default system coordinates.
563 * @param[in] rect the window's current position and size with current window rotation angle.
564 * @return the re-calculated rect on the default system coordinates.
566 Rect<int> RecalculateRect(const Rect<int>& rect);
568 private: // Dali::Internal::Adaptor::SceneHolder
570 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
572 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
575 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
577 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
580 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
582 void OnPause() override;
585 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
587 void OnResume() override;
590 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
592 void RecalculateTouchPosition(Integration::Point& point) override;
594 private: // Dali::Internal::Adaptor::EventHandler::Observer
596 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
598 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
601 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
603 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
606 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
608 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
611 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
613 void OnRotation(const RotationEvent& rotation) override;
617 * @copydoc Dali::Window::FocusChangeSignal()
619 FocusChangeSignalType& FocusChangeSignal()
621 return mFocusChangeSignal;
625 * @copydoc Dali::Window::ResizedSignal()
627 ResizeSignalType& ResizeSignal()
629 return mResizeSignal;
633 * This signal is emitted when the window is requesting to be deleted
635 SignalType& DeleteRequestSignal()
637 return mDeleteRequestSignal;
641 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
643 VisibilityChangedSignalType& VisibilityChangedSignal()
645 return mVisibilityChangedSignal;
649 * @copydoc Dali::Window::SignalEventProcessingFinished()
651 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
653 return mScene.EventProcessingFinishedSignal();
657 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
659 TransitionEffectEventSignalType& TransitionEffectEventSignal()
661 return mTransitionEffectEventSignal;
665 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
667 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
669 return mKeyboardRepeatSettingsChangedSignal;
673 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
675 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
677 return mAuxiliaryMessageSignal;
681 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
682 WindowBase* mWindowBase;
684 std::string mClassName;
685 bool mIsTransparent : 1;
686 bool mIsFocusAcceptable : 1;
688 bool mOpaqueState : 1;
689 bool mWindowRotationAcknowledgement : 1;
691 Dali::Window mParentWindow;
693 OrientationPtr mOrientation;
694 std::vector<int> mAvailableAngles;
697 int mRotationAngle; ///< The angle of the rotation
698 int mWindowWidth; ///< The width of the window
699 int mWindowHeight; ///< The height of the window
701 EventHandlerPtr mEventHandler; ///< The window events handler
703 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
705 int mNativeWindowId; ///< The Native Window Id
708 SignalType mDeleteRequestSignal;
709 FocusChangeSignalType mFocusChangeSignal;
710 ResizeSignalType mResizeSignal;
711 VisibilityChangedSignalType mVisibilityChangedSignal;
712 TransitionEffectEventSignalType mTransitionEffectEventSignal;
713 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
714 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
717 } // namespace Adaptor
718 } // namespace Internal
720 // Helpers for public-api forwarding methods
722 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
724 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
725 BaseObject& object = window.GetBaseObject();
726 return static_cast<Internal::Adaptor::Window&>(object);
729 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
731 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
732 const BaseObject& object = window.GetBaseObject();
733 return static_cast<const Internal::Adaptor::Window&>(object);
738 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H