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(),
96 mOrientationChangedSignal(),
99 mIsTransparent(false),
100 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);
121 if(DALI_LIKELY(mAdaptor))
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->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
155 mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
156 mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
157 mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
158 mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
159 mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
160 mWindowBase->AuxiliaryMessageSignal().Connect(this, &Window::OnAuxiliaryMessage);
162 mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
163 mWindowSurface->RotationFinishedSignal().Connect(this, &Window::OnRotationFinished);
165 AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
167 SetClass(name, className);
169 mOrientation = Orientation::New(this);
171 // Get OrientationMode
172 int screenWidth, screenHeight;
173 WindowSystem::GetScreenSize(screenWidth, screenHeight);
174 if(screenWidth > screenHeight)
176 mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
180 mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
183 if(positionSize.width <= 0 || positionSize.height <= 0)
185 mWindowWidth = screenWidth;
186 mWindowHeight = screenHeight;
190 mWindowWidth = positionSize.width;
191 mWindowHeight = positionSize.height;
195 mNativeWindowId = mWindowBase->GetNativeWindowId();
198 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
200 mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
201 mEventHandler->AddObserver(*this);
203 // Add Window to bridge for ATSPI
204 auto bridge = Accessibility::Bridge::GetCurrentBridge();
207 auto rootLayer = mScene.GetRootLayer();
208 auto accessible = Accessibility::Accessible::Get(rootLayer);
209 bridge->AddTopLevelWindow(accessible);
212 bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
213 bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
215 // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
216 // The show must be called after the adaptor is initialized.
220 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
222 mWindowSurface = static_cast<WindowRenderSurface*>(surface);
225 void Window::SetClass(std::string name, std::string className)
228 mClassName = className;
229 mWindowBase->SetClass(name, className);
232 std::string Window::GetClassName() const
239 mWindowBase->Raise();
241 mSurface->SetFullSwapNextFrame();
243 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
248 mWindowBase->Lower();
250 mSurface->SetFullSwapNextFrame();
252 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
255 void Window::Activate()
257 mWindowBase->Activate();
259 mSurface->SetFullSwapNextFrame();
261 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
264 void Window::Maximize(bool maximize)
266 mWindowBase->Maximize(maximize);
268 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Maximize: %d\n", this, mNativeWindowId, maximize);
271 bool Window::IsMaximized() const
273 return mWindowBase->IsMaximized();
276 void Window::SetMaximumSize(Dali::Window::WindowSize size)
278 mWindowBase->SetMaximumSize(size);
281 void Window::Minimize(bool minimize)
283 mWindowBase->Minimize(minimize);
285 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Minimize: %d\n", this, mNativeWindowId, minimize);
288 bool Window::IsMinimized() const
290 return mWindowBase->IsMinimized();
293 void Window::SetMimimumSize(Dali::Window::WindowSize size)
295 mWindowBase->SetMimimumSize(size);
298 uint32_t Window::GetLayerCount() const
300 return mScene.GetLayerCount();
303 Dali::Layer Window::GetLayer(uint32_t depth) const
305 return mScene.GetLayer(depth);
308 Dali::RenderTaskList Window::GetRenderTaskList() const
310 return mScene.GetRenderTaskList();
313 std::string Window::GetNativeResourceId() const
315 return mWindowBase->GetNativeWindowResourceId();
318 void Window::AddAvailableOrientation(WindowOrientation orientation)
320 if(IsOrientationAvailable(orientation) == false)
326 int convertedAngle = ConvertToAngle(orientation);
327 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
328 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
330 if(mAvailableAngles[i] == convertedAngle)
339 mAvailableAngles.push_back(convertedAngle);
340 SetAvailableAnlges(mAvailableAngles);
344 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
346 if(IsOrientationAvailable(orientation) == false)
351 int convertedAngle = ConvertToAngle(orientation);
352 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
353 for(std::vector<int>::iterator iter = mAvailableAngles.begin();
354 iter != mAvailableAngles.end();
357 if(*iter == convertedAngle)
359 mAvailableAngles.erase(iter);
364 SetAvailableAnlges(mAvailableAngles);
367 void Window::SetPreferredOrientation(WindowOrientation orientation)
369 if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
371 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
374 mPreferredAngle = ConvertToAngle(orientation);
375 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
376 mWindowBase->SetPreferredAngle(mPreferredAngle);
379 WindowOrientation Window::GetPreferredOrientation()
381 WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
382 return preferredOrientation;
385 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
387 int angle = ConvertToAngle(orientation);
388 mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
391 void Window::EmitAccessibilityHighlightSignal(bool highlight)
393 Dali::Window handle(this);
394 mAccessibilityHighlightSignal.Emit(handle, highlight);
397 void Window::SetAvailableAnlges(const std::vector<int>& angles)
399 if(angles.size() > 4)
401 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
405 mWindowBase->SetAvailableAnlges(angles);
408 int Window::ConvertToAngle(WindowOrientation orientation)
410 int convertAngle = static_cast<int>(orientation);
411 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
415 case WindowOrientation::LANDSCAPE:
420 case WindowOrientation::PORTRAIT:
425 case WindowOrientation::LANDSCAPE_INVERSE:
430 case WindowOrientation::PORTRAIT_INVERSE:
435 case WindowOrientation::NO_ORIENTATION_PREFERENCE:
445 WindowOrientation Window::ConvertToOrientation(int angle) const
447 WindowOrientation orientation = static_cast<WindowOrientation>(angle);
448 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
454 orientation = WindowOrientation::LANDSCAPE;
459 orientation = WindowOrientation::PORTRAIT;
464 orientation = WindowOrientation::LANDSCAPE_INVERSE;
469 orientation = WindowOrientation::PORTRAIT_INVERSE;
474 orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
482 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
484 if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
486 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
492 Dali::Any Window::GetNativeHandle() const
494 return mWindowSurface->GetNativeWindow();
497 void Window::SetAcceptFocus(bool accept)
499 mIsFocusAcceptable = accept;
501 mWindowBase->SetAcceptFocus(accept);
504 bool Window::IsFocusAcceptable() const
506 return mIsFocusAcceptable;
517 Dali::Window handle(this);
518 mVisibilityChangedSignal.Emit(handle, true);
519 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
521 WindowVisibilityObserver* observer(mAdaptor);
522 observer->OnWindowShown();
525 mSurface->SetFullSwapNextFrame();
527 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
538 Dali::Window handle(this);
539 mVisibilityChangedSignal.Emit(handle, false);
540 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
542 WindowVisibilityObserver* observer(mAdaptor);
543 observer->OnWindowHidden();
546 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
549 bool Window::IsVisible() const
551 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
552 return mVisible && !mIconified;
555 unsigned int Window::GetSupportedAuxiliaryHintCount() const
557 return mWindowBase->GetSupportedAuxiliaryHintCount();
560 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
562 return mWindowBase->GetSupportedAuxiliaryHint(index);
565 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
567 return mWindowBase->AddAuxiliaryHint(hint, value);
570 bool Window::RemoveAuxiliaryHint(unsigned int id)
572 return mWindowBase->RemoveAuxiliaryHint(id);
575 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
577 return mWindowBase->SetAuxiliaryHintValue(id, value);
580 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
582 return mWindowBase->GetAuxiliaryHintValue(id);
585 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
587 return mWindowBase->GetAuxiliaryHintId(hint);
590 void Window::SetInputRegion(const Rect<int>& inputRegion)
592 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);
593 mWindowBase->SetInputRegion(inputRegion);
596 void Window::SetType(WindowType type)
598 mWindowBase->SetType(type);
601 WindowType Window::GetType() const
603 return mWindowBase->GetType();
606 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
608 WindowType type = mWindowBase->GetType();
609 if(type != WindowType::NOTIFICATION)
611 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
612 return WindowOperationResult::INVALID_OPERATION;
615 return mWindowBase->SetNotificationLevel(level);
618 WindowNotificationLevel Window::GetNotificationLevel() const
620 WindowType type = mWindowBase->GetType();
621 if(type != WindowType::NOTIFICATION)
623 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
624 return WindowNotificationLevel::NONE;
627 return mWindowBase->GetNotificationLevel();
630 void Window::SetOpaqueState(bool opaque)
632 mOpaqueState = opaque;
634 mWindowBase->SetOpaqueState(opaque);
636 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
639 bool Window::IsOpaqueState() const
644 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
646 return mWindowBase->SetScreenOffMode(screenOffMode);
649 WindowScreenOffMode Window::GetScreenOffMode() const
651 return mWindowBase->GetScreenOffMode();
654 WindowOperationResult Window::SetBrightness(int brightness)
656 if(brightness < 0 || brightness > 100)
658 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
659 return WindowOperationResult::INVALID_OPERATION;
662 return mWindowBase->SetBrightness(brightness);
665 int Window::GetBrightness() const
667 return mWindowBase->GetBrightness();
670 void Window::SetSize(Dali::Window::WindowSize size)
672 PositionSize oldRect = GetPositionSize();
674 PositionSize newRect;
675 newRect.width = size.GetWidth();
676 newRect.height = size.GetHeight();
678 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
679 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
681 mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, newRect.width, newRect.height));
683 Uint16Pair newSize(newRect.width, newRect.height);
685 mWindowWidth = newRect.width;
686 mWindowHeight = newRect.height;
688 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);
690 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
692 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
694 Dali::Window handle(this);
695 mResizeSignal.Emit(handle, newSize);
697 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
700 mSurface->SetFullSwapNextFrame();
702 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
705 Dali::Window::WindowSize Window::GetSize() const
707 return Dali::Window::WindowSize(mWindowWidth, mWindowHeight);
710 void Window::SetPosition(Dali::Window::WindowPosition position)
712 PositionSize oldRect = mSurface->GetPositionSize();
713 int32_t newX = position.GetX();
714 int32_t newY = position.GetY();
716 mWindowSurface->MoveResize(PositionSize(newX, newY, oldRect.width, oldRect.height));
718 if((oldRect.x != newX) || (oldRect.y != newY))
720 Dali::Window handle(this);
721 Dali::Window::WindowPosition newPosition(newX, newY);
723 DALI_LOG_RELEASE_INFO("send moved signal with new position: %d, %d\n", newPosition.GetX(), newPosition.GetY());
724 mMovedSignal.Emit(handle, newPosition);
727 mSurface->SetFullSwapNextFrame();
729 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
732 Dali::Window::WindowPosition Window::GetPosition() const
734 PositionSize positionSize = GetPositionSize();
735 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
738 PositionSize Window::GetPositionSize() const
740 PositionSize positionSize = mSurface->GetPositionSize();
741 positionSize.width = mWindowWidth;
742 positionSize.height = mWindowHeight;
746 void Window::SetPositionSize(PositionSize positionSize)
751 PositionSize oldRect = GetPositionSize();
752 Dali::Window handle(this);
754 if((oldRect.x != positionSize.x) || (oldRect.y != positionSize.y))
759 if((oldRect.width != positionSize.width) || (oldRect.height != positionSize.height))
766 mWindowSurface->MoveResize(positionSize);
769 // When window is moved, emit Moved Signal
772 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, positionSize.x, positionSize.y);
773 Dali::Window::WindowPosition position(positionSize.x, positionSize.y);
774 mMovedSignal.Emit(handle, position);
777 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
780 Uint16Pair newSize(positionSize.width, positionSize.height);
782 mWindowWidth = positionSize.width;
783 mWindowHeight = positionSize.height;
785 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
787 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
789 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resize signal emit [%d x %d]\n", this, mNativeWindowId, positionSize.width, positionSize.height);
791 mResizeSignal.Emit(handle, newSize);
792 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
795 mSurface->SetFullSwapNextFrame();
797 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
800 Dali::Layer Window::GetRootLayer() const
802 return mScene.GetRootLayer();
805 void Window::SetTransparency(bool transparent)
807 mWindowSurface->SetTransparency(transparent);
810 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
812 return mWindowBase->GrabKey(key, grabMode);
815 bool Window::UngrabKey(Dali::KEY key)
817 return mWindowBase->UngrabKey(key);
820 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
822 return mWindowBase->GrabKeyList(key, grabMode, result);
825 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
827 return mWindowBase->UngrabKeyList(key, result);
830 void Window::OnIconifyChanged(bool iconified)
838 Dali::Window handle(this);
839 mVisibilityChangedSignal.Emit(handle, false);
840 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
842 if(DALI_LIKELY(mAdaptor))
844 WindowVisibilityObserver* observer(mAdaptor);
845 observer->OnWindowHidden();
849 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
857 Dali::Window handle(this);
858 mVisibilityChangedSignal.Emit(handle, true);
859 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
861 if(DALI_LIKELY(mAdaptor))
863 WindowVisibilityObserver* observer(mAdaptor);
864 observer->OnWindowShown();
868 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
871 mSurface->SetFullSwapNextFrame();
874 void Window::OnFocusChanged(bool focusIn)
876 Dali::Window handle(this);
877 mFocusChangeSignal.Emit(handle, focusIn);
879 mSurface->SetFullSwapNextFrame();
881 if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
885 bridge->WindowFocused(handle);
889 bridge->WindowUnfocused(handle);
895 void Window::OnOutputTransformed()
897 PositionSize positionSize = GetPositionSize();
899 SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), mRotationAngle, mWindowBase->GetScreenRotationAngle());
901 if(DALI_LIKELY(mAdaptor))
903 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
904 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
908 void Window::OnDeleteRequest()
910 mDeleteRequestSignal.Emit();
913 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
915 Dali::Window handle(this);
916 mTransitionEffectEventSignal.Emit(handle, state, type);
919 void Window::OnKeyboardRepeatSettingsChanged()
921 Dali::Window handle(this);
922 mKeyboardRepeatSettingsChangedSignal.Emit();
925 void Window::OnWindowRedrawRequest()
927 if(DALI_LIKELY(mAdaptor))
929 mAdaptor->RenderOnce();
933 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
938 Dali::Window handle(this);
940 PositionSize oldRect = GetPositionSize();
941 PositionSize newRect = positionSize;
943 if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
948 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
955 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);
956 mWindowSurface->UpdatePositionSize(positionSize);
959 if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
961 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, newRect.x, newRect.y);
962 Dali::Window::WindowPosition position(newRect.x, newRect.y);
963 mMovedSignal.Emit(handle, position);
966 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
967 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
969 Uint16Pair newSize(newRect.width, newRect.height);
971 mWindowWidth = newRect.width;
972 mWindowHeight = newRect.height;
974 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
976 if(DALI_LIKELY(mAdaptor))
978 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
981 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resized signal emit [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
982 mResizeSignal.Emit(handle, newSize);
983 if(DALI_LIKELY(mAdaptor))
985 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
989 mSurface->SetFullSwapNextFrame();
991 if(DALI_LIKELY(mScene))
993 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
997 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
999 mLastTouchEvent = Dali::Integration::NewTouchEvent(timeStamp, point);
1000 FeedTouchPoint(point, timeStamp);
1003 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
1005 FeedWheelEvent(wheelEvent);
1008 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
1010 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);
1011 FeedKeyEvent(keyEvent);
1014 void Window::OnRotation(const RotationEvent& rotation)
1016 PositionSize newPositionSize(rotation.x, rotation.y, rotation.width, rotation.height);
1018 mRotationAngle = rotation.angle;
1019 mWindowWidth = rotation.width;
1020 mWindowHeight = rotation.height;
1022 mIsWindowRotating = true;
1023 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);
1025 // Notify that the orientation is changed
1026 mOrientation->OnOrientationChange(rotation);
1028 mWindowSurface->RequestRotation(mRotationAngle, newPositionSize);
1030 SurfaceRotated(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight), mRotationAngle, mWindowBase->GetScreenRotationAngle());
1032 if(DALI_LIKELY(mAdaptor))
1034 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1037 Dali::Window handle(this);
1038 mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
1039 mOrientationChangedSignal.Emit(handle, GetCurrentOrientation());
1041 if(DALI_LIKELY(mAdaptor))
1043 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1047 void Window::OnRotationFinished()
1049 mIsWindowRotating = false;
1050 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), window rotation is finised\n", this, mNativeWindowId);
1053 void Window::OnPause()
1057 mEventHandler->Pause();
1061 void Window::OnResume()
1065 mEventHandler->Resume();
1068 mSurface->SetFullSwapNextFrame();
1071 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
1073 mAuxiliaryMessageSignal.Emit(key, value, options);
1076 void Window::OnAccessibilityEnabled()
1078 auto bridge = Accessibility::Bridge::GetCurrentBridge();
1079 auto rootLayer = mScene.GetRootLayer();
1080 auto accessible = Accessibility::Accessible::Get(rootLayer);
1081 bridge->AddTopLevelWindow(accessible);
1083 if(!mVisible || mIconified)
1088 Dali::Window handle(this);
1089 bridge->WindowShown(handle);
1093 bridge->WindowFocused(handle);
1097 void Window::OnAccessibilityDisabled()
1099 auto bridge = Accessibility::Bridge::GetCurrentBridge();
1100 auto rootLayer = mScene.GetRootLayer();
1101 auto accessible = Accessibility::Accessible::Get(rootLayer);
1102 bridge->RemoveTopLevelWindow(accessible);
1105 Vector2 Window::RecalculatePosition(const Vector2& position)
1107 Vector2 convertedPosition;
1109 switch(mRotationAngle)
1113 convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
1114 convertedPosition.y = position.x;
1119 convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
1120 convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
1125 convertedPosition.x = position.y;
1126 convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
1131 convertedPosition = position;
1135 return convertedPosition;
1138 Dali::Window Window::Get(Dali::Actor actor)
1140 Internal::Adaptor::Window* windowImpl = nullptr;
1142 if(Internal::Adaptor::Adaptor::IsAvailable())
1144 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
1145 windowImpl = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
1148 return Dali::Window(windowImpl);
1152 return Dali::Window();
1155 void Window::SetParent(Dali::Window& parent)
1157 if(DALI_UNLIKELY(parent))
1159 mParentWindow = parent;
1160 Dali::Window self = Dali::Window(this);
1161 // check circular parent window setting
1162 if(Dali::DevelWindow::GetParent(parent) == self)
1164 Dali::DevelWindow::Unparent(parent);
1166 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
1170 void Window::SetParent(Dali::Window& parent, bool belowParent)
1172 if(DALI_UNLIKELY(parent))
1174 mParentWindow = parent;
1175 Dali::Window self = Dali::Window(this);
1176 // check circular parent window setting
1177 if(Dali::DevelWindow::GetParent(parent) == self)
1179 Dali::DevelWindow::Unparent(parent);
1181 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
1185 void Window::Unparent()
1187 mWindowBase->SetParent(nullptr, false);
1188 mParentWindow.Reset();
1191 Dali::Window Window::GetParent()
1193 return mParentWindow;
1196 WindowOrientation Window::GetCurrentOrientation() const
1198 return ConvertToOrientation(mRotationAngle);
1201 int Window::GetPhysicalOrientation() const
1203 return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
1206 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
1208 Dali::Vector<float>::SizeType count = orientations.Count();
1209 for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
1211 if(IsOrientationAvailable(orientations[index]) == false)
1213 DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1218 int convertedAngle = ConvertToAngle(orientations[index]);
1220 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1222 if(mAvailableAngles[i] == convertedAngle)
1231 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1232 mAvailableAngles.push_back(convertedAngle);
1235 SetAvailableAnlges(mAvailableAngles);
1238 int32_t Window::GetNativeId() const
1240 return mWindowBase->GetNativeWindowId();
1243 void Window::RequestMoveToServer()
1245 mWindowBase->RequestMoveToServer();
1248 void Window::RequestResizeToServer(WindowResizeDirection direction)
1250 mWindowBase->RequestResizeToServer(direction);
1253 void Window::EnableFloatingMode(bool enable)
1255 mWindowBase->EnableFloatingMode(enable);
1258 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1260 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);
1261 mWindowBase->IncludeInputRegion(inputRegion);
1264 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1266 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);
1267 mWindowBase->ExcludeInputRegion(inputRegion);
1270 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1272 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1273 mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1274 mWindowRotationAcknowledgement = needAcknowledgement;
1277 void Window::SendRotationCompletedAcknowledgement()
1279 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1280 if(mWindowRotationAcknowledgement)
1282 SetRotationCompletedAcknowledgement();
1286 bool Window::IsWindowRotating() const
1288 return mIsWindowRotating;
1291 const Dali::KeyEvent& Window::GetLastKeyEvent() const
1293 return mLastKeyEvent;
1296 const Dali::TouchEvent& Window::GetLastTouchEvent() const
1298 return mLastTouchEvent;
1301 } // namespace Adaptor
1303 } // namespace Internal