2 * Copyright (c) 2023 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/devel-api/events/key-event-devel.h>
24 #include <dali/integration-api/core.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/touch-integ.h>
27 #include <dali/public-api/actors/actor.h>
28 #include <dali/public-api/actors/camera-actor.h>
29 #include <dali/public-api/actors/layer.h>
30 #include <dali/public-api/adaptor-framework/window-enumerations.h>
31 #include <dali/public-api/render-tasks/render-task-list.h>
32 #include <dali/public-api/render-tasks/render-task.h>
33 #include <dali/public-api/rendering/frame-buffer.h>
37 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
38 #include <dali/devel-api/atspi-interfaces/accessible.h>
39 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
40 #include <dali/internal/graphics/gles/egl-graphics.h>
41 #include <dali/internal/window-system/common/event-handler.h>
42 #include <dali/internal/window-system/common/orientation-impl.h>
43 #include <dali/internal/window-system/common/render-surface-factory.h>
44 #include <dali/internal/window-system/common/window-base.h>
45 #include <dali/internal/window-system/common/window-factory.h>
46 #include <dali/internal/window-system/common/window-render-surface.h>
47 #include <dali/internal/window-system/common/window-system.h>
48 #include <dali/internal/window-system/common/window-visibility-observer.h>
58 #if defined(DEBUG_ENABLED)
59 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
61 } // unnamed namespace
63 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
66 return Window::New(surface, positionSize, name, className, type, isTransparent);
69 Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
71 Window* window = new Window();
72 window->mIsTransparent = isTransparent;
73 window->Initialize(surface, positionSize, name, className, type);
78 : mWindowSurface(nullptr),
81 mPreferredAngle(static_cast<int>(WindowOrientation::NO_ORIENTATION_PREFERENCE)),
86 mOrientationMode(Internal::Adaptor::Window::OrientationMode::PORTRAIT),
87 mDeleteRequestSignal(),
90 mVisibilityChangedSignal(),
91 mTransitionEffectEventSignal(),
92 mKeyboardRepeatSettingsChangedSignal(),
93 mAuxiliaryMessageSignal(),
95 mOrientationChangedSignal(),
98 mIsTransparent(false),
99 mIsFocusAcceptable(true),
103 mWindowRotationAcknowledgement(false),
105 mIsWindowRotating(false)
113 auto bridge = Accessibility::Bridge::GetCurrentBridge();
114 auto rootLayer = mScene.GetRootLayer();
115 auto accessible = Accessibility::Accessible::Get(rootLayer);
116 bridge->RemoveTopLevelWindow(accessible);
117 // Related to multi-window case. This is called for default window and non-default window, but it is effective for non-default window.
118 bridge->Emit(accessible, Accessibility::WindowEvent::DESTROY);
123 mAdaptor->RemoveWindow(this);
128 mEventHandler->RemoveObserver(*this);
132 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type)
134 // Create a window render surface
135 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
136 mSurface = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
137 mWindowSurface = static_cast<WindowRenderSurface*>(mSurface.get());
140 mWindowBase = mWindowSurface->GetWindowBase();
143 mWindowBase->SetType(type);
145 // Initialize for Ime window type
146 if(type == WindowType::IME)
148 mWindowBase->InitializeIme();
149 mWindowSurface->InitializeImeSurface();
153 mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
154 mWindowBase->MaximizeChangedSignal().Connect(this, &Window::OnMaximizeChanged);
155 mWindowBase->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
156 mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
157 mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
158 mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
159 mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
160 mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
161 mWindowBase->AuxiliaryMessageSignal().Connect(this, &Window::OnAuxiliaryMessage);
163 mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
164 mWindowSurface->RotationFinishedSignal().Connect(this, &Window::OnRotationFinished);
166 AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
168 SetClass(name, className);
170 mOrientation = Orientation::New(this);
172 // Get OrientationMode
173 int screenWidth, screenHeight;
174 WindowSystem::GetScreenSize(screenWidth, screenHeight);
175 if(screenWidth > screenHeight)
177 mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
181 mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
184 if(positionSize.width <= 0 || positionSize.height <= 0)
186 mWindowWidth = screenWidth;
187 mWindowHeight = screenHeight;
191 mWindowWidth = positionSize.width;
192 mWindowHeight = positionSize.height;
196 mNativeWindowId = mWindowBase->GetNativeWindowId();
199 void Window::SetRenderNotification(TriggerEventInterface *renderNotification)
206 mWindowSurface->SetRenderNotification(renderNotification);
209 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
211 mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
212 mEventHandler->AddObserver(*this);
214 // Add Window to bridge for ATSPI
215 auto bridge = Accessibility::Bridge::GetCurrentBridge();
218 auto rootLayer = mScene.GetRootLayer();
219 auto accessible = Accessibility::Accessible::Get(rootLayer);
220 bridge->AddTopLevelWindow(accessible);
222 // Emit Window create event
223 // Create and Destory signal only emit in multi-window environment, so it does not emit on default layer.
224 bridge->Emit(accessible, Accessibility::WindowEvent::CREATE);
227 bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
228 bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
230 // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
231 // The show must be called after the adaptor is initialized.
235 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
237 mWindowSurface = static_cast<WindowRenderSurface*>(surface);
240 void Window::SetClass(std::string name, std::string className)
243 mClassName = className;
244 mWindowBase->SetClass(name, className);
247 std::string Window::GetClassName() const
254 mWindowBase->Raise();
256 mSurface->SetFullSwapNextFrame();
258 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
263 mWindowBase->Lower();
265 mSurface->SetFullSwapNextFrame();
267 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
270 void Window::Activate()
272 mWindowBase->Activate();
274 mSurface->SetFullSwapNextFrame();
276 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
279 void Window::Maximize(bool maximize)
281 mWindowBase->Maximize(maximize);
283 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Maximize: %d\n", this, mNativeWindowId, maximize);
286 bool Window::IsMaximized() const
288 return mWindowBase->IsMaximized();
291 void Window::SetMaximumSize(Dali::Window::WindowSize size)
293 mWindowBase->SetMaximumSize(size);
296 void Window::Minimize(bool minimize)
298 mWindowBase->Minimize(minimize);
300 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Minimize: %d\n", this, mNativeWindowId, minimize);
303 bool Window::IsMinimized() const
305 return mWindowBase->IsMinimized();
308 void Window::SetMimimumSize(Dali::Window::WindowSize size)
310 mWindowBase->SetMimimumSize(size);
313 uint32_t Window::GetLayerCount() const
315 return mScene.GetLayerCount();
318 Dali::Layer Window::GetLayer(uint32_t depth) const
320 return mScene.GetLayer(depth);
323 Dali::RenderTaskList Window::GetRenderTaskList() const
325 return mScene.GetRenderTaskList();
328 std::string Window::GetNativeResourceId() const
330 return mWindowBase->GetNativeWindowResourceId();
333 void Window::AddAvailableOrientation(WindowOrientation orientation)
335 if(IsOrientationAvailable(orientation) == false)
341 int convertedAngle = ConvertToAngle(orientation);
342 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
343 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
345 if(mAvailableAngles[i] == convertedAngle)
354 mAvailableAngles.push_back(convertedAngle);
355 SetAvailableAnlges(mAvailableAngles);
359 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
361 if(IsOrientationAvailable(orientation) == false)
366 int convertedAngle = ConvertToAngle(orientation);
367 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
368 for(std::vector<int>::iterator iter = mAvailableAngles.begin();
369 iter != mAvailableAngles.end();
372 if(*iter == convertedAngle)
374 mAvailableAngles.erase(iter);
379 SetAvailableAnlges(mAvailableAngles);
382 void Window::SetPreferredOrientation(WindowOrientation orientation)
384 if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
386 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
389 mPreferredAngle = ConvertToAngle(orientation);
390 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
391 mWindowBase->SetPreferredAngle(mPreferredAngle);
394 WindowOrientation Window::GetPreferredOrientation()
396 WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
397 return preferredOrientation;
400 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
402 int angle = ConvertToAngle(orientation);
403 mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
406 void Window::EmitAccessibilityHighlightSignal(bool highlight)
408 Dali::Window handle(this);
409 mAccessibilityHighlightSignal.Emit(handle, highlight);
412 void Window::SetAvailableAnlges(const std::vector<int>& angles)
414 if(angles.size() > 4)
416 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
420 mWindowBase->SetAvailableAnlges(angles);
423 int Window::ConvertToAngle(WindowOrientation orientation)
425 int convertAngle = static_cast<int>(orientation);
426 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
430 case WindowOrientation::LANDSCAPE:
435 case WindowOrientation::PORTRAIT:
440 case WindowOrientation::LANDSCAPE_INVERSE:
445 case WindowOrientation::PORTRAIT_INVERSE:
450 case WindowOrientation::NO_ORIENTATION_PREFERENCE:
460 WindowOrientation Window::ConvertToOrientation(int angle) const
462 WindowOrientation orientation = static_cast<WindowOrientation>(angle);
463 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
469 orientation = WindowOrientation::LANDSCAPE;
474 orientation = WindowOrientation::PORTRAIT;
479 orientation = WindowOrientation::LANDSCAPE_INVERSE;
484 orientation = WindowOrientation::PORTRAIT_INVERSE;
489 orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
497 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
499 if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
501 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
507 Dali::Any Window::GetNativeHandle() const
509 return mWindowSurface->GetNativeWindow();
512 void Window::SetAcceptFocus(bool accept)
514 mIsFocusAcceptable = accept;
516 mWindowBase->SetAcceptFocus(accept);
519 bool Window::IsFocusAcceptable() const
521 return mIsFocusAcceptable;
532 Dali::Window handle(this);
533 mVisibilityChangedSignal.Emit(handle, true);
534 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
536 WindowVisibilityObserver* observer(mAdaptor);
537 observer->OnWindowShown();
540 mSurface->SetFullSwapNextFrame();
542 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
553 Dali::Window handle(this);
554 mVisibilityChangedSignal.Emit(handle, false);
555 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
557 WindowVisibilityObserver* observer(mAdaptor);
558 observer->OnWindowHidden();
561 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
564 bool Window::IsVisible() const
566 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
567 return mVisible && !mIconified;
570 unsigned int Window::GetSupportedAuxiliaryHintCount() const
572 return mWindowBase->GetSupportedAuxiliaryHintCount();
575 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
577 return mWindowBase->GetSupportedAuxiliaryHint(index);
580 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
582 return mWindowBase->AddAuxiliaryHint(hint, value);
585 bool Window::RemoveAuxiliaryHint(unsigned int id)
587 return mWindowBase->RemoveAuxiliaryHint(id);
590 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
592 return mWindowBase->SetAuxiliaryHintValue(id, value);
595 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
597 return mWindowBase->GetAuxiliaryHintValue(id);
600 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
602 return mWindowBase->GetAuxiliaryHintId(hint);
605 void Window::SetInputRegion(const Rect<int>& inputRegion)
607 Rect<int> convertRegion = RecalculateRect(inputRegion);
609 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);
611 mWindowBase->SetInputRegion(convertRegion);
614 void Window::SetType(WindowType type)
616 mWindowBase->SetType(type);
619 WindowType Window::GetType() const
621 return mWindowBase->GetType();
624 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
626 WindowType type = mWindowBase->GetType();
627 if(type != WindowType::NOTIFICATION)
629 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
630 return WindowOperationResult::INVALID_OPERATION;
633 return mWindowBase->SetNotificationLevel(level);
636 WindowNotificationLevel Window::GetNotificationLevel() const
638 WindowType type = mWindowBase->GetType();
639 if(type != WindowType::NOTIFICATION)
641 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
642 return WindowNotificationLevel::NONE;
645 return mWindowBase->GetNotificationLevel();
648 void Window::SetOpaqueState(bool opaque)
650 mOpaqueState = opaque;
652 mWindowBase->SetOpaqueState(opaque);
654 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
657 bool Window::IsOpaqueState() const
662 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
664 return mWindowBase->SetScreenOffMode(screenOffMode);
667 WindowScreenOffMode Window::GetScreenOffMode() const
669 return mWindowBase->GetScreenOffMode();
672 WindowOperationResult Window::SetBrightness(int brightness)
674 if(brightness < 0 || brightness > 100)
676 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
677 return WindowOperationResult::INVALID_OPERATION;
680 return mWindowBase->SetBrightness(brightness);
683 int Window::GetBrightness() const
685 return mWindowBase->GetBrightness();
688 void Window::SetSize(Dali::Window::WindowSize size)
690 PositionSize oldRect = GetPositionSize();
692 PositionSize newRect;
693 newRect.width = size.GetWidth();
694 newRect.height = size.GetHeight();
696 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
697 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
699 mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, newRect.width, newRect.height));
701 Uint16Pair newSize(newRect.width, newRect.height);
703 mWindowWidth = newRect.width;
704 mWindowHeight = newRect.height;
706 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), current angle (%d), SetSize(): (%d, %d), [%d x %d]\n", this, mNativeWindowId, mRotationAngle, oldRect.x, oldRect.y, newRect.width, newRect.height);
708 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
710 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
712 Dali::Window handle(this);
713 mResizeSignal.Emit(handle, newSize);
715 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
718 mSurface->SetFullSwapNextFrame();
720 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
723 Dali::Window::WindowSize Window::GetSize() const
725 return Dali::Window::WindowSize(mWindowWidth, mWindowHeight);
728 void Window::SetPosition(Dali::Window::WindowPosition position)
730 PositionSize oldRect = mSurface->GetPositionSize();
731 int32_t newX = position.GetX();
732 int32_t newY = position.GetY();
734 mWindowSurface->Move(PositionSize(newX, newY, oldRect.width, oldRect.height));
736 if((oldRect.x != newX) || (oldRect.y != newY))
738 Dali::Window handle(this);
739 Dali::Window::WindowPosition newPosition(newX, newY);
741 DALI_LOG_RELEASE_INFO("send moved signal with new position: %d, %d\n", newPosition.GetX(), newPosition.GetY());
742 mMovedSignal.Emit(handle, newPosition);
745 mSurface->SetFullSwapNextFrame();
747 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
750 Dali::Window::WindowPosition Window::GetPosition() const
752 PositionSize positionSize = GetPositionSize();
753 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
756 PositionSize Window::GetPositionSize() const
758 PositionSize positionSize = mSurface->GetPositionSize();
759 positionSize.width = mWindowWidth;
760 positionSize.height = mWindowHeight;
764 void Window::SetPositionSize(PositionSize positionSize)
769 PositionSize oldRect = GetPositionSize();
770 Dali::Window handle(this);
772 if((oldRect.x != positionSize.x) || (oldRect.y != positionSize.y))
777 if((oldRect.width != positionSize.width) || (oldRect.height != positionSize.height))
784 mWindowSurface->MoveResize(positionSize);
787 // When window is moved, emit Moved Signal
790 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, positionSize.x, positionSize.y);
791 Dali::Window::WindowPosition position(positionSize.x, positionSize.y);
792 mMovedSignal.Emit(handle, position);
795 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
798 Uint16Pair newSize(positionSize.width, positionSize.height);
800 mWindowWidth = positionSize.width;
801 mWindowHeight = positionSize.height;
803 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
805 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
807 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resize signal emit [%d x %d]\n", this, mNativeWindowId, positionSize.width, positionSize.height);
809 mResizeSignal.Emit(handle, newSize);
810 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
813 mSurface->SetFullSwapNextFrame();
815 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
818 Dali::Layer Window::GetRootLayer() const
820 return mScene.GetRootLayer();
823 void Window::SetTransparency(bool transparent)
825 mWindowSurface->SetTransparency(transparent);
828 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
830 return mWindowBase->GrabKey(key, grabMode);
833 bool Window::UngrabKey(Dali::KEY key)
835 return mWindowBase->UngrabKey(key);
838 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
840 return mWindowBase->GrabKeyList(key, grabMode, result);
843 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
845 return mWindowBase->UngrabKeyList(key, result);
848 void Window::OnIconifyChanged(bool iconified)
850 const bool isActuallyChanged = (iconified != mIconified);
851 auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge();
852 Dali::Window handle(this);
860 mVisibilityChangedSignal.Emit(handle, false);
861 bridge->WindowHidden(handle);
863 WindowVisibilityObserver* observer(mAdaptor);
864 observer->OnWindowHidden();
867 if(isActuallyChanged)
869 bridge->WindowMinimized(handle);
872 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
880 mVisibilityChangedSignal.Emit(handle, true);
881 bridge->WindowShown(handle);
883 WindowVisibilityObserver* observer(mAdaptor);
884 observer->OnWindowShown();
887 if(isActuallyChanged)
889 bridge->WindowRestored(handle, Dali::Accessibility::WindowRestoreType::RESTORE_FROM_ICONIFY);
892 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
895 mSurface->SetFullSwapNextFrame();
898 void Window::OnMaximizeChanged(bool maximized)
900 const bool isActuallyChanged = (maximized != mMaximized);
902 if(isActuallyChanged)
904 auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge();
905 Dali::Window handle(this);
910 bridge->WindowMaximized(handle);
915 bridge->WindowRestored(handle, Dali::Accessibility::WindowRestoreType::RESTORE_FROM_MAXIMIZE);
920 void Window::OnFocusChanged(bool focusIn)
922 Dali::Window handle(this);
923 mFocusChangeSignal.Emit(handle, focusIn);
925 mSurface->SetFullSwapNextFrame();
926 auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge();
930 bridge->WindowFocused(handle);
934 bridge->WindowUnfocused(handle);
940 void Window::OnOutputTransformed()
942 PositionSize positionSize = GetPositionSize();
944 SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), mRotationAngle, mWindowBase->GetScreenRotationAngle());
946 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
947 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
950 void Window::OnDeleteRequest()
952 mDeleteRequestSignal.Emit();
955 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
957 Dali::Window handle(this);
958 mTransitionEffectEventSignal.Emit(handle, state, type);
961 void Window::OnKeyboardRepeatSettingsChanged()
963 Dali::Window handle(this);
964 mKeyboardRepeatSettingsChangedSignal.Emit();
967 void Window::OnWindowRedrawRequest()
969 mAdaptor->RenderOnce();
972 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
977 Dali::Window handle(this);
979 PositionSize oldRect = GetPositionSize();
980 PositionSize newRect = positionSize;
982 if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
987 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
994 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), current angle (%d), position or size is updated by server , (%d, %d) [%d x %d]\n", this, mNativeWindowId, mRotationAngle, newRect.x, newRect.y, newRect.width, newRect.height);
995 mWindowSurface->UpdatePositionSize(positionSize);
998 if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
1000 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, newRect.x, newRect.y);
1001 Dali::Window::WindowPosition position(newRect.x, newRect.y);
1002 mMovedSignal.Emit(handle, position);
1005 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
1006 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
1008 Uint16Pair newSize(newRect.width, newRect.height);
1010 mWindowWidth = newRect.width;
1011 mWindowHeight = newRect.height;
1013 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
1015 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
1017 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resized signal emit [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
1018 mResizeSignal.Emit(handle, newSize);
1019 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
1022 mSurface->SetFullSwapNextFrame();
1024 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
1027 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
1029 mLastTouchEvent = Dali::Integration::NewTouchEvent(timeStamp, point);
1030 FeedTouchPoint(point, timeStamp);
1033 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
1035 FeedWheelEvent(wheelEvent);
1038 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
1040 mLastKeyEvent = Dali::DevelKeyEvent::New(keyEvent.keyName, keyEvent.logicalKey, keyEvent.keyString, keyEvent.keyCode, keyEvent.keyModifier, keyEvent.time, static_cast<Dali::KeyEvent::State>(keyEvent.state), keyEvent.compose, keyEvent.deviceName, keyEvent.deviceClass, keyEvent.deviceSubclass);
1041 FeedKeyEvent(keyEvent);
1044 void Window::OnRotation(const RotationEvent& rotation)
1046 PositionSize newPositionSize(rotation.x, rotation.y, rotation.width, rotation.height);
1048 mRotationAngle = rotation.angle;
1049 mWindowWidth = rotation.width;
1050 mWindowHeight = rotation.height;
1052 mIsWindowRotating = true;
1053 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), angle(%d), Window Rotation (%d , %d) [%d x %d]\n", this, mNativeWindowId, mRotationAngle, newPositionSize.x, newPositionSize.y, mWindowWidth, mWindowHeight);
1055 // Notify that the orientation is changed
1056 mOrientation->OnOrientationChange(rotation);
1058 mWindowSurface->RequestRotation(mRotationAngle, newPositionSize);
1060 SurfaceRotated(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight), mRotationAngle, mWindowBase->GetScreenRotationAngle());
1062 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1064 Dali::Window handle(this);
1065 mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
1066 mOrientationChangedSignal.Emit(handle, GetCurrentOrientation());
1068 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1071 void Window::OnRotationFinished()
1073 mIsWindowRotating = false;
1074 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), window rotation is finised\n", this, mNativeWindowId);
1077 void Window::OnPause()
1081 mEventHandler->Pause();
1085 void Window::OnResume()
1089 mEventHandler->Resume();
1092 mSurface->SetFullSwapNextFrame();
1095 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
1097 mAuxiliaryMessageSignal.Emit(key, value, options);
1100 void Window::OnAccessibilityEnabled()
1102 auto bridge = Accessibility::Bridge::GetCurrentBridge();
1103 auto rootLayer = mScene.GetRootLayer();
1104 auto accessible = Accessibility::Accessible::Get(rootLayer);
1105 bridge->AddTopLevelWindow(accessible);
1107 if(!mVisible || mIconified)
1112 Dali::Window handle(this);
1113 bridge->WindowShown(handle);
1117 bridge->WindowFocused(handle);
1121 void Window::OnAccessibilityDisabled()
1123 auto bridge = Accessibility::Bridge::GetCurrentBridge();
1124 auto rootLayer = mScene.GetRootLayer();
1125 auto accessible = Accessibility::Accessible::Get(rootLayer);
1126 bridge->RemoveTopLevelWindow(accessible);
1129 Vector2 Window::RecalculatePosition(const Vector2& position)
1131 Vector2 convertedPosition;
1133 switch(mRotationAngle)
1137 convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
1138 convertedPosition.y = position.x;
1143 convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
1144 convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
1149 convertedPosition.x = position.y;
1150 convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
1155 convertedPosition = position;
1159 return convertedPosition;
1162 Dali::Window Window::Get(Dali::Actor actor)
1164 Internal::Adaptor::Window* windowImpl = nullptr;
1166 if(Internal::Adaptor::Adaptor::IsAvailable())
1168 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
1169 windowImpl = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
1172 return Dali::Window(windowImpl);
1176 return Dali::Window();
1179 void Window::SetParent(Dali::Window& parent)
1181 if(DALI_UNLIKELY(parent))
1183 mParentWindow = parent;
1184 Dali::Window self = Dali::Window(this);
1185 // check circular parent window setting
1186 if(Dali::DevelWindow::GetParent(parent) == self)
1188 Dali::DevelWindow::Unparent(parent);
1190 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
1194 void Window::SetParent(Dali::Window& parent, bool belowParent)
1196 if(DALI_UNLIKELY(parent))
1198 mParentWindow = parent;
1199 Dali::Window self = Dali::Window(this);
1200 // check circular parent window setting
1201 if(Dali::DevelWindow::GetParent(parent) == self)
1203 Dali::DevelWindow::Unparent(parent);
1205 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
1209 void Window::Unparent()
1211 mWindowBase->SetParent(nullptr, false);
1212 mParentWindow.Reset();
1215 Dali::Window Window::GetParent()
1217 return mParentWindow;
1220 WindowOrientation Window::GetCurrentOrientation() const
1222 return ConvertToOrientation(mRotationAngle);
1225 int Window::GetPhysicalOrientation() const
1227 return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
1230 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
1232 Dali::Vector<float>::SizeType count = orientations.Count();
1233 for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
1235 if(IsOrientationAvailable(orientations[index]) == false)
1237 DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1242 int convertedAngle = ConvertToAngle(orientations[index]);
1244 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1246 if(mAvailableAngles[i] == convertedAngle)
1255 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1256 mAvailableAngles.push_back(convertedAngle);
1259 SetAvailableAnlges(mAvailableAngles);
1262 int32_t Window::GetNativeId() const
1264 return mWindowBase->GetNativeWindowId();
1267 void Window::RequestMoveToServer()
1269 mWindowBase->RequestMoveToServer();
1272 void Window::RequestResizeToServer(WindowResizeDirection direction)
1274 mWindowBase->RequestResizeToServer(direction);
1277 void Window::EnableFloatingMode(bool enable)
1279 mWindowBase->EnableFloatingMode(enable);
1282 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
1285 int screenWidth, screenHeight;
1287 WindowSystem::GetScreenSize(screenWidth, screenHeight);
1289 if(mRotationAngle == 90)
1292 newRect.y = screenHeight - (rect.x + rect.width);
1293 newRect.width = rect.height;
1294 newRect.height = rect.width;
1296 else if(mRotationAngle == 180)
1298 newRect.x = screenWidth - (rect.x + rect.width);
1299 newRect.y = screenHeight - (rect.y + rect.height);
1300 newRect.width = rect.width;
1301 newRect.height = rect.height;
1303 else if(mRotationAngle == 270)
1305 newRect.x = screenWidth - (rect.y + rect.height);
1307 newRect.width = rect.height;
1308 newRect.height = rect.width;
1314 newRect.width = rect.width;
1315 newRect.height = rect.height;
1320 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1322 Rect<int> convertRegion = RecalculateRect(inputRegion);
1324 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);
1325 mWindowBase->IncludeInputRegion(convertRegion);
1328 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1330 Rect<int> convertRegion = RecalculateRect(inputRegion);
1332 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);
1333 mWindowBase->ExcludeInputRegion(convertRegion);
1336 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1338 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1339 mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1340 mWindowRotationAcknowledgement = needAcknowledgement;
1343 void Window::SendRotationCompletedAcknowledgement()
1345 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1346 if(mWindowRotationAcknowledgement)
1348 SetRotationCompletedAcknowledgement();
1352 bool Window::IsWindowRotating() const
1354 return mIsWindowRotating;
1357 const Dali::KeyEvent& Window::GetLastKeyEvent() const
1359 return mLastKeyEvent;
1362 const Dali::TouchEvent& Window::GetLastTouchEvent() const
1364 return mLastTouchEvent;
1367 } // namespace Adaptor
1369 } // namespace Internal