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()
331 void SetParent(Dali::Window& parent);
334 * @copydoc Dali::DevelWindow::Unparent()
339 * @copydoc Dali::DevelWindow::GetParent()
341 Dali::Window GetParent();
344 * @copydoc Dali::DevelWindow::GetCurrentOrientation()
346 WindowOrientation GetCurrentOrientation() const;
349 * @copydoc Dali::DevelWindow::GetPhysicalOrientation()
351 int GetPhysicalOrientation() const;
354 * @copydoc Dali::DevelWindow::SetAvailableOrientations()
356 void SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations);
359 * @copydoc Dali::DevelWindow::SetPositionSizeWithOrientation()
361 void SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation);
363 public: // Dali::Internal::Adaptor::SceneHolder
365 * @copydoc Dali::Internal::Adaptor::SceneHolder::GetNativeHandle
367 Dali::Any GetNativeHandle() const override;
370 * @copydoc Dali::Internal::Adaptor::SceneHolder::IsVisible
372 bool IsVisible() const override;
375 * @copydoc Dali::DevelWindow::GetNativeId()
377 int32_t GetNativeId() const;
381 * @brief Enumeration for orietation mode.
382 * The Orientation Mode is related to screen size.
383 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
384 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
386 enum class OrientationMode
393 * Private constructor.
404 * Second stage initialization
406 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
409 * Called when the window becomes iconified or deiconified.
411 void OnIconifyChanged(bool iconified);
414 * Called when the window focus is changed.
416 void OnFocusChanged(bool focusIn);
419 * Called when the output is transformed.
421 void OnOutputTransformed();
424 * Called when the window receives a delete request.
426 void OnDeleteRequest();
429 * Called when the window receives a Transition effect-start/end event.
431 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
434 * @brief Called when window receives a keyboard repeat event.
436 void OnKeyboardRepeatSettingsChanged();
439 * @brief Called when the window redraw is requested.
441 void OnWindowRedrawRequest();
444 * @brief Called when the window is resized or moved by display server.
446 * @param positionSize the updated window's position and size.
448 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
451 * @brief Set available orientation to window base.
453 void SetAvailableAnlges(const std::vector<int>& angles);
456 * @brief Convert from window orientation to angle using OrientationMode.
458 int ConvertToAngle(WindowOrientation orientation);
461 * @brief Convert from angle to window orientation using OrientationMode.
463 WindowOrientation ConvertToOrientation(int angle) const;
466 * @brief Check available window orientation for Available orientation.
468 bool IsOrientationAvailable(WindowOrientation orientation) const;
470 private: // Dali::Internal::Adaptor::SceneHolder
472 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
474 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
477 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
479 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
482 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
484 void OnPause() override;
487 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
489 void OnResume() override;
492 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
494 void RecalculateTouchPosition(Integration::Point& point) override;
496 private: // Dali::Internal::Adaptor::EventHandler::Observer
498 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
500 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
503 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
505 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
508 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
510 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
513 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
515 void OnRotation(const RotationEvent& rotation) override;
519 * @copydoc Dali::Window::FocusChangeSignal()
521 FocusChangeSignalType& FocusChangeSignal()
523 return mFocusChangeSignal;
527 * @copydoc Dali::Window::ResizedSignal()
529 ResizeSignalType& ResizeSignal()
531 return mResizeSignal;
535 * This signal is emitted when the window is requesting to be deleted
537 SignalType& DeleteRequestSignal()
539 return mDeleteRequestSignal;
543 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
545 VisibilityChangedSignalType& VisibilityChangedSignal()
547 return mVisibilityChangedSignal;
551 * @copydoc Dali::Window::SignalEventProcessingFinished()
553 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
555 return mScene.EventProcessingFinishedSignal();
559 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
561 TransitionEffectEventSignalType& TransitionEffectEventSignal()
563 return mTransitionEffectEventSignal;
567 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
569 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
571 return mKeyboardRepeatSettingsChangedSignal;
575 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
576 WindowBase* mWindowBase;
578 std::string mClassName;
579 bool mIsTransparent : 1;
580 bool mIsFocusAcceptable : 1;
582 bool mOpaqueState : 1;
583 Dali::Window mParentWindow;
585 OrientationPtr mOrientation;
586 std::vector<int> mAvailableAngles;
589 int mRotationAngle; ///< The angle of the rotation
590 int mWindowWidth; ///< The width of the window
591 int mWindowHeight; ///< The height of the window
593 EventHandlerPtr mEventHandler; ///< The window events handler
595 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
597 int mNativeWindowId; ///< The Native Window Id
600 SignalType mDeleteRequestSignal;
601 FocusChangeSignalType mFocusChangeSignal;
602 ResizeSignalType mResizeSignal;
603 VisibilityChangedSignalType mVisibilityChangedSignal;
604 TransitionEffectEventSignalType mTransitionEffectEventSignal;
605 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
608 } // namespace Adaptor
609 } // namespace Internal
611 // Helpers for public-api forwarding methods
613 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
615 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
616 BaseObject& object = window.GetBaseObject();
617 return static_cast<Internal::Adaptor::Window&>(object);
620 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
622 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
623 const BaseObject& object = window.GetBaseObject();
624 return static_cast<const Internal::Adaptor::Window&>(object);
629 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H