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-bridge.h>
36 #include <dali/devel-api/atspi-interfaces/accessible.h>
37 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
38 #include <dali/internal/graphics/gles/egl-graphics.h>
39 #include <dali/internal/window-system/common/event-handler.h>
40 #include <dali/internal/window-system/common/orientation-impl.h>
41 #include <dali/internal/window-system/common/render-surface-factory.h>
42 #include <dali/internal/window-system/common/window-base.h>
43 #include <dali/internal/window-system/common/window-factory.h>
44 #include <dali/internal/window-system/common/window-render-surface.h>
45 #include <dali/internal/window-system/common/window-system.h>
46 #include <dali/internal/window-system/common/window-visibility-observer.h>
56 #if defined(DEBUG_ENABLED)
57 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
60 } // unnamed namespace
62 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
65 return Window::New(surface, positionSize, name, className, type, isTransparent);
68 Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
70 Window* window = new Window();
71 window->mIsTransparent = isTransparent;
72 window->Initialize(surface, positionSize, name, className, type);
77 : mWindowSurface(nullptr),
79 mIsTransparent(false),
80 mIsFocusAcceptable(true),
83 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()
103 auto bridge = Accessibility::Bridge::GetCurrentBridge();
104 auto rootLayer = mScene.GetRootLayer();
105 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
106 bridge->RemoveTopLevelWindow(accessible);
110 mAdaptor->RemoveWindow(this);
115 mEventHandler->RemoveObserver(*this);
119 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type)
121 // Create a window render surface
122 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
123 mSurface = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
124 mWindowSurface = static_cast<WindowRenderSurface*>(mSurface.get());
127 mWindowBase = mWindowSurface->GetWindowBase();
130 mWindowBase->SetType(type);
132 // Initialize for Ime window type
133 if(type == WindowType::IME)
135 mWindowBase->InitializeIme();
136 mWindowSurface->InitializeImeSurface();
140 mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
141 mWindowBase->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
142 mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
143 mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
144 mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
145 mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
146 mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
147 mWindowBase->AuxiliaryMessageSignal().Connect(this, &Window::OnAuxiliaryMessage);
149 mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
151 AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
153 SetClass(name, className);
155 mOrientation = Orientation::New(this);
157 // Get OrientationMode
158 int screenWidth, screenHeight;
159 WindowSystem::GetScreenSize(screenWidth, screenHeight);
160 if(screenWidth > screenHeight)
162 mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
166 mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
169 mNativeWindowId = mWindowBase->GetNativeWindowId();
172 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
174 mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
175 mEventHandler->AddObserver(*this);
177 // Add Window to bridge for ATSPI
178 auto bridge = Accessibility::Bridge::GetCurrentBridge();
179 auto rootLayer = mScene.GetRootLayer();
180 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
181 bridge->AddTopLevelWindow(accessible);
183 bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
184 bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
186 // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
187 // The show must be called after the adaptor is initialized.
191 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
193 mWindowSurface = static_cast<WindowRenderSurface*>(surface);
196 void Window::SetClass(std::string name, std::string className)
199 mClassName = className;
200 mWindowBase->SetClass(name, className);
203 std::string Window::GetClassName() const
210 mWindowBase->Raise();
212 mSurface->SetFullSwapNextFrame();
214 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
219 mWindowBase->Lower();
221 mSurface->SetFullSwapNextFrame();
223 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
226 void Window::Activate()
228 mWindowBase->Activate();
230 mSurface->SetFullSwapNextFrame();
232 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
235 void Window::Maximize(bool maximize)
237 mWindowBase->Maximize(maximize);
239 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Maximize: %d\n", this, mNativeWindowId, maximize);
242 bool Window::IsMaximized() const
244 return mWindowBase->IsMaximized();
247 void Window::Minimize(bool minimize)
249 mWindowBase->Minimize(minimize);
251 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Minimize: %d\n", this, mNativeWindowId, minimize);
254 bool Window::IsMinimized() const
256 return mWindowBase->IsMinimized();
259 uint32_t Window::GetLayerCount() const
261 return mScene.GetLayerCount();
264 Dali::Layer Window::GetLayer(uint32_t depth) const
266 return mScene.GetLayer(depth);
269 Dali::RenderTaskList Window::GetRenderTaskList() const
271 return mScene.GetRenderTaskList();
274 void Window::AddAvailableOrientation(WindowOrientation orientation)
276 if(IsOrientationAvailable(orientation) == false)
282 int convertedAngle = ConvertToAngle(orientation);
283 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
284 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
286 if(mAvailableAngles[i] == convertedAngle)
295 mAvailableAngles.push_back(convertedAngle);
296 SetAvailableAnlges(mAvailableAngles);
300 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
302 if(IsOrientationAvailable(orientation) == false)
307 int convertedAngle = ConvertToAngle(orientation);
308 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
309 for(std::vector<int>::iterator iter = mAvailableAngles.begin();
310 iter != mAvailableAngles.end();
313 if(*iter == convertedAngle)
315 mAvailableAngles.erase(iter);
320 SetAvailableAnlges(mAvailableAngles);
323 void Window::SetPreferredOrientation(WindowOrientation orientation)
325 if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
327 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
330 mPreferredAngle = ConvertToAngle(orientation);
331 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
332 mWindowBase->SetPreferredAngle(mPreferredAngle);
335 WindowOrientation Window::GetPreferredOrientation()
337 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
338 WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
339 return preferredOrientation;
342 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
344 int angle = ConvertToAngle(orientation);
345 mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
348 void Window::SetAvailableAnlges(const std::vector<int>& angles)
350 if(angles.size() > 4)
352 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
356 mWindowBase->SetAvailableAnlges(angles);
359 int Window::ConvertToAngle(WindowOrientation orientation)
361 int convertAngle = static_cast<int>(orientation);
362 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
366 case WindowOrientation::LANDSCAPE:
371 case WindowOrientation::PORTRAIT:
376 case WindowOrientation::LANDSCAPE_INVERSE:
381 case WindowOrientation::PORTRAIT_INVERSE:
386 case WindowOrientation::NO_ORIENTATION_PREFERENCE:
396 WindowOrientation Window::ConvertToOrientation(int angle) const
398 WindowOrientation orientation = static_cast<WindowOrientation>(angle);
399 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
405 orientation = WindowOrientation::LANDSCAPE;
410 orientation = WindowOrientation::PORTRAIT;
415 orientation = WindowOrientation::LANDSCAPE_INVERSE;
420 orientation = WindowOrientation::PORTRAIT_INVERSE;
425 orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
433 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
435 if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
437 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
443 Dali::Any Window::GetNativeHandle() const
445 return mWindowSurface->GetNativeWindow();
448 void Window::SetAcceptFocus(bool accept)
450 mIsFocusAcceptable = accept;
452 mWindowBase->SetAcceptFocus(accept);
455 bool Window::IsFocusAcceptable() const
457 return mIsFocusAcceptable;
468 Dali::Window handle(this);
469 mVisibilityChangedSignal.Emit(handle, true);
471 WindowVisibilityObserver* observer(mAdaptor);
472 observer->OnWindowShown();
475 mSurface->SetFullSwapNextFrame();
477 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
488 Dali::Window handle(this);
489 mVisibilityChangedSignal.Emit(handle, false);
491 WindowVisibilityObserver* observer(mAdaptor);
492 observer->OnWindowHidden();
495 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
498 bool Window::IsVisible() const
500 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
501 return mVisible && !mIconified;
504 unsigned int Window::GetSupportedAuxiliaryHintCount() const
506 return mWindowBase->GetSupportedAuxiliaryHintCount();
509 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
511 return mWindowBase->GetSupportedAuxiliaryHint(index);
514 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
516 return mWindowBase->AddAuxiliaryHint(hint, value);
519 bool Window::RemoveAuxiliaryHint(unsigned int id)
521 return mWindowBase->RemoveAuxiliaryHint(id);
524 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
526 return mWindowBase->SetAuxiliaryHintValue(id, value);
529 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
531 return mWindowBase->GetAuxiliaryHintValue(id);
534 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
536 return mWindowBase->GetAuxiliaryHintId(hint);
539 void Window::SetInputRegion(const Rect<int>& inputRegion)
541 Rect<int> convertRegion = RecalculateRect(inputRegion);
543 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);
545 mWindowBase->SetInputRegion(convertRegion);
548 void Window::SetType(WindowType type)
550 mWindowBase->SetType(type);
553 WindowType Window::GetType() const
555 return mWindowBase->GetType();
558 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
560 WindowType type = mWindowBase->GetType();
561 if(type != WindowType::NOTIFICATION)
563 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
564 return WindowOperationResult::INVALID_OPERATION;
567 return mWindowBase->SetNotificationLevel(level);
570 WindowNotificationLevel Window::GetNotificationLevel() const
572 WindowType type = mWindowBase->GetType();
573 if(type != WindowType::NOTIFICATION)
575 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
576 return WindowNotificationLevel::NONE;
579 return mWindowBase->GetNotificationLevel();
582 void Window::SetOpaqueState(bool opaque)
584 mOpaqueState = opaque;
586 mWindowBase->SetOpaqueState(opaque);
588 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
591 bool Window::IsOpaqueState() const
596 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
598 return mWindowBase->SetScreenOffMode(screenOffMode);
601 WindowScreenOffMode Window::GetScreenOffMode() const
603 return mWindowBase->GetScreenOffMode();
606 WindowOperationResult Window::SetBrightness(int brightness)
608 if(brightness < 0 || brightness > 100)
610 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
611 return WindowOperationResult::INVALID_OPERATION;
614 return mWindowBase->SetBrightness(brightness);
617 int Window::GetBrightness() const
619 return mWindowBase->GetBrightness();
622 void Window::SetSize(Dali::Window::WindowSize size)
624 PositionSize oldRect = mSurface->GetPositionSize();
626 mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
628 PositionSize newRect = mSurface->GetPositionSize();
630 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
631 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
633 Uint16Pair newSize(newRect.width, newRect.height);
637 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
639 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
641 Dali::Window handle(this);
642 mResizeSignal.Emit(handle, newSize);
644 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
647 mSurface->SetFullSwapNextFrame();
649 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
652 Dali::Window::WindowSize Window::GetSize() const
654 PositionSize positionSize = mSurface->GetPositionSize();
656 return Dali::Window::WindowSize(positionSize.width, positionSize.height);
659 void Window::SetPosition(Dali::Window::WindowPosition position)
661 PositionSize oldRect = mSurface->GetPositionSize();
663 mWindowSurface->MoveResize(PositionSize(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
665 mSurface->SetFullSwapNextFrame();
667 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
670 Dali::Window::WindowPosition Window::GetPosition() const
672 PositionSize positionSize = mSurface->GetPositionSize();
674 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
677 PositionSize Window::GetPositionSize() const
679 return mSurface->GetPositionSize();
682 void Window::SetPositionSize(PositionSize positionSize)
684 PositionSize oldRect = mSurface->GetPositionSize();
686 mWindowSurface->MoveResize(positionSize);
688 PositionSize newRect = mSurface->GetPositionSize();
690 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
691 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
693 Uint16Pair newSize(newRect.width, newRect.height);
697 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
699 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
700 Dali::Window handle(this);
701 mResizeSignal.Emit(handle, newSize);
702 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
705 mSurface->SetFullSwapNextFrame();
707 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
710 Dali::Layer Window::GetRootLayer() const
712 return mScene.GetRootLayer();
715 void Window::SetTransparency(bool transparent)
717 mWindowSurface->SetTransparency(transparent);
720 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
722 return mWindowBase->GrabKey(key, grabMode);
725 bool Window::UngrabKey(Dali::KEY key)
727 return mWindowBase->UngrabKey(key);
730 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
732 return mWindowBase->GrabKeyList(key, grabMode, result);
735 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
737 return mWindowBase->UngrabKeyList(key, result);
740 void Window::OnIconifyChanged(bool iconified)
748 Dali::Window handle(this);
749 mVisibilityChangedSignal.Emit(handle, false);
751 WindowVisibilityObserver* observer(mAdaptor);
752 observer->OnWindowHidden();
755 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
763 Dali::Window handle(this);
764 mVisibilityChangedSignal.Emit(handle, true);
766 WindowVisibilityObserver* observer(mAdaptor);
767 observer->OnWindowShown();
770 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
773 mSurface->SetFullSwapNextFrame();
776 void Window::OnFocusChanged(bool focusIn)
778 Dali::Window handle(this);
779 mFocusChangeSignal.Emit(handle, focusIn);
781 mSurface->SetFullSwapNextFrame();
783 if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
787 bridge->WindowFocused(handle);
791 bridge->WindowUnfocused(handle);
796 void Window::OnOutputTransformed()
798 PositionSize positionSize = mSurface->GetPositionSize();
800 int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
801 SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), orientation);
803 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
804 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
807 void Window::OnDeleteRequest()
809 mDeleteRequestSignal.Emit();
812 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
814 Dali::Window handle(this);
815 mTransitionEffectEventSignal.Emit(handle, state, type);
818 void Window::OnKeyboardRepeatSettingsChanged()
820 Dali::Window handle(this);
821 mKeyboardRepeatSettingsChangedSignal.Emit();
824 void Window::OnWindowRedrawRequest()
826 mAdaptor->RenderOnce();
829 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
831 PositionSize oldRect = mSurface->GetPositionSize();
833 mWindowSurface->UpdatePositionSize(positionSize);
835 PositionSize newRect = positionSize;
837 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
838 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
840 Uint16Pair newSize(newRect.width, newRect.height);
844 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
846 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Updated PositionSize by server :resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
847 Dali::Window handle(this);
848 mResizeSignal.Emit(handle, newSize);
849 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
852 mSurface->SetFullSwapNextFrame();
854 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
857 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
859 FeedTouchPoint(point, timeStamp);
862 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
864 FeedWheelEvent(wheelEvent);
867 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
869 FeedKeyEvent(keyEvent);
872 void Window::OnRotation(const RotationEvent& rotation)
874 mRotationAngle = rotation.angle;
875 mWindowWidth = rotation.width;
876 mWindowHeight = rotation.height;
878 // Notify that the orientation is changed
879 mOrientation->OnOrientationChange(rotation);
881 mWindowSurface->RequestRotation(mRotationAngle, mWindowWidth, mWindowHeight);
883 int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
884 SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
886 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
888 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): resize signal emit [%d x %d]\n", this, mNativeWindowId, mWindowWidth, mWindowHeight);
890 Dali::Window handle(this);
891 mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
893 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
896 void Window::OnPause()
900 mEventHandler->Pause();
904 void Window::OnResume()
908 mEventHandler->Resume();
911 mSurface->SetFullSwapNextFrame();
914 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
916 mAuxiliaryMessageSignal.Emit(key, value, options);
919 void Window::OnAccessibilityEnabled()
921 auto bridge = Accessibility::Bridge::GetCurrentBridge();
922 auto rootLayer = mScene.GetRootLayer();
923 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
924 bridge->AddTopLevelWindow(accessible);
927 void Window::OnAccessibilityDisabled()
929 auto bridge = Accessibility::Bridge::GetCurrentBridge();
930 auto rootLayer = mScene.GetRootLayer();
931 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
932 bridge->RemoveTopLevelWindow(accessible);
935 void Window::RecalculateTouchPosition(Integration::Point& point)
937 Vector2 position = point.GetScreenPosition();
938 Vector2 convertedPosition;
940 switch(mRotationAngle)
944 convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
945 convertedPosition.y = position.x;
950 convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
951 convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
956 convertedPosition.x = position.y;
957 convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
962 convertedPosition = position;
967 point.SetScreenPosition(convertedPosition);
970 Dali::Window Window::Get(Dali::Actor actor)
972 Internal::Adaptor::Window* windowImpl = nullptr;
974 if(Internal::Adaptor::Adaptor::IsAvailable())
976 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
977 windowImpl = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
980 return Dali::Window(windowImpl);
984 return Dali::Window();
987 void Window::SetParent(Dali::Window& parent)
989 if(DALI_UNLIKELY(parent))
991 mParentWindow = parent;
992 Dali::Window self = Dali::Window(this);
993 // check circular parent window setting
994 if(Dali::DevelWindow::GetParent(parent) == self)
996 Dali::DevelWindow::Unparent(parent);
998 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
1002 void Window::SetParent(Dali::Window& parent, bool belowParent)
1004 if(DALI_UNLIKELY(parent))
1006 mParentWindow = parent;
1007 Dali::Window self = Dali::Window(this);
1008 // check circular parent window setting
1009 if(Dali::DevelWindow::GetParent(parent) == self)
1011 Dali::DevelWindow::Unparent(parent);
1013 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
1017 void Window::Unparent()
1019 mWindowBase->SetParent(nullptr, false);
1020 mParentWindow.Reset();
1023 Dali::Window Window::GetParent()
1025 return mParentWindow;
1028 WindowOrientation Window::GetCurrentOrientation() const
1030 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle);
1031 return ConvertToOrientation(mRotationAngle);
1034 int Window::GetPhysicalOrientation() const
1036 return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
1039 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
1041 Dali::Vector<float>::SizeType count = orientations.Count();
1042 for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
1044 if(IsOrientationAvailable(orientations[index]) == false)
1046 DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1051 int convertedAngle = ConvertToAngle(orientations[index]);
1053 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1055 if(mAvailableAngles[i] == convertedAngle)
1064 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1065 mAvailableAngles.push_back(convertedAngle);
1068 SetAvailableAnlges(mAvailableAngles);
1071 int32_t Window::GetNativeId() const
1073 return mWindowBase->GetNativeWindowId();
1076 void Window::RequestMoveToServer()
1078 mWindowBase->RequestMoveToServer();
1081 void Window::RequestResizeToServer(WindowResizeDirection direction)
1083 mWindowBase->RequestResizeToServer(direction);
1086 void Window::EnableFloatingMode(bool enable)
1088 mWindowBase->EnableFloatingMode(enable);
1091 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
1094 int screenWidth, screenHeight;
1096 WindowSystem::GetScreenSize(screenWidth, screenHeight);
1098 if(mRotationAngle == 90)
1101 newRect.y = screenHeight - (rect.x + rect.width);
1102 newRect.width = rect.height;
1103 newRect.height = rect.width;
1105 else if(mRotationAngle == 180)
1107 newRect.x = screenWidth - (rect.x + rect.width);
1108 newRect.y = screenHeight - (rect.y + rect.height);
1109 newRect.width = rect.width;
1110 newRect.height = rect.height;
1112 else if(mRotationAngle == 270)
1114 newRect.x = screenWidth - (rect.y + rect.height);
1116 newRect.width = rect.height;
1117 newRect.height = rect.width;
1123 newRect.width = rect.width;
1124 newRect.height = rect.height;
1129 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1131 Rect<int> convertRegion = RecalculateRect(inputRegion);
1133 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);
1134 mWindowBase->IncludeInputRegion(convertRegion);
1137 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1139 Rect<int> convertRegion = RecalculateRect(inputRegion);
1141 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);
1142 mWindowBase->ExcludeInputRegion(convertRegion);
1145 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1147 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1148 mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1149 mWindowRotationAcknowledgement = needAcknowledgement;
1152 void Window::SendRotationCompletedAcknowledgement()
1154 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1155 if(mWindowRotationAcknowledgement)
1157 SetRotationCompletedAcknowledgement();
1161 } // namespace Adaptor
1163 } // namespace Internal