2 * Copyright (c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/window-system/common/window-impl.h>
22 #include <dali/devel-api/adaptor-framework/orientation.h>
23 #include <dali/integration-api/core.h>
24 #include <dali/integration-api/events/touch-event-integ.h>
25 #include <dali/public-api/actors/actor.h>
26 #include <dali/public-api/actors/camera-actor.h>
27 #include <dali/public-api/actors/layer.h>
28 #include <dali/public-api/adaptor-framework/window-enumerations.h>
29 #include <dali/public-api/render-tasks/render-task-list.h>
30 #include <dali/public-api/render-tasks/render-task.h>
31 #include <dali/public-api/rendering/frame-buffer.h>
35 #include <dali/devel-api/adaptor-framework/accessibility-impl.h>
36 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
37 #include <dali/internal/graphics/gles/egl-graphics.h>
38 #include <dali/internal/window-system/common/event-handler.h>
39 #include <dali/internal/window-system/common/orientation-impl.h>
40 #include <dali/internal/window-system/common/render-surface-factory.h>
41 #include <dali/internal/window-system/common/window-base.h>
42 #include <dali/internal/window-system/common/window-factory.h>
43 #include <dali/internal/window-system/common/window-render-surface.h>
44 #include <dali/internal/window-system/common/window-system.h>
45 #include <dali/internal/window-system/common/window-visibility-observer.h>
55 #if defined(DEBUG_ENABLED)
56 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
59 } // unnamed namespace
61 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
64 return Window::New(surface, positionSize, name, className, type, isTransparent);
67 Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
69 Window* window = new Window();
70 window->mIsTransparent = isTransparent;
71 window->Initialize(surface, positionSize, name, className, type);
76 : mWindowSurface(nullptr),
78 mIsTransparent(false),
79 mIsFocusAcceptable(true),
82 mWindowRotationAcknowledgement(false),
85 mPreferredAngle(static_cast<int>(WindowOrientation::NO_ORIENTATION_PREFERENCE)),
89 mOrientationMode(Internal::Adaptor::Window::OrientationMode::PORTRAIT),
91 mDeleteRequestSignal(),
94 mVisibilityChangedSignal(),
95 mTransitionEffectEventSignal(),
96 mKeyboardRepeatSettingsChangedSignal(),
97 mAuxiliaryMessageSignal()
105 auto bridge = Accessibility::Bridge::GetCurrentBridge();
106 auto rootLayer = mScene.GetRootLayer();
107 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
108 bridge->RemoveTopLevelWindow(accessible);
113 mAdaptor->RemoveWindow(this);
118 mEventHandler->RemoveObserver(*this);
122 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type)
124 // Create a window render surface
125 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
126 mSurface = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
127 mWindowSurface = static_cast<WindowRenderSurface*>(mSurface.get());
130 mWindowBase = mWindowSurface->GetWindowBase();
133 mWindowBase->SetType(type);
135 // Initialize for Ime window type
136 if(type == WindowType::IME)
138 mWindowBase->InitializeIme();
139 mWindowSurface->InitializeImeSurface();
143 mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
144 mWindowBase->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
145 mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
146 mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
147 mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
148 mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
149 mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
150 mWindowBase->AuxiliaryMessageSignal().Connect(this, &Window::OnAuxiliaryMessage);
152 mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
154 AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
156 SetClass(name, className);
158 mOrientation = Orientation::New(this);
160 // Get OrientationMode
161 int screenWidth, screenHeight;
162 WindowSystem::GetScreenSize(screenWidth, screenHeight);
163 if(screenWidth > screenHeight)
165 mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
169 mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
172 mNativeWindowId = mWindowBase->GetNativeWindowId();
175 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
177 mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
178 mEventHandler->AddObserver(*this);
180 // Add Window to bridge for ATSPI
181 auto bridge = Accessibility::Bridge::GetCurrentBridge();
184 auto rootLayer = mScene.GetRootLayer();
185 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
186 bridge->AddTopLevelWindow(accessible);
189 bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
190 bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
192 // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
193 // The show must be called after the adaptor is initialized.
197 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
199 mWindowSurface = static_cast<WindowRenderSurface*>(surface);
202 void Window::SetClass(std::string name, std::string className)
205 mClassName = className;
206 mWindowBase->SetClass(name, className);
209 std::string Window::GetClassName() const
216 mWindowBase->Raise();
218 mSurface->SetFullSwapNextFrame();
220 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
225 mWindowBase->Lower();
227 mSurface->SetFullSwapNextFrame();
229 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
232 void Window::Activate()
234 mWindowBase->Activate();
236 mSurface->SetFullSwapNextFrame();
238 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
241 uint32_t Window::GetLayerCount() const
243 return mScene.GetLayerCount();
246 Dali::Layer Window::GetLayer(uint32_t depth) const
248 return mScene.GetLayer(depth);
251 Dali::RenderTaskList Window::GetRenderTaskList() const
253 return mScene.GetRenderTaskList();
256 void Window::AddAvailableOrientation(WindowOrientation orientation)
258 if(IsOrientationAvailable(orientation) == false)
264 int convertedAngle = ConvertToAngle(orientation);
265 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
266 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
268 if(mAvailableAngles[i] == convertedAngle)
277 mAvailableAngles.push_back(convertedAngle);
278 SetAvailableAnlges(mAvailableAngles);
282 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
284 if(IsOrientationAvailable(orientation) == false)
289 int convertedAngle = ConvertToAngle(orientation);
290 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
291 for(std::vector<int>::iterator iter = mAvailableAngles.begin();
292 iter != mAvailableAngles.end();
295 if(*iter == convertedAngle)
297 mAvailableAngles.erase(iter);
302 SetAvailableAnlges(mAvailableAngles);
305 void Window::SetPreferredOrientation(WindowOrientation orientation)
307 if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
309 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
312 mPreferredAngle = ConvertToAngle(orientation);
313 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
314 mWindowBase->SetPreferredAngle(mPreferredAngle);
317 WindowOrientation Window::GetPreferredOrientation()
319 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
320 WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
321 return preferredOrientation;
324 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
326 int angle = ConvertToAngle(orientation);
327 mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
330 void Window::SetAvailableAnlges(const std::vector<int>& angles)
332 if(angles.size() > 4)
334 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
338 mWindowBase->SetAvailableAnlges(angles);
341 int Window::ConvertToAngle(WindowOrientation orientation)
343 int convertAngle = static_cast<int>(orientation);
344 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
348 case WindowOrientation::LANDSCAPE:
353 case WindowOrientation::PORTRAIT:
358 case WindowOrientation::LANDSCAPE_INVERSE:
363 case WindowOrientation::PORTRAIT_INVERSE:
368 case WindowOrientation::NO_ORIENTATION_PREFERENCE:
378 WindowOrientation Window::ConvertToOrientation(int angle) const
380 WindowOrientation orientation = static_cast<WindowOrientation>(angle);
381 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
387 orientation = WindowOrientation::LANDSCAPE;
392 orientation = WindowOrientation::PORTRAIT;
397 orientation = WindowOrientation::LANDSCAPE_INVERSE;
402 orientation = WindowOrientation::PORTRAIT_INVERSE;
407 orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
415 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
417 if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
419 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
425 Dali::Any Window::GetNativeHandle() const
427 return mWindowSurface->GetNativeWindow();
430 void Window::SetAcceptFocus(bool accept)
432 mIsFocusAcceptable = accept;
434 mWindowBase->SetAcceptFocus(accept);
437 bool Window::IsFocusAcceptable() const
439 return mIsFocusAcceptable;
450 Dali::Window handle(this);
451 mVisibilityChangedSignal.Emit(handle, true);
452 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
454 WindowVisibilityObserver* observer(mAdaptor);
455 observer->OnWindowShown();
458 mSurface->SetFullSwapNextFrame();
460 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
471 Dali::Window handle(this);
472 mVisibilityChangedSignal.Emit(handle, false);
473 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
475 WindowVisibilityObserver* observer(mAdaptor);
476 observer->OnWindowHidden();
479 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
482 bool Window::IsVisible() const
484 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
485 return mVisible && !mIconified;
488 unsigned int Window::GetSupportedAuxiliaryHintCount() const
490 return mWindowBase->GetSupportedAuxiliaryHintCount();
493 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
495 return mWindowBase->GetSupportedAuxiliaryHint(index);
498 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
500 return mWindowBase->AddAuxiliaryHint(hint, value);
503 bool Window::RemoveAuxiliaryHint(unsigned int id)
505 return mWindowBase->RemoveAuxiliaryHint(id);
508 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
510 return mWindowBase->SetAuxiliaryHintValue(id, value);
513 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
515 return mWindowBase->GetAuxiliaryHintValue(id);
518 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
520 return mWindowBase->GetAuxiliaryHintId(hint);
523 void Window::SetInputRegion(const Rect<int>& inputRegion)
525 Rect<int> convertRegion = RecalculateRect(inputRegion);
527 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window (%p), WinId (%d), SetInputRegion, RecalculateRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, convertRegion.x, convertRegion.y, convertRegion.width, convertRegion.height);
529 mWindowBase->SetInputRegion(convertRegion);
532 void Window::SetType(WindowType type)
534 mWindowBase->SetType(type);
537 WindowType Window::GetType() const
539 return mWindowBase->GetType();
542 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
544 WindowType type = mWindowBase->GetType();
545 if(type != WindowType::NOTIFICATION)
547 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
548 return WindowOperationResult::INVALID_OPERATION;
551 return mWindowBase->SetNotificationLevel(level);
554 WindowNotificationLevel Window::GetNotificationLevel() const
556 WindowType type = mWindowBase->GetType();
557 if(type != WindowType::NOTIFICATION)
559 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
560 return WindowNotificationLevel::NONE;
563 return mWindowBase->GetNotificationLevel();
566 void Window::SetOpaqueState(bool opaque)
568 mOpaqueState = opaque;
570 mWindowBase->SetOpaqueState(opaque);
572 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
575 bool Window::IsOpaqueState() const
580 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
582 return mWindowBase->SetScreenOffMode(screenOffMode);
585 WindowScreenOffMode Window::GetScreenOffMode() const
587 return mWindowBase->GetScreenOffMode();
590 WindowOperationResult Window::SetBrightness(int brightness)
592 if(brightness < 0 || brightness > 100)
594 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
595 return WindowOperationResult::INVALID_OPERATION;
598 return mWindowBase->SetBrightness(brightness);
601 int Window::GetBrightness() const
603 return mWindowBase->GetBrightness();
606 void Window::SetSize(Dali::Window::WindowSize size)
608 PositionSize oldRect = mSurface->GetPositionSize();
610 mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
612 PositionSize newRect = mSurface->GetPositionSize();
614 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
615 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
617 Uint16Pair newSize(newRect.width, newRect.height);
621 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
623 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
625 Dali::Window handle(this);
626 mResizeSignal.Emit(handle, newSize);
628 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
631 mSurface->SetFullSwapNextFrame();
633 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
636 Dali::Window::WindowSize Window::GetSize() const
638 PositionSize positionSize = mSurface->GetPositionSize();
640 return Dali::Window::WindowSize(positionSize.width, positionSize.height);
643 void Window::SetPosition(Dali::Window::WindowPosition position)
645 PositionSize oldRect = mSurface->GetPositionSize();
647 mWindowSurface->MoveResize(PositionSize(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
649 mSurface->SetFullSwapNextFrame();
651 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
654 Dali::Window::WindowPosition Window::GetPosition() const
656 PositionSize positionSize = mSurface->GetPositionSize();
658 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
661 PositionSize Window::GetPositionSize() const
663 return mSurface->GetPositionSize();
666 void Window::SetPositionSize(PositionSize positionSize)
668 PositionSize oldRect = mSurface->GetPositionSize();
670 mWindowSurface->MoveResize(positionSize);
672 PositionSize newRect = mSurface->GetPositionSize();
674 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
675 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
677 Uint16Pair newSize(newRect.width, newRect.height);
681 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
683 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
684 Dali::Window handle(this);
685 mResizeSignal.Emit(handle, newSize);
686 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
689 mSurface->SetFullSwapNextFrame();
691 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
694 Dali::Layer Window::GetRootLayer() const
696 return mScene.GetRootLayer();
699 void Window::SetTransparency(bool transparent)
701 mWindowSurface->SetTransparency(transparent);
704 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
706 return mWindowBase->GrabKey(key, grabMode);
709 bool Window::UngrabKey(Dali::KEY key)
711 return mWindowBase->UngrabKey(key);
714 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
716 return mWindowBase->GrabKeyList(key, grabMode, result);
719 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
721 return mWindowBase->UngrabKeyList(key, result);
724 void Window::OnIconifyChanged(bool iconified)
732 Dali::Window handle(this);
733 mVisibilityChangedSignal.Emit(handle, false);
734 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
736 WindowVisibilityObserver* observer(mAdaptor);
737 observer->OnWindowHidden();
740 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
748 Dali::Window handle(this);
749 mVisibilityChangedSignal.Emit(handle, true);
750 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
752 WindowVisibilityObserver* observer(mAdaptor);
753 observer->OnWindowShown();
756 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
759 mSurface->SetFullSwapNextFrame();
762 void Window::OnFocusChanged(bool focusIn)
764 Dali::Window handle(this);
765 mFocusChangeSignal.Emit(handle, focusIn);
767 mSurface->SetFullSwapNextFrame();
769 if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
773 bridge->WindowFocused(handle);
777 bridge->WindowUnfocused(handle);
783 void Window::OnOutputTransformed()
785 PositionSize positionSize = mSurface->GetPositionSize();
787 int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
788 SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), orientation);
790 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
791 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
794 void Window::OnDeleteRequest()
796 mDeleteRequestSignal.Emit();
799 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
801 Dali::Window handle(this);
802 mTransitionEffectEventSignal.Emit(handle, state, type);
805 void Window::OnKeyboardRepeatSettingsChanged()
807 Dali::Window handle(this);
808 mKeyboardRepeatSettingsChangedSignal.Emit();
811 void Window::OnWindowRedrawRequest()
813 mAdaptor->RenderOnce();
816 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
818 SetPositionSize(positionSize);
821 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
823 FeedTouchPoint(point, timeStamp);
826 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
828 FeedWheelEvent(wheelEvent);
831 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
833 FeedKeyEvent(keyEvent);
836 void Window::OnRotation(const RotationEvent& rotation)
838 mRotationAngle = rotation.angle;
839 mWindowWidth = rotation.width;
840 mWindowHeight = rotation.height;
842 // Notify that the orientation is changed
843 mOrientation->OnOrientationChange(rotation);
845 mWindowSurface->RequestRotation(mRotationAngle, mWindowWidth, mWindowHeight);
847 int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
848 SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
850 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
852 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight);
854 Dali::Window handle(this);
855 mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
857 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
860 void Window::OnPause()
864 mEventHandler->Pause();
868 void Window::OnResume()
872 mEventHandler->Resume();
875 mSurface->SetFullSwapNextFrame();
878 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
880 mAuxiliaryMessageSignal.Emit(key, value, options);
883 void Window::OnAccessibilityEnabled()
885 auto bridge = Accessibility::Bridge::GetCurrentBridge();
886 auto rootLayer = mScene.GetRootLayer();
887 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
888 bridge->AddTopLevelWindow(accessible);
892 Dali::Window handle(this);
893 bridge->WindowFocused(handle);
897 void Window::OnAccessibilityDisabled()
899 auto bridge = Accessibility::Bridge::GetCurrentBridge();
900 auto rootLayer = mScene.GetRootLayer();
901 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
902 bridge->RemoveTopLevelWindow(accessible);
905 void Window::RecalculateTouchPosition(Integration::Point& point)
907 Vector2 position = point.GetScreenPosition();
908 Vector2 convertedPosition;
910 switch(mRotationAngle)
914 convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
915 convertedPosition.y = position.x;
920 convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
921 convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
926 convertedPosition.x = position.y;
927 convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
932 convertedPosition = position;
937 point.SetScreenPosition(convertedPosition);
940 Dali::Window Window::Get(Dali::Actor actor)
942 Internal::Adaptor::Window* windowImpl = nullptr;
944 if(Internal::Adaptor::Adaptor::IsAvailable())
946 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
947 windowImpl = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
950 return Dali::Window(windowImpl);
954 return Dali::Window();
957 void Window::SetParent(Dali::Window& parent)
959 if(DALI_UNLIKELY(parent))
961 mParentWindow = parent;
962 Dali::Window self = Dali::Window(this);
963 // check circular parent window setting
964 if(Dali::DevelWindow::GetParent(parent) == self)
966 Dali::DevelWindow::Unparent(parent);
968 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
972 void Window::SetParent(Dali::Window& parent, bool belowParent)
974 if(DALI_UNLIKELY(parent))
976 mParentWindow = parent;
977 Dali::Window self = Dali::Window(this);
978 // check circular parent window setting
979 if(Dali::DevelWindow::GetParent(parent) == self)
981 Dali::DevelWindow::Unparent(parent);
983 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
987 void Window::Unparent()
989 mWindowBase->SetParent(nullptr, false);
990 mParentWindow.Reset();
993 Dali::Window Window::GetParent()
995 return mParentWindow;
998 WindowOrientation Window::GetCurrentOrientation() const
1000 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle);
1001 return ConvertToOrientation(mRotationAngle);
1004 int Window::GetPhysicalOrientation() const
1006 return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
1009 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
1011 Dali::Vector<float>::SizeType count = orientations.Count();
1012 for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
1014 if(IsOrientationAvailable(orientations[index]) == false)
1016 DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1021 int convertedAngle = ConvertToAngle(orientations[index]);
1023 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1025 if(mAvailableAngles[i] == convertedAngle)
1034 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1035 mAvailableAngles.push_back(convertedAngle);
1038 SetAvailableAnlges(mAvailableAngles);
1041 int32_t Window::GetNativeId() const
1043 return mWindowBase->GetNativeWindowId();
1046 void Window::RequestMoveToServer()
1048 mWindowBase->RequestMoveToServer();
1051 void Window::RequestResizeToServer(WindowResizeDirection direction)
1053 mWindowBase->RequestResizeToServer(direction);
1056 void Window::EnableFloatingMode(bool enable)
1058 mWindowBase->EnableFloatingMode(enable);
1061 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
1064 int screenWidth, screenHeight;
1066 WindowSystem::GetScreenSize(screenWidth, screenHeight);
1068 if(mRotationAngle == 90)
1071 newRect.y = screenHeight - (rect.x + rect.width);
1072 newRect.width = rect.height;
1073 newRect.height = rect.width;
1075 else if(mRotationAngle == 180)
1077 newRect.x = screenWidth - (rect.x + rect.width);
1078 newRect.y = screenHeight - (rect.y + rect.height);
1079 newRect.width = rect.width;
1080 newRect.height = rect.height;
1082 else if(mRotationAngle == 270)
1084 newRect.x = screenWidth - (rect.y + rect.height);
1086 newRect.width = rect.height;
1087 newRect.height = rect.width;
1093 newRect.width = rect.width;
1094 newRect.height = rect.height;
1099 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1101 Rect<int> convertRegion = RecalculateRect(inputRegion);
1103 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IncludeInputRegion, RecalculateRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, convertRegion.x, convertRegion.y, convertRegion.width, convertRegion.height);
1104 mWindowBase->IncludeInputRegion(convertRegion);
1107 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1109 Rect<int> convertRegion = RecalculateRect(inputRegion);
1111 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), ExcludeInputRegion, RecalculateRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, convertRegion.x, convertRegion.y, convertRegion.width, convertRegion.height);
1112 mWindowBase->ExcludeInputRegion(convertRegion);
1115 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1117 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1118 mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1119 mWindowRotationAcknowledgement = needAcknowledgement;
1122 void Window::SendRotationCompletedAcknowledgement()
1124 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1125 if(mWindowRotationAcknowledgement)
1127 SetRotationCompletedAcknowledgement();
1131 bool Window::IsWindowRotating() const
1133 return mWindowSurface->IsWindowRotating();
1136 } // namespace Adaptor
1138 } // namespace Internal