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");
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::OnAdaptorSet(Dali::Adaptor& adaptor)
201 mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
202 mEventHandler->AddObserver(*this);
204 // Add Window to bridge for ATSPI
205 auto bridge = Accessibility::Bridge::GetCurrentBridge();
208 auto rootLayer = mScene.GetRootLayer();
209 auto accessible = Accessibility::Accessible::Get(rootLayer);
210 bridge->AddTopLevelWindow(accessible);
213 bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
214 bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
216 // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
217 // The show must be called after the adaptor is initialized.
221 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
223 mWindowSurface = static_cast<WindowRenderSurface*>(surface);
226 void Window::SetClass(std::string name, std::string className)
229 mClassName = className;
230 mWindowBase->SetClass(name, className);
233 std::string Window::GetClassName() const
240 mWindowBase->Raise();
242 mSurface->SetFullSwapNextFrame();
244 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
249 mWindowBase->Lower();
251 mSurface->SetFullSwapNextFrame();
253 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
256 void Window::Activate()
258 mWindowBase->Activate();
260 mSurface->SetFullSwapNextFrame();
262 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
265 void Window::Maximize(bool maximize)
267 mWindowBase->Maximize(maximize);
269 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Maximize: %d\n", this, mNativeWindowId, maximize);
272 bool Window::IsMaximized() const
274 return mWindowBase->IsMaximized();
277 void Window::SetMaximumSize(Dali::Window::WindowSize size)
279 mWindowBase->SetMaximumSize(size);
282 void Window::Minimize(bool minimize)
284 mWindowBase->Minimize(minimize);
286 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Minimize: %d\n", this, mNativeWindowId, minimize);
289 bool Window::IsMinimized() const
291 return mWindowBase->IsMinimized();
294 void Window::SetMimimumSize(Dali::Window::WindowSize size)
296 mWindowBase->SetMimimumSize(size);
299 uint32_t Window::GetLayerCount() const
301 return mScene.GetLayerCount();
304 Dali::Layer Window::GetLayer(uint32_t depth) const
306 return mScene.GetLayer(depth);
309 Dali::RenderTaskList Window::GetRenderTaskList() const
311 return mScene.GetRenderTaskList();
314 std::string Window::GetNativeResourceId() const
316 return mWindowBase->GetNativeWindowResourceId();
319 void Window::AddAvailableOrientation(WindowOrientation orientation)
321 if(IsOrientationAvailable(orientation) == false)
327 int convertedAngle = ConvertToAngle(orientation);
328 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
329 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
331 if(mAvailableAngles[i] == convertedAngle)
340 mAvailableAngles.push_back(convertedAngle);
341 SetAvailableAnlges(mAvailableAngles);
345 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
347 if(IsOrientationAvailable(orientation) == false)
352 int convertedAngle = ConvertToAngle(orientation);
353 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
354 for(std::vector<int>::iterator iter = mAvailableAngles.begin();
355 iter != mAvailableAngles.end();
358 if(*iter == convertedAngle)
360 mAvailableAngles.erase(iter);
365 SetAvailableAnlges(mAvailableAngles);
368 void Window::SetPreferredOrientation(WindowOrientation orientation)
370 if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
372 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
375 mPreferredAngle = ConvertToAngle(orientation);
376 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
377 mWindowBase->SetPreferredAngle(mPreferredAngle);
380 WindowOrientation Window::GetPreferredOrientation()
382 WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
383 return preferredOrientation;
386 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
388 int angle = ConvertToAngle(orientation);
389 mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
392 void Window::EmitAccessibilityHighlightSignal(bool highlight)
394 Dali::Window handle(this);
395 mAccessibilityHighlightSignal.Emit(handle, highlight);
398 void Window::SetAvailableAnlges(const std::vector<int>& angles)
400 if(angles.size() > 4)
402 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
406 mWindowBase->SetAvailableAnlges(angles);
409 int Window::ConvertToAngle(WindowOrientation orientation)
411 int convertAngle = static_cast<int>(orientation);
412 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
416 case WindowOrientation::LANDSCAPE:
421 case WindowOrientation::PORTRAIT:
426 case WindowOrientation::LANDSCAPE_INVERSE:
431 case WindowOrientation::PORTRAIT_INVERSE:
436 case WindowOrientation::NO_ORIENTATION_PREFERENCE:
446 WindowOrientation Window::ConvertToOrientation(int angle) const
448 WindowOrientation orientation = static_cast<WindowOrientation>(angle);
449 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
455 orientation = WindowOrientation::LANDSCAPE;
460 orientation = WindowOrientation::PORTRAIT;
465 orientation = WindowOrientation::LANDSCAPE_INVERSE;
470 orientation = WindowOrientation::PORTRAIT_INVERSE;
475 orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
483 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
485 if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
487 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
493 Dali::Any Window::GetNativeHandle() const
495 return mWindowSurface->GetNativeWindow();
498 void Window::SetAcceptFocus(bool accept)
500 mIsFocusAcceptable = accept;
502 mWindowBase->SetAcceptFocus(accept);
505 bool Window::IsFocusAcceptable() const
507 return mIsFocusAcceptable;
518 Dali::Window handle(this);
519 mVisibilityChangedSignal.Emit(handle, true);
520 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
522 WindowVisibilityObserver* observer(mAdaptor);
523 observer->OnWindowShown();
526 mSurface->SetFullSwapNextFrame();
528 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
539 Dali::Window handle(this);
540 mVisibilityChangedSignal.Emit(handle, false);
541 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
543 WindowVisibilityObserver* observer(mAdaptor);
544 observer->OnWindowHidden();
547 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
550 bool Window::IsVisible() const
552 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
553 return mVisible && !mIconified;
556 unsigned int Window::GetSupportedAuxiliaryHintCount() const
558 return mWindowBase->GetSupportedAuxiliaryHintCount();
561 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
563 return mWindowBase->GetSupportedAuxiliaryHint(index);
566 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
568 return mWindowBase->AddAuxiliaryHint(hint, value);
571 bool Window::RemoveAuxiliaryHint(unsigned int id)
573 return mWindowBase->RemoveAuxiliaryHint(id);
576 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
578 return mWindowBase->SetAuxiliaryHintValue(id, value);
581 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
583 return mWindowBase->GetAuxiliaryHintValue(id);
586 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
588 return mWindowBase->GetAuxiliaryHintId(hint);
591 void Window::SetInputRegion(const Rect<int>& inputRegion)
593 Rect<int> convertRegion = RecalculateRect(inputRegion);
595 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);
597 mWindowBase->SetInputRegion(convertRegion);
600 void Window::SetType(WindowType type)
602 mWindowBase->SetType(type);
605 WindowType Window::GetType() const
607 return mWindowBase->GetType();
610 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
612 WindowType type = mWindowBase->GetType();
613 if(type != WindowType::NOTIFICATION)
615 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
616 return WindowOperationResult::INVALID_OPERATION;
619 return mWindowBase->SetNotificationLevel(level);
622 WindowNotificationLevel Window::GetNotificationLevel() const
624 WindowType type = mWindowBase->GetType();
625 if(type != WindowType::NOTIFICATION)
627 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
628 return WindowNotificationLevel::NONE;
631 return mWindowBase->GetNotificationLevel();
634 void Window::SetOpaqueState(bool opaque)
636 mOpaqueState = opaque;
638 mWindowBase->SetOpaqueState(opaque);
640 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
643 bool Window::IsOpaqueState() const
648 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
650 return mWindowBase->SetScreenOffMode(screenOffMode);
653 WindowScreenOffMode Window::GetScreenOffMode() const
655 return mWindowBase->GetScreenOffMode();
658 WindowOperationResult Window::SetBrightness(int brightness)
660 if(brightness < 0 || brightness > 100)
662 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
663 return WindowOperationResult::INVALID_OPERATION;
666 return mWindowBase->SetBrightness(brightness);
669 int Window::GetBrightness() const
671 return mWindowBase->GetBrightness();
674 void Window::SetSize(Dali::Window::WindowSize size)
676 PositionSize oldRect = GetPositionSize();
678 PositionSize newRect;
679 newRect.width = size.GetWidth();
680 newRect.height = size.GetHeight();
682 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
683 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
685 mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, newRect.width, newRect.height));
687 Uint16Pair newSize(newRect.width, newRect.height);
689 mWindowWidth = newRect.width;
690 mWindowHeight = newRect.height;
692 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);
694 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
696 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
698 Dali::Window handle(this);
699 mResizeSignal.Emit(handle, newSize);
701 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
704 mSurface->SetFullSwapNextFrame();
706 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
709 Dali::Window::WindowSize Window::GetSize() const
711 return Dali::Window::WindowSize(mWindowWidth, mWindowHeight);
714 void Window::SetPosition(Dali::Window::WindowPosition position)
716 PositionSize oldRect = mSurface->GetPositionSize();
717 int32_t newX = position.GetX();
718 int32_t newY = position.GetY();
720 mWindowSurface->MoveResize(PositionSize(newX, newY, oldRect.width, oldRect.height));
722 if((oldRect.x != newX) || (oldRect.y != newY))
724 Dali::Window handle(this);
725 Dali::Window::WindowPosition newPosition(newX, newY);
727 DALI_LOG_RELEASE_INFO("send moved signal with new position: %d, %d\n", newPosition.GetX(), newPosition.GetY());
728 mMovedSignal.Emit(handle, newPosition);
731 mSurface->SetFullSwapNextFrame();
733 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
736 Dali::Window::WindowPosition Window::GetPosition() const
738 PositionSize positionSize = GetPositionSize();
739 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
742 PositionSize Window::GetPositionSize() const
744 PositionSize positionSize = mSurface->GetPositionSize();
745 positionSize.width = mWindowWidth;
746 positionSize.height = mWindowHeight;
750 void Window::SetPositionSize(PositionSize positionSize)
755 PositionSize oldRect = GetPositionSize();
756 Dali::Window handle(this);
758 if((oldRect.x != positionSize.x) || (oldRect.y != positionSize.y))
763 if((oldRect.width != positionSize.width) || (oldRect.height != positionSize.height))
770 mWindowSurface->MoveResize(positionSize);
773 // When window is moved, emit Moved Signal
776 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, positionSize.x, positionSize.y);
777 Dali::Window::WindowPosition position(positionSize.x, positionSize.y);
778 mMovedSignal.Emit(handle, position);
781 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
784 Uint16Pair newSize(positionSize.width, positionSize.height);
786 mWindowWidth = positionSize.width;
787 mWindowHeight = positionSize.height;
789 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
791 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
793 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resize signal emit [%d x %d]\n", this, mNativeWindowId, positionSize.width, positionSize.height);
795 mResizeSignal.Emit(handle, newSize);
796 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
799 mSurface->SetFullSwapNextFrame();
801 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
804 Dali::Layer Window::GetRootLayer() const
806 return mScene.GetRootLayer();
809 void Window::SetTransparency(bool transparent)
811 mWindowSurface->SetTransparency(transparent);
814 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
816 return mWindowBase->GrabKey(key, grabMode);
819 bool Window::UngrabKey(Dali::KEY key)
821 return mWindowBase->UngrabKey(key);
824 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
826 return mWindowBase->GrabKeyList(key, grabMode, result);
829 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
831 return mWindowBase->UngrabKeyList(key, result);
834 void Window::OnIconifyChanged(bool iconified)
836 const bool isActuallyChanged = (iconified != mIconified);
837 auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge();
838 Dali::Window handle(this);
846 mVisibilityChangedSignal.Emit(handle, false);
847 bridge->WindowHidden(handle);
849 WindowVisibilityObserver* observer(mAdaptor);
850 observer->OnWindowHidden();
853 if(isActuallyChanged)
855 bridge->WindowMinimized(handle);
858 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
866 mVisibilityChangedSignal.Emit(handle, true);
867 bridge->WindowShown(handle);
869 WindowVisibilityObserver* observer(mAdaptor);
870 observer->OnWindowShown();
873 if(isActuallyChanged)
875 bridge->WindowRestored(handle, Dali::Accessibility::WindowRestoreType::RESTORE_FROM_ICONIFY);
878 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
881 mSurface->SetFullSwapNextFrame();
884 void Window::OnMaximizeChanged(bool maximized)
886 const bool isActuallyChanged = (maximized != mMaximized);
888 if(isActuallyChanged)
890 auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge();
891 Dali::Window handle(this);
896 bridge->WindowMaximized(handle);
901 bridge->WindowRestored(handle, Dali::Accessibility::WindowRestoreType::RESTORE_FROM_MAXIMIZE);
906 void Window::OnFocusChanged(bool focusIn)
908 Dali::Window handle(this);
909 mFocusChangeSignal.Emit(handle, focusIn);
911 mSurface->SetFullSwapNextFrame();
912 auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge();
916 bridge->WindowFocused(handle);
920 bridge->WindowUnfocused(handle);
926 void Window::OnOutputTransformed()
928 PositionSize positionSize = GetPositionSize();
930 SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), mRotationAngle, mWindowBase->GetScreenRotationAngle());
932 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
933 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
936 void Window::OnDeleteRequest()
938 mDeleteRequestSignal.Emit();
941 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
943 Dali::Window handle(this);
944 mTransitionEffectEventSignal.Emit(handle, state, type);
947 void Window::OnKeyboardRepeatSettingsChanged()
949 Dali::Window handle(this);
950 mKeyboardRepeatSettingsChangedSignal.Emit();
953 void Window::OnWindowRedrawRequest()
955 mAdaptor->RenderOnce();
958 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
963 Dali::Window handle(this);
965 PositionSize oldRect = GetPositionSize();
966 PositionSize newRect = positionSize;
968 if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
973 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
980 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);
981 mWindowSurface->UpdatePositionSize(positionSize);
984 if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
986 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, newRect.x, newRect.y);
987 Dali::Window::WindowPosition position(newRect.x, newRect.y);
988 mMovedSignal.Emit(handle, position);
991 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
992 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
994 Uint16Pair newSize(newRect.width, newRect.height);
996 mWindowWidth = newRect.width;
997 mWindowHeight = newRect.height;
999 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
1001 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
1003 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resized signal emit [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
1004 mResizeSignal.Emit(handle, newSize);
1005 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
1008 mSurface->SetFullSwapNextFrame();
1010 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
1013 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
1015 mLastTouchEvent = Dali::Integration::NewTouchEvent(timeStamp, point);
1016 FeedTouchPoint(point, timeStamp);
1019 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
1021 FeedWheelEvent(wheelEvent);
1024 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
1026 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);
1027 FeedKeyEvent(keyEvent);
1030 void Window::OnRotation(const RotationEvent& rotation)
1032 PositionSize newPositionSize(rotation.x, rotation.y, rotation.width, rotation.height);
1034 mRotationAngle = rotation.angle;
1035 mWindowWidth = rotation.width;
1036 mWindowHeight = rotation.height;
1038 mIsWindowRotating = true;
1039 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);
1041 // Notify that the orientation is changed
1042 mOrientation->OnOrientationChange(rotation);
1044 mWindowSurface->RequestRotation(mRotationAngle, newPositionSize);
1046 SurfaceRotated(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight), mRotationAngle, mWindowBase->GetScreenRotationAngle());
1048 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1050 Dali::Window handle(this);
1051 mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
1052 mOrientationChangedSignal.Emit(handle, GetCurrentOrientation());
1054 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1057 void Window::OnRotationFinished()
1059 mIsWindowRotating = false;
1060 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), window rotation is finised\n", this, mNativeWindowId);
1063 void Window::OnPause()
1067 mEventHandler->Pause();
1071 void Window::OnResume()
1075 mEventHandler->Resume();
1078 mSurface->SetFullSwapNextFrame();
1081 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
1083 mAuxiliaryMessageSignal.Emit(key, value, options);
1086 void Window::OnAccessibilityEnabled()
1088 auto bridge = Accessibility::Bridge::GetCurrentBridge();
1089 auto rootLayer = mScene.GetRootLayer();
1090 auto accessible = Accessibility::Accessible::Get(rootLayer);
1091 bridge->AddTopLevelWindow(accessible);
1093 if(!mVisible || mIconified)
1098 Dali::Window handle(this);
1099 bridge->WindowShown(handle);
1103 bridge->WindowFocused(handle);
1107 void Window::OnAccessibilityDisabled()
1109 auto bridge = Accessibility::Bridge::GetCurrentBridge();
1110 auto rootLayer = mScene.GetRootLayer();
1111 auto accessible = Accessibility::Accessible::Get(rootLayer);
1112 bridge->RemoveTopLevelWindow(accessible);
1115 void Window::RecalculateTouchPosition(Integration::Point& point)
1117 Vector2 position = point.GetScreenPosition();
1118 Vector2 convertedPosition;
1120 switch(mRotationAngle)
1124 convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
1125 convertedPosition.y = position.x;
1130 convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
1131 convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
1136 convertedPosition.x = position.y;
1137 convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
1142 convertedPosition = position;
1147 point.SetScreenPosition(convertedPosition);
1150 Dali::Window Window::Get(Dali::Actor actor)
1152 Internal::Adaptor::Window* windowImpl = nullptr;
1154 if(Internal::Adaptor::Adaptor::IsAvailable())
1156 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
1157 windowImpl = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
1160 return Dali::Window(windowImpl);
1164 return Dali::Window();
1167 void Window::SetParent(Dali::Window& parent)
1169 if(DALI_UNLIKELY(parent))
1171 mParentWindow = parent;
1172 Dali::Window self = Dali::Window(this);
1173 // check circular parent window setting
1174 if(Dali::DevelWindow::GetParent(parent) == self)
1176 Dali::DevelWindow::Unparent(parent);
1178 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
1182 void Window::SetParent(Dali::Window& parent, bool belowParent)
1184 if(DALI_UNLIKELY(parent))
1186 mParentWindow = parent;
1187 Dali::Window self = Dali::Window(this);
1188 // check circular parent window setting
1189 if(Dali::DevelWindow::GetParent(parent) == self)
1191 Dali::DevelWindow::Unparent(parent);
1193 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
1197 void Window::Unparent()
1199 mWindowBase->SetParent(nullptr, false);
1200 mParentWindow.Reset();
1203 Dali::Window Window::GetParent()
1205 return mParentWindow;
1208 WindowOrientation Window::GetCurrentOrientation() const
1210 return ConvertToOrientation(mRotationAngle);
1213 int Window::GetPhysicalOrientation() const
1215 return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
1218 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
1220 Dali::Vector<float>::SizeType count = orientations.Count();
1221 for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
1223 if(IsOrientationAvailable(orientations[index]) == false)
1225 DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1230 int convertedAngle = ConvertToAngle(orientations[index]);
1232 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1234 if(mAvailableAngles[i] == convertedAngle)
1243 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1244 mAvailableAngles.push_back(convertedAngle);
1247 SetAvailableAnlges(mAvailableAngles);
1250 int32_t Window::GetNativeId() const
1252 return mWindowBase->GetNativeWindowId();
1255 void Window::RequestMoveToServer()
1257 mWindowBase->RequestMoveToServer();
1260 void Window::RequestResizeToServer(WindowResizeDirection direction)
1262 mWindowBase->RequestResizeToServer(direction);
1265 void Window::EnableFloatingMode(bool enable)
1267 mWindowBase->EnableFloatingMode(enable);
1270 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
1273 int screenWidth, screenHeight;
1275 WindowSystem::GetScreenSize(screenWidth, screenHeight);
1277 if(mRotationAngle == 90)
1280 newRect.y = screenHeight - (rect.x + rect.width);
1281 newRect.width = rect.height;
1282 newRect.height = rect.width;
1284 else if(mRotationAngle == 180)
1286 newRect.x = screenWidth - (rect.x + rect.width);
1287 newRect.y = screenHeight - (rect.y + rect.height);
1288 newRect.width = rect.width;
1289 newRect.height = rect.height;
1291 else if(mRotationAngle == 270)
1293 newRect.x = screenWidth - (rect.y + rect.height);
1295 newRect.width = rect.height;
1296 newRect.height = rect.width;
1302 newRect.width = rect.width;
1303 newRect.height = rect.height;
1308 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1310 Rect<int> convertRegion = RecalculateRect(inputRegion);
1312 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);
1313 mWindowBase->IncludeInputRegion(convertRegion);
1316 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1318 Rect<int> convertRegion = RecalculateRect(inputRegion);
1320 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);
1321 mWindowBase->ExcludeInputRegion(convertRegion);
1324 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1326 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1327 mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1328 mWindowRotationAcknowledgement = needAcknowledgement;
1331 void Window::SendRotationCompletedAcknowledgement()
1333 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1334 if(mWindowRotationAcknowledgement)
1336 SetRotationCompletedAcknowledgement();
1340 bool Window::IsWindowRotating() const
1342 return mIsWindowRotating;
1345 const Dali::KeyEvent& Window::GetLastKeyEvent() const
1347 return mLastKeyEvent;
1350 const Dali::TouchEvent& Window::GetLastTouchEvent() const
1352 return mLastTouchEvent;
1355 } // namespace Adaptor
1357 } // namespace Internal