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(),
97 mIsTransparent(false),
98 mIsFocusAcceptable(true),
101 mWindowRotationAcknowledgement(false),
110 auto bridge = Accessibility::Bridge::GetCurrentBridge();
111 auto rootLayer = mScene.GetRootLayer();
112 auto accessible = Accessibility::Accessible::Get(rootLayer);
113 bridge->RemoveTopLevelWindow(accessible);
114 // Related to multi-window case. This is called for default window and non-default window, but it is effective for non-default window.
115 bridge->Emit(accessible, Accessibility::WindowEvent::DESTROY);
120 mAdaptor->RemoveWindow(this);
125 mEventHandler->RemoveObserver(*this);
129 void Window::Initialize(Any surface, const PositionSize& positionSize, const std::string& name, const std::string& className, WindowType type)
131 // Create a window render surface
132 auto renderSurfaceFactory = Dali::Internal::Adaptor::GetRenderSurfaceFactory();
133 mSurface = renderSurfaceFactory->CreateWindowRenderSurface(positionSize, surface, mIsTransparent);
134 mWindowSurface = static_cast<WindowRenderSurface*>(mSurface.get());
137 mWindowBase = mWindowSurface->GetWindowBase();
140 mWindowBase->SetType(type);
142 // Initialize for Ime window type
143 if(type == WindowType::IME)
145 mWindowBase->InitializeIme();
146 mWindowSurface->InitializeImeSurface();
150 mWindowBase->IconifyChangedSignal().Connect(this, &Window::OnIconifyChanged);
151 mWindowBase->FocusChangedSignal().Connect(this, &Window::OnFocusChanged);
152 mWindowBase->DeleteRequestSignal().Connect(this, &Window::OnDeleteRequest);
153 mWindowBase->TransitionEffectEventSignal().Connect(this, &Window::OnTransitionEffectEvent);
154 mWindowBase->KeyboardRepeatSettingsChangedSignal().Connect(this, &Window::OnKeyboardRepeatSettingsChanged);
155 mWindowBase->WindowRedrawRequestSignal().Connect(this, &Window::OnWindowRedrawRequest);
156 mWindowBase->UpdatePositionSizeSignal().Connect(this, &Window::OnUpdatePositionSize);
157 mWindowBase->AuxiliaryMessageSignal().Connect(this, &Window::OnAuxiliaryMessage);
159 mWindowSurface->OutputTransformedSignal().Connect(this, &Window::OnOutputTransformed);
161 AddAuxiliaryHint("wm.policy.win.user.geometry", "1");
163 SetClass(name, className);
165 mOrientation = Orientation::New(this);
167 // Get OrientationMode
168 int screenWidth, screenHeight;
169 WindowSystem::GetScreenSize(screenWidth, screenHeight);
170 if(screenWidth > screenHeight)
172 mOrientationMode = Internal::Adaptor::Window::OrientationMode::LANDSCAPE;
176 mOrientationMode = Internal::Adaptor::Window::OrientationMode::PORTRAIT;
179 mNativeWindowId = mWindowBase->GetNativeWindowId();
182 void Window::OnAdaptorSet(Dali::Adaptor& adaptor)
184 mEventHandler = EventHandlerPtr(new EventHandler(mWindowSurface->GetWindowBase(), *mAdaptor));
185 mEventHandler->AddObserver(*this);
187 // Add Window to bridge for ATSPI
188 auto bridge = Accessibility::Bridge::GetCurrentBridge();
191 auto rootLayer = mScene.GetRootLayer();
192 auto accessible = Accessibility::Accessible::Get(rootLayer);
193 bridge->AddTopLevelWindow(accessible);
196 bridge->EnabledSignal().Connect(this, &Window::OnAccessibilityEnabled);
197 bridge->DisabledSignal().Connect(this, &Window::OnAccessibilityDisabled);
199 // If you call the 'Show' before creating the adaptor, the application cannot know the app resource id.
200 // The show must be called after the adaptor is initialized.
204 void Window::OnSurfaceSet(Dali::RenderSurfaceInterface* surface)
206 mWindowSurface = static_cast<WindowRenderSurface*>(surface);
209 void Window::SetClass(std::string name, std::string className)
212 mClassName = className;
213 mWindowBase->SetClass(name, className);
216 std::string Window::GetClassName() const
223 mWindowBase->Raise();
225 mSurface->SetFullSwapNextFrame();
227 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Raise() \n", this, mNativeWindowId);
232 mWindowBase->Lower();
234 mSurface->SetFullSwapNextFrame();
236 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Lower() \n", this, mNativeWindowId);
239 void Window::Activate()
241 mWindowBase->Activate();
243 mSurface->SetFullSwapNextFrame();
245 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Activate() \n", this, mNativeWindowId);
248 void Window::Maximize(bool maximize)
250 mWindowBase->Maximize(maximize);
252 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Maximize: %d\n", this, mNativeWindowId, maximize);
255 bool Window::IsMaximized() const
257 return mWindowBase->IsMaximized();
260 void Window::Minimize(bool minimize)
262 mWindowBase->Minimize(minimize);
264 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Minimize: %d\n", this, mNativeWindowId, minimize);
267 bool Window::IsMinimized() const
269 return mWindowBase->IsMinimized();
272 uint32_t Window::GetLayerCount() const
274 return mScene.GetLayerCount();
277 Dali::Layer Window::GetLayer(uint32_t depth) const
279 return mScene.GetLayer(depth);
282 Dali::RenderTaskList Window::GetRenderTaskList() const
284 return mScene.GetRenderTaskList();
287 std::string Window::GetNativeResourceId() const
289 return mWindowBase->GetNativeWindowResourceId();
292 void Window::AddAvailableOrientation(WindowOrientation orientation)
294 if(IsOrientationAvailable(orientation) == false)
300 int convertedAngle = ConvertToAngle(orientation);
301 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), AddAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
302 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
304 if(mAvailableAngles[i] == convertedAngle)
313 mAvailableAngles.push_back(convertedAngle);
314 SetAvailableAnlges(mAvailableAngles);
318 void Window::RemoveAvailableOrientation(WindowOrientation orientation)
320 if(IsOrientationAvailable(orientation) == false)
325 int convertedAngle = ConvertToAngle(orientation);
326 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), RemoveAvailableOrientation: %d\n", this, mNativeWindowId, convertedAngle);
327 for(std::vector<int>::iterator iter = mAvailableAngles.begin();
328 iter != mAvailableAngles.end();
331 if(*iter == convertedAngle)
333 mAvailableAngles.erase(iter);
338 SetAvailableAnlges(mAvailableAngles);
341 void Window::SetPreferredOrientation(WindowOrientation orientation)
343 if(orientation < WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
345 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::CheckOrientation: Invalid input orientation [%d]\n", orientation);
348 mPreferredAngle = ConvertToAngle(orientation);
349 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
350 mWindowBase->SetPreferredAngle(mPreferredAngle);
353 WindowOrientation Window::GetPreferredOrientation()
355 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetPreferredOrientation: %d\n", this, mNativeWindowId, mPreferredAngle);
356 WindowOrientation preferredOrientation = ConvertToOrientation(mPreferredAngle);
357 return preferredOrientation;
360 void Window::SetPositionSizeWithOrientation(PositionSize positionSize, WindowOrientation orientation)
362 int angle = ConvertToAngle(orientation);
363 mWindowBase->SetPositionSizeWithAngle(positionSize, angle);
366 void Window::EmitAccessibilityHighlightSignal(bool highlight)
368 Dali::Window handle(this);
369 mAccessibilityHighlightSignal.Emit(handle, highlight);
372 void Window::SetAvailableAnlges(const std::vector<int>& angles)
374 if(angles.size() > 4)
376 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetAvailableAnlges: Invalid vector size! [%d]\n", angles.size());
380 mWindowBase->SetAvailableAnlges(angles);
383 int Window::ConvertToAngle(WindowOrientation orientation)
385 int convertAngle = static_cast<int>(orientation);
386 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
390 case WindowOrientation::LANDSCAPE:
395 case WindowOrientation::PORTRAIT:
400 case WindowOrientation::LANDSCAPE_INVERSE:
405 case WindowOrientation::PORTRAIT_INVERSE:
410 case WindowOrientation::NO_ORIENTATION_PREFERENCE:
420 WindowOrientation Window::ConvertToOrientation(int angle) const
422 WindowOrientation orientation = static_cast<WindowOrientation>(angle);
423 if(mOrientationMode == Internal::Adaptor::Window::OrientationMode::LANDSCAPE)
429 orientation = WindowOrientation::LANDSCAPE;
434 orientation = WindowOrientation::PORTRAIT;
439 orientation = WindowOrientation::LANDSCAPE_INVERSE;
444 orientation = WindowOrientation::PORTRAIT_INVERSE;
449 orientation = WindowOrientation::NO_ORIENTATION_PREFERENCE;
457 bool Window::IsOrientationAvailable(WindowOrientation orientation) const
459 if(orientation <= WindowOrientation::NO_ORIENTATION_PREFERENCE || orientation > WindowOrientation::LANDSCAPE_INVERSE)
461 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::IsOrientationAvailable: Invalid input orientation [%d]\n", orientation);
467 Dali::Any Window::GetNativeHandle() const
469 return mWindowSurface->GetNativeWindow();
472 void Window::SetAcceptFocus(bool accept)
474 mIsFocusAcceptable = accept;
476 mWindowBase->SetAcceptFocus(accept);
479 bool Window::IsFocusAcceptable() const
481 return mIsFocusAcceptable;
492 Dali::Window handle(this);
493 mVisibilityChangedSignal.Emit(handle, true);
494 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
496 WindowVisibilityObserver* observer(mAdaptor);
497 observer->OnWindowShown();
500 mSurface->SetFullSwapNextFrame();
502 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Show(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
513 Dali::Window handle(this);
514 mVisibilityChangedSignal.Emit(handle, false);
515 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
517 WindowVisibilityObserver* observer(mAdaptor);
518 observer->OnWindowHidden();
521 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Hide(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
524 bool Window::IsVisible() const
526 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), IsVisible(): iconified = %d, visible = %d\n", this, mNativeWindowId, mIconified, mVisible);
527 return mVisible && !mIconified;
530 unsigned int Window::GetSupportedAuxiliaryHintCount() const
532 return mWindowBase->GetSupportedAuxiliaryHintCount();
535 std::string Window::GetSupportedAuxiliaryHint(unsigned int index) const
537 return mWindowBase->GetSupportedAuxiliaryHint(index);
540 unsigned int Window::AddAuxiliaryHint(const std::string& hint, const std::string& value)
542 return mWindowBase->AddAuxiliaryHint(hint, value);
545 bool Window::RemoveAuxiliaryHint(unsigned int id)
547 return mWindowBase->RemoveAuxiliaryHint(id);
550 bool Window::SetAuxiliaryHintValue(unsigned int id, const std::string& value)
552 return mWindowBase->SetAuxiliaryHintValue(id, value);
555 std::string Window::GetAuxiliaryHintValue(unsigned int id) const
557 return mWindowBase->GetAuxiliaryHintValue(id);
560 unsigned int Window::GetAuxiliaryHintId(const std::string& hint) const
562 return mWindowBase->GetAuxiliaryHintId(hint);
565 void Window::SetInputRegion(const Rect<int>& inputRegion)
567 Rect<int> convertRegion = RecalculateRect(inputRegion);
569 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);
571 mWindowBase->SetInputRegion(convertRegion);
574 void Window::SetType(WindowType type)
576 mWindowBase->SetType(type);
579 WindowType Window::GetType() const
581 return mWindowBase->GetType();
584 WindowOperationResult Window::SetNotificationLevel(WindowNotificationLevel level)
586 WindowType type = mWindowBase->GetType();
587 if(type != WindowType::NOTIFICATION)
589 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetNotificationLevel: Not supported window type [%d]\n", type);
590 return WindowOperationResult::INVALID_OPERATION;
593 return mWindowBase->SetNotificationLevel(level);
596 WindowNotificationLevel Window::GetNotificationLevel() const
598 WindowType type = mWindowBase->GetType();
599 if(type != WindowType::NOTIFICATION)
601 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::GetNotificationLevel: Not supported window type [%d]\n", type);
602 return WindowNotificationLevel::NONE;
605 return mWindowBase->GetNotificationLevel();
608 void Window::SetOpaqueState(bool opaque)
610 mOpaqueState = opaque;
612 mWindowBase->SetOpaqueState(opaque);
614 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetOpaqueState: opaque = %d\n", opaque);
617 bool Window::IsOpaqueState() const
622 WindowOperationResult Window::SetScreenOffMode(WindowScreenOffMode screenOffMode)
624 return mWindowBase->SetScreenOffMode(screenOffMode);
627 WindowScreenOffMode Window::GetScreenOffMode() const
629 return mWindowBase->GetScreenOffMode();
632 WindowOperationResult Window::SetBrightness(int brightness)
634 if(brightness < 0 || brightness > 100)
636 DALI_LOG_INFO(gWindowLogFilter, Debug::Verbose, "Window::SetBrightness: Invalid brightness value [%d]\n", brightness);
637 return WindowOperationResult::INVALID_OPERATION;
640 return mWindowBase->SetBrightness(brightness);
643 int Window::GetBrightness() const
645 return mWindowBase->GetBrightness();
648 void Window::SetSize(Dali::Window::WindowSize size)
650 PositionSize oldRect = mSurface->GetPositionSize();
652 mWindowSurface->MoveResize(PositionSize(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
654 PositionSize newRect = mSurface->GetPositionSize();
656 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
657 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
659 Uint16Pair newSize(newRect.width, newRect.height);
661 mWindowWidth = newRect.width;
662 mWindowHeight = newRect.height;
666 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
668 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), current angle (%d), SetSize(): resize signal [%d x %d]\n", this, mNativeWindowId, mRotationAngle, newRect.width, newRect.height);
670 Dali::Window handle(this);
671 mResizeSignal.Emit(handle, newSize);
673 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
676 mSurface->SetFullSwapNextFrame();
678 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(oldRect.x, oldRect.y, size.GetWidth(), size.GetHeight()));
681 Dali::Window::WindowSize Window::GetSize() const
683 PositionSize positionSize = mSurface->GetPositionSize();
685 return Dali::Window::WindowSize(positionSize.width, positionSize.height);
688 void Window::SetPosition(Dali::Window::WindowPosition position)
690 PositionSize oldRect = mSurface->GetPositionSize();
692 mWindowSurface->MoveResize(PositionSize(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
694 mSurface->SetFullSwapNextFrame();
696 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(position.GetX(), position.GetY(), oldRect.width, oldRect.height));
699 Dali::Window::WindowPosition Window::GetPosition() const
701 PositionSize positionSize = mSurface->GetPositionSize();
703 return Dali::Window::WindowPosition(positionSize.x, positionSize.y);
706 PositionSize Window::GetPositionSize() const
708 return mSurface->GetPositionSize();
711 void Window::SetPositionSize(PositionSize positionSize)
713 PositionSize oldRect = mSurface->GetPositionSize();
715 mWindowSurface->MoveResize(positionSize);
717 PositionSize newRect = mSurface->GetPositionSize();
719 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
720 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
722 Uint16Pair newSize(newRect.width, newRect.height);
724 mWindowWidth = newRect.width;
725 mWindowHeight = newRect.height;
729 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
731 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), current angle (%d), SetPositionSize():resize signal [%d x %d]\n", this, mNativeWindowId, mRotationAngle, newRect.width, newRect.height);
732 Dali::Window handle(this);
733 mResizeSignal.Emit(handle, newSize);
734 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
737 mSurface->SetFullSwapNextFrame();
739 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
742 Dali::Layer Window::GetRootLayer() const
744 return mScene.GetRootLayer();
747 void Window::SetTransparency(bool transparent)
749 mWindowSurface->SetTransparency(transparent);
752 bool Window::GrabKey(Dali::KEY key, KeyGrab::KeyGrabMode grabMode)
754 return mWindowBase->GrabKey(key, grabMode);
757 bool Window::UngrabKey(Dali::KEY key)
759 return mWindowBase->UngrabKey(key);
762 bool Window::GrabKeyList(const Dali::Vector<Dali::KEY>& key, const Dali::Vector<KeyGrab::KeyGrabMode>& grabMode, Dali::Vector<bool>& result)
764 return mWindowBase->GrabKeyList(key, grabMode, result);
767 bool Window::UngrabKeyList(const Dali::Vector<Dali::KEY>& key, Dali::Vector<bool>& result)
769 return mWindowBase->UngrabKeyList(key, result);
772 void Window::OnIconifyChanged(bool iconified)
780 Dali::Window handle(this);
781 mVisibilityChangedSignal.Emit(handle, false);
782 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowHidden(handle);
784 WindowVisibilityObserver* observer(mAdaptor);
785 observer->OnWindowHidden();
788 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Iconified: visible = %d\n", this, mNativeWindowId, mVisible);
796 Dali::Window handle(this);
797 mVisibilityChangedSignal.Emit(handle, true);
798 Dali::Accessibility::Bridge::GetCurrentBridge()->WindowShown(handle);
800 WindowVisibilityObserver* observer(mAdaptor);
801 observer->OnWindowShown();
804 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Deiconified: visible = %d\n", this, mNativeWindowId, mVisible);
807 mSurface->SetFullSwapNextFrame();
810 void Window::OnFocusChanged(bool focusIn)
812 Dali::Window handle(this);
813 mFocusChangeSignal.Emit(handle, focusIn);
815 mSurface->SetFullSwapNextFrame();
817 if(auto bridge = Dali::Accessibility::Bridge::GetCurrentBridge())
821 bridge->WindowFocused(handle);
825 bridge->WindowUnfocused(handle);
831 void Window::OnOutputTransformed()
833 PositionSize positionSize = mSurface->GetPositionSize();
835 int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
836 SurfaceRotated(static_cast<float>(positionSize.width), static_cast<float>(positionSize.height), orientation);
838 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
839 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(positionSize.width, positionSize.height));
842 void Window::OnDeleteRequest()
844 mDeleteRequestSignal.Emit();
847 void Window::OnTransitionEffectEvent(WindowEffectState state, WindowEffectType type)
849 Dali::Window handle(this);
850 mTransitionEffectEventSignal.Emit(handle, state, type);
853 void Window::OnKeyboardRepeatSettingsChanged()
855 Dali::Window handle(this);
856 mKeyboardRepeatSettingsChangedSignal.Emit();
859 void Window::OnWindowRedrawRequest()
861 mAdaptor->RenderOnce();
864 void Window::OnUpdatePositionSize(Dali::PositionSize& positionSize)
866 PositionSize oldRect = mSurface->GetPositionSize();
868 mWindowSurface->UpdatePositionSize(positionSize);
870 PositionSize newRect = positionSize;
872 // When surface size is updated, inform adaptor of resizing and emit ResizeSignal
873 if((oldRect.width != newRect.width) || (oldRect.height != newRect.height))
875 Uint16Pair newSize(newRect.width, newRect.height);
879 mAdaptor->SurfaceResizePrepare(mSurface.get(), newSize);
881 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), Updated PositionSize by server :resize signal [%d x %d]\n", this, mNativeWindowId, newRect.width, newRect.height);
882 Dali::Window handle(this);
883 mResizeSignal.Emit(handle, newSize);
884 mAdaptor->SurfaceResizeComplete(mSurface.get(), newSize);
887 mSurface->SetFullSwapNextFrame();
889 Dali::Accessibility::Accessible::Get(mScene.GetRootLayer())->EmitBoundsChanged(Dali::Rect<>(positionSize.x, positionSize.y, positionSize.width, positionSize.height));
892 void Window::OnTouchPoint(Dali::Integration::Point& point, int timeStamp)
894 mLastTouchEvent = Dali::Integration::NewTouchEvent(timeStamp, point);
895 FeedTouchPoint(point, timeStamp);
898 void Window::OnWheelEvent(Dali::Integration::WheelEvent& wheelEvent)
900 FeedWheelEvent(wheelEvent);
903 void Window::OnKeyEvent(Dali::Integration::KeyEvent& keyEvent)
905 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);
906 FeedKeyEvent(keyEvent);
909 void Window::OnRotation(const RotationEvent& rotation)
911 PositionSize newPositionSize(rotation.x, rotation.y, rotation.width, rotation.height);
913 mRotationAngle = rotation.angle;
914 mWindowWidth = rotation.width;
915 mWindowHeight = rotation.height;
917 // Notify that the orientation is changed
918 mOrientation->OnOrientationChange(rotation);
920 mWindowSurface->RequestRotation(mRotationAngle, newPositionSize);
922 int orientation = (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
923 SurfaceRotated(mWindowWidth, mWindowHeight, orientation);
925 mAdaptor->SurfaceResizePrepare(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
927 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), OnRotation(): x[%d], y[%d], resize signal emit [%d x %d]\n", this, mNativeWindowId, newPositionSize.x, newPositionSize.y, mWindowWidth, mWindowHeight);
929 Dali::Window handle(this);
930 mResizeSignal.Emit(handle, Dali::Window::WindowSize(mWindowWidth, mWindowHeight));
932 mAdaptor->SurfaceResizeComplete(mSurface.get(), Adaptor::SurfaceSize(mWindowWidth, mWindowHeight));
935 void Window::OnPause()
939 mEventHandler->Pause();
943 void Window::OnResume()
947 mEventHandler->Resume();
950 mSurface->SetFullSwapNextFrame();
953 void Window::OnAuxiliaryMessage(const std::string& key, const std::string& value, const Property::Array& options)
955 mAuxiliaryMessageSignal.Emit(key, value, options);
958 void Window::OnAccessibilityEnabled()
960 auto bridge = Accessibility::Bridge::GetCurrentBridge();
961 auto rootLayer = mScene.GetRootLayer();
962 auto accessible = Accessibility::Accessible::Get(rootLayer);
963 bridge->AddTopLevelWindow(accessible);
965 if(!mVisible || mIconified)
970 Dali::Window handle(this);
971 bridge->WindowShown(handle);
975 bridge->WindowFocused(handle);
979 void Window::OnAccessibilityDisabled()
981 auto bridge = Accessibility::Bridge::GetCurrentBridge();
982 auto rootLayer = mScene.GetRootLayer();
983 auto accessible = Accessibility::Accessible::Get(rootLayer);
984 bridge->RemoveTopLevelWindow(accessible);
987 void Window::RecalculateTouchPosition(Integration::Point& point)
989 Vector2 position = point.GetScreenPosition();
990 Vector2 convertedPosition;
992 switch(mRotationAngle)
996 convertedPosition.x = static_cast<float>(mWindowWidth) - position.y;
997 convertedPosition.y = position.x;
1002 convertedPosition.x = static_cast<float>(mWindowWidth) - position.x;
1003 convertedPosition.y = static_cast<float>(mWindowHeight) - position.y;
1008 convertedPosition.x = position.y;
1009 convertedPosition.y = static_cast<float>(mWindowHeight) - position.x;
1014 convertedPosition = position;
1019 point.SetScreenPosition(convertedPosition);
1022 Dali::Window Window::Get(Dali::Actor actor)
1024 Internal::Adaptor::Window* windowImpl = nullptr;
1026 if(Internal::Adaptor::Adaptor::IsAvailable())
1028 Dali::Internal::Adaptor::Adaptor& adaptor = Internal::Adaptor::Adaptor::GetImplementation(Internal::Adaptor::Adaptor::Get());
1029 windowImpl = dynamic_cast<Internal::Adaptor::Window*>(adaptor.GetWindow(actor));
1032 return Dali::Window(windowImpl);
1036 return Dali::Window();
1039 void Window::SetParent(Dali::Window& parent)
1041 if(DALI_UNLIKELY(parent))
1043 mParentWindow = parent;
1044 Dali::Window self = Dali::Window(this);
1045 // check circular parent window setting
1046 if(Dali::DevelWindow::GetParent(parent) == self)
1048 Dali::DevelWindow::Unparent(parent);
1050 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, false);
1054 void Window::SetParent(Dali::Window& parent, bool belowParent)
1056 if(DALI_UNLIKELY(parent))
1058 mParentWindow = parent;
1059 Dali::Window self = Dali::Window(this);
1060 // check circular parent window setting
1061 if(Dali::DevelWindow::GetParent(parent) == self)
1063 Dali::DevelWindow::Unparent(parent);
1065 mWindowBase->SetParent(GetImplementation(mParentWindow).mWindowBase, belowParent);
1069 void Window::Unparent()
1071 mWindowBase->SetParent(nullptr, false);
1072 mParentWindow.Reset();
1075 Dali::Window Window::GetParent()
1077 return mParentWindow;
1080 WindowOrientation Window::GetCurrentOrientation() const
1082 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), GetCurrentOrientation(): %d\n", this, mNativeWindowId, mRotationAngle);
1083 return ConvertToOrientation(mRotationAngle);
1086 int Window::GetPhysicalOrientation() const
1088 return (mRotationAngle + mWindowBase->GetScreenRotationAngle()) % 360;
1091 void Window::SetAvailableOrientations(const Dali::Vector<WindowOrientation>& orientations)
1093 Dali::Vector<float>::SizeType count = orientations.Count();
1094 for(Dali::Vector<float>::SizeType index = 0; index < count; ++index)
1096 if(IsOrientationAvailable(orientations[index]) == false)
1098 DALI_LOG_ERROR("Window::SetAvailableOrientations, invalid orientation: %d\n", orientations[index]);
1103 int convertedAngle = ConvertToAngle(orientations[index]);
1105 for(std::size_t i = 0; i < mAvailableAngles.size(); i++)
1107 if(mAvailableAngles[i] == convertedAngle)
1116 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SetAvailableOrientations: %d\n", this, mNativeWindowId, convertedAngle);
1117 mAvailableAngles.push_back(convertedAngle);
1120 SetAvailableAnlges(mAvailableAngles);
1123 int32_t Window::GetNativeId() const
1125 return mWindowBase->GetNativeWindowId();
1128 void Window::RequestMoveToServer()
1130 mWindowBase->RequestMoveToServer();
1133 void Window::RequestResizeToServer(WindowResizeDirection direction)
1135 mWindowBase->RequestResizeToServer(direction);
1138 void Window::EnableFloatingMode(bool enable)
1140 mWindowBase->EnableFloatingMode(enable);
1143 Rect<int> Window::RecalculateRect(const Rect<int>& rect)
1146 int screenWidth, screenHeight;
1148 WindowSystem::GetScreenSize(screenWidth, screenHeight);
1150 if(mRotationAngle == 90)
1153 newRect.y = screenHeight - (rect.x + rect.width);
1154 newRect.width = rect.height;
1155 newRect.height = rect.width;
1157 else if(mRotationAngle == 180)
1159 newRect.x = screenWidth - (rect.x + rect.width);
1160 newRect.y = screenHeight - (rect.y + rect.height);
1161 newRect.width = rect.width;
1162 newRect.height = rect.height;
1164 else if(mRotationAngle == 270)
1166 newRect.x = screenWidth - (rect.y + rect.height);
1168 newRect.width = rect.height;
1169 newRect.height = rect.width;
1175 newRect.width = rect.width;
1176 newRect.height = rect.height;
1181 void Window::IncludeInputRegion(const Rect<int>& inputRegion)
1183 Rect<int> convertRegion = RecalculateRect(inputRegion);
1185 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);
1186 mWindowBase->IncludeInputRegion(convertRegion);
1189 void Window::ExcludeInputRegion(const Rect<int>& inputRegion)
1191 Rect<int> convertRegion = RecalculateRect(inputRegion);
1193 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);
1194 mWindowBase->ExcludeInputRegion(convertRegion);
1197 void Window::SetNeedsRotationCompletedAcknowledgement(bool needAcknowledgement)
1199 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), needAcknowledgement(%d) Set needs Rotation Completed Acknowledgement\n", this, mNativeWindowId, needAcknowledgement);
1200 mWindowSurface->SetNeedsRotationCompletedAcknowledgement(needAcknowledgement);
1201 mWindowRotationAcknowledgement = needAcknowledgement;
1204 void Window::SendRotationCompletedAcknowledgement()
1206 DALI_LOG_RELEASE_INFO("Window (%p), WinId (%d), SendRotationCompletedAcknowledgement(): orientation: %d, mWindowRotationAcknowledgement: %d\n", this, mNativeWindowId, mRotationAngle, mWindowRotationAcknowledgement);
1207 if(mWindowRotationAcknowledgement)
1209 SetRotationCompletedAcknowledgement();
1213 bool Window::IsWindowRotating() const
1215 return mWindowSurface->IsWindowRotating();
1218 const Dali::KeyEvent& Window::GetLastKeyEvent() const
1220 return mLastKeyEvent;
1223 const Dali::TouchEvent& Window::GetLastTouchEvent() const
1225 return mLastTouchEvent;
1228 } // namespace Adaptor
1230 } // namespace Internal