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/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");
62 } // unnamed namespace
64 Window* Window::New(const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
67 return Window::New(surface, positionSize, name, className, type, isTransparent);
70 Window* Window::New(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, Dali::WindowType type, bool isTransparent)
72 Window* window = new Window();
73 window->mIsTransparent = isTransparent;
74 window->Initialize(surface, positionSize, name, className, type);
79 : mWindowSurface(nullptr),
82 mPreferredAngle(static_cast<int>(WindowOrientation::NO_ORIENTATION_PREFERENCE)),
87 mOrientationMode(Internal::Adaptor::Window::OrientationMode::PORTRAIT),
88 mDeleteRequestSignal(),
91 mVisibilityChangedSignal(),
92 mTransitionEffectEventSignal(),
93 mKeyboardRepeatSettingsChangedSignal(),
94 mAuxiliaryMessageSignal(),
98 mIsTransparent(false),
99 mIsFocusAcceptable(true),
102 mWindowRotationAcknowledgement(false),
104 mIsWindowRotating(false)
112 auto bridge = Accessibility::Bridge::GetCurrentBridge();
113 auto rootLayer = mScene.GetRootLayer();
114 auto accessible = Accessibility::Accessible::Get(rootLayer);
115 bridge->RemoveTopLevelWindow(accessible);
116 // Related to multi-window case. This is called for default window and non-default window, but it is effective for non-default window.
117 bridge->Emit(accessible, Accessibility::WindowEvent::DESTROY);
122 mAdaptor->RemoveWindow(this);
127 mEventHandler->RemoveObserver(*this);
131 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type)
133 // Create a window render surface
134 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
135 mSurface = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
136 mWindowSurface = static_cast<WindowRenderSurface*>(mSurface.get());
139 mWindowBase = mWindowSurface->GetWindowBase();
142 mWindowBase->SetType(type);
144 // Initialize for Ime window type
145 if(type == WindowType::IME)
147 mWindowBase->InitializeIme();
148 mWindowSurface->InitializeImeSurface();
152 mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
153 mWindowBase->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
154 mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
155 mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
156 mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
157 mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
158 mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
159 mWindowBase->AuxiliaryMessageSignal().Connect(this, &Window::OnAuxiliaryMessage);
161 mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
162 mWindowSurface->RotationFinishedSignal().Connect(this, &Window::OnRotationFinished);
164 AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
166 SetClass(name, className);
168 mOrientation = Orientation::New(this);
170 // Get OrientationMode
171 int screenWidth, screenHeight;
172 WindowSystem::GetScreenSize(screenWidth, screenHeight);
173 if(screenWidth > screenHeight)
175 mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
179 mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
182 if(positionSize.width <= 0 || positionSize.height <= 0)
184 mWindowWidth = screenWidth;
185 mWindowHeight = screenHeight;
189 mWindowWidth = positionSize.width;
190 mWindowHeight = positionSize.height;
194 mNativeWindowId = mWindowBase->GetNativeWindowId();
197 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
199 mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
200 mEventHandler->AddObserver(*this);
202 // Add Window to bridge for ATSPI
203 auto bridge = Accessibility::Bridge::GetCurrentBridge();
206 auto rootLayer = mScene.GetRootLayer();
207 auto accessible = Accessibility::Accessible::Get(rootLayer);
208 bridge->AddTopLevelWindow(accessible);
211 bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
212 bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
214 // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
215 // The show must be called after the adaptor is initialized.
219 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
221 mWindowSurface = static_cast<WindowRenderSurface*>(surface);
224 void Window::SetClass(std::string name, std::string className)
227 mClassName = className;
228 mWindowBase->SetClass(name, className);
231 std::string Window::GetClassName() const
238 mWindowBase->Raise();
240 mSurface->SetFullSwapNextFrame();
242 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
247 mWindowBase->Lower();
249 mSurface->SetFullSwapNextFrame();
251 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
254 void Window::Activate()
256 mWindowBase->Activate();
258 mSurface->SetFullSwapNextFrame();
260 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
263 void Window::Maximize(bool maximize)
265 mWindowBase->Maximize(maximize);
267 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Maximize: %d\n", this, mNativeWindowId, maximize);
270 bool Window::IsMaximized() const
272 return mWindowBase->IsMaximized();
275 void Window::SetMaximumSize(Dali::Window::WindowSize size)
277 mWindowBase->SetMaximumSize(size);
280 void Window::Minimize(bool minimize)
282 mWindowBase->Minimize(minimize);
284 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Minimize: %d\n", this, mNativeWindowId, minimize);
287 bool Window::IsMinimized() const
289 return mWindowBase->IsMinimized();
292 void Window::SetMimimumSize(Dali::Window::WindowSize size)
294 mWindowBase->SetMimimumSize(size);
297 uint32_t Window::GetLayerCount() const
299 return mScene.GetLayerCount();
302 Dali::Layer Window::GetLayer(uint32_t depth) const
304 return mScene.GetLayer(depth);
307 Dali::RenderTaskList Window::GetRenderTaskList() const
309 return mScene.GetRenderTaskList();
312 std::string Window::GetNativeResourceId() const
314 return mWindowBase->GetNativeWindowResourceId();
317 void Window::AddAvailableOrientation(WindowOrientation orientation)
319 if(IsOrientationAvailable(orientation) == false)
325 int convertedAngle = ConvertToAngle(orientation);
326 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
327 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
329 if(mAvailableAngles[i] == convertedAngle)
338 mAvailableAngles.push_back(convertedAngle);
339 SetAvailableAnlges(mAvailableAngles);
343 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
345 if(IsOrientationAvailable(orientation) == false)
350 int convertedAngle = ConvertToAngle(orientation);
351 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
352 for(std::vector<int>::iterator iter = mAvailableAngles.begin();
353 iter != mAvailableAngles.end();
356 if(*iter == convertedAngle)
358 mAvailableAngles.erase(iter);
363 SetAvailableAnlges(mAvailableAngles);
366 void Window::SetPreferredOrientation(WindowOrientation orientation)
368 if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
370 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
373 mPreferredAngle = ConvertToAngle(orientation);
374 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
375 mWindowBase->SetPreferredAngle(mPreferredAngle);
378 WindowOrientation Window::GetPreferredOrientation()
380 WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
381 return preferredOrientation;
384 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
386 int angle = ConvertToAngle(orientation);
387 mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
390 void Window::EmitAccessibilityHighlightSignal(bool highlight)
392 Dali::Window handle(this);
393 mAccessibilityHighlightSignal.Emit(handle, highlight);
396 void Window::SetAvailableAnlges(const std::vector<int>& angles)
398 if(angles.size() > 4)
400 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
404 mWindowBase->SetAvailableAnlges(angles);
407 int Window::ConvertToAngle(WindowOrientation orientation)
409 int convertAngle = static_cast<int>(orientation);
410 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
414 case WindowOrientation::LANDSCAPE:
419 case WindowOrientation::PORTRAIT:
424 case WindowOrientation::LANDSCAPE_INVERSE:
429 case WindowOrientation::PORTRAIT_INVERSE:
434 case WindowOrientation::NO_ORIENTATION_PREFERENCE:
444 WindowOrientation Window::ConvertToOrientation(int angle) const
446 WindowOrientation orientation = static_cast<WindowOrientation>(angle);
447 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
453 orientation = WindowOrientation::LANDSCAPE;
458 orientation = WindowOrientation::PORTRAIT;
463 orientation = WindowOrientation::LANDSCAPE_INVERSE;
468 orientation = WindowOrientation::PORTRAIT_INVERSE;
473 orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
481 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
483 if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
485 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
491 Dali::Any Window::GetNativeHandle() const
493 return mWindowSurface->GetNativeWindow();
496 void Window::SetAcceptFocus(bool accept)
498 mIsFocusAcceptable = accept;
500 mWindowBase->SetAcceptFocus(accept);
503 bool Window::IsFocusAcceptable() const
505 return mIsFocusAcceptable;
516 Dali::Window handle(this);
517 mVisibilityChangedSignal.Emit(handle, true);
518 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
520 WindowVisibilityObserver* observer(mAdaptor);
521 observer->OnWindowShown();
524 mSurface->SetFullSwapNextFrame();
526 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
537 Dali::Window handle(this);
538 mVisibilityChangedSignal.Emit(handle, false);
539 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
541 WindowVisibilityObserver* observer(mAdaptor);
542 observer->OnWindowHidden();
545 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
548 bool Window::IsVisible() const
550 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
551 return mVisible && !mIconified;
554 unsigned int Window::GetSupportedAuxiliaryHintCount() const
556 return mWindowBase->GetSupportedAuxiliaryHintCount();
559 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
561 return mWindowBase->GetSupportedAuxiliaryHint(index);
564 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
566 return mWindowBase->AddAuxiliaryHint(hint, value);
569 bool Window::RemoveAuxiliaryHint(unsigned int id)
571 return mWindowBase->RemoveAuxiliaryHint(id);
574 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
576 return mWindowBase->SetAuxiliaryHintValue(id, value);
579 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
581 return mWindowBase->GetAuxiliaryHintValue(id);
584 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
586 return mWindowBase->GetAuxiliaryHintId(hint);
589 void Window::SetInputRegion(const Rect<int>& inputRegion)
591 Rect<int> convertRegion = RecalculateRect(inputRegion);
593 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);
595 mWindowBase->SetInputRegion(convertRegion);
598 void Window::SetType(WindowType type)
600 mWindowBase->SetType(type);
603 WindowType Window::GetType() const
605 return mWindowBase->GetType();
608 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
610 WindowType type = mWindowBase->GetType();
611 if(type != WindowType::NOTIFICATION)
613 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
614 return WindowOperationResult::INVALID_OPERATION;
617 return mWindowBase->SetNotificationLevel(level);
620 WindowNotificationLevel Window::GetNotificationLevel() const
622 WindowType type = mWindowBase->GetType();
623 if(type != WindowType::NOTIFICATION)
625 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
626 return WindowNotificationLevel::NONE;
629 return mWindowBase->GetNotificationLevel();
632 void Window::SetOpaqueState(bool opaque)
634 mOpaqueState = opaque;
636 mWindowBase->SetOpaqueState(opaque);
638 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
641 bool Window::IsOpaqueState() const
646 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
648 return mWindowBase->SetScreenOffMode(screenOffMode);
651 WindowScreenOffMode Window::GetScreenOffMode() const
653 return mWindowBase->GetScreenOffMode();
656 WindowOperationResult Window::SetBrightness(int brightness)
658 if(brightness < 0 || brightness > 100)
660 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
661 return WindowOperationResult::INVALID_OPERATION;
664 return mWindowBase->SetBrightness(brightness);
667 int Window::GetBrightness() const
669 return mWindowBase->GetBrightness();
672 void Window::SetSize(Dali::Window::WindowSize size)
674 PositionSize oldRect = GetPositionSize();
676 PositionSize newRect;
677 newRect.width = size.GetWidth();
678 newRect.height = size.GetHeight();
680 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
681 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
683 mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, newRect.width, newRect.height));
685 Uint16Pair newSize(newRect.width, newRect.height);
687 mWindowWidth = newRect.width;
688 mWindowHeight = newRect.height;
690 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);
692 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
694 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
696 Dali::Window handle(this);
697 mResizeSignal.Emit(handle, newSize);
699 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
702 mSurface->SetFullSwapNextFrame();
704 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
707 Dali::Window::WindowSize Window::GetSize() const
709 return Dali::Window::WindowSize(mWindowWidth, mWindowHeight);
712 void Window::SetPosition(Dali::Window::WindowPosition position)
714 PositionSize oldRect = mSurface->GetPositionSize();
715 int32_t newX = position.GetX();
716 int32_t newY = position.GetY();
718 mWindowSurface->MoveResize(PositionSize(newX, newY, oldRect.width, oldRect.height));
720 if((oldRect.x != newX) || (oldRect.y != newY))
722 Dali::Window handle(this);
723 Dali::Window::WindowPosition newPosition(newX, newY);
725 DALI_LOG_RELEASE_INFO("send moved signal with new position: %d, %d\n", newPosition.GetX(), newPosition.GetY());
726 mMovedSignal.Emit(handle, newPosition);
729 mSurface->SetFullSwapNextFrame();
731 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
734 Dali::Window::WindowPosition Window::GetPosition() const
736 PositionSize positionSize = GetPositionSize();
737 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
740 PositionSize Window::GetPositionSize() const
742 PositionSize positionSize = mSurface->GetPositionSize();
743 positionSize.width = mWindowWidth;
744 positionSize.height = mWindowHeight;
748 void Window::SetPositionSize(PositionSize positionSize)
753 PositionSize oldRect = GetPositionSize();
754 Dali::Window handle(this);
756 if((oldRect.x != positionSize.x) || (oldRect.y != positionSize.y))
761 if((oldRect.width != positionSize.width) || (oldRect.height != positionSize.height))
768 mWindowSurface->MoveResize(positionSize);
771 // When window is moved, emit Moved Signal
774 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, positionSize.x, positionSize.y);
775 Dali::Window::WindowPosition position(positionSize.x, positionSize.y);
776 mMovedSignal.Emit(handle, position);
779 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
782 Uint16Pair newSize(positionSize.width, positionSize.height);
784 mWindowWidth = positionSize.width;
785 mWindowHeight = positionSize.height;
787 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
789 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
791 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resize signal emit [%d x %d]\n", this, mNativeWindowId, positionSize.width, positionSize.height);
793 mResizeSignal.Emit(handle, newSize);
794 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
797 mSurface->SetFullSwapNextFrame();
799 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
802 Dali::Layer Window::GetRootLayer() const
804 return mScene.GetRootLayer();
807 void Window::SetTransparency(bool transparent)
809 mWindowSurface->SetTransparency(transparent);
812 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
814 return mWindowBase->GrabKey(key, grabMode);
817 bool Window::UngrabKey(Dali::KEY key)
819 return mWindowBase->UngrabKey(key);
822 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
824 return mWindowBase->GrabKeyList(key, grabMode, result);
827 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
829 return mWindowBase->UngrabKeyList(key, result);
832 void Window::OnIconifyChanged(bool iconified)
840 Dali::Window handle(this);
841 mVisibilityChangedSignal.Emit(handle, false);
842 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
844 WindowVisibilityObserver* observer(mAdaptor);
845 observer->OnWindowHidden();
848 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
856 Dali::Window handle(this);
857 mVisibilityChangedSignal.Emit(handle, true);
858 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
860 WindowVisibilityObserver* observer(mAdaptor);
861 observer->OnWindowShown();
864 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
867 mSurface->SetFullSwapNextFrame();
870 void Window::OnFocusChanged(bool focusIn)
872 Dali::Window handle(this);
873 mFocusChangeSignal.Emit(handle, focusIn);
875 mSurface->SetFullSwapNextFrame();
877 if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
881 bridge->WindowFocused(handle);
885 bridge->WindowUnfocused(handle);
891 void Window::OnOutputTransformed()
893 PositionSize positionSize = GetPositionSize();
895 SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), mRotationAngle, mWindowBase->GetScreenRotationAngle());
897 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
898 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
901 void Window::OnDeleteRequest()
903 mDeleteRequestSignal.Emit();
906 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
908 Dali::Window handle(this);
909 mTransitionEffectEventSignal.Emit(handle, state, type);
912 void Window::OnKeyboardRepeatSettingsChanged()
914 Dali::Window handle(this);
915 mKeyboardRepeatSettingsChangedSignal.Emit();
918 void Window::OnWindowRedrawRequest()
920 mAdaptor->RenderOnce();
923 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
928 Dali::Window handle(this);
930 PositionSize oldRect = GetPositionSize();
931 PositionSize newRect = positionSize;
933 if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
938 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
945 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);
946 mWindowSurface->UpdatePositionSize(positionSize);
949 if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
951 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, newRect.x, newRect.y);
952 Dali::Window::WindowPosition position(newRect.x, newRect.y);
953 mMovedSignal.Emit(handle, position);
956 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
957 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
959 Uint16Pair newSize(newRect.width, newRect.height);
961 mWindowWidth = newRect.width;
962 mWindowHeight = newRect.height;
964 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
966 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
968 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resized signal emit [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
969 mResizeSignal.Emit(handle, newSize);
970 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
973 mSurface->SetFullSwapNextFrame();
975 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
978 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
980 mLastTouchEvent = Dali::Integration::NewTouchEvent(timeStamp, point);
981 FeedTouchPoint(point, timeStamp);
984 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
986 FeedWheelEvent(wheelEvent);
989 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
991 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);
992 FeedKeyEvent(keyEvent);
995 void Window::OnRotation(const RotationEvent& rotation)
997 PositionSize newPositionSize(rotation.x, rotation.y, rotation.width, rotation.height);
999 mRotationAngle = rotation.angle;
1000 mWindowWidth = rotation.width;
1001 mWindowHeight = rotation.height;
1003 mIsWindowRotating = true;
1004 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);
1006 // Notify that the orientation is changed
1007 mOrientation->OnOrientationChange(rotation);
1009 mWindowSurface->RequestRotation(mRotationAngle, newPositionSize);
1011 SurfaceRotated(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight), mRotationAngle, mWindowBase->GetScreenRotationAngle());
1013 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1015 Dali::Window handle(this);
1016 mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
1018 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1021 void Window::OnRotationFinished()
1023 mIsWindowRotating = false;
1024 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), window rotation is finised\n", this, mNativeWindowId);
1027 void Window::OnPause()
1031 mEventHandler->Pause();
1035 void Window::OnResume()
1039 mEventHandler->Resume();
1042 mSurface->SetFullSwapNextFrame();
1045 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
1047 mAuxiliaryMessageSignal.Emit(key, value, options);
1050 void Window::OnAccessibilityEnabled()
1052 auto bridge = Accessibility::Bridge::GetCurrentBridge();
1053 auto rootLayer = mScene.GetRootLayer();
1054 auto accessible = Accessibility::Accessible::Get(rootLayer);
1055 bridge->AddTopLevelWindow(accessible);
1057 if(!mVisible || mIconified)
1062 Dali::Window handle(this);
1063 bridge->WindowShown(handle);
1067 bridge->WindowFocused(handle);
1071 void Window::OnAccessibilityDisabled()
1073 auto bridge = Accessibility::Bridge::GetCurrentBridge();
1074 auto rootLayer = mScene.GetRootLayer();
1075 auto accessible = Accessibility::Accessible::Get(rootLayer);
1076 bridge->RemoveTopLevelWindow(accessible);
1079 void Window::RecalculateTouchPosition(Integration::Point& point)
1081 Vector2 position = point.GetScreenPosition();
1082 Vector2 convertedPosition;
1084 switch(mRotationAngle)
1088 convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
1089 convertedPosition.y = position.x;
1094 convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
1095 convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
1100 convertedPosition.x = position.y;
1101 convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
1106 convertedPosition = position;
1111 point.SetScreenPosition(convertedPosition);
1114 Dali::Window Window::Get(Dali::Actor actor)
1116 Internal::Adaptor::Window* windowImpl = nullptr;
1118 if(Internal::Adaptor::Adaptor::IsAvailable())
1120 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
1121 windowImpl = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
1124 return Dali::Window(windowImpl);
1128 return Dali::Window();
1131 void Window::SetParent(Dali::Window& parent)
1133 if(DALI_UNLIKELY(parent))
1135 mParentWindow = parent;
1136 Dali::Window self = Dali::Window(this);
1137 // check circular parent window setting
1138 if(Dali::DevelWindow::GetParent(parent) == self)
1140 Dali::DevelWindow::Unparent(parent);
1142 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
1146 void Window::SetParent(Dali::Window& parent, bool belowParent)
1148 if(DALI_UNLIKELY(parent))
1150 mParentWindow = parent;
1151 Dali::Window self = Dali::Window(this);
1152 // check circular parent window setting
1153 if(Dali::DevelWindow::GetParent(parent) == self)
1155 Dali::DevelWindow::Unparent(parent);
1157 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
1161 void Window::Unparent()
1163 mWindowBase->SetParent(nullptr, false);
1164 mParentWindow.Reset();
1167 Dali::Window Window::GetParent()
1169 return mParentWindow;
1172 WindowOrientation Window::GetCurrentOrientation() const
1174 return ConvertToOrientation(mRotationAngle);
1177 int Window::GetPhysicalOrientation() const
1179 return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
1182 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
1184 Dali::Vector<float>::SizeType count = orientations.Count();
1185 for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
1187 if(IsOrientationAvailable(orientations[index]) == false)
1189 DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1194 int convertedAngle = ConvertToAngle(orientations[index]);
1196 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1198 if(mAvailableAngles[i] == convertedAngle)
1207 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1208 mAvailableAngles.push_back(convertedAngle);
1211 SetAvailableAnlges(mAvailableAngles);
1214 int32_t Window::GetNativeId() const
1216 return mWindowBase->GetNativeWindowId();
1219 void Window::RequestMoveToServer()
1221 mWindowBase->RequestMoveToServer();
1224 void Window::RequestResizeToServer(WindowResizeDirection direction)
1226 mWindowBase->RequestResizeToServer(direction);
1229 void Window::EnableFloatingMode(bool enable)
1231 mWindowBase->EnableFloatingMode(enable);
1234 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
1237 int screenWidth, screenHeight;
1239 WindowSystem::GetScreenSize(screenWidth, screenHeight);
1241 if(mRotationAngle == 90)
1244 newRect.y = screenHeight - (rect.x + rect.width);
1245 newRect.width = rect.height;
1246 newRect.height = rect.width;
1248 else if(mRotationAngle == 180)
1250 newRect.x = screenWidth - (rect.x + rect.width);
1251 newRect.y = screenHeight - (rect.y + rect.height);
1252 newRect.width = rect.width;
1253 newRect.height = rect.height;
1255 else if(mRotationAngle == 270)
1257 newRect.x = screenWidth - (rect.y + rect.height);
1259 newRect.width = rect.height;
1260 newRect.height = rect.width;
1266 newRect.width = rect.width;
1267 newRect.height = rect.height;
1272 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1274 Rect<int> convertRegion = RecalculateRect(inputRegion);
1276 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);
1277 mWindowBase->IncludeInputRegion(convertRegion);
1280 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1282 Rect<int> convertRegion = RecalculateRect(inputRegion);
1284 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);
1285 mWindowBase->ExcludeInputRegion(convertRegion);
1288 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1290 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1291 mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1292 mWindowRotationAcknowledgement = needAcknowledgement;
1295 void Window::SendRotationCompletedAcknowledgement()
1297 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1298 if(mWindowRotationAcknowledgement)
1300 SetRotationCompletedAcknowledgement();
1304 bool Window::IsWindowRotating() const
1306 return mIsWindowRotating;
1309 const Dali::KeyEvent& Window::GetLastKeyEvent() const
1311 return mLastKeyEvent;
1314 const Dali::TouchEvent& Window::GetLastTouchEvent() const
1316 return mLastTouchEvent;
1319 } // namespace Adaptor
1321 } // namespace Internal