2 * Copyright (c) 2022 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),
86 mPreferredAngle(static_cast<int>(WindowOrientation::NO_ORIENTATION_PREFERENCE)),
90 mOrientationMode(Internal::Adaptor::Window::OrientationMode::PORTRAIT),
92 mDeleteRequestSignal(),
95 mVisibilityChangedSignal(),
96 mTransitionEffectEventSignal(),
97 mKeyboardRepeatSettingsChangedSignal(),
98 mAuxiliaryMessageSignal()
106 auto bridge = Accessibility::Bridge::GetCurrentBridge();
107 auto rootLayer = mScene.GetRootLayer();
108 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
109 bridge->RemoveTopLevelWindow(accessible);
110 // Related to multi-window case. This is called for default window and non-default window, but it is effective for non-default window.
111 bridge->Emit(accessible, Accessibility::WindowEvent::DESTROY);
116 mAdaptor->RemoveWindow(this);
121 mEventHandler->RemoveObserver(*this);
125 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type)
127 // Create a window render surface
128 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
129 mSurface = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
130 mWindowSurface = static_cast<WindowRenderSurface*>(mSurface.get());
133 mWindowBase = mWindowSurface->GetWindowBase();
136 mWindowBase->SetType(type);
138 // Initialize for Ime window type
139 if(type == WindowType::IME)
141 mWindowBase->InitializeIme();
142 mWindowSurface->InitializeImeSurface();
146 mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
147 mWindowBase->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
148 mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
149 mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
150 mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
151 mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
152 mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
153 mWindowBase->AuxiliaryMessageSignal().Connect(this, &Window::OnAuxiliaryMessage);
155 mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
157 AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
159 SetClass(name, className);
161 mOrientation = Orientation::New(this);
163 // Get OrientationMode
164 int screenWidth, screenHeight;
165 WindowSystem::GetScreenSize(screenWidth, screenHeight);
166 if(screenWidth > screenHeight)
168 mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
172 mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
175 mNativeWindowId = mWindowBase->GetNativeWindowId();
178 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
180 mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
181 mEventHandler->AddObserver(*this);
183 // Add Window to bridge for ATSPI
184 auto bridge = Accessibility::Bridge::GetCurrentBridge();
187 auto rootLayer = mScene.GetRootLayer();
188 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
189 bridge->AddTopLevelWindow(accessible);
192 bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
193 bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
195 // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
196 // The show must be called after the adaptor is initialized.
200 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
202 mWindowSurface = static_cast<WindowRenderSurface*>(surface);
205 void Window::SetClass(std::string name, std::string className)
208 mClassName = className;
209 mWindowBase->SetClass(name, className);
212 std::string Window::GetClassName() const
219 mWindowBase->Raise();
221 mSurface->SetFullSwapNextFrame();
223 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
228 mWindowBase->Lower();
230 mSurface->SetFullSwapNextFrame();
232 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
235 void Window::Activate()
237 mWindowBase->Activate();
239 mSurface->SetFullSwapNextFrame();
241 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
244 void Window::Maximize(bool maximize)
246 mWindowBase->Maximize(maximize);
248 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Maximize: %d\n", this, mNativeWindowId, maximize);
251 bool Window::IsMaximized() const
253 return mWindowBase->IsMaximized();
256 void Window::Minimize(bool minimize)
258 mWindowBase->Minimize(minimize);
260 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Minimize: %d\n", this, mNativeWindowId, minimize);
263 bool Window::IsMinimized() const
265 return mWindowBase->IsMinimized();
268 uint32_t Window::GetLayerCount() const
270 return mScene.GetLayerCount();
273 Dali::Layer Window::GetLayer(uint32_t depth) const
275 return mScene.GetLayer(depth);
278 Dali::RenderTaskList Window::GetRenderTaskList() const
280 return mScene.GetRenderTaskList();
283 std::string Window::GetNativeResourceId() const
285 return mWindowBase->GetNativeWindowResourceId();
288 void Window::AddAvailableOrientation(WindowOrientation orientation)
290 if(IsOrientationAvailable(orientation) == false)
296 int convertedAngle = ConvertToAngle(orientation);
297 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
298 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
300 if(mAvailableAngles[i] == convertedAngle)
309 mAvailableAngles.push_back(convertedAngle);
310 SetAvailableAnlges(mAvailableAngles);
314 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
316 if(IsOrientationAvailable(orientation) == false)
321 int convertedAngle = ConvertToAngle(orientation);
322 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
323 for(std::vector<int>::iterator iter = mAvailableAngles.begin();
324 iter != mAvailableAngles.end();
327 if(*iter == convertedAngle)
329 mAvailableAngles.erase(iter);
334 SetAvailableAnlges(mAvailableAngles);
337 void Window::SetPreferredOrientation(WindowOrientation orientation)
339 if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
341 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
344 mPreferredAngle = ConvertToAngle(orientation);
345 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
346 mWindowBase->SetPreferredAngle(mPreferredAngle);
349 WindowOrientation Window::GetPreferredOrientation()
351 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
352 WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
353 return preferredOrientation;
356 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
358 int angle = ConvertToAngle(orientation);
359 mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
362 void Window::EmitAccessibilityHighlightSignal(bool highlight)
364 Dali::Window handle(this);
365 mAccessibilityHighlightSignal.Emit(handle, highlight);
368 void Window::SetAvailableAnlges(const std::vector<int>& angles)
370 if(angles.size() > 4)
372 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
376 mWindowBase->SetAvailableAnlges(angles);
379 int Window::ConvertToAngle(WindowOrientation orientation)
381 int convertAngle = static_cast<int>(orientation);
382 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
386 case WindowOrientation::LANDSCAPE:
391 case WindowOrientation::PORTRAIT:
396 case WindowOrientation::LANDSCAPE_INVERSE:
401 case WindowOrientation::PORTRAIT_INVERSE:
406 case WindowOrientation::NO_ORIENTATION_PREFERENCE:
416 WindowOrientation Window::ConvertToOrientation(int angle) const
418 WindowOrientation orientation = static_cast<WindowOrientation>(angle);
419 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
425 orientation = WindowOrientation::LANDSCAPE;
430 orientation = WindowOrientation::PORTRAIT;
435 orientation = WindowOrientation::LANDSCAPE_INVERSE;
440 orientation = WindowOrientation::PORTRAIT_INVERSE;
445 orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
453 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
455 if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
457 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
463 Dali::Any Window::GetNativeHandle() const
465 return mWindowSurface->GetNativeWindow();
468 void Window::SetAcceptFocus(bool accept)
470 mIsFocusAcceptable = accept;
472 mWindowBase->SetAcceptFocus(accept);
475 bool Window::IsFocusAcceptable() const
477 return mIsFocusAcceptable;
488 Dali::Window handle(this);
489 mVisibilityChangedSignal.Emit(handle, true);
490 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
492 WindowVisibilityObserver* observer(mAdaptor);
493 observer->OnWindowShown();
496 mSurface->SetFullSwapNextFrame();
498 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
509 Dali::Window handle(this);
510 mVisibilityChangedSignal.Emit(handle, false);
511 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
513 WindowVisibilityObserver* observer(mAdaptor);
514 observer->OnWindowHidden();
517 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
520 bool Window::IsVisible() const
522 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
523 return mVisible && !mIconified;
526 unsigned int Window::GetSupportedAuxiliaryHintCount() const
528 return mWindowBase->GetSupportedAuxiliaryHintCount();
531 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
533 return mWindowBase->GetSupportedAuxiliaryHint(index);
536 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
538 return mWindowBase->AddAuxiliaryHint(hint, value);
541 bool Window::RemoveAuxiliaryHint(unsigned int id)
543 return mWindowBase->RemoveAuxiliaryHint(id);
546 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
548 return mWindowBase->SetAuxiliaryHintValue(id, value);
551 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
553 return mWindowBase->GetAuxiliaryHintValue(id);
556 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
558 return mWindowBase->GetAuxiliaryHintId(hint);
561 void Window::SetInputRegion(const Rect<int>& inputRegion)
563 Rect<int> convertRegion = RecalculateRect(inputRegion);
565 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);
567 mWindowBase->SetInputRegion(convertRegion);
570 void Window::SetType(WindowType type)
572 mWindowBase->SetType(type);
575 WindowType Window::GetType() const
577 return mWindowBase->GetType();
580 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
582 WindowType type = mWindowBase->GetType();
583 if(type != WindowType::NOTIFICATION)
585 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
586 return WindowOperationResult::INVALID_OPERATION;
589 return mWindowBase->SetNotificationLevel(level);
592 WindowNotificationLevel Window::GetNotificationLevel() const
594 WindowType type = mWindowBase->GetType();
595 if(type != WindowType::NOTIFICATION)
597 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
598 return WindowNotificationLevel::NONE;
601 return mWindowBase->GetNotificationLevel();
604 void Window::SetOpaqueState(bool opaque)
606 mOpaqueState = opaque;
608 mWindowBase->SetOpaqueState(opaque);
610 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
613 bool Window::IsOpaqueState() const
618 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
620 return mWindowBase->SetScreenOffMode(screenOffMode);
623 WindowScreenOffMode Window::GetScreenOffMode() const
625 return mWindowBase->GetScreenOffMode();
628 WindowOperationResult Window::SetBrightness(int brightness)
630 if(brightness < 0 || brightness > 100)
632 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
633 return WindowOperationResult::INVALID_OPERATION;
636 return mWindowBase->SetBrightness(brightness);
639 int Window::GetBrightness() const
641 return mWindowBase->GetBrightness();
644 void Window::SetSize(Dali::Window::WindowSize size)
646 PositionSize oldRect = mSurface->GetPositionSize();
648 mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
650 PositionSize newRect = mSurface->GetPositionSize();
652 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
653 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
655 Uint16Pair newSize(newRect.width, newRect.height);
657 mWindowWidth = newRect.width;
658 mWindowHeight = newRect.height;
662 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
664 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), current angle (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, mRotationAngle, newRect.width, newRect.height);
666 Dali::Window handle(this);
667 mResizeSignal.Emit(handle, newSize);
669 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
672 mSurface->SetFullSwapNextFrame();
674 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
677 Dali::Window::WindowSize Window::GetSize() const
679 PositionSize positionSize = mSurface->GetPositionSize();
681 return Dali::Window::WindowSize(positionSize.width, positionSize.height);
684 void Window::SetPosition(Dali::Window::WindowPosition position)
686 PositionSize oldRect = mSurface->GetPositionSize();
688 mWindowSurface->MoveResize(PositionSize(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
690 mSurface->SetFullSwapNextFrame();
692 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
695 Dali::Window::WindowPosition Window::GetPosition() const
697 PositionSize positionSize = mSurface->GetPositionSize();
699 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
702 PositionSize Window::GetPositionSize() const
704 return mSurface->GetPositionSize();
707 void Window::SetPositionSize(PositionSize positionSize)
709 PositionSize oldRect = mSurface->GetPositionSize();
711 mWindowSurface->MoveResize(positionSize);
713 PositionSize newRect = mSurface->GetPositionSize();
715 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
716 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
718 Uint16Pair newSize(newRect.width, newRect.height);
720 mWindowWidth = newRect.width;
721 mWindowHeight = newRect.height;
725 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
727 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), current angle (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, mRotationAngle, newRect.width, newRect.height);
728 Dali::Window handle(this);
729 mResizeSignal.Emit(handle, newSize);
730 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
733 mSurface->SetFullSwapNextFrame();
735 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
738 Dali::Layer Window::GetRootLayer() const
740 return mScene.GetRootLayer();
743 void Window::SetTransparency(bool transparent)
745 mWindowSurface->SetTransparency(transparent);
748 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
750 return mWindowBase->GrabKey(key, grabMode);
753 bool Window::UngrabKey(Dali::KEY key)
755 return mWindowBase->UngrabKey(key);
758 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
760 return mWindowBase->GrabKeyList(key, grabMode, result);
763 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
765 return mWindowBase->UngrabKeyList(key, result);
768 void Window::OnIconifyChanged(bool iconified)
776 Dali::Window handle(this);
777 mVisibilityChangedSignal.Emit(handle, false);
778 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
780 WindowVisibilityObserver* observer(mAdaptor);
781 observer->OnWindowHidden();
784 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
792 Dali::Window handle(this);
793 mVisibilityChangedSignal.Emit(handle, true);
794 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
796 WindowVisibilityObserver* observer(mAdaptor);
797 observer->OnWindowShown();
800 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
803 mSurface->SetFullSwapNextFrame();
806 void Window::OnFocusChanged(bool focusIn)
808 Dali::Window handle(this);
809 mFocusChangeSignal.Emit(handle, focusIn);
811 mSurface->SetFullSwapNextFrame();
813 if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
817 bridge->WindowFocused(handle);
821 bridge->WindowUnfocused(handle);
827 void Window::OnOutputTransformed()
829 PositionSize positionSize = mSurface->GetPositionSize();
831 int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
832 SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), orientation);
834 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
835 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
838 void Window::OnDeleteRequest()
840 mDeleteRequestSignal.Emit();
843 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
845 Dali::Window handle(this);
846 mTransitionEffectEventSignal.Emit(handle, state, type);
849 void Window::OnKeyboardRepeatSettingsChanged()
851 Dali::Window handle(this);
852 mKeyboardRepeatSettingsChangedSignal.Emit();
855 void Window::OnWindowRedrawRequest()
857 mAdaptor->RenderOnce();
860 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
862 PositionSize oldRect = mSurface->GetPositionSize();
864 mWindowSurface->UpdatePositionSize(positionSize);
866 PositionSize newRect = positionSize;
868 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
869 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
871 Uint16Pair newSize(newRect.width, newRect.height);
875 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
877 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Updated PositionSize by server :resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
878 Dali::Window handle(this);
879 mResizeSignal.Emit(handle, newSize);
880 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
883 mSurface->SetFullSwapNextFrame();
885 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer(), true)->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
888 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
890 FeedTouchPoint(point, timeStamp);
893 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
895 FeedWheelEvent(wheelEvent);
898 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
900 FeedKeyEvent(keyEvent);
903 void Window::OnRotation(const RotationEvent& rotation)
905 PositionSize newPositionSize(rotation.x, rotation.y, rotation.width, rotation.height);
907 mRotationAngle = rotation.angle;
908 mWindowWidth = rotation.width;
909 mWindowHeight = rotation.height;
911 // Notify that the orientation is changed
912 mOrientation->OnOrientationChange(rotation);
914 mWindowSurface->RequestRotation(mRotationAngle, newPositionSize);
916 int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
917 SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
919 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
921 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): x[%d], y[%d], resize signal emit [%d x %d]\n", this, mNativeWindowId, newPositionSize.x, newPositionSize.y, mWindowWidth, mWindowHeight);
923 Dali::Window handle(this);
924 mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
926 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
929 void Window::OnPause()
933 mEventHandler->Pause();
937 void Window::OnResume()
941 mEventHandler->Resume();
944 mSurface->SetFullSwapNextFrame();
947 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
949 mAuxiliaryMessageSignal.Emit(key, value, options);
952 void Window::OnAccessibilityEnabled()
954 auto bridge = Accessibility::Bridge::GetCurrentBridge();
955 auto rootLayer = mScene.GetRootLayer();
956 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
957 bridge->AddTopLevelWindow(accessible);
961 Dali::Window handle(this);
962 bridge->WindowFocused(handle);
966 void Window::OnAccessibilityDisabled()
968 auto bridge = Accessibility::Bridge::GetCurrentBridge();
969 auto rootLayer = mScene.GetRootLayer();
970 auto accessible = Accessibility::Accessible::Get(rootLayer, true);
971 bridge->RemoveTopLevelWindow(accessible);
974 void Window::RecalculateTouchPosition(Integration::Point& point)
976 Vector2 position = point.GetScreenPosition();
977 Vector2 convertedPosition;
979 switch(mRotationAngle)
983 convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
984 convertedPosition.y = position.x;
989 convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
990 convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
995 convertedPosition.x = position.y;
996 convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
1001 convertedPosition = position;
1006 point.SetScreenPosition(convertedPosition);
1009 Dali::Window Window::Get(Dali::Actor actor)
1011 Internal::Adaptor::Window* windowImpl = nullptr;
1013 if(Internal::Adaptor::Adaptor::IsAvailable())
1015 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
1016 windowImpl = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
1019 return Dali::Window(windowImpl);
1023 return Dali::Window();
1026 void Window::SetParent(Dali::Window& parent)
1028 if(DALI_UNLIKELY(parent))
1030 mParentWindow = parent;
1031 Dali::Window self = Dali::Window(this);
1032 // check circular parent window setting
1033 if(Dali::DevelWindow::GetParent(parent) == self)
1035 Dali::DevelWindow::Unparent(parent);
1037 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
1041 void Window::SetParent(Dali::Window& parent, bool belowParent)
1043 if(DALI_UNLIKELY(parent))
1045 mParentWindow = parent;
1046 Dali::Window self = Dali::Window(this);
1047 // check circular parent window setting
1048 if(Dali::DevelWindow::GetParent(parent) == self)
1050 Dali::DevelWindow::Unparent(parent);
1052 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
1056 void Window::Unparent()
1058 mWindowBase->SetParent(nullptr, false);
1059 mParentWindow.Reset();
1062 Dali::Window Window::GetParent()
1064 return mParentWindow;
1067 WindowOrientation Window::GetCurrentOrientation() const
1069 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle);
1070 return ConvertToOrientation(mRotationAngle);
1073 int Window::GetPhysicalOrientation() const
1075 return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
1078 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
1080 Dali::Vector<float>::SizeType count = orientations.Count();
1081 for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
1083 if(IsOrientationAvailable(orientations[index]) == false)
1085 DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1090 int convertedAngle = ConvertToAngle(orientations[index]);
1092 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1094 if(mAvailableAngles[i] == convertedAngle)
1103 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1104 mAvailableAngles.push_back(convertedAngle);
1107 SetAvailableAnlges(mAvailableAngles);
1110 int32_t Window::GetNativeId() const
1112 return mWindowBase->GetNativeWindowId();
1115 void Window::RequestMoveToServer()
1117 mWindowBase->RequestMoveToServer();
1120 void Window::RequestResizeToServer(WindowResizeDirection direction)
1122 mWindowBase->RequestResizeToServer(direction);
1125 void Window::EnableFloatingMode(bool enable)
1127 mWindowBase->EnableFloatingMode(enable);
1130 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
1133 int screenWidth, screenHeight;
1135 WindowSystem::GetScreenSize(screenWidth, screenHeight);
1137 if(mRotationAngle == 90)
1140 newRect.y = screenHeight - (rect.x + rect.width);
1141 newRect.width = rect.height;
1142 newRect.height = rect.width;
1144 else if(mRotationAngle == 180)
1146 newRect.x = screenWidth - (rect.x + rect.width);
1147 newRect.y = screenHeight - (rect.y + rect.height);
1148 newRect.width = rect.width;
1149 newRect.height = rect.height;
1151 else if(mRotationAngle == 270)
1153 newRect.x = screenWidth - (rect.y + rect.height);
1155 newRect.width = rect.height;
1156 newRect.height = rect.width;
1162 newRect.width = rect.width;
1163 newRect.height = rect.height;
1168 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1170 Rect<int> convertRegion = RecalculateRect(inputRegion);
1172 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);
1173 mWindowBase->IncludeInputRegion(convertRegion);
1176 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1178 Rect<int> convertRegion = RecalculateRect(inputRegion);
1180 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);
1181 mWindowBase->ExcludeInputRegion(convertRegion);
1184 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1186 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1187 mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1188 mWindowRotationAcknowledgement = needAcknowledgement;
1191 void Window::SendRotationCompletedAcknowledgement()
1193 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1194 if(mWindowRotationAcknowledgement)
1196 SetRotationCompletedAcknowledgement();
1200 bool Window::IsWindowRotating() const
1202 return mWindowSurface->IsWindowRotating();
1205 } // namespace Adaptor
1207 } // namespace Internal