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::Window::GetLayerCount()
122 uint32_t GetLayerCount() const;
125 * @copydoc Dali::Window::GetLayer()
127 Dali::Layer GetLayer(uint32_t depth) const;
130 * @copydoc Dali::DevelWindow::GetRenderTaskList()
132 Dali::RenderTaskList GetRenderTaskList() const;
135 * @copydoc Dali::Window::AddAvailableOrientation()
137 void AddAvailableOrientation(WindowOrientation orientation);
140 * @copydoc Dali::Window::RemoveAvailableOrientation()
142 void RemoveAvailableOrientation(WindowOrientation orientation);
145 * @copydoc Dali::Window::SetPreferredOrientation()
147 void SetPreferredOrientation(WindowOrientation orientation);
150 * @copydoc Dali::Window::GetPreferredOrientation()
152 WindowOrientation GetPreferredOrientation();
155 * @copydoc Dali::Window::SetAcceptFocus()
157 void SetAcceptFocus(bool accept);
160 * @copydoc Dali::Window::IsFocusAcceptable()
162 bool IsFocusAcceptable() const;
165 * @copydoc Dali::Window::Show()
170 * @copydoc Dali::Window::Hide()
175 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
177 unsigned int GetSupportedAuxiliaryHintCount() const;
180 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
182 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
185 * @copydoc Dali::Window::AddAuxiliaryHint()
187 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
190 * @copydoc Dali::Window::RemoveAuxiliaryHint()
192 bool RemoveAuxiliaryHint(unsigned int id);
195 * @copydoc Dali::Window::SetAuxiliaryHintValue()
197 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
200 * @copydoc Dali::Window::GetAuxiliaryHintValue()
202 std::string GetAuxiliaryHintValue(unsigned int id) const;
205 * @copydoc Dali::Window::GetAuxiliaryHintId()
207 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
210 * @copydoc Dali::Window::SetInputRegion()
212 void SetInputRegion(const Rect<int>& inputRegion);
215 * @copydoc Dali::Window::SetType()
217 void SetType(WindowType type);
220 * @copydoc Dali::Window::GetType() const
222 WindowType GetType() const;
225 * @copydoc Dali::Window::SetNotificationLevel()
227 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
230 * @copydoc Dali::Window::GetNotificationLevel()
232 WindowNotificationLevel GetNotificationLevel() const;
235 * @copydoc Dali::Window::SetOpaqueState()
237 void SetOpaqueState(bool opaque);
240 * @copydoc Dali::Window::IsOpaqueState()
242 bool IsOpaqueState() const;
245 * @copydoc Dali::Window::SetScreenOffMode()
247 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
250 * @copydoc Dali::Window::GetScreenOffMode()
252 WindowScreenOffMode GetScreenOffMode() const;
255 * @copydoc Dali::Window::SetBrightness()
257 WindowOperationResult SetBrightness(int brightness);
260 * @copydoc Dali::Window::GetBrightness()
262 int GetBrightness() const;
265 * @copydoc Dali::Window::SetSize()
267 void SetSize(Dali::Window::WindowSize size);
270 * @copydoc Dali::Window::GetSize()
272 Dali::Window::WindowSize GetSize() const;
275 * @copydoc Dali::Window::SetPosition()
277 void SetPosition(Dali::Window::WindowPosition position);
280 * @copydoc Dali::Window::GetPosition()
282 Dali::Window::WindowPosition GetPosition() const;
285 * @copydoc Dali::DevelWindow::SetPositionSize()
287 void SetPositionSize(PositionSize positionSize);
290 * @copydoc Dali::DevelWindow::GetPositionSize()
292 PositionSize GetPositionSize() const;
295 * @copydoc Dali::Window::GetRootLayer()
297 Dali::Layer GetRootLayer() const;
300 * @copydoc Dali::Window::SetTransparency()
302 void SetTransparency(bool transparent);
305 * @copydoc Dali::KeyGrab::GrabKey()
307 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
310 * @copydoc Dali::KeyGrab::UngrabKey()
312 bool UngrabKey(Dali::KEY key);
315 * @copydoc Dali::KeyGrab::GrabKeyList()
317 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
320 * @copydoc Dali::KeyGrab::UngrabKeyList()
322 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
325 * @copydoc Dali::DevelWindow::Get()
327 static Dali::Window Get(Dali::Actor actor);
330 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
332 void SetParent(Dali::Window& parent);
335 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
337 void SetParent(Dali::Window& parent, bool belowParent);
340 * @copydoc Dali::DevelWindow::Unparent()
345 * @copydoc Dali::DevelWindow::GetParent()
347 Dali::Window GetParent();
350 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
352 WindowOrientation GetCurrentOrientation() const;
355 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
357 int GetPhysicalOrientation() const;
360 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
362 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
365 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
367 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
369 public: // Dali::Internal::Adaptor::SceneHolder
371 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
373 Dali::Any GetNativeHandle() const override;
376 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
378 bool IsVisible() const override;
381 * @copydoc Dali::DevelWindow::GetNativeId()
383 int32_t GetNativeId() const;
386 * @copydoc Dali::DevelWindow::RequestMoveToServer()
388 void RequestMoveToServer();
391 * @copydoc Dali::DevelWindow::RequestResizeToServer()
393 void RequestResizeToServer(WindowResizeDirection direction);
396 * @copydoc Dali::DevelWindow::EnableFloatingMode()
398 void EnableFloatingMode(bool enable);
401 * @copydoc Dali::DevelWindow::IncludeInputRegion()
403 void IncludeInputRegion(const Rect<int>& inputRegion);
406 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
408 void ExcludeInputRegion(const Rect<int>& inputRegion);
411 * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
413 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
416 * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
418 void SendRotationCompletedAcknowledgement();
422 * @brief Enumeration for orietation mode.
423 * The Orientation Mode is related to screen size.
424 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
425 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
427 enum class OrientationMode
434 * Private constructor.
445 * Second stage initialization
447 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
450 * Called when the window becomes iconified or deiconified.
452 void OnIconifyChanged(bool iconified);
455 * Called when the window focus is changed.
457 void OnFocusChanged(bool focusIn);
460 * Called when the output is transformed.
462 void OnOutputTransformed();
465 * Called when the window receives a delete request.
467 void OnDeleteRequest();
470 * Called when the window receives a Transition effect-start/end event.
472 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
475 * @brief Called when window receives a keyboard repeat event.
477 void OnKeyboardRepeatSettingsChanged();
480 * @brief Called when the window redraw is requested.
482 void OnWindowRedrawRequest();
485 * @brief Called when the window is resized or moved by display server.
487 * @param[in] positionSize the updated window's position and size.
489 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
492 * @brief Called when display server sent the auxiliary message.
494 * @param[in] key the auxiliary message's key.
495 * @param[in] value the auxiliary message's value.
496 * @param[in] options the auxiliary message's options. This is the list of string.
498 void OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options);
501 * @brief Called when Accessibility is enabled.
503 * This method is to register the window to accessibility bridge.
505 void OnAccessibilityEnabled();
508 * @brief Called when Accessibility is disabled.
510 * This method is to remove the window from accessibility bridge.
512 void OnAccessibilityDisabled();
515 * @brief Set available orientation to window base.
517 void SetAvailableAnlges(const std::vector<int>& angles);
520 * @brief Convert from window orientation to angle using OrientationMode.
522 int ConvertToAngle(WindowOrientation orientation);
525 * @brief Convert from angle to window orientation using OrientationMode.
527 WindowOrientation ConvertToOrientation(int angle) const;
530 * @brief Check available window orientation for Available orientation.
532 bool IsOrientationAvailable(WindowOrientation orientation) const;
535 * @brief Return the rect value to recalulate with the default system coordinates.
537 * Some native window APIs work the geometry value based on the default system coordinates.
538 * IncludeInputRegion() and ExcludeInputRegion() are one of them.
539 * When the window is rotated, current window's geometry already were set with the rotated angle.
540 * If IncludeInputRegion() or ExcludeInputRegion() are called with rotated angle by application,
541 * the rect's area should be re-calcuated on the default system coordinates.
543 * @param[in] rect the window's current position and size with current window rotation angle.
544 * @return the re-calculated rect on the default system coordinates.
546 Rect<int> RecalculateRect(const Rect<int>& rect);
548 private: // Dali::Internal::Adaptor::SceneHolder
550 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
552 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
555 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
557 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
560 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
562 void OnPause() override;
565 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
567 void OnResume() override;
570 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
572 void RecalculateTouchPosition(Integration::Point& point) override;
574 private: // Dali::Internal::Adaptor::EventHandler::Observer
576 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
578 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
581 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
583 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
586 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
588 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
591 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
593 void OnRotation(const RotationEvent& rotation) override;
597 * @copydoc Dali::Window::FocusChangeSignal()
599 FocusChangeSignalType& FocusChangeSignal()
601 return mFocusChangeSignal;
605 * @copydoc Dali::Window::ResizedSignal()
607 ResizeSignalType& ResizeSignal()
609 return mResizeSignal;
613 * This signal is emitted when the window is requesting to be deleted
615 SignalType& DeleteRequestSignal()
617 return mDeleteRequestSignal;
621 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
623 VisibilityChangedSignalType& VisibilityChangedSignal()
625 return mVisibilityChangedSignal;
629 * @copydoc Dali::Window::SignalEventProcessingFinished()
631 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
633 return mScene.EventProcessingFinishedSignal();
637 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
639 TransitionEffectEventSignalType& TransitionEffectEventSignal()
641 return mTransitionEffectEventSignal;
645 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
647 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
649 return mKeyboardRepeatSettingsChangedSignal;
653 * @copydoc Dali::DevelWindow::AuxiliaryMessageSignal()
655 AuxiliaryMessageSignalType& AuxiliaryMessageSignal()
657 return mAuxiliaryMessageSignal;
661 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
662 WindowBase* mWindowBase;
664 std::string mClassName;
665 bool mIsTransparent : 1;
666 bool mIsFocusAcceptable : 1;
668 bool mOpaqueState : 1;
669 bool mWindowRotationAcknowledgement : 1;
670 Dali::Window mParentWindow;
672 OrientationPtr mOrientation;
673 std::vector<int> mAvailableAngles;
676 int mRotationAngle; ///< The angle of the rotation
677 int mWindowWidth; ///< The width of the window
678 int mWindowHeight; ///< The height of the window
680 EventHandlerPtr mEventHandler; ///< The window events handler
682 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
684 int mNativeWindowId; ///< The Native Window Id
687 SignalType mDeleteRequestSignal;
688 FocusChangeSignalType mFocusChangeSignal;
689 ResizeSignalType mResizeSignal;
690 VisibilityChangedSignalType mVisibilityChangedSignal;
691 TransitionEffectEventSignalType mTransitionEffectEventSignal;
692 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
693 AuxiliaryMessageSignalType mAuxiliaryMessageSignal;
696 } // namespace Adaptor
697 } // namespace Internal
699 // Helpers for public-api forwarding methods
701 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
703 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
704 BaseObject& object = window.GetBaseObject();
705 return static_cast<Internal::Adaptor::Window&>(object);
708 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
710 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
711 const BaseObject& object = window.GetBaseObject();
712 return static_cast<const Internal::Adaptor::Window&>(object);
717 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H