2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include <dali/internal/window-system/common/window-impl.h>
22 #include <dali/devel-api/adaptor-framework/orientation.h>
23 #include <dali/devel-api/events/key-event-devel.h>
24 #include <dali/integration-api/core.h>
25 #include <dali/integration-api/events/touch-event-integ.h>
26 #include <dali/integration-api/events/touch-integ.h>
27 #include <dali/public-api/actors/actor.h>
28 #include <dali/public-api/actors/camera-actor.h>
29 #include <dali/public-api/actors/layer.h>
30 #include <dali/public-api/adaptor-framework/window-enumerations.h>
31 #include <dali/public-api/render-tasks/render-task-list.h>
32 #include <dali/public-api/render-tasks/render-task.h>
33 #include <dali/public-api/rendering/frame-buffer.h>
37 #include <dali/devel-api/adaptor-framework/accessibility-bridge.h>
38 #include <dali/devel-api/atspi-interfaces/accessible.h>
39 #include <dali/integration-api/adaptor-framework/render-surface-interface.h>
40 #include <dali/internal/graphics/gles/egl-graphics.h>
41 #include <dali/internal/window-system/common/event-handler.h>
42 #include <dali/internal/window-system/common/orientation-impl.h>
43 #include <dali/internal/window-system/common/render-surface-factory.h>
44 #include <dali/internal/window-system/common/window-base.h>
45 #include <dali/internal/window-system/common/window-factory.h>
46 #include <dali/internal/window-system/common/window-render-surface.h>
47 #include <dali/internal/window-system/common/window-system.h>
48 #include <dali/internal/window-system/common/window-visibility-observer.h>
58 #if defined(DEBUG_ENABLED)
59 Debug::Filter* gWindowLogFilter = Debug::Filter::New(Debug::NoLogging, false, "LOG_WINDOW");
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(),
97 mMouseInOutEventSignal(),
100 mIsTransparent(false),
101 mIsFocusAcceptable(true),
104 mWindowRotationAcknowledgement(false),
106 mIsWindowRotating(false)
114 auto bridge = Accessibility::Bridge::GetCurrentBridge();
115 auto rootLayer = mScene.GetRootLayer();
116 auto accessible = Accessibility::Accessible::Get(rootLayer);
117 bridge->RemoveTopLevelWindow(accessible);
118 // Related to multi-window case. This is called for default window and non-default window, but it is effective for non-default window.
119 bridge->Emit(accessible, Accessibility::WindowEvent::DESTROY);
122 if(DALI_LIKELY(mAdaptor))
124 mAdaptor->RemoveWindow(this);
129 mEventHandler->RemoveObserver(*this);
133 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type)
135 // Create a window render surface
136 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
137 mSurface = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
138 mWindowSurface = static_cast<WindowRenderSurface*>(mSurface.get());
141 mWindowBase = mWindowSurface->GetWindowBase();
144 mWindowBase->SetType(type);
146 // Initialize for Ime window type
147 if(type == WindowType::IME)
149 mWindowBase->InitializeIme();
150 mWindowSurface->InitializeImeSurface();
154 mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
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);
162 mWindowBase->MouseInOutEventSignal().Connect(this, &Window::OnMouseInOutEvent);
164 mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
165 mWindowSurface->RotationFinishedSignal().Connect(this, &Window::OnRotationFinished);
167 AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
169 SetClass(name, className);
171 mOrientation = Orientation::New(this);
173 // Get OrientationMode
174 int screenWidth, screenHeight;
175 WindowSystem::GetScreenSize(screenWidth, screenHeight);
176 if(screenWidth > screenHeight)
178 mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
182 mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
185 if(positionSize.width <= 0 || positionSize.height <= 0)
187 mWindowWidth = screenWidth;
188 mWindowHeight = screenHeight;
192 mWindowWidth = positionSize.width;
193 mWindowHeight = positionSize.height;
197 mNativeWindowId = mWindowBase->GetNativeWindowId();
200 void Window::SetRenderNotification(TriggerEventInterface* renderNotification)
207 mWindowSurface->SetRenderNotification(renderNotification);
210 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
212 mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
213 mEventHandler->AddObserver(*this);
215 // Add Window to bridge for ATSPI
216 auto bridge = Accessibility::Bridge::GetCurrentBridge();
219 auto rootLayer = mScene.GetRootLayer();
220 auto accessible = Accessibility::Accessible::Get(rootLayer);
221 bridge->AddTopLevelWindow(accessible);
224 bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
225 bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
227 // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
228 // The show must be called after the adaptor is initialized.
232 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
234 mWindowSurface = static_cast<WindowRenderSurface*>(surface);
237 void Window::SetClass(std::string name, std::string className)
240 mClassName = className;
241 mWindowBase->SetClass(name, className);
244 std::string Window::GetClassName() const
251 mWindowBase->Raise();
253 mSurface->SetFullSwapNextFrame();
255 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
260 mWindowBase->Lower();
262 mSurface->SetFullSwapNextFrame();
264 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
267 void Window::Activate()
269 mWindowBase->Activate();
271 mSurface->SetFullSwapNextFrame();
273 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
276 void Window::Maximize(bool maximize)
278 mWindowBase->Maximize(maximize);
280 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Maximize: %d\n", this, mNativeWindowId, maximize);
283 bool Window::IsMaximized() const
285 return mWindowBase->IsMaximized();
288 void Window::SetMaximumSize(Dali::Window::WindowSize size)
290 mWindowBase->SetMaximumSize(size);
293 void Window::Minimize(bool minimize)
295 mWindowBase->Minimize(minimize);
297 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Minimize: %d\n", this, mNativeWindowId, minimize);
300 bool Window::IsMinimized() const
302 return mWindowBase->IsMinimized();
305 void Window::SetMimimumSize(Dali::Window::WindowSize size)
307 mWindowBase->SetMimimumSize(size);
310 uint32_t Window::GetLayerCount() const
312 return mScene.GetLayerCount();
315 Dali::Layer Window::GetLayer(uint32_t depth) const
317 return mScene.GetLayer(depth);
320 Dali::RenderTaskList Window::GetRenderTaskList() const
322 return mScene.GetRenderTaskList();
325 std::string Window::GetNativeResourceId() const
327 return mWindowBase->GetNativeWindowResourceId();
330 void Window::AddAvailableOrientation(WindowOrientation orientation)
332 if(IsOrientationAvailable(orientation) == false)
338 int convertedAngle = ConvertToAngle(orientation);
339 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
340 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
342 if(mAvailableAngles[i] == convertedAngle)
351 mAvailableAngles.push_back(convertedAngle);
352 SetAvailableAnlges(mAvailableAngles);
356 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
358 if(IsOrientationAvailable(orientation) == false)
363 int convertedAngle = ConvertToAngle(orientation);
364 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
365 for(std::vector<int>::iterator iter = mAvailableAngles.begin();
366 iter != mAvailableAngles.end();
369 if(*iter == convertedAngle)
371 mAvailableAngles.erase(iter);
376 SetAvailableAnlges(mAvailableAngles);
379 void Window::SetPreferredOrientation(WindowOrientation orientation)
381 if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
383 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
386 mPreferredAngle = ConvertToAngle(orientation);
387 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
388 mWindowBase->SetPreferredAngle(mPreferredAngle);
391 WindowOrientation Window::GetPreferredOrientation()
393 WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
394 return preferredOrientation;
397 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
399 int angle = ConvertToAngle(orientation);
400 mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
403 void Window::EmitAccessibilityHighlightSignal(bool highlight)
405 Dali::Window handle(this);
406 mAccessibilityHighlightSignal.Emit(handle, highlight);
409 void Window::SetAvailableAnlges(const std::vector<int>& angles)
411 if(angles.size() > 4)
413 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
417 mWindowBase->SetAvailableAnlges(angles);
420 int Window::ConvertToAngle(WindowOrientation orientation)
422 int convertAngle = static_cast<int>(orientation);
423 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
427 case WindowOrientation::LANDSCAPE:
432 case WindowOrientation::PORTRAIT:
437 case WindowOrientation::LANDSCAPE_INVERSE:
442 case WindowOrientation::PORTRAIT_INVERSE:
447 case WindowOrientation::NO_ORIENTATION_PREFERENCE:
457 WindowOrientation Window::ConvertToOrientation(int angle) const
459 WindowOrientation orientation = static_cast<WindowOrientation>(angle);
460 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
466 orientation = WindowOrientation::LANDSCAPE;
471 orientation = WindowOrientation::PORTRAIT;
476 orientation = WindowOrientation::LANDSCAPE_INVERSE;
481 orientation = WindowOrientation::PORTRAIT_INVERSE;
486 orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
494 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
496 if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
498 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
504 Dali::Any Window::GetNativeHandle() const
506 return mWindowSurface->GetNativeWindow();
509 void Window::SetAcceptFocus(bool accept)
511 mIsFocusAcceptable = accept;
513 mWindowBase->SetAcceptFocus(accept);
516 bool Window::IsFocusAcceptable() const
518 return mIsFocusAcceptable;
529 Dali::Window handle(this);
530 mVisibilityChangedSignal.Emit(handle, true);
531 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
533 WindowVisibilityObserver* observer(mAdaptor);
534 observer->OnWindowShown();
537 mSurface->SetFullSwapNextFrame();
539 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
550 Dali::Window handle(this);
551 mVisibilityChangedSignal.Emit(handle, false);
552 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
554 WindowVisibilityObserver* observer(mAdaptor);
555 observer->OnWindowHidden();
558 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
561 bool Window::IsVisible() const
563 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
564 return mVisible && !mIconified;
567 unsigned int Window::GetSupportedAuxiliaryHintCount() const
569 return mWindowBase->GetSupportedAuxiliaryHintCount();
572 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
574 return mWindowBase->GetSupportedAuxiliaryHint(index);
577 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
579 return mWindowBase->AddAuxiliaryHint(hint, value);
582 bool Window::RemoveAuxiliaryHint(unsigned int id)
584 return mWindowBase->RemoveAuxiliaryHint(id);
587 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
589 return mWindowBase->SetAuxiliaryHintValue(id, value);
592 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
594 return mWindowBase->GetAuxiliaryHintValue(id);
597 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
599 return mWindowBase->GetAuxiliaryHintId(hint);
602 void Window::SetInputRegion(const Rect<int>& inputRegion)
604 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);
605 mWindowBase->SetInputRegion(inputRegion);
608 void Window::SetType(WindowType type)
610 mWindowBase->SetType(type);
613 WindowType Window::GetType() const
615 return mWindowBase->GetType();
618 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
620 WindowType type = mWindowBase->GetType();
621 if(type != WindowType::NOTIFICATION)
623 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
624 return WindowOperationResult::INVALID_OPERATION;
627 return mWindowBase->SetNotificationLevel(level);
630 WindowNotificationLevel Window::GetNotificationLevel() const
632 WindowType type = mWindowBase->GetType();
633 if(type != WindowType::NOTIFICATION)
635 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
636 return WindowNotificationLevel::NONE;
639 return mWindowBase->GetNotificationLevel();
642 void Window::SetOpaqueState(bool opaque)
644 mOpaqueState = opaque;
646 mWindowBase->SetOpaqueState(opaque);
648 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
651 bool Window::IsOpaqueState() const
656 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
658 return mWindowBase->SetScreenOffMode(screenOffMode);
661 WindowScreenOffMode Window::GetScreenOffMode() const
663 return mWindowBase->GetScreenOffMode();
666 WindowOperationResult Window::SetBrightness(int brightness)
668 if(brightness < 0 || brightness > 100)
670 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
671 return WindowOperationResult::INVALID_OPERATION;
674 return mWindowBase->SetBrightness(brightness);
677 int Window::GetBrightness() const
679 return mWindowBase->GetBrightness();
682 void Window::SetSize(Dali::Window::WindowSize size)
684 PositionSize oldRect = GetPositionSize();
686 PositionSize newRect;
687 newRect.width = size.GetWidth();
688 newRect.height = size.GetHeight();
690 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
691 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
693 mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, newRect.width, newRect.height));
695 Uint16Pair newSize(newRect.width, newRect.height);
697 mWindowWidth = newRect.width;
698 mWindowHeight = newRect.height;
700 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);
702 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
704 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
706 Dali::Window handle(this);
707 mResizeSignal.Emit(handle, newSize);
709 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
712 mSurface->SetFullSwapNextFrame();
714 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
717 Dali::Window::WindowSize Window::GetSize() const
719 return Dali::Window::WindowSize(mWindowWidth, mWindowHeight);
722 void Window::SetPosition(Dali::Window::WindowPosition position)
724 PositionSize oldRect = mSurface->GetPositionSize();
725 int32_t newX = position.GetX();
726 int32_t newY = position.GetY();
728 mWindowSurface->MoveResize(PositionSize(newX, newY, oldRect.width, oldRect.height));
730 if((oldRect.x != newX) || (oldRect.y != newY))
732 Dali::Window handle(this);
733 Dali::Window::WindowPosition newPosition(newX, newY);
735 DALI_LOG_RELEASE_INFO("send moved signal with new position: %d, %d\n", newPosition.GetX(), newPosition.GetY());
736 mMovedSignal.Emit(handle, newPosition);
739 mSurface->SetFullSwapNextFrame();
741 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
744 Dali::Window::WindowPosition Window::GetPosition() const
746 PositionSize positionSize = GetPositionSize();
747 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
750 PositionSize Window::GetPositionSize() const
752 PositionSize positionSize = mSurface->GetPositionSize();
753 positionSize.width = mWindowWidth;
754 positionSize.height = mWindowHeight;
758 void Window::SetPositionSize(PositionSize positionSize)
763 PositionSize oldRect = GetPositionSize();
764 Dali::Window handle(this);
766 if((oldRect.x != positionSize.x) || (oldRect.y != positionSize.y))
771 if((oldRect.width != positionSize.width) || (oldRect.height != positionSize.height))
778 mWindowSurface->MoveResize(positionSize);
781 // When window is moved, emit Moved Signal
784 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, positionSize.x, positionSize.y);
785 Dali::Window::WindowPosition position(positionSize.x, positionSize.y);
786 mMovedSignal.Emit(handle, position);
789 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
792 Uint16Pair newSize(positionSize.width, positionSize.height);
794 mWindowWidth = positionSize.width;
795 mWindowHeight = positionSize.height;
797 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
799 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
801 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resize signal emit [%d x %d]\n", this, mNativeWindowId, positionSize.width, positionSize.height);
803 mResizeSignal.Emit(handle, newSize);
804 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
807 mSurface->SetFullSwapNextFrame();
809 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
812 void Window::SetLayout(unsigned int numCols, unsigned int numRows, unsigned int column, unsigned int row, unsigned int colSpan, unsigned int rowSpan)
814 mWindowBase->SetLayout(numCols, numRows, column, row, colSpan, rowSpan);
817 Dali::Layer Window::GetRootLayer() const
819 return mScene.GetRootLayer();
822 void Window::SetTransparency(bool transparent)
824 mWindowSurface->SetTransparency(transparent);
827 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
829 return mWindowBase->GrabKey(key, grabMode);
832 bool Window::UngrabKey(Dali::KEY key)
834 return mWindowBase->UngrabKey(key);
837 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
839 return mWindowBase->GrabKeyList(key, grabMode, result);
842 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
844 return mWindowBase->UngrabKeyList(key, result);
847 void Window::OnIconifyChanged(bool iconified)
855 Dali::Window handle(this);
856 mVisibilityChangedSignal.Emit(handle, false);
857 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
859 if(DALI_LIKELY(mAdaptor))
861 WindowVisibilityObserver* observer(mAdaptor);
862 observer->OnWindowHidden();
866 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
874 Dali::Window handle(this);
875 mVisibilityChangedSignal.Emit(handle, true);
876 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
878 if(DALI_LIKELY(mAdaptor))
880 WindowVisibilityObserver* observer(mAdaptor);
881 observer->OnWindowShown();
885 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
888 mSurface->SetFullSwapNextFrame();
891 void Window::OnFocusChanged(bool focusIn)
893 Dali::Window handle(this);
894 mFocusChangeSignal.Emit(handle, focusIn);
896 mSurface->SetFullSwapNextFrame();
898 if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
902 bridge->WindowFocused(handle);
906 bridge->WindowUnfocused(handle);
912 void Window::OnOutputTransformed()
914 PositionSize positionSize = GetPositionSize();
916 SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), mRotationAngle, mWindowBase->GetScreenRotationAngle());
918 if(DALI_LIKELY(mAdaptor))
920 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
921 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
925 void Window::OnDeleteRequest()
927 mDeleteRequestSignal.Emit();
930 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
932 Dali::Window handle(this);
933 mTransitionEffectEventSignal.Emit(handle, state, type);
936 void Window::OnKeyboardRepeatSettingsChanged()
938 Dali::Window handle(this);
939 mKeyboardRepeatSettingsChangedSignal.Emit();
942 void Window::OnWindowRedrawRequest()
944 if(DALI_LIKELY(mAdaptor))
946 mAdaptor->RenderOnce();
950 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
955 Dali::Window handle(this);
957 PositionSize oldRect = GetPositionSize();
958 PositionSize newRect = positionSize;
960 if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
965 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
972 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);
973 mWindowSurface->UpdatePositionSize(positionSize);
976 if((oldRect.x != newRect.x) || (oldRect.y != newRect.y))
978 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Moved signal emit (%d, %d)\n", this, mNativeWindowId, newRect.x, newRect.y);
979 Dali::Window::WindowPosition position(newRect.x, newRect.y);
980 mMovedSignal.Emit(handle, position);
983 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
984 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
986 Uint16Pair newSize(newRect.width, newRect.height);
988 mWindowWidth = newRect.width;
989 mWindowHeight = newRect.height;
991 SurfaceResized(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight));
993 if(DALI_LIKELY(mAdaptor))
995 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
998 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Resized signal emit [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
999 mResizeSignal.Emit(handle, newSize);
1000 if(DALI_LIKELY(mAdaptor))
1002 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
1006 mSurface->SetFullSwapNextFrame();
1008 if(DALI_LIKELY(mScene))
1010 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
1014 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
1016 mLastTouchEvent = Dali::Integration::NewTouchEvent(timeStamp, point);
1017 FeedTouchPoint(point, timeStamp);
1020 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
1022 FeedWheelEvent(wheelEvent);
1025 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
1027 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);
1028 FeedKeyEvent(keyEvent);
1031 void Window::OnMouseInOutEvent(const Dali::DevelWindow::MouseInOutEvent& mouseInOutEvent)
1033 Dali::Window handle(this);
1035 mMouseInOutEventSignal.Emit(handle, mouseInOutEvent);
1038 void Window::OnRotation(const RotationEvent& rotation)
1040 PositionSize newPositionSize(rotation.x, rotation.y, rotation.width, rotation.height);
1042 mRotationAngle = rotation.angle;
1043 mWindowWidth = rotation.width;
1044 mWindowHeight = rotation.height;
1046 mIsWindowRotating = true;
1047 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);
1049 // Notify that the orientation is changed
1050 mOrientation->OnOrientationChange(rotation);
1052 mWindowSurface->RequestRotation(mRotationAngle, newPositionSize);
1054 SurfaceRotated(static_cast<float>(mWindowWidth), static_cast<float>(mWindowHeight), mRotationAngle, mWindowBase->GetScreenRotationAngle());
1056 if(DALI_LIKELY(mAdaptor))
1058 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1061 Dali::Window handle(this);
1062 mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
1063 mOrientationChangedSignal.Emit(handle, GetCurrentOrientation());
1065 if(DALI_LIKELY(mAdaptor))
1067 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
1071 void Window::OnRotationFinished()
1073 mIsWindowRotating = false;
1074 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), window rotation is finised\n", this, mNativeWindowId);
1077 void Window::OnPause()
1081 mEventHandler->Pause();
1085 void Window::OnResume()
1089 mEventHandler->Resume();
1092 mSurface->SetFullSwapNextFrame();
1095 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
1097 mAuxiliaryMessageSignal.Emit(key, value, options);
1100 void Window::OnAccessibilityEnabled()
1102 auto bridge = Accessibility::Bridge::GetCurrentBridge();
1103 auto rootLayer = mScene.GetRootLayer();
1104 auto accessible = Accessibility::Accessible::Get(rootLayer);
1105 bridge->AddTopLevelWindow(accessible);
1107 if(!mVisible || mIconified)
1112 Dali::Window handle(this);
1113 bridge->WindowShown(handle);
1117 bridge->WindowFocused(handle);
1121 void Window::OnAccessibilityDisabled()
1123 auto bridge = Accessibility::Bridge::GetCurrentBridge();
1124 auto rootLayer = mScene.GetRootLayer();
1125 auto accessible = Accessibility::Accessible::Get(rootLayer);
1126 bridge->RemoveTopLevelWindow(accessible);
1129 Vector2 Window::RecalculatePosition(const Vector2& position)
1131 Vector2 convertedPosition;
1133 switch(mRotationAngle)
1137 convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
1138 convertedPosition.y = position.x;
1143 convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
1144 convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
1149 convertedPosition.x = position.y;
1150 convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
1155 convertedPosition = position;
1159 return convertedPosition;
1162 Dali::Window Window::Get(Dali::Actor actor)
1164 Internal::Adaptor::Window* windowImpl = nullptr;
1166 if(Internal::Adaptor::Adaptor::IsAvailable())
1168 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
1169 windowImpl = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
1172 return Dali::Window(windowImpl);
1176 return Dali::Window();
1179 void Window::SetParent(Dali::Window& parent)
1181 if(DALI_UNLIKELY(parent))
1183 mParentWindow = parent;
1184 Dali::Window self = Dali::Window(this);
1185 // check circular parent window setting
1186 if(Dali::DevelWindow::GetParent(parent) == self)
1188 Dali::DevelWindow::Unparent(parent);
1190 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
1194 void Window::SetParent(Dali::Window& parent, bool belowParent)
1196 if(DALI_UNLIKELY(parent))
1198 mParentWindow = parent;
1199 Dali::Window self = Dali::Window(this);
1200 // check circular parent window setting
1201 if(Dali::DevelWindow::GetParent(parent) == self)
1203 Dali::DevelWindow::Unparent(parent);
1205 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
1209 void Window::Unparent()
1211 mWindowBase->SetParent(nullptr, false);
1212 mParentWindow.Reset();
1215 Dali::Window Window::GetParent()
1217 return mParentWindow;
1220 WindowOrientation Window::GetCurrentOrientation() const
1222 return ConvertToOrientation(mRotationAngle);
1225 int Window::GetPhysicalOrientation() const
1227 return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
1230 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
1232 Dali::Vector<float>::SizeType count = orientations.Count();
1233 for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
1235 if(IsOrientationAvailable(orientations[index]) == false)
1237 DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1242 int convertedAngle = ConvertToAngle(orientations[index]);
1244 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1246 if(mAvailableAngles[i] == convertedAngle)
1255 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1256 mAvailableAngles.push_back(convertedAngle);
1259 SetAvailableAnlges(mAvailableAngles);
1262 int32_t Window::GetNativeId() const
1264 return mWindowBase->GetNativeWindowId();
1267 void Window::RequestMoveToServer()
1269 mWindowBase->RequestMoveToServer();
1272 void Window::RequestResizeToServer(WindowResizeDirection direction)
1274 mWindowBase->RequestResizeToServer(direction);
1277 void Window::EnableFloatingMode(bool enable)
1279 mWindowBase->EnableFloatingMode(enable);
1282 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1284 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);
1285 mWindowBase->IncludeInputRegion(inputRegion);
1288 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1290 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);
1291 mWindowBase->ExcludeInputRegion(inputRegion);
1294 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1296 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1297 mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1298 mWindowRotationAcknowledgement = needAcknowledgement;
1301 void Window::SendRotationCompletedAcknowledgement()
1303 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1304 if(mWindowRotationAcknowledgement)
1306 SetRotationCompletedAcknowledgement();
1310 bool Window::IsWindowRotating() const
1312 return mIsWindowRotating;
1315 const Dali::KeyEvent& Window::GetLastKeyEvent() const
1317 return mLastKeyEvent;
1320 const Dali::TouchEvent& Window::GetLastTouchEvent() const
1322 return mLastTouchEvent;
1325 } // namespace Adaptor
1327 } // namespace Internal