8#include <qpa/qplatformscreen.h>
9#include <qpa/qwindowsysteminterface.h>
11#include <private/qwindow_p.h>
12#include <private/qguiapplication_p.h>
17 : QPlatformWindow(window)
18 , m_positionIncludesFrame(
false)
20 , m_pendingGeometryChangeOnShow(
true)
21 , m_frameMarginsRequested(frameMarginsEnabled)
23 if (window->windowState() == Qt::WindowNoState) {
24 setGeometry(windowGeometry());
26 setWindowState(window->windowStates());
29 static WId counter = 0;
32 m_windowForWinIdHash[m_winId] =
this;
37 if (QOffscreenScreen::windowContainingCursor ==
this)
38 QOffscreenScreen::windowContainingCursor =
nullptr;
39 m_windowForWinIdHash.remove(m_winId);
44 if (window()->windowState() != Qt::WindowNoState)
47 m_positionIncludesFrame = qt_window_private(window())->positionPolicy == QWindowPrivate::WindowFrameInclusive;
49 setFrameMarginsEnabled(m_frameMarginsRequested);
50 setGeometryImpl(rect);
52 m_normalGeometry = geometry();
57 QRect adjusted = rect;
58 if (adjusted.width() <= 0)
60 if (adjusted.height() <= 0)
61 adjusted.setHeight(1);
63 if (m_positionIncludesFrame) {
64 adjusted.translate(m_margins.left(), m_margins.top());
67 if (adjusted.left() < m_margins.left())
68 adjusted.translate(m_margins.left(), 0);
69 if (adjusted.top() < m_margins.top())
70 adjusted.translate(0, m_margins.top());
73 QPlatformWindow::setGeometry(adjusted);
75 QPlatformScreen *newScreen = screenForGeometry(rect);
76 if (newScreen != screen())
77 QWindowSystemInterface::handleWindowScreenChanged(window(), newScreen->screen());
80 QWindowSystemInterface::handleGeometryChange(window(), adjusted);
81 QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(), adjusted.size()));
83 m_pendingGeometryChangeOnShow =
true;
89 if (visible == m_visible)
93 if (window()->type() != Qt::ToolTip)
94 QWindowSystemInterface::handleFocusWindowChanged(window(), Qt::ActiveWindowFocusReason);
96 if (m_pendingGeometryChangeOnShow) {
97 m_pendingGeometryChangeOnShow =
false;
98 QWindowSystemInterface::handleGeometryChange(window(), geometry());
102 const QPoint cursorPos = QCursor::pos();
104 QRect rect(QPoint(), geometry().size());
105 QWindowSystemInterface::handleExposeEvent(window(), rect);
106 if (QWindowPrivate::get(window())->isPopup() && QGuiApplicationPrivate::currentMouseWindow) {
107 QWindowSystemInterface::handleLeaveEvent<QWindowSystemInterface::SynchronousDelivery>
108 (QGuiApplicationPrivate::currentMouseWindow);
110 if (geometry().contains(cursorPos))
111 QWindowSystemInterface::handleEnterEvent(window(),
112 window()->mapFromGlobal(cursorPos), cursorPos);
114 QWindowSystemInterface::handleExposeEvent(window(), QRegion());
115 if (window()->type() & Qt::Window) {
116 if (QWindow *windowUnderMouse = QGuiApplication::topLevelAt(cursorPos)) {
117 QWindowSystemInterface::handleEnterEvent(windowUnderMouse,
118 windowUnderMouse->mapFromGlobal(cursorPos),
130 QWindowSystemInterface::handleFocusWindowChanged(window(), Qt::ActiveWindowFocusReason);
140 return window()->requestedFormat();
151 && !(window()->flags() & Qt::FramelessWindowHint)
152 && (parent() ==
nullptr)) {
153 m_margins = QMargins(2, 2, 2, 2);
155 m_margins = QMargins(0, 0, 0, 0);
161 setFrameMarginsEnabled(m_frameMarginsRequested && !(state & Qt::WindowFullScreen));
162 m_positionIncludesFrame =
false;
164 if (state & Qt::WindowMinimized)
166 else if (state & Qt::WindowFullScreen)
167 setGeometryImpl(screen()->geometry());
168 else if (state & Qt::WindowMaximized)
169 setGeometryImpl(screen()->availableGeometry().adjusted(m_margins.left(), m_margins.top(), -m_margins.right(), -m_margins.bottom()));
171 setGeometryImpl(m_normalGeometry);
173 QWindowSystemInterface::handleWindowStateChanged(window(), state);
178 return m_windowForWinIdHash.value(id,
nullptr);
181Q_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.
Combined button and popup list for selecting options.