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 Signal<void()> SignalType;
70 * @brief Create a new Window. This should only be called once by the Application class
71 * @param[in] positionSize The position and size of the window
72 * @param[in] name The window title
73 * @param[in] className The window class name
74 * @param[in] type Window type.
75 * @param[in] isTransparent Whether window is transparent
76 * @return A newly allocated Window
78 static Window* New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
81 * @brief Create a new Window. This should only be called once by the Application class
82 * @param[in] surface The surface used to render on.
83 * @param[in] positionSize The position and size of the window
84 * @param[in] name The window title
85 * @param[in] className The window class name
86 * @param[in] type Window type.
87 * @param[in] isTransparent Whether window is transparent
88 * @return A newly allocated Window
90 static Window* New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent = false);
93 * @copydoc Dali::Window::SetClass()
95 void SetClass(std::string name, std::string className);
98 * @brief Gets the window class name.
99 * @return The class of the window
101 std::string GetClassName() const;
104 * @copydoc Dali::Window::Raise()
109 * @copydoc Dali::Window::Lower()
114 * @copydoc Dali::Window::Activate()
119 * @copydoc Dali::Window::GetLayerCount()
121 uint32_t GetLayerCount() const;
124 * @copydoc Dali::Window::GetLayer()
126 Dali::Layer GetLayer(uint32_t depth) const;
129 * @copydoc Dali::DevelWindow::GetRenderTaskList()
131 Dali::RenderTaskList GetRenderTaskList() const;
134 * @copydoc Dali::Window::AddAvailableOrientation()
136 void AddAvailableOrientation(WindowOrientation orientation);
139 * @copydoc Dali::Window::RemoveAvailableOrientation()
141 void RemoveAvailableOrientation(WindowOrientation orientation);
144 * @copydoc Dali::Window::SetPreferredOrientation()
146 void SetPreferredOrientation(WindowOrientation orientation);
149 * @copydoc Dali::Window::GetPreferredOrientation()
151 WindowOrientation GetPreferredOrientation();
154 * @copydoc Dali::Window::SetAcceptFocus()
156 void SetAcceptFocus(bool accept);
159 * @copydoc Dali::Window::IsFocusAcceptable()
161 bool IsFocusAcceptable() const;
164 * @copydoc Dali::Window::Show()
169 * @copydoc Dali::Window::Hide()
174 * @copydoc Dali::Window::GetSupportedAuxiliaryHintCount()
176 unsigned int GetSupportedAuxiliaryHintCount() const;
179 * @copydoc Dali::Window::GetSupportedAuxiliaryHint()
181 std::string GetSupportedAuxiliaryHint(unsigned int index) const;
184 * @copydoc Dali::Window::AddAuxiliaryHint()
186 unsigned int AddAuxiliaryHint(const std::string& hint, const std::string& value);
189 * @copydoc Dali::Window::RemoveAuxiliaryHint()
191 bool RemoveAuxiliaryHint(unsigned int id);
194 * @copydoc Dali::Window::SetAuxiliaryHintValue()
196 bool SetAuxiliaryHintValue(unsigned int id, const std::string& value);
199 * @copydoc Dali::Window::GetAuxiliaryHintValue()
201 std::string GetAuxiliaryHintValue(unsigned int id) const;
204 * @copydoc Dali::Window::GetAuxiliaryHintId()
206 unsigned int GetAuxiliaryHintId(const std::string& hint) const;
209 * @copydoc Dali::Window::SetInputRegion()
211 void SetInputRegion(const Rect<int>& inputRegion);
214 * @copydoc Dali::Window::SetType()
216 void SetType(WindowType type);
219 * @copydoc Dali::Window::GetType() const
221 WindowType GetType() const;
224 * @copydoc Dali::Window::SetNotificationLevel()
226 WindowOperationResult SetNotificationLevel(WindowNotificationLevel level);
229 * @copydoc Dali::Window::GetNotificationLevel()
231 WindowNotificationLevel GetNotificationLevel() const;
234 * @copydoc Dali::Window::SetOpaqueState()
236 void SetOpaqueState(bool opaque);
239 * @copydoc Dali::Window::IsOpaqueState()
241 bool IsOpaqueState() const;
244 * @copydoc Dali::Window::SetScreenOffMode()
246 WindowOperationResult SetScreenOffMode(WindowScreenOffMode screenOffMode);
249 * @copydoc Dali::Window::GetScreenOffMode()
251 WindowScreenOffMode GetScreenOffMode() const;
254 * @copydoc Dali::Window::SetBrightness()
256 WindowOperationResult SetBrightness(int brightness);
259 * @copydoc Dali::Window::GetBrightness()
261 int GetBrightness() const;
264 * @copydoc Dali::Window::SetSize()
266 void SetSize(Dali::Window::WindowSize size);
269 * @copydoc Dali::Window::GetSize()
271 Dali::Window::WindowSize GetSize() const;
274 * @copydoc Dali::Window::SetPosition()
276 void SetPosition(Dali::Window::WindowPosition position);
279 * @copydoc Dali::Window::GetPosition()
281 Dali::Window::WindowPosition GetPosition() const;
284 * @copydoc Dali::DevelWindow::SetPositionSize()
286 void SetPositionSize(PositionSize positionSize);
289 * @copydoc Dali::DevelWindow::GetPositionSize()
291 PositionSize GetPositionSize() const;
294 * @copydoc Dali::Window::GetRootLayer()
296 Dali::Layer GetRootLayer() const;
299 * @copydoc Dali::Window::SetTransparency()
301 void SetTransparency(bool transparent);
304 * @copydoc Dali::KeyGrab::GrabKey()
306 bool GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode);
309 * @copydoc Dali::KeyGrab::UngrabKey()
311 bool UngrabKey(Dali::KEY key);
314 * @copydoc Dali::KeyGrab::GrabKeyList()
316 bool GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result);
319 * @copydoc Dali::KeyGrab::UngrabKeyList()
321 bool UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result);
324 * @copydoc Dali::DevelWindow::Get()
326 static Dali::Window Get(Dali::Actor actor);
329 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent)
331 void SetParent(Dali::Window& parent);
334 * @copydoc Dali::DevelWindow::SetParent(Window window, Window parent, bool belowParent)
336 void SetParent(Dali::Window& parent, bool belowParent);
339 * @copydoc Dali::DevelWindow::Unparent()
344 * @copydoc Dali::DevelWindow::GetParent()
346 Dali::Window GetParent();
349 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
351 WindowOrientation GetCurrentOrientation() const;
354 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
356 int GetPhysicalOrientation() const;
359 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
361 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
364 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
366 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
368 public: // Dali::Internal::Adaptor::SceneHolder
370 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
372 Dali::Any GetNativeHandle() const override;
375 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
377 bool IsVisible() const override;
380 * @copydoc Dali::DevelWindow::GetNativeId()
382 int32_t GetNativeId() const;
385 * @copydoc Dali::DevelWindow::RequestMoveToServer()
387 void RequestMoveToServer();
390 * @copydoc Dali::DevelWindow::RequestResizeToServer()
392 void RequestResizeToServer(WindowResizeDirection direction);
395 * @copydoc Dali::DevelWindow::EnableFloatingMode()
397 void EnableFloatingMode(bool enable);
400 * @copydoc Dali::DevelWindow::IncludeInputRegion()
402 void IncludeInputRegion(const Rect<int>& inputRegion);
405 * @copydoc Dali::DevelWindow::ExcludeInputRegion()
407 void ExcludeInputRegion(const Rect<int>& inputRegion);
410 * @copydoc Dali::DevelWindow::SetNeedsRotationCompletedAcknowledgement()
412 void SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement);
415 * @copydoc Dali::DevelWindow::SendRotationCompletedAcknowledgement()
417 void SendRotationCompletedAcknowledgement();
421 * @brief Enumeration for orietation mode.
422 * The Orientation Mode is related to screen size.
423 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
424 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
426 enum class OrientationMode
433 * Private constructor.
444 * Second stage initialization
446 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
449 * Called when the window becomes iconified or deiconified.
451 void OnIconifyChanged(bool iconified);
454 * Called when the window focus is changed.
456 void OnFocusChanged(bool focusIn);
459 * Called when the output is transformed.
461 void OnOutputTransformed();
464 * Called when the window receives a delete request.
466 void OnDeleteRequest();
469 * Called when the window receives a Transition effect-start/end event.
471 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
474 * @brief Called when window receives a keyboard repeat event.
476 void OnKeyboardRepeatSettingsChanged();
479 * @brief Called when the window redraw is requested.
481 void OnWindowRedrawRequest();
484 * @brief Called when the window is resized or moved by display server.
486 * @param[in] positionSize the updated window's position and size.
488 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
491 * @brief Set available orientation to window base.
493 void SetAvailableAnlges(const std::vector<int>& angles);
496 * @brief Convert from window orientation to angle using OrientationMode.
498 int ConvertToAngle(WindowOrientation orientation);
501 * @brief Convert from angle to window orientation using OrientationMode.
503 WindowOrientation ConvertToOrientation(int angle) const;
506 * @brief Check available window orientation for Available orientation.
508 bool IsOrientationAvailable(WindowOrientation orientation) const;
511 * @brief Return the rect value to recalulate with the default system coordinates.
513 * Some native window APIs work the geometry value based on the default system coordinates.
514 * IncludeInputRegion() and ExcludeInputRegion() are one of them.
515 * When the window is rotated, current window's geometry already were set with the rotated angle.
516 * If IncludeInputRegion() or ExcludeInputRegion() are called with rotated angle by application,
517 * the rect's area should be re-calcuated on the default system coordinates.
519 * @param[in] rect the window's current position and size with current window rotation angle.
520 * @return the re-calculated rect on the default system coordinates.
522 Rect<int> RecalculateRect(const Rect<int>& rect);
524 private: // Dali::Internal::Adaptor::SceneHolder
526 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
528 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
531 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
533 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
536 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
538 void OnPause() override;
541 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
543 void OnResume() override;
546 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
548 void RecalculateTouchPosition(Integration::Point& point) override;
550 private: // Dali::Internal::Adaptor::EventHandler::Observer
552 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
554 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
557 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
559 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
562 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
564 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
567 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
569 void OnRotation(const RotationEvent& rotation) override;
573 * @copydoc Dali::Window::FocusChangeSignal()
575 FocusChangeSignalType& FocusChangeSignal()
577 return mFocusChangeSignal;
581 * @copydoc Dali::Window::ResizedSignal()
583 ResizeSignalType& ResizeSignal()
585 return mResizeSignal;
589 * This signal is emitted when the window is requesting to be deleted
591 SignalType& DeleteRequestSignal()
593 return mDeleteRequestSignal;
597 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
599 VisibilityChangedSignalType& VisibilityChangedSignal()
601 return mVisibilityChangedSignal;
605 * @copydoc Dali::Window::SignalEventProcessingFinished()
607 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
609 return mScene.EventProcessingFinishedSignal();
613 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
615 TransitionEffectEventSignalType& TransitionEffectEventSignal()
617 return mTransitionEffectEventSignal;
621 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
623 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
625 return mKeyboardRepeatSettingsChangedSignal;
629 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
630 WindowBase* mWindowBase;
632 std::string mClassName;
633 bool mIsTransparent : 1;
634 bool mIsFocusAcceptable : 1;
636 bool mOpaqueState : 1;
637 bool mWindowRotationAcknowledgement : 1;
638 Dali::Window mParentWindow;
640 OrientationPtr mOrientation;
641 std::vector<int> mAvailableAngles;
644 int mRotationAngle; ///< The angle of the rotation
645 int mWindowWidth; ///< The width of the window
646 int mWindowHeight; ///< The height of the window
648 EventHandlerPtr mEventHandler; ///< The window events handler
650 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
652 int mNativeWindowId; ///< The Native Window Id
655 SignalType mDeleteRequestSignal;
656 FocusChangeSignalType mFocusChangeSignal;
657 ResizeSignalType mResizeSignal;
658 VisibilityChangedSignalType mVisibilityChangedSignal;
659 TransitionEffectEventSignalType mTransitionEffectEventSignal;
660 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
663 } // namespace Adaptor
664 } // namespace Internal
666 // Helpers for public-api forwarding methods
668 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
670 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
671 BaseObject& object = window.GetBaseObject();
672 return static_cast<Internal::Adaptor::Window&>(object);
675 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
677 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
678 const BaseObject& object = window.GetBaseObject();
679 return static_cast<const Internal::Adaptor::Window&>(object);
684 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H