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;
380 * @copydoc Dali::DevelWindow::RequestMoveToServer()
382 void RequestMoveToServer();
385 * @copydoc Dali::DevelWindow::RequestResizeToServer()
387 void RequestResizeToServer(WindowResizeDirection direction);
390 * @copydoc Dali::DevelWindow::EnableFloatingMode()
392 void EnableFloatingMode(bool enable);
396 * @brief Enumeration for orietation mode.
397 * The Orientation Mode is related to screen size.
398 * If screen width is longer than height, the Orientation Mode will have LANDSCAPE.
399 * Otherwise screen width is shorter than height or same, the Orientation Mode will have PORTRAIT.
401 enum class OrientationMode
408 * Private constructor.
419 * Second stage initialization
421 void Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type);
424 * Called when the window becomes iconified or deiconified.
426 void OnIconifyChanged(bool iconified);
429 * Called when the window focus is changed.
431 void OnFocusChanged(bool focusIn);
434 * Called when the output is transformed.
436 void OnOutputTransformed();
439 * Called when the window receives a delete request.
441 void OnDeleteRequest();
444 * Called when the window receives a Transition effect-start/end event.
446 void OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type);
449 * @brief Called when window receives a keyboard repeat event.
451 void OnKeyboardRepeatSettingsChanged();
454 * @brief Called when the window redraw is requested.
456 void OnWindowRedrawRequest();
459 * @brief Called when the window is resized or moved by display server.
461 * @param positionSize the updated window's position and size.
463 void OnUpdatePositionSize(Dali::PositionSize& positionSize);
466 * @brief Set available orientation to window base.
468 void SetAvailableAnlges(const std::vector<int>& angles);
471 * @brief Convert from window orientation to angle using OrientationMode.
473 int ConvertToAngle(WindowOrientation orientation);
476 * @brief Convert from angle to window orientation using OrientationMode.
478 WindowOrientation ConvertToOrientation(int angle) const;
481 * @brief Check available window orientation for Available orientation.
483 bool IsOrientationAvailable(WindowOrientation orientation) const;
485 private: // Dali::Internal::Adaptor::SceneHolder
487 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnAdaptorSet
489 void OnAdaptorSet(Dali::Adaptor& adaptor) override;
492 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnSurfaceSet
494 void OnSurfaceSet(Dali::RenderSurfaceInterface* surface) override;
497 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnPause
499 void OnPause() override;
502 * @copydoc Dali::Internal::Adaptor::SceneHolder::OnResume
504 void OnResume() override;
507 * @copydoc Dali::Internal::Adaptor::SceneHolder::RecalculateTouchPosition
509 void RecalculateTouchPosition(Integration::Point& point) override;
511 private: // Dali::Internal::Adaptor::EventHandler::Observer
513 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnTouchPoint
515 void OnTouchPoint(Dali::Integration::Point& point, int timeStamp) override;
518 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnWheelEvent
520 void OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent) override;
523 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnKeyEvent
525 void OnKeyEvent(Dali::Integration::KeyEvent& keyEvent) override;
528 * @copydoc Dali::Internal::Adaptor::EventHandler::Observer::OnRotation
530 void OnRotation(const RotationEvent& rotation) override;
534 * @copydoc Dali::Window::FocusChangeSignal()
536 FocusChangeSignalType& FocusChangeSignal()
538 return mFocusChangeSignal;
542 * @copydoc Dali::Window::ResizedSignal()
544 ResizeSignalType& ResizeSignal()
546 return mResizeSignal;
550 * This signal is emitted when the window is requesting to be deleted
552 SignalType& DeleteRequestSignal()
554 return mDeleteRequestSignal;
558 * @copydoc Dali::DevelWindow::VisibilityChangedSignal()
560 VisibilityChangedSignalType& VisibilityChangedSignal()
562 return mVisibilityChangedSignal;
566 * @copydoc Dali::Window::SignalEventProcessingFinished()
568 Dali::DevelWindow::EventProcessingFinishedSignalType& EventProcessingFinishedSignal()
570 return mScene.EventProcessingFinishedSignal();
574 * @copydoc Dali::DevelWindow::TransitionEffectEventSignal()
576 TransitionEffectEventSignalType& TransitionEffectEventSignal()
578 return mTransitionEffectEventSignal;
582 * @copydoc Dali::DevelWindow::KeyboardRepeatSettingsChangedSignal()
584 KeyboardRepeatSettingsChangedSignalType& KeyboardRepeatSettingsChangedSignal()
586 return mKeyboardRepeatSettingsChangedSignal;
590 WindowRenderSurface* mWindowSurface; ///< The window rendering surface
591 WindowBase* mWindowBase;
593 std::string mClassName;
594 bool mIsTransparent : 1;
595 bool mIsFocusAcceptable : 1;
597 bool mOpaqueState : 1;
598 Dali::Window mParentWindow;
600 OrientationPtr mOrientation;
601 std::vector<int> mAvailableAngles;
604 int mRotationAngle; ///< The angle of the rotation
605 int mWindowWidth; ///< The width of the window
606 int mWindowHeight; ///< The height of the window
608 EventHandlerPtr mEventHandler; ///< The window events handler
610 OrientationMode mOrientationMode; ///< The physical screen mode is portrait or landscape
612 int mNativeWindowId; ///< The Native Window Id
615 SignalType mDeleteRequestSignal;
616 FocusChangeSignalType mFocusChangeSignal;
617 ResizeSignalType mResizeSignal;
618 VisibilityChangedSignalType mVisibilityChangedSignal;
619 TransitionEffectEventSignalType mTransitionEffectEventSignal;
620 KeyboardRepeatSettingsChangedSignalType mKeyboardRepeatSettingsChangedSignal;
623 } // namespace Adaptor
624 } // namespace Internal
626 // Helpers for public-api forwarding methods
628 inline Internal::Adaptor::Window& GetImplementation(Dali::Window& window)
630 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
631 BaseObject& object = window.GetBaseObject();
632 return static_cast<Internal::Adaptor::Window&>(object);
635 inline const Internal::Adaptor::Window& GetImplementation(const Dali::Window& window)
637 DALI_ASSERT_ALWAYS(window && "Window handle is empty");
638 const BaseObject& object = window.GetBaseObject();
639 return static_cast<const Internal::Adaptor::Window&>(object);
644 #endif // DALI_INTERNAL_WINDOWSYSTEM_COMMON_WINDOW_IMPL_H