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 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetInputRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height);
608 mWindowBase->SetInputRegion(inputRegion);
611 void Window::SetType(WindowType type)
613 mWindowBase->SetType(type);
616 WindowType Window::GetType() const
618 return mWindowBase->GetType();
621 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
623 WindowType type = mWindowBase->GetType();
624 if(type != WindowType::NOTIFICATION)
626 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
627 return WindowOperationResult::INVALID_OPERATION;
630 return mWindowBase->SetNotificationLevel(level);
633 WindowNotificationLevel Window::GetNotificationLevel() const
635 WindowType type = mWindowBase->GetType();
636 if(type != WindowType::NOTIFICATION)
638 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
639 return WindowNotificationLevel::NONE;
642 return mWindowBase->GetNotificationLevel();
645 void Window::SetOpaqueState(bool opaque)
647 mOpaqueState = opaque;
649 mWindowBase->SetOpaqueState(opaque);
651 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
654 bool Window::IsOpaqueState() const
659 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
661 return mWindowBase->SetScreenOffMode(screenOffMode);
664 WindowScreenOffMode Window::GetScreenOffMode() const
666 return mWindowBase->GetScreenOffMode();
669 WindowOperationResult Window::SetBrightness(int brightness)
671 if(brightness < 0 || brightness > 100)
673 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
674 return WindowOperationResult::INVALID_OPERATION;
677 return mWindowBase->SetBrightness(brightness);
680 int Window::GetBrightness() const
682 return mWindowBase->GetBrightness();
685 void Window::SetSize(Dali::Window::WindowSize size)
687 PositionSize oldRect = GetPositionSize();
689 PositionSize newRect;
690 newRect.width = size.GetWidth();
691 newRect.height = size.GetHeight();
693 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
694 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
696 mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, newRect.width, newRect.height));
698 Uint16Pair newSize(newRect.width, newRect.height);
700 mWindowWidth = newRect.width;
701 mWindowHeight = newRect.height;
703 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);
705 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
707 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
709 Dali::Window handle(this);
710 mResizeSignal.Emit(handle, newSize);
712 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
715 mSurface->SetFullSwapNextFrame();
717 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
720 Dali::Window::WindowSize Window::GetSize() const
722 return Dali::Window::WindowSize(mWindowWidth, mWindowHeight);
725 void Window::SetPosition(Dali::Window::WindowPosition position)
727 PositionSize oldRect = mSurface->GetPositionSize();
728 int32_t newX = position.GetX();
729 int32_t newY = position.GetY();
731 mWindowSurface->Move(PositionSize(newX, newY, oldRect.width, oldRect.height));
733 if((oldRect.x != newX) || (oldRect.y != newY))
735 Dali::Window handle(this);
736 Dali::Window::WindowPosition newPosition(newX, newY);
738 DALI_LOG_RELEASE_INFO("send moved signal with new position: %d, %d\n", newPosition.GetX(), newPosition.GetY());
739 mMovedSignal.Emit(handle, newPosition);
742 mSurface->SetFullSwapNextFrame();
744 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
747 Dali::Window::WindowPosition Window::GetPosition() const
749 PositionSize positionSize = GetPositionSize();
750 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
753 PositionSize Window::GetPositionSize() const
755 PositionSize positionSize = mSurface->GetPositionSize();
756 positionSize.width = mWindowWidth;
757 positionSize.height = mWindowHeight;
761 void Window::SetPositionSize(PositionSize positionSize)
766 PositionSize oldRect = GetPositionSize();
767 Dali::Window handle(this);
769 if((oldRect.x != positionSize.x) || (oldRect.y != positionSize.y))
774 if((oldRect.width != positionSize.width) || (oldRect.height != positionSize.height))
781 mWindowSurface->MoveResize(positionSize);
784 // When window is moved, emit Moved Signal
787 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, positionSize.x, positionSize.y);
788 Dali::Window::WindowPosition position(positionSize.x, positionSize.y);
789 mMovedSignal.Emit(handle, position);
792 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
795 Uint16Pair newSize(positionSize.width, positionSize.height);
797 mWindowWidth = positionSize.width;
798 mWindowHeight = positionSize.height;
800 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
802 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
804 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resize signal emit [%d x %d]\n", this, mNativeWindowId, positionSize.width, positionSize.height);
806 mResizeSignal.Emit(handle, newSize);
807 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
810 mSurface->SetFullSwapNextFrame();
812 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
815 void Window::SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan)
817 mWindowBase->SetLayout(numCols, numRows, column, row, colSpan, rowSpan);
820 Dali::Layer Window::GetRootLayer() const
822 return mScene.GetRootLayer();
825 void Window::SetTransparency(bool transparent)
827 mWindowSurface->SetTransparency(transparent);
830 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
832 return mWindowBase->GrabKey(key, grabMode);
835 bool Window::UngrabKey(Dali::KEY key)
837 return mWindowBase->UngrabKey(key);
840 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
842 return mWindowBase->GrabKeyList(key, grabMode, result);
845 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
847 return mWindowBase->UngrabKeyList(key, result);
850 void Window::OnIconifyChanged(bool iconified)
852 const bool isActuallyChanged = (iconified != mIconified);
853 auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge();
854 Dali::Window handle(this);
862 mVisibilityChangedSignal.Emit(handle, false);
863 bridge->WindowHidden(handle);
865 WindowVisibilityObserver* observer(mAdaptor);
866 observer->OnWindowHidden();
869 if(isActuallyChanged)
871 bridge->WindowMinimized(handle);
874 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
882 mVisibilityChangedSignal.Emit(handle, true);
883 bridge->WindowShown(handle);
885 WindowVisibilityObserver* observer(mAdaptor);
886 observer->OnWindowShown();
889 if(isActuallyChanged)
891 bridge->WindowRestored(handle, Dali::Accessibility::WindowRestoreType::RESTORE_FROM_ICONIFY);
894 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
897 mSurface->SetFullSwapNextFrame();
900 void Window::OnMaximizeChanged(bool maximized)
902 const bool isActuallyChanged = (maximized != mMaximized);
904 if(isActuallyChanged)
906 auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge();
907 Dali::Window handle(this);
912 bridge->WindowMaximized(handle);
917 bridge->WindowRestored(handle, Dali::Accessibility::WindowRestoreType::RESTORE_FROM_MAXIMIZE);
922 void Window::OnFocusChanged(bool focusIn)
924 Dali::Window handle(this);
925 mFocusChangeSignal.Emit(handle, focusIn);
927 mSurface->SetFullSwapNextFrame();
928 auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge();
932 bridge->WindowFocused(handle);
936 bridge->WindowUnfocused(handle);
942 void Window::OnOutputTransformed()
944 PositionSize positionSize = GetPositionSize();
946 SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), mRotationAngle, mWindowBase->GetScreenRotationAngle());
948 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
949 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
952 void Window::OnDeleteRequest()
954 mDeleteRequestSignal.Emit();
957 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
959 Dali::Window handle(this);
960 mTransitionEffectEventSignal.Emit(handle, state, type);
963 void Window::OnKeyboardRepeatSettingsChanged()
965 Dali::Window handle(this);
966 mKeyboardRepeatSettingsChangedSignal.Emit();
969 void Window::OnWindowRedrawRequest()
971 mAdaptor->RenderOnce();
974 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
979 Dali::Window handle(this);
981 PositionSize oldRect = GetPositionSize();
982 PositionSize newRect = positionSize;
984 if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
989 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
996 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);
997 mWindowSurface->UpdatePositionSize(positionSize);
1000 if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
1002 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, newRect.x, newRect.y);
1003 Dali::Window::WindowPosition position(newRect.x, newRect.y);
1004 mMovedSignal.Emit(handle, position);
1007 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
1008 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
1010 Uint16Pair newSize(newRect.width, newRect.height);
1012 mWindowWidth = newRect.width;
1013 mWindowHeight = newRect.height;
1015 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
1017 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
1019 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resized signal emit [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
1020 mResizeSignal.Emit(handle, newSize);
1021 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
1024 mSurface->SetFullSwapNextFrame();
1026 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
1029 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
1031 mLastTouchEvent = Dali::Integration::NewTouchEvent(timeStamp, point);
1032 FeedTouchPoint(point, timeStamp);
1035 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
1037 FeedWheelEvent(wheelEvent);
1040 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
1042 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);
1043 FeedKeyEvent(keyEvent);
1046 void Window::OnRotation(const RotationEvent& rotation)
1048 PositionSize newPositionSize(rotation.x, rotation.y, rotation.width, rotation.height);
1050 mRotationAngle = rotation.angle;
1051 mWindowWidth = rotation.width;
1052 mWindowHeight = rotation.height;
1054 mIsWindowRotating = true;
1055 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);
1057 // Notify that the orientation is changed
1058 mOrientation->OnOrientationChange(rotation);
1060 mWindowSurface->RequestRotation(mRotationAngle, newPositionSize);
1062 SurfaceRotated(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight), mRotationAngle, mWindowBase->GetScreenRotationAngle());
1064 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1066 Dali::Window handle(this);
1067 mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
1068 mOrientationChangedSignal.Emit(handle, GetCurrentOrientation());
1070 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1073 void Window::OnRotationFinished()
1075 mIsWindowRotating = false;
1076 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), window rotation is finised\n", this, mNativeWindowId);
1079 void Window::OnPause()
1083 mEventHandler->Pause();
1087 void Window::OnResume()
1091 mEventHandler->Resume();
1094 mSurface->SetFullSwapNextFrame();
1097 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
1099 mAuxiliaryMessageSignal.Emit(key, value, options);
1102 void Window::OnAccessibilityEnabled()
1104 auto bridge = Accessibility::Bridge::GetCurrentBridge();
1105 auto rootLayer = mScene.GetRootLayer();
1106 auto accessible = Accessibility::Accessible::Get(rootLayer);
1107 bridge->AddTopLevelWindow(accessible);
1109 if(!mVisible || mIconified)
1114 Dali::Window handle(this);
1115 bridge->WindowShown(handle);
1119 bridge->WindowFocused(handle);
1123 void Window::OnAccessibilityDisabled()
1125 auto bridge = Accessibility::Bridge::GetCurrentBridge();
1126 auto rootLayer = mScene.GetRootLayer();
1127 auto accessible = Accessibility::Accessible::Get(rootLayer);
1128 bridge->RemoveTopLevelWindow(accessible);
1131 Vector2 Window::RecalculatePosition(const Vector2& position)
1133 Vector2 convertedPosition;
1135 switch(mRotationAngle)
1139 convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
1140 convertedPosition.y = position.x;
1145 convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
1146 convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
1151 convertedPosition.x = position.y;
1152 convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
1157 convertedPosition = position;
1161 return convertedPosition;
1164 Dali::Window Window::Get(Dali::Actor actor)
1166 Internal::Adaptor::Window* windowImpl = nullptr;
1168 if(Internal::Adaptor::Adaptor::IsAvailable())
1170 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
1171 windowImpl = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
1174 return Dali::Window(windowImpl);
1178 return Dali::Window();
1181 void Window::SetParent(Dali::Window& parent)
1183 if(DALI_UNLIKELY(parent))
1185 mParentWindow = parent;
1186 Dali::Window self = Dali::Window(this);
1187 // check circular parent window setting
1188 if(Dali::DevelWindow::GetParent(parent) == self)
1190 Dali::DevelWindow::Unparent(parent);
1192 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
1196 void Window::SetParent(Dali::Window& parent, bool belowParent)
1198 if(DALI_UNLIKELY(parent))
1200 mParentWindow = parent;
1201 Dali::Window self = Dali::Window(this);
1202 // check circular parent window setting
1203 if(Dali::DevelWindow::GetParent(parent) == self)
1205 Dali::DevelWindow::Unparent(parent);
1207 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
1211 void Window::Unparent()
1213 mWindowBase->SetParent(nullptr, false);
1214 mParentWindow.Reset();
1217 Dali::Window Window::GetParent()
1219 return mParentWindow;
1222 WindowOrientation Window::GetCurrentOrientation() const
1224 return ConvertToOrientation(mRotationAngle);
1227 int Window::GetPhysicalOrientation() const
1229 return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
1232 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
1234 Dali::Vector<float>::SizeType count = orientations.Count();
1235 for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
1237 if(IsOrientationAvailable(orientations[index]) == false)
1239 DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1244 int convertedAngle = ConvertToAngle(orientations[index]);
1246 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1248 if(mAvailableAngles[i] == convertedAngle)
1257 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1258 mAvailableAngles.push_back(convertedAngle);
1261 SetAvailableAnlges(mAvailableAngles);
1264 int32_t Window::GetNativeId() const
1266 return mWindowBase->GetNativeWindowId();
1269 void Window::RequestMoveToServer()
1271 mWindowBase->RequestMoveToServer();
1274 void Window::RequestResizeToServer(WindowResizeDirection direction)
1276 mWindowBase->RequestResizeToServer(direction);
1279 void Window::EnableFloatingMode(bool enable)
1281 mWindowBase->EnableFloatingMode(enable);
1284 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1286 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IncludeInputRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height);
1287 mWindowBase->IncludeInputRegion(inputRegion);
1290 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1292 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), ExcludeInputRegion, (%d,%d), (%d x %d)\n", this, mNativeWindowId, inputRegion.x, inputRegion.y, inputRegion.width, inputRegion.height);
1293 mWindowBase->ExcludeInputRegion(inputRegion);
1296 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1298 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1299 mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1300 mWindowRotationAcknowledgement = needAcknowledgement;
1303 void Window::SendRotationCompletedAcknowledgement()
1305 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1306 if(mWindowRotationAcknowledgement)
1308 SetRotationCompletedAcknowledgement();
1312 bool Window::IsWindowRotating() const
1314 return mIsWindowRotating;
1317 const Dali::KeyEvent& Window::GetLastKeyEvent() const
1319 return mLastKeyEvent;
1322 const Dali::TouchEvent& Window::GetLastTouchEvent() const
1324 return mLastTouchEvent;
1327 } // namespace Adaptor
1329 } // namespace Internal