7#include <qpa/qplatformscreen.h>
8#include <qpa/qwindowsysteminterface.h>
10#include <private/qwindow_p.h>
11#include <private/qguiapplication_p.h>
16 : QPlatformWindow(window)
17 , m_positionIncludesFrame(
false)
19 , m_pendingGeometryChangeOnShow(
true)
20 , m_frameMarginsRequested(frameMarginsEnabled)
22 if (window->windowState() == Qt::WindowNoState) {
23 setGeometry(windowGeometry());
25 setWindowState(window->windowStates());
28 static WId counter = 0;
31 m_windowForWinIdHash[m_winId] =
this;
36 if (QOffscreenScreen::windowContainingCursor ==
this)
37 QOffscreenScreen::windowContainingCursor =
nullptr;
38 m_windowForWinIdHash.remove(m_winId);
43 if (window()->windowState() != Qt::WindowNoState)
46 m_positionIncludesFrame = qt_window_private(window())->positionPolicy == QWindowPrivate::WindowFrameInclusive;
48 setFrameMarginsEnabled(m_frameMarginsRequested);
49 setGeometryImpl(rect);
51 m_normalGeometry = geometry();
56 QRect adjusted = rect;
57 if (adjusted.width() <= 0)
59 if (adjusted.height() <= 0)
60 adjusted.setHeight(1);
62 if (m_positionIncludesFrame) {
63 adjusted.translate(m_margins.left(), m_margins.top());
66 if (adjusted.left() < m_margins.left())
67 adjusted.translate(m_margins.left(), 0);
68 if (adjusted.top() < m_margins.top())
69 adjusted.translate(0, m_margins.top());
72 QPlatformWindow::setGeometry(adjusted);
75 QWindowSystemInterface::handleGeometryChange(window(), adjusted);
76 QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(), adjusted.size()));
78 m_pendingGeometryChangeOnShow =
true;
84 if (visible == m_visible)
88 if (window()->type() != Qt::ToolTip)
89 QWindowSystemInterface::handleFocusWindowChanged(window(), Qt::ActiveWindowFocusReason);
91 if (m_pendingGeometryChangeOnShow) {
92 m_pendingGeometryChangeOnShow =
false;
93 QWindowSystemInterface::handleGeometryChange(window(), geometry());
97 const QPoint cursorPos = QCursor::pos();
99 QRect rect(QPoint(), geometry().size());
100 QWindowSystemInterface::handleExposeEvent(window(), rect);
101 if (QWindowPrivate::get(window())->isPopup() && QGuiApplicationPrivate::currentMouseWindow) {
102 QWindowSystemInterface::handleLeaveEvent<QWindowSystemInterface::SynchronousDelivery>
103 (QGuiApplicationPrivate::currentMouseWindow);
105 if (geometry().contains(cursorPos))
106 QWindowSystemInterface::handleEnterEvent(window(),
107 window()->mapFromGlobal(cursorPos), cursorPos);
109 QWindowSystemInterface::handleExposeEvent(window(), QRegion());
110 if (window()->type() & Qt::Window) {
111 if (QWindow *windowUnderMouse = QGuiApplication::topLevelAt(cursorPos)) {
112 QWindowSystemInterface::handleEnterEvent(windowUnderMouse,
113 windowUnderMouse->mapFromGlobal(cursorPos),
125 QWindowSystemInterface::handleFocusWindowChanged(window(), Qt::ActiveWindowFocusReason);
135 return window()->requestedFormat();
146 && !(window()->flags() & Qt::FramelessWindowHint)
147 && (parent() ==
nullptr)) {
148 m_margins = QMargins(2, 2, 2, 2);
150 m_margins = QMargins(0, 0, 0, 0);
156 setFrameMarginsEnabled(m_frameMarginsRequested && !(state & Qt::WindowFullScreen));
157 m_positionIncludesFrame =
false;
159 if (state & Qt::WindowMinimized)
161 else if (state & Qt::WindowFullScreen)
162 setGeometryImpl(screen()->geometry());
163 else if (state & Qt::WindowMaximized)
164 setGeometryImpl(screen()->availableGeometry().adjusted(m_margins.left(), m_margins.top(), -m_margins.right(), -m_margins.bottom()));
166 setGeometryImpl(m_normalGeometry);
168 QWindowSystemInterface::handleWindowStateChanged(window(), state);
173 return m_windowForWinIdHash.value(id,
nullptr);
176Q_CONSTINIT QHash<WId, QOffscreenWindow *> QOffscreenWindow::m_windowForWinIdHash;
QSurfaceFormat format() const override
Returns the actual surface format of the window.
void setWindowState(Qt::WindowStates states) override
Requests setting the window state of this surface to type.
WId winId() const override
Reimplement in subclasses to return a handle to the native window.
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
QMargins frameMargins() const override
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.