5#include <QtCore/qt_windows.h>
6#include <QtGui/qpainter.h>
8#include <QtGui/qstylehints.h>
9#include <QtGui/qtextoption.h>
13#if QT_CONFIG(directmanipulation)
14# include "qwindowsdirectmanipulation.h"
17#if QT_CONFIG(draganddrop)
18# include "qwindowsdrag.h"
24#if QT_CONFIG(dynamicgl)
25# include "qwindowsglcontext.h"
31# include "qwindowscursor.h"
36#include <QtGui/qguiapplication.h>
37#include <QtGui/qscreen.h>
38#include <QtGui/qwindow.h>
39#include <QtGui/qregion.h>
40#include <QtGui/qopenglcontext.h>
41#include <QtGui/qpainterpath.h>
42#include <QtGui/private/qwindowsthemecache_p.h>
43#include <private/qwindow_p.h>
44#include <private/qguiapplication_p.h>
45#include <private/qhighdpiscaling_p.h>
46#include <qpa/qwindowsysteminterface.h>
47#include <private/qsystemlibrary_p.h>
48#include <private/qwinregistry_p.h>
51#include <QtCore/qdebug.h>
52#include <QtCore/qlibraryinfo.h>
53#include <QtCore/qoperatingsystemversion.h>
58#include "qwindowsvulkaninstance.h"
61#include <shellscalingapi.h>
63#include <private/qdxgivsyncservice_p.h>
66# define GWL_HWNDPARENT (-8
)
71using namespace Qt::StringLiterals;
73using QWindowCreationContextPtr = QSharedPointer<QWindowCreationContext>;
80Q_GUI_EXPORT HICON qt_pixmapToWinHICON(
const QPixmap &);
85 rc += QByteArray::number(qulonglong(style), 16);
90 if (style & WS_OVERLAPPED)
91 rc +=
" WS_OVERLAPPED";
92 if (style & WS_CLIPSIBLINGS)
93 rc +=
" WS_CLIPSIBLINGS";
94 if (style & WS_CLIPCHILDREN)
95 rc +=
" WS_CLIPCHILDREN";
96 if (style & WS_THICKFRAME)
97 rc +=
" WS_THICKFRAME";
98 if (style & WS_DLGFRAME)
100 if (style & WS_SYSMENU)
102 if (style & WS_MINIMIZEBOX)
103 rc +=
" WS_MINIMIZEBOX";
104 if (style & WS_MAXIMIZEBOX)
105 rc +=
" WS_MAXIMIZEBOX";
106 if (style & WS_BORDER)
108 if (style & WS_CAPTION)
110 if (style & WS_CHILDWINDOW)
111 rc +=
" WS_CHILDWINDOW";
112 if (style & WS_DISABLED)
113 rc +=
" WS_DISABLED";
114 if (style & WS_GROUP)
116 if (style & WS_HSCROLL)
118 if (style & WS_ICONIC)
120 if (style & WS_MAXIMIZE)
121 rc +=
" WS_MAXIMIZE";
122 if (style & WS_MINIMIZE)
123 rc +=
" WS_MINIMIZE";
124 if (style & WS_SIZEBOX)
126 if (style & WS_TABSTOP)
128 if (style & WS_TILED)
130 if (style & WS_VISIBLE)
132 if (style & WS_VSCROLL)
139 QByteArray rc =
"0x";
140 rc += QByteArray::number(qulonglong(exStyle), 16);
141 if (exStyle & WS_EX_TOOLWINDOW)
142 rc +=
" WS_EX_TOOLWINDOW";
143 if (exStyle & WS_EX_CONTEXTHELP)
144 rc +=
" WS_EX_CONTEXTHELP";
145 if (exStyle & WS_EX_LAYERED)
146 rc +=
" WS_EX_LAYERED";
147 if (exStyle & WS_EX_DLGMODALFRAME)
148 rc +=
" WS_EX_DLGMODALFRAME";
149 if (exStyle & WS_EX_LAYOUTRTL)
150 rc +=
" WS_EX_LAYOUTRTL";
151 if (exStyle & WS_EX_NOINHERITLAYOUT)
152 rc +=
" WS_EX_NOINHERITLAYOUT";
153 if (exStyle & WS_EX_ACCEPTFILES)
154 rc +=
" WS_EX_ACCEPTFILES";
155 if (exStyle & WS_EX_APPWINDOW)
156 rc +=
" WS_EX_APPWINDOW";
157 if (exStyle & WS_EX_CLIENTEDGE)
158 rc +=
" WS_EX_CLIENTEDGE";
159 if (exStyle & WS_EX_COMPOSITED)
160 rc +=
" WS_EX_COMPOSITED";
161 if (exStyle & WS_EX_CONTROLPARENT)
162 rc +=
" WS_EX_CONTROLPARENT";
163 if (exStyle & WS_EX_LEFT)
165 if (exStyle & WS_EX_LEFTSCROLLBAR)
166 rc +=
" WS_EX_LEFTSCROLLBAR";
167 if (exStyle & WS_EX_LTRREADING)
168 rc +=
" WS_EX_LTRREADING";
169 if (exStyle & WS_EX_MDICHILD)
170 rc +=
" WS_EX_MDICHILD";
171 if (exStyle & WS_EX_NOACTIVATE)
172 rc +=
" WS_EX_NOACTIVATE";
173 if (exStyle & WS_EX_NOPARENTNOTIFY)
174 rc +=
" WS_EX_NOPARENTNOTIFY";
175 if (exStyle & WS_EX_NOREDIRECTIONBITMAP)
176 rc +=
" WS_EX_NOREDIRECTIONBITMAP";
177 if (exStyle & WS_EX_RIGHT)
178 rc +=
" WS_EX_RIGHT";
179 if (exStyle & WS_EX_RIGHTSCROLLBAR)
180 rc +=
" WS_EX_RIGHTSCROLLBAR";
181 if (exStyle & WS_EX_RTLREADING)
182 rc +=
" WS_EX_RTLREADING";
183 if (exStyle & WS_EX_STATICEDGE)
184 rc +=
" WS_EX_STATICEDGE";
185 if (exStyle & WS_EX_TOPMOST)
186 rc +=
" WS_EX_TOPMOST";
187 if (exStyle & WS_EX_TRANSPARENT)
188 rc +=
" WS_EX_TRANSPARENT";
189 if (exStyle & WS_EX_WINDOWEDGE)
190 rc +=
" WS_EX_WINDOWEDGE";
196 QByteArray rc =
"0x";
197 rc += QByteArray::number(flags, 16);
198 if (flags & SWP_FRAMECHANGED)
199 rc +=
" SWP_FRAMECHANGED";
200 if (flags & SWP_HIDEWINDOW)
201 rc +=
" SWP_HIDEWINDOW";
202 if (flags & SWP_NOACTIVATE)
203 rc +=
" SWP_NOACTIVATE";
204 if (flags & SWP_NOCOPYBITS)
205 rc +=
" SWP_NOCOPYBITS";
206 if (flags & SWP_NOMOVE)
208 if (flags & SWP_NOOWNERZORDER)
209 rc +=
" SWP_NOOWNERZORDER";
210 if (flags & SWP_NOREDRAW)
211 rc +=
" SWP_NOREDRAW";
212 if (flags & SWP_NOSENDCHANGING)
213 rc +=
" SWP_NOSENDCHANGING";
214 if (flags & SWP_NOSIZE)
216 if (flags & SWP_NOZORDER)
217 rc +=
" SWP_NOZORDER";
218 if (flags & SWP_SHOWWINDOW)
219 rc +=
" SWP_SHOWWINDOW";
220 if (flags & SWP_ASYNCWINDOWPOS)
221 rc +=
" SWP_ASYNCWINDOWPOS";
222 if (flags & SWP_DEFERERASE)
223 rc +=
" SWP_DEFERERASE";
224 if (flags & SWP_DRAWFRAME)
225 rc +=
" SWP_DRAWFRAME";
226 if (flags & SWP_NOREPOSITION)
227 rc +=
" SWP_NOREPOSITION";
233 QByteArray rc =
"0x";
234 rc += QByteArray::number(flags, 16);
235 if (flags & WPF_SETMINPOSITION)
236 rc +=
" WPF_SETMINPOSITION";
237 if (flags & WPF_RESTORETOMAXIMIZED)
238 rc +=
" WPF_RESTORETOMAXIMIZED";
239 if (flags & WPF_ASYNCWINDOWPLACEMENT)
240 rc +=
" WPF_ASYNCWINDOWPLACEMENT";
247 rc += QByteArray::number(cmd);
250 if (cmd == SW_SHOWNORMAL)
251 rc +=
" SW_SHOWNORMAL";
252 if (cmd == SW_NORMAL)
254 if (cmd == SW_SHOWMINIMIZED)
255 rc +=
" SW_SHOWMINIMIZED";
256 if (cmd == SW_SHOWMAXIMIZED)
257 rc +=
" SW_SHOWMAXIMIZED";
258 if (cmd == SW_MAXIMIZE)
259 rc +=
" SW_MAXIMIZE";
260 if (cmd == SW_SHOWNOACTIVATE)
261 rc +=
" SW_SHOWNOACTIVATE";
264 if (cmd == SW_MINIMIZE)
265 rc +=
" SW_MINIMIZE";
266 if (cmd == SW_SHOWMINNOACTIVE)
267 rc +=
" SW_SHOWMINNOACTIVE";
268 if (cmd == SW_SHOWNA)
270 if (cmd == SW_RESTORE)
272 if (cmd == SW_SHOWDEFAULT)
273 rc +=
" SW_SHOWDEFAULT";
274 if (cmd == SW_FORCEMINIMIZE)
275 rc +=
" SW_FORCEMINIMIZE";
281 return QSize(rect.right -rect.left, rect.bottom - rect.top);
286 return QRect(
QPoint(rect.left, rect.top), qSizeOfRect(rect));
291 const int x = rect.left();
292 const int y = rect.top();
293 RECT result = { x, y, x + rect.width(), y + rect.height() };
297#ifndef QT_NO_DEBUG_STREAM
298QDebug operator<<(QDebug d,
const RECT &r)
300 QDebugStateSaver saver(d);
302 d <<
"RECT(left=" << r.left <<
", top=" << r.top
303 <<
", right=" << r.right <<
", bottom=" << r.bottom
304 <<
" (" << r.right - r.left <<
'x' << r.bottom - r.top <<
"))";
308QDebug operator<<(QDebug d,
const POINT &p)
310 QDebugStateSaver saver(d);
312 d <<
"POINT(x=" << p.x <<
", y=" << p.y <<
')';
316QDebug operator<<(QDebug d,
const WINDOWPOS &wp)
318 QDebugStateSaver saver(d);
321 d <<
"WINDOWPOS(flags=" << debugWinSwpPos(wp.flags) <<
", hwnd="
322 << wp.hwnd <<
", hwndInsertAfter=" << wp.hwndInsertAfter <<
", x=" << wp.x
323 <<
", y=" << wp.y <<
", cx=" << wp.cx <<
", cy=" << wp.cy <<
')';
327QDebug operator<<(QDebug d,
const NCCALCSIZE_PARAMS &p)
329 QDebugStateSaver saver(d);
331 d <<
"NCCALCSIZE_PARAMS(rgrc=[" << p.rgrc[0] <<
", " << p.rgrc[1] <<
", "
332 << p.rgrc[2] <<
"], lppos=" << *p.lppos <<
')';
336QDebug operator<<(QDebug d,
const MINMAXINFO &i)
338 QDebugStateSaver saver(d);
340 d <<
"MINMAXINFO(maxSize=" << i.ptMaxSize <<
", "
341 <<
"maxpos=" << i.ptMaxPosition <<
", "
342 <<
"maxtrack=" << i.ptMaxTrackSize <<
", "
343 <<
"mintrack=" << i.ptMinTrackSize <<
')';
347QDebug operator<<(QDebug d,
const WINDOWPLACEMENT &wp)
349 QDebugStateSaver saver(d);
352 d <<
"WINDOWPLACEMENT(flags=" << debugWindowPlacementFlags(wp.flags) <<
", showCmd="
353 << debugShowWindowCmd(wp.showCmd) <<
", ptMinPosition=" << wp.ptMinPosition
354 <<
", ptMaxPosition=" << wp.ptMaxPosition <<
", rcNormalPosition="
355 << wp.rcNormalPosition <<
')';
359QDebug operator<<(QDebug d,
const GUID &guid)
361 QDebugStateSaver saver(d);
363 d <<
'{' << Qt::hex << Qt::uppercasedigits << qSetPadChar(u'0')
364 << qSetFieldWidth(8) << guid.Data1
365 << qSetFieldWidth(0) <<
'-' << qSetFieldWidth(4)
366 << guid.Data2 << qSetFieldWidth(0) <<
'-' << qSetFieldWidth(4)
367 << guid.Data3 << qSetFieldWidth(0) <<
'-' << qSetFieldWidth(4)
368 << qSetFieldWidth(2) << guid.Data4[0] << guid.Data4[1]
369 << qSetFieldWidth(0) <<
'-' << qSetFieldWidth(2);
370 for (
int i = 2; i < 8; ++i)
372 d << qSetFieldWidth(0) <<
'}';
379 d << r.width() <<
'x' << r.height() << Qt::forcesign << r.x() << r.y() << Qt::noforcesign;
384 d << m.left() <<
", " << m.top() <<
", " << m.right() <<
", " << m.bottom();
391 if (GetWindowLongPtr(hwnd, GWL_EXSTYLE) & WS_EX_TOOLWINDOW)
394 const QWindowsScreen *screen = screenManager.screens().size() == 1
395 ? screenManager.screens().constFirst() : screenManager
.screenAtDp(point
);
397 return screen->availableGeometry().topLeft() - screen->geometry().topLeft();
405 RECT rect = { 0, 0, 0, 0 };
407 WINDOWPLACEMENT windowPlacement;
408 windowPlacement.length =
sizeof(WINDOWPLACEMENT);
409 GetWindowPlacement(hwnd, &windowPlacement);
410 if (windowPlacement.showCmd == SW_SHOWMINIMIZED) {
411 const QRect result = qrectFromRECT(windowPlacement.rcNormalPosition);
412 return result.translated(windowPlacementOffset(hwnd, result.topLeft()));
415 GetWindowRect(hwnd, &rect);
416 const HWND parent = GetParent(hwnd);
417 if (parent && !topLevel) {
418 const int width = rect.right - rect.left;
419 const int height = rect.bottom - rect.top;
420 POINT leftTop = { rect.left, rect.top };
421 screenToClient(parent, &leftTop);
422 rect.left = leftTop.x;
423 rect.top = leftTop.y;
424 rect.right = leftTop.x + width;
425 rect.bottom = leftTop.y + height;
427 return qrectFromRECT(rect);
433 if (!IsWindowVisible(hwnd))
434 return QWindow::Hidden;
435 WINDOWPLACEMENT windowPlacement;
436 windowPlacement.length =
sizeof(WINDOWPLACEMENT);
437 if (GetWindowPlacement(hwnd, &windowPlacement)) {
438 switch (windowPlacement.showCmd) {
439 case SW_SHOWMINIMIZED:
441 case SW_FORCEMINIMIZE:
442 return QWindow::Minimized;
443 case SW_SHOWMAXIMIZED:
444 return QWindow::Maximized;
449 return QWindow::Windowed;
454 switch (w->surfaceType()) {
455 case QSurface::OpenGLSurface:
456 case QSurface::VulkanSurface:
457 case QSurface::Direct3DSurface:
466 DWM_BLURBEHIND blurBehind = {0, 0,
nullptr, 0};
468 blurBehind.dwFlags = DWM_BB_ENABLE | DWM_BB_BLURREGION;
469 blurBehind.fEnable = TRUE;
470 blurBehind.hRgnBlur = CreateRectRgn(0, 0, -1, -1);
472 const bool result = DwmEnableBlurBehindWindow(hwnd, &blurBehind) == S_OK;
474 if (blurBehind.hRgnBlur)
475 DeleteObject(blurBehind.hRgnBlur);
483 if ((flags & Qt::MSWindowsFixedSizeDialogHint) || !(flags & Qt::WindowMaximizeButtonHint))
487 return (flags & Qt::CustomizeWindowHint) ||
488 w->maximumSize() == QSize(QWINDOWSIZE_MAX, QWINDOWSIZE_MAX);
493 const LONG_PTR style = GetWindowLongPtr(hwnd, GWL_STYLE);
494 return (style & WS_CHILD) || (flags & Qt::FramelessWindowHint);
500bool QWindowsWindow::setWindowLayered(HWND hwnd, Qt::WindowFlags flags,
bool hasAlpha, qreal opacity)
502 const LONG_PTR exStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
504 const bool needsLayered = (flags & Qt::WindowTransparentForInput)
505 || (hasAlpha && hasNoNativeFrame(hwnd, flags)) || opacity < 1.0;
506 const bool isLayered = (exStyle & WS_EX_LAYERED);
507 if (needsLayered != isLayered) {
509 SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle | WS_EX_LAYERED);
511 SetWindowLongPtr(hwnd, GWL_EXSTYLE, exStyle & ~WS_EX_LAYERED);
517static void setWindowOpacity(HWND hwnd, Qt::WindowFlags flags,
bool hasAlpha,
bool accelerated, qreal level)
519 if (QWindowsWindow::setWindowLayered(hwnd, flags, hasAlpha, level)) {
520 const BYTE alpha = BYTE(qRound(255.0 * level));
521 if (hasAlpha && !accelerated && QWindowsWindow::hasNoNativeFrame(hwnd, flags)) {
523 BLENDFUNCTION blend = {AC_SRC_OVER, 0, alpha, AC_SRC_ALPHA};
524 UpdateLayeredWindow(hwnd,
nullptr,
nullptr,
nullptr,
nullptr,
nullptr, 0, &blend, ULW_ALPHA);
526 SetLayeredWindowAttributes(hwnd, 0, alpha, LWA_ALPHA);
528 }
else if (IsWindowVisible(hwnd)) {
529 InvalidateRect(hwnd,
nullptr, TRUE);
538 return GetSystemMetricsForDpi(SM_CXSIZEFRAME, dpi)
539 + GetSystemMetricsForDpi(SM_CXPADDEDBORDER, dpi);
543
544
545
549 POINT pt = {screenPoint.x(), screenPoint.y()};
550 if (HMONITOR hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONULL)) {
553 if (SUCCEEDED(GetDpiForMonitor(hMonitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY))) {
554 const int gap = getResizeBorderThickness(dpiX);
555 return QMargins(gap, 0, gap, gap);
563 const UINT dpi = GetDpiForWindow(hwnd);
564 const int gap = getResizeBorderThickness(dpi);
565 return QMargins(gap, 0, gap, gap);
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
601 void fromWindow(
const QWindow *w,
const Qt::WindowFlags flags,
unsigned creationFlags = 0);
604 void initialize(
const QWindow *w, HWND h,
bool frameChange, qreal opacityLevel)
const;
621 QDebugStateSaver saver(debug);
624 debug <<
"WindowCreationData: " << d.flags
627 debug <<
" parent=" << d.parentHandle;
630 <<
"\n style=" << debugWinStyle(d.style);
632 debug <<
"\n exStyle=" << debugWinExStyle(d.exStyle);
640 flags &= ~Qt::WindowFullscreenButtonHint;
645 constexpr Qt::WindowFlags clientAreaHints =
646 Qt::ExpandedClientAreaHint | Qt::NoTitleBarBackgroundHint;
647 switch (flags & ~clientAreaHints) {
649 flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinimizeButtonHint
650 |Qt::WindowMaximizeButtonHint|Qt::WindowCloseButtonHint;
654 flags |= Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowCloseButtonHint;
659 if ((flags & Qt::WindowType_Mask) == Qt::SplashScreen)
660 flags |= Qt::FramelessWindowHint;
665 const auto getDeviceName = [](
const QScreen *screen) -> QString {
666 if (
const auto s =
static_cast<
const QWindowsScreen *>(screen->handle()))
667 return s->data().deviceName;
670 QScreen *winScreen = w ? w->screen() : QGuiApplication::primaryScreen();
671 if (winScreen && getDeviceName(winScreen) != name) {
672 const auto screens = winScreen->virtualSiblings();
673 for (QScreen *screen : screens) {
674 if (getDeviceName(screen) == name)
681static QPoint calcPosition(
const QWindow *w,
const QWindowCreationContextPtr &context,
const QMargins &invMargins)
683 const QPoint orgPos(context->frameX - invMargins.left(), context->frameY - invMargins.top());
685 if (!w || w->type() != Qt::Window)
689 const QScreen *screenForGL = QWindowsWindow::forcedScreenForGLWindow(w);
693 const QPoint posFrame(context->frameX, context->frameY);
694 const QMargins margins = context->margins;
695 const QRect scrGeo = screenForGL->handle()->availableGeometry();
698 if (scrGeo.contains(orgPos))
703 if (scrGeo.contains(posFrame))
707 const auto screens = screenForGL->virtualSiblings();
708 const QScreen *orgScreen =
nullptr;
709 for (QScreen *screen : screens) {
710 if (screen->handle()->availableGeometry().contains(posFrame)) {
715 const QPoint ctPos = QPoint(qMax(scrGeo.left(), scrGeo.center().x()
716 + (margins.right() - margins.left() - context->frameWidth)/2),
717 qMax(scrGeo.top(), scrGeo.center().y()
718 + (margins.bottom() - margins.top() - context->frameHeight)/2));
724 const QRect orgGeo = orgScreen->handle()->availableGeometry();
725 const QRect orgFrame(
QPoint(context->frameX, context->frameY),
726 QSize(context->frameWidth, context->frameHeight));
729 if (orgGeo.center() == (orgFrame - margins).center())
733 const QPoint newPos(scrGeo.left() + ((posFrame.x() - orgGeo.left()) * scrGeo.width()) / orgGeo.width(),
734 scrGeo.top() + ((posFrame.y() - orgGeo.top()) * scrGeo.height()) / orgGeo.height());
735 const QPoint newPosNoMargin(newPos.x() - invMargins.left(), newPos.y() - invMargins.top());
737 return scrGeo.contains(newPosNoMargin) ? newPosNoMargin : newPos;
741 unsigned creationFlags)
748 QVariant prop = w->property(QWindowsWindow::embeddedNativeParentHandleProperty);
749 if (prop.isValid()) {
751 parentHandle =
reinterpret_cast<HWND>(prop.value<WId>());
765 fixTopLevelWindowFlags(flags);
767 type =
static_cast<Qt::WindowType>(
int(flags) & Qt::WindowType_Mask);
783 if ((flags & Qt::MSWindowsFixedSizeDialogHint))
792 if (QGuiApplication::layoutDirection() == Qt::RightToLeft
793 && (QWindowsIntegration::instance()->options() & QWindowsIntegration::RtlEnabled) != 0) {
794 exStyle |= WS_EX_LAYOUTRTL | WS_EX_NOINHERITLAYOUT;
799 flags |= Qt::WindowStaysOnTopHint;
801 if (
const QWindow *parentWindow = topLevel ? w->transientParent() : w->parent())
802 parentHandle = QWindowsWindow::handleOf(parentWindow);
805 if (popup || (type == Qt::ToolTip) || (type == Qt::SplashScreen)) {
808 if (flags & Qt::FramelessWindowHint)
810 else if (flags & Qt::WindowTitleHint)
811 style = WS_OVERLAPPED;
818 style |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN ;
820 if (flags & Qt::WindowDoesNotAcceptFocus)
824 if ((type == Qt::Window || dialog || tool)) {
825 if (!(flags & Qt::FramelessWindowHint)) {
827 if (flags & Qt::MSWindowsFixedSizeDialogHint) {
828 style |= WS_DLGFRAME;
830 style |= WS_THICKFRAME;
832 if (flags & Qt::WindowTitleHint)
835 if (flags & Qt::WindowSystemMenuHint)
837 else if (dialog && (flags & Qt::WindowCloseButtonHint) && !(flags & Qt::FramelessWindowHint)) {
838 style |= WS_SYSMENU | WS_BORDER;
839 exStyle |= WS_EX_DLGMODALFRAME;
841 const bool showMinimizeButton = flags & Qt::WindowMinimizeButtonHint;
842 if (showMinimizeButton)
843 style |= WS_MINIMIZEBOX;
844 const bool showMaximizeButton = shouldShowMaximizeButton(w, flags);
845 if (showMaximizeButton)
846 style |= WS_MAXIMIZEBOX;
847 if (showMinimizeButton || showMaximizeButton)
851 if ((flags & Qt::WindowContextHelpButtonHint) && !showMinimizeButton
852 && !showMaximizeButton)
860 if (flagsIn & Qt::WindowTransparentForInput)
864 if (qEnvironmentVariableIntValue(
"QT_QPA_DISABLE_REDIRECTION_SURFACE"))
865 exStyle |= WS_EX_NOREDIRECTIONBITMAP;
871 if (!w->isTopLevel() || w->flags().testFlag(Qt::FramelessWindowHint))
880 auto *dWindow = QWindowPrivate::get(
const_cast<QWindow*>(w));
881 const QPalette windowPal = dWindow->windowPalette();
882 return windowPal.color(QPalette::WindowText).lightness()
883 > windowPal.color(QPalette::Window).lightness();
889 return getResizeBorderThickness(dpi) +
890 ::GetSystemMetricsForDpi(SM_CYCAPTION, dpi);
897 result.flags = flags;
899 const auto appinst =
reinterpret_cast<HINSTANCE>(GetModuleHandle(
nullptr));
904 windowTitlebarDescription.name =
"_q_titlebar"_L1;
905 windowTitlebarDescription
.style = CS_VREDRAW | CS_HREDRAW;
909 const QScreen *screen{};
910 const QRect rect = QPlatformWindow::initialGeometry(w, data.geometry,
911 defaultWindowWidth, defaultWindowHeight,
914 if (title.isEmpty() && (result.flags & Qt::WindowTitleHint))
915 title =
topLevel ? qAppName() : w->objectName();
917 const auto *titleUtf16 =
reinterpret_cast<
const wchar_t *>(title.utf16());
918 const auto *classNameUtf16 =
reinterpret_cast<
const wchar_t *>(windowClassName.utf16());
919 const auto *classTitleBarNameUtf16 =
reinterpret_cast<
const wchar_t *>(windowTitlebarName.utf16());
924 rect, data.customMargins,
928 const bool hasFrame = (style & (WS_DLGFRAME | WS_THICKFRAME))
929 && !(result.flags & Qt::FramelessWindowHint);
930 QMargins invMargins = topLevel && hasFrame && QWindowsGeometryHint::positionIncludesFrame(w)
931 ? invisibleMargins(QPoint(context->frameX, context->frameY)) : QMargins();
933 qCDebug(lcQpaWindow).nospace()
934 <<
"CreateWindowEx: " << w <<
" class=" << windowClassName <<
" title=" << title
935 <<
'\n' << *
this <<
"\nrequested: " << rect <<
": "
936 << context->frameWidth <<
'x' << context->frameHeight
937 <<
'+' << context->frameX <<
'+' << context->frameY
938 <<
" custom margins: " << context->customMargins
939 <<
" invisible margins: " << invMargins;
942 QPoint pos = calcPosition(w, context, invMargins);
945 int mirrorParentWidth = 0;
946 if (!w->isTopLevel() && QWindowsBaseWindow::isRtlLayout(parentHandle)) {
948 GetClientRect(parentHandle, &rect);
949 mirrorParentWidth = rect.right;
951 if (mirrorParentWidth != 0 && pos.x() != CW_USEDEFAULT && context->frameWidth != CW_USEDEFAULT)
952 pos.setX(mirrorParentWidth - context->frameWidth - pos.x());
954 result.hwnd = CreateWindowEx(
exStyle, classNameUtf16, titleUtf16,
957 context->frameWidth, context->frameHeight,
958 parentHandle,
nullptr, appinst,
nullptr);
960 const UINT dpi = ::GetDpiForWindow(result.hwnd);
961 const int titleBarHeight = getTitleBarHeight_sys(dpi);
962 result.hwndTitlebar = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_NOACTIVATE,
963 classTitleBarNameUtf16, classTitleBarNameUtf16,
965 context->frameWidth, titleBarHeight,
966 nullptr,
nullptr, appinst,
nullptr);
968 qCDebug(lcQpaWindow).nospace()
969 <<
"CreateWindowEx: returns " << w <<
' ' << result.hwnd <<
" obtained geometry: "
970 << context->obtainedPos << context->obtainedSize <<
' ' << context->margins;
973 qErrnoWarning(
"%s: CreateWindowEx failed",
__FUNCTION__);
977 if (QWindowsTheme::instance()->colorScheme() == Qt::ColorScheme::Dark && shouldApplyDarkFrame(w))
978 QWindowsWindow::setDarkBorderToWindow(result.hwnd,
true);
980 if (mirrorParentWidth != 0) {
981 context->obtainedPos.setX(mirrorParentWidth - context->obtainedSize.width()
982 - context->obtainedPos.x());
985 QRect obtainedGeometry(context->obtainedPos, context->obtainedSize);
987 result.geometry = obtainedGeometry;
988 result.restoreGeometry = frameGeometry(result.hwnd, topLevel);
989 result.fullFrameMargins = context->margins;
992 result.customMargins = context->customMargins;
1000 const LONG_PTR oldStyle = GetWindowLongPtr(hwnd, GWL_STYLE);
1001 const LONG_PTR oldExStyle = GetWindowLongPtr(hwnd, GWL_EXSTYLE);
1003 const LONG_PTR newStyle =
style | (oldStyle & (WS_DISABLED|WS_VISIBLE));
1004 if (oldStyle != newStyle)
1005 SetWindowLongPtr(hwnd, GWL_STYLE, newStyle);
1006 const LONG_PTR newExStyle =
exStyle;
1007 if (newExStyle != oldExStyle)
1008 SetWindowLongPtr(hwnd, GWL_EXSTYLE, newExStyle);
1009 qCDebug(lcQpaWindow).nospace() <<
__FUNCTION__ << hwnd << *
this
1010 <<
"\n Style from " << debugWinStyle(DWORD(oldStyle)) <<
"\n to "
1011 << debugWinStyle(DWORD(newStyle)) <<
"\n ExStyle from "
1012 << debugWinExStyle(DWORD(oldExStyle)) <<
" to "
1013 << debugWinExStyle(DWORD(newExStyle));
1020 UINT swpFlags = SWP_NOMOVE | SWP_NOSIZE | SWP_NOOWNERZORDER;
1022 swpFlags |= SWP_FRAMECHANGED;
1024 swpFlags |= SWP_NOACTIVATE;
1025 if ((flags & Qt::WindowStaysOnTopHint) || (type == Qt::ToolTip)) {
1026 SetWindowPos(hwnd, HWND_TOPMOST, 0, 0, 0, 0, swpFlags);
1027 if (flags & Qt::WindowStaysOnBottomHint)
1028 qWarning(
"QWidget: Incompatible window flags: the window can't be on top and on bottom at the same time");
1029 }
else if (flags & Qt::WindowStaysOnBottomHint) {
1030 SetWindowPos(hwnd, HWND_BOTTOM, 0, 0, 0, 0, swpFlags);
1031 }
else if (frameChange) {
1032 SetWindowPos(hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, swpFlags);
1034 if (flags & (Qt::CustomizeWindowHint|Qt::WindowTitleHint)) {
1035 HMENU systemMenu = GetSystemMenu(hwnd, FALSE);
1036 if (flags & Qt::WindowCloseButtonHint)
1037 EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_ENABLED);
1039 EnableMenuItem(systemMenu, SC_CLOSE, MF_BYCOMMAND|MF_GRAYED);
1041 if (flags & Qt::ExpandedClientAreaHint) {
1042 MARGINS margins = { -1, -1, -1, -1 };
1043 DwmExtendFrameIntoClientArea(hwnd, &margins);
1045 MARGINS margins = { 0, 0, 0, 0 };
1046 DwmExtendFrameIntoClientArea(hwnd, &margins);
1049 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, swpFlags);
1053 const bool hasAlpha = w->format().hasAlpha();
1054 if (isAccelerated && hasAlpha)
1055 applyBlurBehindWindow(hwnd);
1056 setWindowOpacity(hwnd, flags, hasAlpha, isAccelerated, opacityLevel);
1063 if (QHighDpiScaling::isActive()) {
1064 const qreal factor = QHighDpiScaling::factor(s);
1065 if (!qFuzzyCompare(factor, qreal(1))) {
1066 if (dip.width() > 0 && dip.width() < QWINDOWSIZE_MAX)
1067 dip.setWidth(qRound(qreal(dip.width()) * factor));
1068 if (dip.height() > 0 && dip.height() < QWINDOWSIZE_MAX)
1069 dip.setHeight(qRound(qreal(dip.height()) * factor));
1079 return flags.testFlag(Qt::FramelessWindowHint) && !(style & WS_MAXIMIZE);
1086 DWORD style = hwnd !=
nullptr ? DWORD(GetWindowLongPtr(hwnd, GWL_STYLE)) : 0;
1087 return flags.testFlag(Qt::FramelessWindowHint) && !(style & WS_MAXIMIZE);
1091
1092
1093
1094
1095
1096
1097
1098
1102 if (!w->isTopLevel() || shouldOmitFrameAdjustment(w->flags(), style))
1104 RECT rect = {0,0,0,0};
1105 style &= ~DWORD(WS_OVERLAPPED);
1106 if (AdjustWindowRectEx(&rect, style, FALSE, exStyle) == FALSE)
1107 qErrnoWarning(
"%s: AdjustWindowRectEx failed",
__FUNCTION__);
1108 const QMargins result(qAbs(rect.left), qAbs(rect.top),
1109 qAbs(rect.right), qAbs(rect.bottom));
1110 qCDebug(lcQpaWindow).nospace() <<
__FUNCTION__ <<
" style="
1111 << Qt::showbase << Qt::hex << style <<
" exStyle=" << exStyle << Qt::dec << Qt::noshowbase
1112 <<
' ' << rect <<
' ' << result;
1118 return frameOnPrimaryScreen(w, DWORD(GetWindowLongPtr(hwnd, GWL_STYLE)),
1119 DWORD(GetWindowLongPtr(hwnd, GWL_EXSTYLE)));
1124 if (!w->isTopLevel() || shouldOmitFrameAdjustment(w->flags(), style))
1126 RECT rect = {0,0,0,0};
1127 style &= ~DWORD(WS_OVERLAPPED);
1128 if (AdjustWindowRectExForDpi(&rect, style, FALSE, exStyle,
unsigned(qRound(dpi))) == FALSE) {
1129 qErrnoWarning(
"%s: AdjustWindowRectExForDpi failed",
__FUNCTION__);
1131 const QMargins result(qAbs(rect.left), qAbs(rect.top),
1132 qAbs(rect.right), qAbs(rect.bottom));
1133 qCDebug(lcQpaWindow).nospace() <<
__FUNCTION__ <<
" style="
1134 << Qt::showbase << Qt::hex << style <<
" exStyle=" << exStyle << Qt::dec << Qt::noshowbase
1136 <<
' ' << rect <<
' ' << result;
1142 if (!w->isTopLevel() || shouldOmitFrameAdjustment(w->flags(), style))
1144 if (QWindowsScreenManager::isSingleScreen())
1145 return frameOnPrimaryScreen(w, style, exStyle);
1147 auto screen = screenManager.screenForHwnd(hwnd);
1149 screen = screenManager.screens().value(0);
1150 const auto dpi = screen ? screen->logicalDpi().first : qreal(96);
1151 return frame(w, style, exStyle, dpi);
1156 return frame(w, hwnd, DWORD(GetWindowLongPtr(hwnd, GWL_STYLE)),
1157 DWORD(GetWindowLongPtr(hwnd, GWL_EXSTYLE)));
1162 DWORD style, DWORD exStyle)
1164 if (!w->isTopLevel() || shouldOmitFrameAdjustment(w->flags(), style))
1167 || !QWindowsContext::shouldHaveNonClientDpiScaling(w)) {
1168 return frameOnPrimaryScreen(w, style, exStyle);
1174 screen = screenManager.screens().value(0);
1176 dpi = screen->logicalDpi().first;
1177 return QWindowsGeometryHint::frame(w, style, exStyle, dpi);
1180bool QWindowsGeometryHint::handleCalculateSize(
const QWindow *window,
const QMargins &customMargins,
const MSG &msg, LRESULT *result)
1183 if (msg.wParam && window->flags() & Qt::FramelessWindowHint) {
1187 const QWindowsWindow *platformWindow = QWindowsWindow::windowsWindowOf(window);
1189 const bool clientAreaExpanded = platformWindow !=
nullptr ? platformWindow
->isClientAreaExpanded() : window->flags() & Qt::ExpandedClientAreaHint;
1191 if (msg.wParam && clientAreaExpanded) {
1193 const bool maximized = IsZoomed(msg.hwnd) && window->visibility() != QWindow::FullScreen;
1194 auto *ncp =
reinterpret_cast<NCCALCSIZE_PARAMS *>(msg.lParam);
1195 RECT *clientArea = &ncp->rgrc[0];
1196 const int border = getResizeBorderThickness(96);
1198 clientArea->top += border;
1199 clientArea->bottom -= border;
1200 clientArea->left += border;
1201 clientArea->right -= border;
1206 if (!msg.wParam || customMargins.isNull())
1208 *result = DefWindowProc(msg.hwnd, msg.message, msg.wParam, msg.lParam);
1209 auto *ncp =
reinterpret_cast<NCCALCSIZE_PARAMS *>(msg.lParam);
1210 const RECT oldClientArea = ncp->rgrc[0];
1211 ncp->rgrc[0].left += customMargins.left();
1212 ncp->rgrc[0].top += customMargins.top();
1213 ncp->rgrc[0].right -= customMargins.right();
1214 ncp->rgrc[0].bottom -= customMargins.bottom();
1216 qCDebug(lcQpaWindow).nospace() <<
__FUNCTION__ << oldClientArea <<
'+' << customMargins <<
"-->"
1217 << ncp->rgrc[0] <<
' ' << ncp->rgrc[1] <<
' ' << ncp->rgrc[2]
1218 <<
' ' << ncp->lppos->cx <<
',' << ncp->lppos->cy;
1223 const QMargins &margins,
1224 QSize *minimumSize, QSize *maximumSize)
1226 *minimumSize = toNativeSizeConstrained(w->minimumSize(), screen);
1227 *maximumSize = toNativeSizeConstrained(w->maximumSize(), screen);
1229 const int maximumWidth = qMax(maximumSize->width(), minimumSize->width());
1230 const int maximumHeight = qMax(maximumSize->height(), minimumSize->height());
1231 const int frameWidth = margins.left() + margins.right();
1232 const int frameHeight = margins.top() + margins.bottom();
1234 if (minimumSize->width() > 0)
1235 minimumSize->rwidth() += frameWidth;
1236 if (minimumSize->height() > 0)
1237 minimumSize->rheight() += frameHeight;
1238 if (maximumWidth < QWINDOWSIZE_MAX)
1239 maximumSize->setWidth(maximumWidth + frameWidth);
1240 if (maximumHeight < QWINDOWSIZE_MAX)
1241 maximumSize->setHeight(maximumHeight + frameHeight);
1245 const QScreen *screen,
1246 const QMargins &margins,
1251 frameSizeConstraints(w, screen, margins, &minimumSize, &maximumSize);
1252 qCDebug(lcQpaWindow).nospace() <<
'>' <<
__FUNCTION__ <<
'<' <<
" min="
1253 << minimumSize.width() <<
',' << minimumSize.height()
1254 <<
" max=" << maximumSize.width() <<
',' << maximumSize.height()
1255 <<
" margins=" << margins
1258 if (minimumSize.width() > 0)
1259 mmi->ptMinTrackSize.x = minimumSize.width();
1260 if (minimumSize.height() > 0)
1261 mmi->ptMinTrackSize.y = minimumSize.height();
1263 if (maximumSize.width() < QWINDOWSIZE_MAX)
1264 mmi->ptMaxTrackSize.x = maximumSize.width();
1265 if (maximumSize.height() < QWINDOWSIZE_MAX)
1266 mmi->ptMaxTrackSize.y = maximumSize.height();
1267 qCDebug(lcQpaWindow).nospace() <<
'<' <<
__FUNCTION__ <<
" out " << *mmi;
1271 const QMargins &margins,
1274 applyToMinMaxInfo(w, w->screen(), margins, mmi);
1279 return qt_window_private(
const_cast<QWindow *>(w))->positionPolicy
1280 == QWindowPrivate::WindowFrameInclusive;
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1302 return (GetWindowLongPtr(hwnd, GWL_EXSTYLE) & WS_EX_LAYOUTRTL) != 0;
1308 if (QPlatformWindow *pw = w->handle())
1309 return static_cast<QWindowsBaseWindow *>(pw);
1317 return bw ? bw->handle() : HWND(
nullptr);
1322 const HWND parent = parentHwnd();
1323 return !parent || parent == GetDesktopWindow();
1328 return frameGeometry(handle(), isTopLevel());
1333 return frameGeometry_sys().marginsRemoved(fullFrameMargins());
1338 return QWindowsGeometryHint::frame(window(), handle(), style(), exStyle());
1344 ULONG touchFlags = 0;
1345 if (IsTouchWindow(handle(), &touchFlags) == FALSE)
1347 TouchWindowTouchTypes result;
1348 if ((touchFlags & TWF_FINETOUCH) != 0)
1349 result.setFlag(TouchWindowTouchType::FineTouch);
1350 if ((touchFlags & TWF_WANTPALM) != 0)
1351 result.setFlag(TouchWindowTouchType::WantPalmTouch);
1357 SetWindowPos(handle(),
nullptr , 0, 0, 0, 0,
1358 SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
1363 qCDebug(lcQpaWindow) <<
__FUNCTION__ <<
this << window();
1364 const Qt::WindowType type = window()->type();
1365 if (type == Qt::Popup
1366 || type == Qt::SubWindow
1367 || !(window()->flags() & Qt::WindowStaysOnBottomHint)) {
1368 SetWindowPos(handle(), HWND_TOP, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1374 qCDebug(lcQpaWindow) <<
__FUNCTION__ <<
this << window();
1375 if (!(window()->flags() & Qt::WindowStaysOnTopHint))
1376 SetWindowPos(handle(), HWND_BOTTOM, 0, 0, 0, 0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE);
1381 qCDebug(lcQpaWindow) <<
__FUNCTION__ <<
this << window() << title;
1382 SetWindowText(handle(),
reinterpret_cast<
const wchar_t *>(title.utf16()));
1387 return QWindowsGeometryHint::mapToGlobal(handle(), pos);
1392 return QWindowsGeometryHint::mapFromGlobal(handle(), pos);
1418 switch (event->type()) {
1419 case QEvent::ChildWindowAdded:
1420 if (!(GetWindowLongPtr(handle(), GWL_STYLE) & WS_CLIPCHILDREN)) {
1421 auto *childWindowEvent =
static_cast<QChildWindowEvent*>(event);
1422 qWarning() << childWindowEvent->child() <<
"added as child to"
1423 << window() <<
"which does not have WS_CLIPCHILDREN set."
1424 <<
"This will result in drawing artifacts!";
1431 return QPlatformWindow::windowEvent(event);
1435
1436
1437
1438
1439
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1456 , m_topLevelStyle(0)
1458 if (QPlatformWindow::parent())
1459 setParent(QPlatformWindow::parent());
1464 if (QPlatformWindow::parent())
1471 const HWND newParent = newParentWindow ?
reinterpret_cast<HWND>(newParentWindow->winId()) : HWND(
nullptr);
1472 const bool isTopLevel = !newParent;
1473 const DWORD oldStyle =
style();
1475 qCDebug(lcQpaWindow) <<
__FUNCTION__ << window() <<
"newParent="
1476 << newParentWindow << newParent <<
"oldStyle=" << debugWinStyle(oldStyle);
1478 auto updateWindowFlags = [&] {
1480 DWORD newStyle = oldStyle;
1482 newStyle = m_topLevelStyle;
1484 m_topLevelStyle = oldStyle;
1485 newStyle &= ~(WS_OVERLAPPEDWINDOW | WS_POPUPWINDOW);
1486 newStyle |= WS_CHILD;
1488 SetWindowLongPtr(m_hwnd, GWL_STYLE, newStyle);
1491 if (wasTopLevel && !isTopLevel) {
1494 updateWindowFlags();
1497 SetParent(m_hwnd, newParent);
1499 if (!wasTopLevel && isTopLevel) {
1502 updateWindowFlags();
1508 qCDebug(lcQpaWindow) <<
__FUNCTION__ << window() << visible;
1510 ShowWindow(handle(), SW_SHOWNOACTIVATE);
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1536 const QRect &geometryIn,
const QRect &geometry,
1538 DWORD style, DWORD exStyle) :
1541 requestedGeometryIn(geometryIn),
1542 requestedGeometry(geometry),
1543 obtainedPos(geometryIn.topLeft()),
1544 obtainedSize(geometryIn.size()),
1545 margins(QWindowsGeometryHint::frame(w, geometry, style, exStyle))
1552 if (!(w->flags() & Qt::FramelessWindowHint))
1555 if (geometry.isValid()
1556 || !qt_window_private(
const_cast<QWindow *>(w))->resizeAutomatic) {
1557 frameX = geometry.x();
1558 frameY = geometry.y();
1559 const QMargins effectiveMargins = margins + customMargins;
1560 frameWidth = effectiveMargins.left() + geometry.width() + effectiveMargins.right();
1561 frameHeight = effectiveMargins.top() + geometry.height() + effectiveMargins.bottom();
1564 frameHeight += menuHeight;
1566 const bool isDefaultPosition = !frameX && !frameY && w->isTopLevel();
1567 if (!QWindowsGeometryHint::positionIncludesFrame(w) && !isDefaultPosition) {
1568 frameX -= effectiveMargins.left();
1569 frameY -= effectiveMargins.top();
1573 qCDebug(lcQpaWindow).nospace()
1574 <<
__FUNCTION__ <<
' ' << w <<
' ' << geometry
1575 <<
" pos incl. frame=" << QWindowsGeometryHint::positionIncludesFrame(w)
1576 <<
" frame=" << frameWidth <<
'x' << frameHeight <<
'+'
1577 << frameX <<
'+' << frameY
1578 <<
" margins=" << margins <<
" custom margins=" << customMargins;
1583 QWindowsGeometryHint::applyToMinMaxInfo(window, screen, margins + customMargins, mmi);
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1615 m_cursor(
new CursorHandle)
1616#if QT_CONFIG(vulkan)
1617 , m_vkSurface(VK_NULL_HANDLE)
1622 if (aWindow->flags().testFlags(Qt::ExpandedClientAreaHint)) {
1623 SetParent(m_data.hwndTitlebar, m_data.hwnd);
1624 ShowWindow(m_data.hwndTitlebar, SW_SHOW);
1627 if (aWindow->surfaceType() == QWindow::Direct3DSurface)
1629#if QT_CONFIG(opengl)
1630 if (aWindow->surfaceType() == QWindow::OpenGLSurface)
1631 setFlag(OpenGLSurface);
1633#if QT_CONFIG(vulkan)
1634 if (aWindow->surfaceType() == QSurface::VulkanSurface)
1635 setFlag(VulkanSurface);
1637 updateDropSite(window()->isTopLevel());
1641 if (!touchWindowTouchTypes_sys().has_value())
1644#if QT_CONFIG(directmanipulation)
1647 if (
auto *dm = QWindowsContext::instance()->directManipulation())
1648 dm->registerWindow(aWindow, m_data.hwnd);
1651 const qreal opacity = qt_window_private(aWindow)->opacity;
1652 if (!qFuzzyCompare(opacity, qreal(1.0)))
1653 setOpacity(opacity);
1655 setMask(QHighDpi::toNativeLocalRegion(window()->mask(), window()));
1657 if (aWindow->isTopLevel())
1658 setWindowIcon(aWindow->icon());
1666 if (m_vsyncServiceCallbackId != 0)
1667 QDxgiVSyncService::instance()->unregisterCallback(m_vsyncServiceCallbackId);
1669 QWindowsThemeCache::clearThemeCache(m_data.hwnd);
1671 UnregisterTouchWindow(m_data.hwnd);
1672#if QT_CONFIG(directmanipulation)
1673 if (
auto *dm = QWindowsContext::instance()->directManipulation())
1674 dm->unregisterWindow(m_data.hwnd);
1683 QWindowCreationContextPtr creationContext =
1686 QWindow *w = window();
1687 setWindowState(w->windowStates());
1691 const Qt::WindowState state = w->windowState();
1692 const QRect obtainedGeometry(creationContext->obtainedPos, creationContext->obtainedSize);
1693 QPlatformScreen *obtainedScreen = screenForGeometry(obtainedGeometry);
1694 if (obtainedScreen && screen() != obtainedScreen)
1695 QWindowSystemInterface::handleWindowScreenChanged<QWindowSystemInterface::SynchronousDelivery>(w, obtainedScreen->screen());
1696 if (state != Qt::WindowMaximized && state != Qt::WindowFullScreen
1697 && creationContext->requestedGeometryIn != obtainedGeometry) {
1698 QWindowSystemInterface::handleGeometryChange<QWindowSystemInterface::SynchronousDelivery>(w, obtainedGeometry);
1705 return window()->requestedFormat();
1708void QWindowsWindow::fireExpose(
const QRegion ®ion,
bool force)
1710 if (region.isEmpty() && !force)
1714 QWindowSystemInterface::handleExposeEvent(window(), region);
1719 fireExpose(QRect(QPoint(0, 0), m_data.geometry.size()), force);
1724 qCDebug(lcQpaWindow) <<
__FUNCTION__ <<
this << window() << m_data.hwnd;
1728 const auto tlw = QGuiApplication::topLevelWindows();
1729 for (QWindow *w : tlw) {
1730 if (w->transientParent() == window()) {
1731 if (QWindowsWindow *tw = QWindowsWindow::windowsWindowOf(w))
1732 tw->updateTransientParent();
1736 if (context->windowUnderMouse() == window())
1740 setDropSiteEnabled(
false);
1741#if QT_CONFIG(vulkan)
1743 QVulkanInstance *inst = window()->vulkanInstance();
1745 static_cast<QWindowsVulkanInstance *>(inst->handle())->destroySurface(m_vkSurface);
1746 m_vkSurface = VK_NULL_HANDLE;
1753 m_surface =
nullptr;
1756 DestroyWindow(m_data.hwndTitlebar);
1757 DestroyWindow(m_data.hwnd);
1758 context->removeWindow(m_data.hwnd);
1759 m_data.hwndTitlebar =
nullptr;
1760 m_data.hwnd =
nullptr;
1766 bool enabled =
false;
1767 bool parentIsEmbedded =
false;
1772 const QWindow *parent = window()->parent();
1773 if (parent && parent->handle() && parent->handle()->isForeignWindow())
1774 parentIsEmbedded =
true;
1777 if (topLevel || parentIsEmbedded) {
1778 switch (window()->type()) {
1791 setDropSiteEnabled(enabled);
1796 if (isDropSiteEnabled() == dropEnabled)
1798 qCDebug(lcQpaMime) <<
__FUNCTION__ << window() << dropEnabled;
1799#if QT_CONFIG(clipboard) && QT_CONFIG(draganddrop)
1801 Q_ASSERT(m_data.hwnd);
1802 m_dropTarget =
new QWindowsOleDropTarget(window());
1803 RegisterDragDrop(m_data.hwnd, m_dropTarget);
1804 CoLockObjectExternal(m_dropTarget,
true,
true);
1806 CoLockObjectExternal(m_dropTarget,
false,
true);
1807 m_dropTarget->Release();
1808 RevokeDragDrop(m_data.hwnd);
1809 m_dropTarget =
nullptr;
1818 m_screenForGLInitialized =
false;
1823 m_screenForGLInitialized =
false;
1828 static QString forceToScreen;
1829 if (!m_screenForGLInitialized) {
1831 m_screenForGLInitialized =
true;
1833 return forceToScreen.isEmpty() ?
nullptr : screenForDeviceName(w, forceToScreen);
1840 while (QWindow *parent = w->parent())
1843 if (
const QPlatformWindow *handle = w->handle()) {
1844 const auto *ww =
static_cast<
const QWindowsWindow *>(handle);
1845 if (ww->isEmbedded()) {
1846 HWND parentHWND = GetAncestor(ww->handle(), GA_PARENT);
1847 const HWND desktopHwnd = GetDesktopWindow();
1849 while (parentHWND && parentHWND != desktopHwnd) {
1850 if (QWindowsWindow *ancestor = ctx->findPlatformWindow(parentHWND))
1851 return topLevelOf(ancestor->window());
1852 parentHWND = GetAncestor(parentHWND, GA_PARENT);
1862 const QString &title)
1865 creationData.fromWindow(w, parameters.flags);
1868 creationData.initialize(w, result.hwnd, !parameters.customMargins.isNull(), 1);
1874 const QWindow *win = window();
1875 qCDebug(lcQpaWindow) <<
__FUNCTION__ <<
this << win << m_data.hwnd << visible;
1888 if (win->type() == Qt::Popup && !win->parent() && !QGuiApplication::focusWindow())
1889 SetForegroundWindow(m_data.hwnd);
1893 if (window()->flags() & Qt::Popup)
1894 ShowWindow(m_data.hwnd, SW_HIDE);
1904 if (win->isModal()) {
1905 if (QWindow *parent = win->transientParent()) {
1906 if (
auto *pw = QWindowsWindow::windowsWindowOf(parent))
1911 fireExpose(QRegion());
1918 return m_data.hwnd && IsWindowVisible(m_data.hwnd);
1924 if (
const HWND activeHwnd = GetForegroundWindow())
1925 if (m_data.hwnd == activeHwnd || IsChild(activeHwnd, m_data.hwnd))
1932 const auto *childWindow =
static_cast<
const QWindowsWindow *>(child);
1933 return IsChild(m_data.hwnd, childWindow->handle());
1938 return m_data.embedded;
1943 return m_data.hwnd ? QWindowsGeometryHint::mapToGlobal(m_data.hwnd, pos) : pos;
1948 return m_data.hwnd ? QWindowsGeometryHint::mapFromGlobal(m_data.hwnd, pos) : pos;
1958 if (window()->type() == Qt::Popup)
1961 const HWND oldTransientParent = GetWindow(m_data.hwnd, GW_OWNER);
1962 HWND newTransientParent =
nullptr;
1963 if (
const QWindow *tp = window()->transientParent()) {
1964 if (
const QWindowsWindow *tw = QWindowsWindow::windowsWindowOf(tp)) {
1966 newTransientParent = tw->handle();
1969 newTransientParent = tbw->handle();
1975 while (newTransientParent && (GetWindowLongPtr(newTransientParent, GWL_STYLE) & WS_CHILD) != 0)
1976 newTransientParent = GetParent(newTransientParent);
1978 if (newTransientParent != oldTransientParent)
1979 SetWindowLongPtr(m_data.hwnd,
GWL_HWNDPARENT, LONG_PTR(newTransientParent));
1985 const QVariant showWithoutActivating = window->property(
"_q_showWithoutActivating");
1986 return showWithoutActivating.isValid() && showWithoutActivating.toBool();
1991 WINDOWPLACEMENT windowPlacement;
1992 windowPlacement.length =
sizeof(WINDOWPLACEMENT);
1993 if (GetWindowPlacement(hwnd, &windowPlacement)) {
1994 windowPlacement.showCmd = SW_SHOWMINIMIZED;
1995 windowPlacement.rcNormalPosition = RECTfromQRect(r);
1996 SetWindowPlacement(hwnd, &windowPlacement);
2003 WINDOWPLACEMENT windowPlacement;
2004 windowPlacement.length =
sizeof(WINDOWPLACEMENT);
2005 if (GetWindowPlacement(hwnd, &windowPlacement)) {
2007 windowPlacement.flags |= WPF_RESTORETOMAXIMIZED;
2009 windowPlacement.flags &= ~WPF_RESTORETOMAXIMIZED;
2010 SetWindowPlacement(hwnd, &windowPlacement);
2017 int sm = SW_SHOWNORMAL;
2018 bool fakedMaximize =
false;
2019 bool restoreMaximize =
false;
2020 const QWindow *w = window();
2021 const Qt::WindowFlags flags = w->flags();
2022 const Qt::WindowType type = w->type();
2023 if (w->isTopLevel()) {
2024 const Qt::WindowStates state = w->windowStates();
2025 if (state & Qt::WindowMinimized) {
2026 sm = SW_SHOWMINIMIZED;
2028 sm = SW_SHOWMINNOACTIVE;
2029 if (state & Qt::WindowMaximized)
2030 restoreMaximize =
true;
2032 updateTransientParent();
2033 if (state & Qt::WindowMaximized) {
2034 sm = SW_SHOWMAXIMIZED;
2040 if (flags & Qt::WindowTitleHint &&
2041 !(flags & (Qt::WindowMinMaxButtonsHint | Qt::FramelessWindowHint))) {
2042 fakedMaximize = TRUE;
2043 setStyle(style() | WS_MAXIMIZEBOX);
2048 if (type == Qt::Popup ||
2049 type == Qt::ToolTip ||
2051 (flags & Qt::WindowDoesNotAcceptFocus) ||
2052 testShowWithoutActivating(w))
2053 sm = SW_SHOWNOACTIVATE;
2055 if (w->windowStates() & Qt::WindowMaximized)
2058 ShowWindow(m_data.hwnd, sm);
2062 if (fakedMaximize) {
2063 setStyle(style() & ~WS_MAXIMIZEBOX);
2064 SetWindowPos(m_data.hwnd,
nullptr, 0, 0, 0, 0,
2065 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER
2066 | SWP_FRAMECHANGED);
2068 if (restoreMaximize)
2069 setRestoreMaximizedFlag(m_data.hwnd);
2074 qCDebug(lcQpaWindow) <<
__FUNCTION__ << window() << newParent;
2077 setParent_sys(newParent);
2083 HWND oldParentHWND = parentHwnd();
2084 HWND newParentHWND =
nullptr;
2086 const auto *parentW =
static_cast<
const QWindowsWindow *>(parent);
2087 newParentHWND = parentW->handle();
2092 HWND desktopHwnd = GetDesktopWindow();
2093 if (oldParentHWND == desktopHwnd)
2094 oldParentHWND =
nullptr;
2095 if (newParentHWND == desktopHwnd)
2096 newParentHWND =
nullptr;
2098 if (newParentHWND != oldParentHWND) {
2099 const bool wasTopLevel = oldParentHWND ==
nullptr;
2100 const bool isTopLevel = newParentHWND ==
nullptr;
2103 SetParent(m_data.hwnd, newParentHWND);
2109 if (wasTopLevel != isTopLevel) {
2110 setDropSiteEnabled(
false);
2111 m_data = setWindowFlags_sys(window()->flags(),
unsigned(isTopLevel ? WindowCreationData::ForceTopLevel : WindowCreationData::ForceChild));
2118 m_data.fullFrameMargins = {};
2119 setDarkBorder(QWindowsTheme::instance()->colorScheme() == Qt::ColorScheme::Dark);
2120 updateDropSite(isTopLevel);
2127 fireExpose(QRegion());
2132 const QWindow *w = window();
2134 applyBlurBehindWindow(handle());
2139 return QHighDpiScaling::roundScaleFactor(qreal(dpi) / QWindowsScreen::baseDpi) /
2140 QHighDpiScaling::roundScaleFactor(qreal(savedDpi()) / QWindowsScreen::baseDpi);
2150 const UINT dpi = UINT(wParam);
2151 const qreal scale = dpiRelativeScale(dpi);
2152 const QMargins margins = fullFrameMargins();
2153 if (!(m_data.flags & Qt::FramelessWindowHint)) {
2159 m_data.customMargins *= scale;
2162 const QSize windowSize = (geometry().size() * scale).grownBy((margins * scale) + customMargins());
2163 SIZE *size =
reinterpret_cast<SIZE *>(lParam);
2164 size->cx = windowSize.width();
2165 size->cy = windowSize.height();
2171 const UINT dpi = HIWORD(wParam);
2172 const qreal scale = dpiRelativeScale(dpi);
2175 QWindowsThemeCache::clearThemeCache(hwnd);
2179 if (isTopLevel() && !window()->icon().isNull())
2180 setWindowIcon(window()->icon());
2183 const auto prcNewWindow =
reinterpret_cast<
const RECT *>(lParam);
2184 checkForScreenChanged(QWindowsWindow::FromDpiChange, !m_inSetgeometry ? prcNewWindow :
nullptr);
2186 if (!IsZoomed(hwnd))
2187 m_data.restoreGeometry.setSize(m_data.restoreGeometry.size() * scale);
2205 if (!m_inSetgeometry) {
2209 QWindowsContext::forceNcCalcSize(hwnd);
2210 SetWindowPos(hwnd,
nullptr, prcNewWindow->left, prcNewWindow->top,
2211 prcNewWindow->right - prcNewWindow->left,
2212 prcNewWindow->bottom - prcNewWindow->top, SWP_NOZORDER | SWP_NOACTIVATE);
2216 if (shouldOmitFrameAdjustment(m_data.flags, m_data.hwnd))
2217 handleGeometryChange();
2228 setMask(QHighDpi::toNativeLocalRegion(window()->mask(), window()));
2233 const UINT dpi = GetDpiForWindow(hwnd);
2234 const qreal scale = dpiRelativeScale(dpi);
2237 QWindowsThemeCache::clearThemeCache(hwnd);
2239 checkForScreenChanged(QWindowsWindow::FromDpiChange);
2243 QRect currentGeometry = geometry();
2244 QRect scaledGeometry = QRect(currentGeometry.topLeft() * scale, currentGeometry.size() * scale);
2245 setGeometry(scaledGeometry);
2251 wp.length =
sizeof(WINDOWPLACEMENT);
2252 if (GetWindowPlacement(hwnd, &wp)) {
2253 const QRect result = qrectFromRECT(wp.rcNormalPosition);
2254 return result.translated(windowPlacementOffset(hwnd, result.topLeft()));
2262 const bool fakeFullScreen =
2263 m_savedFrameGeometry.isValid() && (window()->windowStates() & Qt::WindowFullScreen);
2264 const QRect frame = fakeFullScreen ? m_savedFrameGeometry : normalFrameGeometry(m_data.hwnd);
2265 const QMargins margins = fakeFullScreen
2266 ? QWindowsGeometryHint::frame(window(), handle(), m_savedStyle, 0)
2267 : fullFrameMargins();
2268 return frame.isValid() ? frame.marginsRemoved(margins) : frame;
2273 if (m_data.flags.testFlags(Qt::ExpandedClientAreaHint)) {
2274 const int titleBarHeight = getTitleBarHeight_sys(96);
2276 return QMargins(0, titleBarHeight, 0, 0);
2282 const QRect &requestedRect,
2283 const QRect &obtainedRect,
2284 const QMargins &fullMargins,
2285 const QMargins &customMargins)
2288 QDebug debug(&result);
2291 const auto window = platformWindow->window();
2292 debug <<
"Unable to set geometry ";
2293 formatBriefRectangle(debug, requestedRect);
2294 debug <<
" (frame: ";
2295 formatBriefRectangle(debug, requestedRect + fullMargins);
2296 debug <<
") on " << window->metaObject()->className() <<
"/\""
2297 << window->objectName() <<
"\" on \"" << window->screen()->name()
2298 <<
"\". Resulting geometry: ";
2299 formatBriefRectangle(debug, obtainedRect);
2300 debug <<
" (frame: ";
2301 formatBriefRectangle(debug, obtainedRect + fullMargins);
2302 debug <<
") margins: ";
2303 formatBriefMargins(debug, fullMargins);
2304 if (!customMargins.isNull()) {
2305 debug <<
" custom margin: ";
2306 formatBriefMargins(debug, customMargins);
2308 const auto minimumSize = window->minimumSize();
2309 const bool hasMinimumSize = !minimumSize.isEmpty();
2311 debug <<
" minimum size: " << minimumSize.width() <<
'x' << minimumSize.height();
2312 const auto maximumSize = window->maximumSize();
2313 const bool hasMaximumSize = maximumSize.width() != QWINDOWSIZE_MAX || maximumSize.height() != QWINDOWSIZE_MAX;
2315 debug <<
" maximum size: " << maximumSize.width() <<
'x' << maximumSize.height();
2316 if (hasMinimumSize || hasMaximumSize) {
2317 MINMAXINFO minmaxInfo;
2318 memset(&minmaxInfo, 0,
sizeof(minmaxInfo));
2319 platformWindow->getSizeHints(&minmaxInfo);
2320 debug <<
' ' << minmaxInfo;
2328 QScopedValueRollback b(m_inSetgeometry,
true);
2330 QRect rect = rectIn;
2333 if (QWindowsGeometryHint::positionIncludesFrame(window())) {
2334 const QMargins margins = frameMargins();
2335 rect.moveTopLeft(rect.topLeft() +
QPoint(margins.left(), margins.top()));
2337 if (m_windowState & Qt::WindowMinimized)
2338 m_data.geometry = rect;
2344 setGeometry_sys(rect);
2346 if (m_data.geometry != rect && (isVisible() || QLibraryInfo::isDebugBuild())) {
2347 const auto warning =
2348 msgUnableToSetGeometry(
this, rectIn, m_data.geometry,
2349 fullFrameMargins(), customMargins());
2350 qWarning(
"%s: %s",
__FUNCTION__, qPrintable(warning));
2353 QPlatformWindow::setGeometry(rect);
2361 handleGeometryChange();
2367 if ((m_data.flags.testFlag(Qt::FramelessWindowHint)
2368 || (m_data.flags.testFlag(Qt::CustomizeWindowHint) && !m_data.flags.testFlag(Qt::WindowTitleHint)))
2369 && IsZoomed(m_data.hwnd)) {
2370 const int resizedWidth = LOWORD(lParam);
2371 const int resizedHeight = HIWORD(lParam);
2373 const HMONITOR monitor = MonitorFromWindow(m_data.hwnd, MONITOR_DEFAULTTOPRIMARY);
2374 MONITORINFO monitorInfo = {};
2375 monitorInfo.cbSize =
sizeof(MONITORINFO);
2376 GetMonitorInfoW(monitor, &monitorInfo);
2378 int correctLeft = monitorInfo.rcMonitor.left;
2379 int correctTop = monitorInfo.rcMonitor.top;
2380 int correctWidth = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
2381 int correctHeight = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
2383 if (!m_data.flags.testFlag(Qt::FramelessWindowHint)) {
2384 const int borderWidth = invisibleMargins(m_data.hwnd).left();
2385 correctLeft -= borderWidth;
2386 correctTop -= borderWidth;
2387 correctWidth += borderWidth * 2;
2388 correctHeight += borderWidth * 2;
2391 if (resizedWidth != correctWidth || resizedHeight != correctHeight) {
2392 qCDebug(lcQpaWindow) <<
__FUNCTION__ <<
"correcting: " << resizedWidth <<
"x"
2393 << resizedHeight <<
" -> " << correctWidth <<
"x" << correctHeight;
2394 SetWindowPos(m_data.hwnd,
nullptr, correctLeft, correctTop, correctWidth, correctHeight,
2395 SWP_NOZORDER | SWP_NOACTIVATE);
2403 case SIZE_MINIMIZED:
2404 if (!testFlag(WithinSetStyle) && !testFlag(WithinSetGeometry))
2405 handleWindowStateChange(m_windowState | Qt::WindowMinimized);
2407 case SIZE_MAXIMIZED:
2408 handleGeometryChange();
2410 if (!testFlag(WithinSetStyle) && !testFlag(WithinSetGeometry))
2411 handleWindowStateChange(Qt::WindowMaximized | (isFullScreen_sys() ? Qt::WindowFullScreen
2412 : Qt::WindowNoState));
2415 handleGeometryChange();
2417 if (isFullScreen_sys())
2418 handleWindowStateChange(
2419 Qt::WindowFullScreen
2420 | (testFlag(MaximizeToFullScreen) ? Qt::WindowMaximized : Qt::WindowNoState));
2421 else if (m_windowState != Qt::WindowNoState && !testFlag(MaximizeToFullScreen))
2422 handleWindowStateChange(Qt::WindowNoState);
2428static inline bool equalDpi(
const QDpi &d1,
const QDpi &d2)
2430 return qFuzzyCompare(d1.first, d2.first) && qFuzzyCompare(d1.second, d2.second);
2438 QPlatformScreen *currentScreen = screen();
2439 auto topLevel = isTopLevel_sys() ? m_data.hwnd : GetAncestor(m_data.hwnd, GA_ROOT);
2444 if (newScreen ==
nullptr || newScreen == currentScreen)
2448 const bool changingDpi = !equalDpi(QDpi(savedDpi(), savedDpi()), newScreen->logicalDpi());
2452 qCDebug(lcQpaWindow).noquote().nospace() <<
__FUNCTION__
2453 <<
' ' << window() <<
" \"" << (currentScreen ? currentScreen->name() : QString())
2454 <<
"\"->\"" << newScreen->name() <<
'"';
2456 QWindowSystemInterface::handleWindowScreenChanged<QWindowSystemInterface::SynchronousDelivery>(window(), newScreen->screen());
2461 const QRect previousGeometry = m_data.geometry;
2463 m_data.geometry = geometry_sys();
2466 if (m_data.geometry == previousGeometry)
2468 QWindowSystemInterface::handleGeometryChange(window(), m_data.geometry);
2473 && m_data.geometry.size() != previousGeometry.size()
2475 && !(m_data.geometry.width() > previousGeometry.width() || m_data.geometry.height() > previousGeometry.height())) {
2476 fireFullExpose(
true);
2480 checkForScreenChanged();
2482 if (testFlag(SynchronousGeometryChangeEvent))
2483 QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents);
2490 qCDebug(lcQpaEvents) <<
__FUNCTION__ <<
this << window() << m_data.geometry;
2492 if (m_data.flags & Qt::ExpandedClientAreaHint) {
2493 const int titleBarHeight = getTitleBarHeight_sys(savedDpi());
2494 MoveWindow(m_data.hwndTitlebar, 0, 0, m_data.geometry.width(), titleBarHeight,
true);
2500 const QMargins margins = fullFrameMargins();
2501 const QRect frameGeometry = rect + margins;
2503 qCDebug(lcQpaWindow) <<
'>' <<
__FUNCTION__ << window()
2504 <<
"\n from " << geometry_sys() <<
" frame: "
2505 << margins <<
" to " <<rect
2506 <<
" new frame: " << frameGeometry;
2508 bool result =
false;
2509 const HWND hwnd = handle();
2510 WINDOWPLACEMENT windowPlacement;
2511 windowPlacement.length =
sizeof(WINDOWPLACEMENT);
2512 GetWindowPlacement(hwnd, &windowPlacement);
2515 if ((windowPlacement.showCmd == SW_MAXIMIZE && !IsWindowVisible(hwnd))
2516 || windowPlacement.showCmd == SW_SHOWMINIMIZED) {
2517 windowPlacement.rcNormalPosition =
2518 RECTfromQRect(frameGeometry.translated(-windowPlacementOffset(hwnd, frameGeometry.topLeft())));
2519 windowPlacement.showCmd = windowPlacement.showCmd == SW_SHOWMINIMIZED ? SW_SHOWMINIMIZED : SW_HIDE;
2520 result = SetWindowPlacement(hwnd, &windowPlacement);
2522 int x = frameGeometry.x();
2523 if (!window()->isTopLevel()) {
2524 const HWND parentHandle = GetParent(hwnd);
2525 if (isRtlLayout(parentHandle)) {
2527 GetClientRect(parentHandle, &rect);
2528 x = rect.right - frameGeometry.width() - x;
2531 result = MoveWindow(hwnd, x, frameGeometry.y(),
2532 frameGeometry.width(), frameGeometry.height(),
true);
2534 qCDebug(lcQpaWindow) <<
'<' <<
__FUNCTION__ << window()
2535 <<
"\n resulting " << result << geometry_sys();
2539
2540
2541
2542
2543
2548 m_hdc = GetDC(handle());
2549 if (QGuiApplication::layoutDirection() == Qt::RightToLeft)
2550 SetLayout(m_hdc, 0);
2556
2557
2558
2559
2560
2565 ReleaseDC(handle(), m_hdc);
2572#if QT_CONFIG(dynamicgl)
2573 return QOpenGLStaticContext::opengl32.moduleIsNotOpengl32()
2574 && QOpenGLContext::openGLModuleType() == QOpenGLContext::LibGL;
2583 if (message == WM_ERASEBKGND) {
2588 if (!window()->isVisible() && (GetWindowLongPtr(hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0)
2591 if (!GetUpdateRect(m_data.hwnd, 0, FALSE))
2598 InvalidateRect(hwnd,
nullptr,
false);
2600 BeginPaint(hwnd, &ps);
2605 fireExpose(QRegion(qrectFromRECT(ps.rcPaint)),
true);
2606 if (!QWindowsContext::instance()->asyncExpose())
2607 QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents);
2609 EndPaint(hwnd, &ps);
2615 m_windowTitle = QWindowsWindow::formatWindowTitle(title);
2616 setWindowTitle_sys(m_windowTitle);
2621 return m_windowTitle;
2626 qCDebug(lcQpaWindow) <<
'>' <<
__FUNCTION__ <<
this << window() <<
"\n from: "
2627 << m_data.flags <<
"\n to: " << flags;
2628 const QRect oldGeometry = geometry();
2629 if (m_data.flags != flags) {
2630 m_data.flags = flags;
2632 m_data = setWindowFlags_sys(flags);
2633 updateDropSite(window()->isTopLevel());
2640 const QRect newGeometry = geometry_sys();
2641 if (oldGeometry != newGeometry)
2642 handleGeometryChange();
2644 qCDebug(lcQpaWindow) <<
'<' <<
__FUNCTION__ <<
"\n returns: "
2645 << m_data.flags <<
" geometry " << oldGeometry <<
"->" << newGeometry;
2649 unsigned flags)
const
2652 creationData.fromWindow(window(), wt, flags);
2653 creationData.applyWindowFlags(m_data.hwnd);
2654 creationData.initialize(window(), m_data.hwnd,
true, m_opacity);
2656 if (creationData.flags.testFlag(Qt::ExpandedClientAreaHint)) {
2657 SetParent(m_data.hwndTitlebar, m_data.hwnd);
2658 ShowWindow(m_data.hwndTitlebar, SW_SHOW);
2660 if (IsWindowVisible(m_data.hwndTitlebar)) {
2661 SetParent(m_data.hwndTitlebar, HWND_MESSAGE);
2662 ShowWindow(m_data.hwndTitlebar, SW_HIDE);
2667 result.flags = creationData.flags;
2669 result
.hasFrame = (creationData.style & (WS_DLGFRAME | WS_THICKFRAME))
2670 && !(creationData.flags & Qt::FramelessWindowHint);
2674void QWindowsWindow::handleWindowStateChange(Qt::WindowStates state)
2676 qCDebug(lcQpaWindow) <<
__FUNCTION__ <<
this << window()
2677 <<
"\n from " << m_windowState <<
" to " << state;
2678 m_windowState = state;
2679 QWindowSystemInterface::handleWindowStateChanged(window(), state);
2680 if (state & Qt::WindowMinimized) {
2682 QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents);
2685 if (state & Qt::WindowMaximized) {
2686 WINDOWPLACEMENT windowPlacement{};
2687 windowPlacement.length =
sizeof(WINDOWPLACEMENT);
2688 GetWindowPlacement(m_data.hwnd, &windowPlacement);
2689 const RECT geometry = RECTfromQRect(m_data.restoreGeometry);
2690 windowPlacement.rcNormalPosition = geometry;
2691 correctWindowPlacement(windowPlacement);
2697 windowPlacement.showCmd = SW_HIDE;
2698 SetWindowPlacement(m_data.hwnd, &windowPlacement);
2702 QWindow *w = window();
2703 bool exposeEventsSent =
false;
2706 exposeEventsSent =
true;
2708 const QWindowList allWindows = QGuiApplication::allWindows();
2709 for (QWindow *child : allWindows) {
2710 if (child != w && child->isVisible() && child->transientParent() == w) {
2711 QWindowsWindow *platformWindow = QWindowsWindow::windowsWindowOf(child);
2712 if (platformWindow && platformWindow->isLayered()) {
2713 platformWindow->fireFullExpose();
2714 exposeEventsSent =
true;
2718 if (exposeEventsSent && !QWindowsContext::instance()->asyncExpose())
2719 QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents);
2728 return window()->maximumHeight() != QWINDOWSIZE_MAX;
2733 return window()->maximumWidth() != QWINDOWSIZE_MAX;
2741void QWindowsWindow::correctWindowPlacement(WINDOWPLACEMENT &windowPlacement)
2743 static const auto windows11 = QOperatingSystemVersion::Windows11_21H2;
2744 static const bool isWindows10 = QOperatingSystemVersion::current() < windows11;
2750 const QPoint offset = windowPlacementOffset(m_data.hwnd, m_data.restoreGeometry.topLeft());
2751 windowPlacement.rcNormalPosition = RECTfromQRect(m_data.restoreGeometry.translated(-offset));
2752 qCDebug(lcQpaWindow) <<
"Corrected normal position by" << -offset;
2761 const QMargins margins = frameMargins_sys();
2762 const QPoint topLeft = window()->screen()->geometry().topLeft();
2763 windowPlacement.ptMaxPosition = POINT{ topLeft.x() - margins.left(), topLeft.y() };
2764 qCDebug(lcQpaWindow) <<
"Window has maximum size. Corrected topLeft by"
2770 const int adjust = offset.x() / window()->devicePixelRatio();
2771 window()->setWidth(window()->width() - adjust);
2772 qCDebug(lcQpaWindow) <<
"Width shortened by" << adjust <<
"logical pixels.";
2775 const int adjust = offset.y() / window()->devicePixelRatio();
2776 window()->setHeight(window()->height() - adjust);
2777 qCDebug(lcQpaWindow) <<
"Height shortened by" << adjust <<
"logical pixels.";
2784 m_data.restoreGeometry = normalFrameGeometry(m_data.hwnd);
2790 setWindowState_sys(state);
2791 m_windowState = state;
2797 const QWindow *w = window();
2798 if (!w->isTopLevel())
2800 QRect geometry = geometry_sys();
2802 geometry += QMargins(1, 1, 1, 1);
2803 QPlatformScreen *screen = screenForGeometry(geometry);
2804 return screen && geometry == screen->geometry();
2808
2809
2810
2811
2812
2813
2814
2815
2816
2818void QWindowsWindow::setWindowState_sys(Qt::WindowStates newState)
2820 const Qt::WindowStates oldState = m_windowState;
2821 if (oldState == newState)
2823 qCDebug(lcQpaWindow) <<
'>' <<
__FUNCTION__ <<
this << window()
2824 <<
" from " << oldState <<
" to " << newState;
2827 auto stateChange = oldState ^ newState;
2829 if (stateChange & Qt::WindowFullScreen) {
2830 if (newState & Qt::WindowFullScreen) {
2831 UINT newStyle = WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_POPUP;
2835 if (!m_savedStyle) {
2836 m_savedStyle =
style();
2837 if ((oldState & Qt::WindowMinimized) || (oldState & Qt::WindowMaximized)) {
2838 const QRect nf = normalFrameGeometry(m_data.hwnd);
2840 m_savedFrameGeometry = nf;
2842 m_savedFrameGeometry = frameGeometry_sys();
2845 if (newState & Qt::WindowMaximized)
2847 if (m_savedStyle & WS_SYSMENU)
2848 newStyle |= WS_SYSMENU;
2850 newStyle |= WS_VISIBLE;
2852 newStyle |= WS_BORDER;
2854 const HMONITOR monitor = MonitorFromWindow(m_data.hwnd, MONITOR_DEFAULTTONEAREST);
2855 MONITORINFO monitorInfo = {};
2856 monitorInfo.cbSize =
sizeof(MONITORINFO);
2857 GetMonitorInfoW(monitor, &monitorInfo);
2858 const QRect screenGeometry(monitorInfo.rcMonitor.left, monitorInfo.rcMonitor.top,
2859 monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left,
2860 monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top);
2861 if (newState & Qt::WindowMinimized) {
2862 setMinimizedGeometry(m_data.hwnd, screenGeometry);
2863 if (stateChange & Qt::WindowMaximized)
2864 setRestoreMaximizedFlag(m_data.hwnd, newState & Qt::WindowMaximized);
2866 const UINT swpf = SWP_FRAMECHANGED | SWP_NOACTIVATE;
2869 SetWindowPos(m_data.hwnd, HWND_TOP, screenGeometry.left(), screenGeometry.top(), screenGeometry.width(), screenGeometry.height(), swpf);
2873 QWindowSystemInterface::handleGeometryChange(window(), screenGeometry);
2874 QWindowSystemInterface::flushWindowSystemEvents(QEventLoop::ExcludeUserInputEvents);
2878 unsigned newStyle = m_savedStyle ? m_savedStyle :
style();
2880 newStyle |= WS_VISIBLE;
2883 const QScreen *screen = window()->screen();
2885 screen = QGuiApplication::primaryScreen();
2887 if (
const auto platformScreen = screen->handle()) {
2888 if (!platformScreen->geometry().intersects(m_savedFrameGeometry))
2889 m_savedFrameGeometry.moveTo(platformScreen->geometry().topLeft());
2892 if (newState & Qt::WindowMinimized) {
2893 setMinimizedGeometry(m_data.hwnd, m_savedFrameGeometry);
2894 if (stateChange & Qt::WindowMaximized)
2895 setRestoreMaximizedFlag(m_data.hwnd, newState & Qt::WindowMaximized);
2897 UINT swpf = SWP_FRAMECHANGED | SWP_NOZORDER | SWP_NOACTIVATE;
2898 if (!m_savedFrameGeometry.isValid())
2899 swpf |= SWP_NOSIZE | SWP_NOMOVE;
2904 if (windowVisibility_sys(m_data.hwnd) == QWindow::Maximized)
2905 ShowWindow(m_data.hwnd, SW_SHOWNOACTIVATE);
2906 SetWindowPos(m_data.hwnd,
nullptr, m_savedFrameGeometry.x(), m_savedFrameGeometry.y(),
2907 m_savedFrameGeometry.width(), m_savedFrameGeometry.height(), swpf);
2913 ShowWindow(m_data.hwnd,
2914 (newState & Qt::WindowMaximized) ? SW_MAXIMIZE : SW_SHOWNA);
2919 m_savedFrameGeometry = QRect();
2921 }
else if ((oldState & Qt::WindowMaximized) != (newState & Qt::WindowMaximized)) {
2922 if (visible && !(newState & Qt::WindowMinimized)) {
2924 if (newState & Qt::WindowFullScreen)
2926 ShowWindow(m_data.hwnd,
2927 (newState & Qt::WindowMaximized) ? SW_MAXIMIZE : SW_SHOWNOACTIVATE);
2930 }
else if (visible && (oldState & newState & Qt::WindowMinimized)) {
2932 setRestoreMaximizedFlag(m_data.hwnd, newState & Qt::WindowMaximized);
2936 if (stateChange & Qt::WindowMinimized) {
2938 ShowWindow(m_data.hwnd,
2939 (newState & Qt::WindowMinimized) ? SW_MINIMIZE :
2940 (newState & Qt::WindowMaximized) ? SW_MAXIMIZE : SW_SHOWNORMAL);
2941 if ((newState & Qt::WindowMinimized) && (stateChange & Qt::WindowMaximized))
2942 setRestoreMaximizedFlag(m_data.hwnd, newState & Qt::WindowMaximized);
2945 qCDebug(lcQpaWindow) <<
'<' <<
__FUNCTION__ <<
this << window() << newState;
2950 qCDebug(lcQpaWindow) <<
__FUNCTION__ <<
this << window() << debugWinStyle(s);
2952 SetWindowLongPtr(m_data.hwnd, GWL_STYLE, s);
2958 qCDebug(lcQpaWindow) <<
__FUNCTION__ <<
this << window() << debugWinExStyle(s);
2959 SetWindowLongPtr(m_data.hwnd, GWL_EXSTYLE, s);
2964 switch (event->type()) {
2965 case QEvent::ApplicationPaletteChange:
2966 setDarkBorder(QWindowsTheme::instance()->colorScheme() == Qt::ColorScheme::Dark);
2968 case QEvent::WindowBlocked:
2974 case QEvent::WindowUnblocked:
2982 return QWindowsBaseWindow::windowEvent(event);
2987 qCDebug(lcQpaWindow) <<
__FUNCTION__ <<
this << window();
2992 bool result =
false;
2993 if ((windowPos->flags & SWP_NOSIZE) == 0) {
2995 GetWindowRect(windowPos->hwnd, &rect);
2996 result = rect.right - rect.left != windowPos->cx || rect.bottom - rect.top != windowPos->cy;
3001bool QWindowsWindow::handleGeometryChangingMessage(MSG *message,
const QWindow *qWindow,
const QMargins &margins)
3003 auto *windowPos =
reinterpret_cast<WINDOWPOS *>(message->lParam);
3004 const QRect suggestedFrameGeometry(windowPos->x, windowPos->y,
3005 windowPos->cx, windowPos->cy);
3006 const QRect suggestedGeometry = suggestedFrameGeometry - margins;
3013 if (isResize(windowPos))
3014 windowPos->flags |= SWP_NOCOPYBITS;
3016 if ((windowPos->flags & SWP_NOZORDER) == 0) {
3017 if (
QWindowsWindow *platformWindow = QWindowsWindow::windowsWindowOf(qWindow)) {
3018 QWindow *parentWindow = qWindow->parent();
3019 HWND parentHWND = GetAncestor(windowPos->hwnd, GA_PARENT);
3020 HWND desktopHWND = GetDesktopWindow();
3021 platformWindow->m_data.embedded = !parentWindow && parentHWND && (parentHWND != desktopHWND);
3023 if (qWindow->flags().testFlag(Qt::WindowStaysOnBottomHint))
3024 windowPos->hwndInsertAfter = HWND_BOTTOM;
3026 if (!qWindow->isTopLevel())
3028 if (windowPos->flags & SWP_NOSIZE)
3030 const QRectF correctedGeometryF = QPlatformWindow::closestAcceptableGeometry(qWindow, suggestedGeometry);
3031 if (!correctedGeometryF.isValid())
3033 const QRect correctedFrameGeometry = correctedGeometryF.toRect() + margins;
3034 if (correctedFrameGeometry == suggestedFrameGeometry)
3036 windowPos->x = correctedFrameGeometry.left();
3037 windowPos->y = correctedFrameGeometry.top();
3038 windowPos->cx = correctedFrameGeometry.width();
3039 windowPos->cy = correctedFrameGeometry.height();
3045 const QMargins margins = window()->isTopLevel() ? fullFrameMargins() : QMargins();
3046 return QWindowsWindow::handleGeometryChangingMessage(message, window(), margins);
3051 if (shouldOmitFrameAdjustment(m_data.flags, m_data.hwnd))
3053 if (m_data.fullFrameMargins != newMargins) {
3054 qCDebug(lcQpaWindow) <<
__FUNCTION__ << window() << m_data.fullFrameMargins <<
"->" << newMargins;
3055 m_data.fullFrameMargins = newMargins;
3062 if (GetMenu(m_data.hwnd))
3063 QWindowsContext::forceNcCalcSize(m_data.hwnd);
3065 calculateFullFrameMargins();
3070 if (shouldOmitFrameAdjustment(m_data.flags, m_data.hwnd))
3083 GetWindowRect(handle(), &windowRect);
3084 GetClientRect(handle(), &clientRect);
3090 if (qSizeOfRect(windowRect) == qSizeOfRect(clientRect))
3095 const auto systemMargins = testFlag(DisableNonClientScaling)
3096 ? QWindowsGeometryHint::frameOnPrimaryScreen(window(), m_data.hwnd)
3097 : frameMargins_sys();
3098 const int extendedClientAreaBorder = window()->flags().testFlag(Qt::ExpandedClientAreaHint) ? qRound(QHighDpiScaling::factor(window())) * 2 : 0;
3099 const QMargins actualMargins = systemMargins + customMargins() - extendedClientAreaBorder;
3101 const int yDiff = (windowRect.bottom - windowRect.top) - (clientRect.bottom - clientRect.top);
3102 const bool typicalFrame = (actualMargins.left() == actualMargins.right())
3103 && (actualMargins.right() == actualMargins.bottom());
3105 const QMargins adjustedMargins = typicalFrame ?
3106 QMargins(actualMargins.left(), (yDiff - actualMargins.bottom()),
3107 actualMargins.right(), actualMargins.bottom())
3110 setFullFrameMargins(adjustedMargins);
3115 QMargins result = fullFrameMargins();
3116 if (isTopLevel() && m_data.hasFrame)
3117 result -= invisibleMargins(m_data.hwnd);
3123 if (shouldOmitFrameAdjustment(m_data.flags, m_data.hwnd))
3125 return m_data.fullFrameMargins;
3130 qCDebug(lcQpaWindow) <<
__FUNCTION__ << level;
3131 if (!qFuzzyCompare(m_opacity, level)) {
3134 setWindowOpacity(m_data.hwnd, m_data.flags,
3142 return CreateRectRgn(r.left(), r.top(), r.x() + r.width(), r.y() + r.height());
3147 if (
const HRGN rectRegion = createRectRegion(rect)) {
3148 HRGN result = CreateRectRgn(0, 0, 0, 0);
3149 if (CombineRgn(result, *winRegion, rectRegion, RGN_OR)) {
3150 DeleteObject(*winRegion);
3151 *winRegion = result;
3153 DeleteObject(rectRegion);
3159 auto it = region.begin();
3160 const auto end = region.end();
3163 HRGN hRegion = createRectRegion(*it);
3165 addRectToWinRegion(*it, &hRegion);
3171 if (region.isEmpty()) {
3172 SetWindowRgn(m_data.hwnd,
nullptr,
true);
3175 const HRGN winRegion = qRegionToWinRegion(region);
3178 if (window()->isTopLevel()) {
3179 const QMargins margins = fullFrameMargins();
3180 OffsetRgn(winRegion, margins.left(), margins.top());
3184 if (!SetWindowRgn(m_data.hwnd, winRegion,
true))
3185 DeleteObject(winRegion);
3190 qCDebug(lcQpaWindow) <<
__FUNCTION__ <<
this << window();
3196 if (QGuiApplication::applicationState() == Qt::ApplicationActive
3197 || activationBehavior != QWindowsApplication::AlwaysActivateWindow) {
3198 SetForegroundWindow(m_data.hwnd);
3199 SetFocus(m_data.hwnd);
3208 if (m_data.flags & Qt::WindowStaysOnBottomHint) {
3209 qCWarning(lcQpaWindow) <<
3210 "Windows with Qt::WindowStaysOnBottomHint can't be brought to the foreground.";
3213 if (m_data.flags & Qt::WindowStaysOnTopHint) {
3214 qCWarning(lcQpaWindow) <<
3215 "Windows with Qt::WindowStaysOnTopHint will always be on the foreground.";
3218 if (window()->type() == Qt::ToolTip) {
3219 qCWarning(lcQpaWindow) <<
"ToolTip windows should not be activated.";
3224 if (!IsWindowVisible(m_data.hwnd))
3225 ShowWindow(m_data.hwnd, SW_SHOW);
3227 if (IsIconic(m_data.hwnd)) {
3228 ShowWindow(m_data.hwnd, SW_RESTORE);
3235 const HWND oldForegroundWindow = GetForegroundWindow();
3236 if (!oldForegroundWindow) {
3238 SetActiveWindow(m_data.hwnd);
3240 SetFocus(m_data.hwnd);
3246 if (SendMessageTimeoutW(oldForegroundWindow, WM_NULL, 0, 0,
3247 SMTO_BLOCK | SMTO_ABORTIFHUNG | SMTO_NOTIMEOUTIFNOTHUNG, 1000,
nullptr) == 0) {
3248 qCWarning(lcQpaWindow) <<
"The foreground window hangs, can't activate current window.";
3252 const DWORD windowThreadProcessId = GetWindowThreadProcessId(oldForegroundWindow,
nullptr);
3253 const DWORD currentThreadId = GetCurrentThreadId();
3255 AttachThreadInput(windowThreadProcessId, currentThreadId, TRUE);
3256 const auto cleanup = qScopeGuard([windowThreadProcessId, currentThreadId](){
3257 AttachThreadInput(windowThreadProcessId, currentThreadId, FALSE);
3260 BringWindowToTop(m_data.hwnd);
3264 SetActiveWindow(m_data.hwnd);
3265 SetFocus(m_data.hwnd);
3271 qWarning(
"%s: No handle",
__FUNCTION__);
3274 qCDebug(lcQpaWindow) <<
__FUNCTION__ <<
this << window() << grab;
3278 context->setKeyGrabber(window());
3280 if (context->keyGrabber() == window())
3281 context->setKeyGrabber(
nullptr);
3288 qCDebug(lcQpaWindow) <<
__FUNCTION__ << window() << grab;
3290 qWarning(
"%s: No handle",
__FUNCTION__);
3294 qWarning(
"%s: Not setting mouse grab for invisible window %s/'%s'",
3295 __FUNCTION__, window()->metaObject()->className(),
3296 qPrintable(window()->objectName()));
3303 SetCapture(m_data.hwnd);
3313 if (edges == Qt::LeftEdge)
3315 else if (edges == (Qt::RightEdge))
3317 else if (edges == (Qt::TopEdge))
3319 else if (edges == (Qt::TopEdge | Qt::LeftEdge))
3321 else if (edges == (Qt::TopEdge | Qt::RightEdge))
3323 else if (edges == (Qt::BottomEdge))
3325 else if (edges == (Qt::BottomEdge | Qt::LeftEdge))
3327 else if (edges == (Qt::BottomEdge | Qt::RightEdge))
3335 if (Q_UNLIKELY(window()->flags().testFlag(Qt::MSWindowsFixedSizeDialogHint)))
3339 PostMessage(m_data.hwnd, WM_SYSCOMMAND, edgesToWinOrientation(edges), 0);
3347 PostMessage(m_data.hwnd, WM_SYSCOMMAND, 0xF012 , 0);
3362 QWindowsGeometryHint::applyToMinMaxInfo(window(), fullFrameMargins(), mmi);
3367 if ((m_data.flags & Qt::FramelessWindowHint) && window()->isTopLevel()
3368 && !testFlag(MaximizeToFullScreen)) {
3369 const HMONITOR monitor = MonitorFromWindow(m_data.hwnd, MONITOR_DEFAULTTONEAREST);
3370 MONITORINFO monitorInfo = {};
3371 monitorInfo.cbSize =
sizeof(MONITORINFO);
3372 GetMonitorInfoW(monitor, &monitorInfo);
3373 const RECT &work = monitorInfo.rcWork;
3374 const RECT &screen = monitorInfo.rcMonitor;
3377 mmi->ptMaxPosition.x = work.left - screen.left;
3378 mmi->ptMaxPosition.y = work.top - screen.top;
3379 mmi->ptMaxSize.x = work.right - work.left;
3380 mmi->ptMaxSize.y = work.bottom - work.top;
3382 qCDebug(lcQpaWindow) <<
__FUNCTION__ << window() << *mmi;
3388 const QWindow *w = window();
3389 const QPoint localPos = w->mapFromGlobal(QHighDpi::fromNativePixels(globalPos, w));
3390 const QRect geom = geometry();
3391 static auto oldMouseButtonState = Qt::NoButton;
3393 if (m_data.flags.testFlags(Qt::ExpandedClientAreaHint)) {
3394 bool isDefaultTitleBar = !w->flags().testFlag(Qt::CustomizeWindowHint);
3395 bool isCustomized = w->flags().testFlags(Qt::CustomizeWindowHint) && w->flags().testAnyFlags(Qt::WindowTitleHint|
3396 Qt::WindowMinimizeButtonHint|
3397 Qt::WindowMaximizeButtonHint|
3398 Qt::WindowCloseButtonHint);
3399 const int border = (IsZoomed(m_data.hwnd) || isFullScreen_sys()) ? 0 : getResizeBorderThickness(savedDpi());
3400 const int titleBarHeight = getTitleBarHeight_sys(savedDpi());
3401 const int titleButtonWidth = titleBarHeight * 1.5;
3402 const bool mouseButtonsSwapped = GetSystemMetrics(SM_SWAPBUTTON);
3403 auto mouseButtons = Qt::NoButton;
3404 if (mouseButtonsSwapped)
3405 mouseButtons = GetAsyncKeyState(VK_LBUTTON) != 0 ? Qt::RightButton : (GetAsyncKeyState(VK_RBUTTON) ? Qt::LeftButton : Qt::NoButton);
3407 mouseButtons = GetAsyncKeyState(VK_LBUTTON) != 0 ? Qt::LeftButton : (GetAsyncKeyState(VK_RBUTTON) ? Qt::RightButton : Qt::NoButton);
3410 if (isCustomized || isDefaultTitleBar) {
3413 if (globalPos.y() < geom.top() + titleBarHeight) {
3414 if (m_data.flags.testFlags(Qt::WindowCloseButtonHint) || isDefaultTitleBar) {
3415 if ((globalPos.x() > geom.right() - titleButtonWidth * buttons) && (globalPos.x() <= geom.right())) {
3416 if (mouseButtons == Qt::LeftButton)
3420 }
if (m_data.flags.testFlags(Qt::WindowMaximizeButtonHint) || isDefaultTitleBar) {
3421 if ((globalPos.x() > geom.right() - titleButtonWidth * buttons) && (globalPos.x() <= geom.right() - titleButtonWidth * (buttons-1))){
3422 if (mouseButtons == Qt::LeftButton) {
3423 if (IsZoomed(m_data.hwnd))
3426 *result = HTMAXBUTTON;
3430 }
if (m_data.flags.testFlags(Qt::WindowMinimizeButtonHint) || isDefaultTitleBar) {
3431 if ((globalPos.x() > geom.right() - titleButtonWidth * buttons) && (globalPos.x() <= geom.right() - titleButtonWidth * (buttons-1))){
3432 if (mouseButtons == Qt::LeftButton)
3433 *result = HTMINBUTTON;
3436 }
if ((isCustomized || isDefaultTitleBar) &&
3437 *result == HTCLIENT){
3438 QWindow* wnd = window();
3439 if (mouseButtons != oldMouseButtonState) {
3440 auto mouseEventType = mouseButtons == Qt::NoButton ? QEvent::MouseButtonRelease : QEvent::MouseButtonPress;
3441 auto mouseEventButtons = mouseEventType == QEvent::MouseButtonPress ? mouseButtons : oldMouseButtonState;
3442 bool accepted = QWindowSystemInterface::handleMouseEvent<QWindowSystemInterface::SynchronousDelivery>(wnd, QHighDpi::toNativeLocalPosition(localPos, w), globalPos, mouseEventButtons, mouseEventButtons, mouseEventType);
3443 if (!accepted && mouseButtons == Qt::RightButton)
3444 *result = HTSYSMENU;
3445 else if (!accepted && globalPos.y() < geom.top() + titleBarHeight)
3446 *result = HTCAPTION;
3450 }
else if (w->flags().testFlag(Qt::CustomizeWindowHint)) {
3452 QWindow* wnd = window();
3453 if (mouseButtons != oldMouseButtonState) {
3454 auto mouseEventType = mouseButtons == Qt::NoButton ? QEvent::MouseButtonRelease : QEvent::MouseButtonPress;
3455 auto mouseEventButtons = mouseEventType == QEvent::MouseButtonPress ? mouseButtons : oldMouseButtonState;
3456 bool accepted = QWindowSystemInterface::handleMouseEvent<QWindowSystemInterface::SynchronousDelivery>(wnd, QHighDpi::toNativeLocalPosition(localPos, w), globalPos, mouseEventButtons, mouseEventButtons, mouseEventType);
3457 if (!accepted && mouseButtons == Qt::RightButton)
3458 *result = HTSYSMENU;
3459 else if (!accepted && globalPos.y() < geom.top() + titleBarHeight)
3460 *result = HTCAPTION;
3463 oldMouseButtonState = mouseButtons;
3466 const bool left = (globalPos.x() >= geom.left()) && (globalPos.x() < geom.left() + border);
3467 const bool right = (globalPos.x() > geom.right() - border) && (globalPos.x() <= geom.right());
3468 const bool top = (globalPos.y() >= geom.top()) && (globalPos.y() < geom.top() + border);
3469 const bool bottom = (globalPos.y() > geom.bottom() - border) && (globalPos.y() <= geom.bottom());
3471 if (left || right || top || bottom) {
3473 *result = top ? HTTOPLEFT : (bottom ? HTBOTTOMLEFT : HTLEFT);
3475 *result = top ? HTTOPRIGHT : (bottom ? HTBOTTOMRIGHT : HTRIGHT);
3477 *result = top ? HTTOP : HTBOTTOM;
3483 const_cast<QWindow *>(w)->close();
3486 const_cast<QWindow *>(w)->showMaximized();
3489 const_cast<QWindow *>(w)->showMinimized();
3492 const_cast<QWindow *>(w)->showNormal();
3495 HWND hwnd =
reinterpret_cast<HWND>(w->winId());
3496 HMENU sysMenu = GetSystemMenu(hwnd,
false);
3497 TrackPopupMenu(sysMenu, 0, globalPos.x(), globalPos.y(), 0, hwnd,
nullptr);
3506 if (m_data.flags & Qt::ExpandedClientAreaHint) {
3507 const int border = (IsZoomed(m_data.hwnd) || isFullScreen_sys()) ? 0 : getResizeBorderThickness(savedDpi());
3512 const QRect rect = geom;
3513 const bool left = (globalPos.x() >= rect.left()) && (globalPos.x() < rect.left() + border);
3514 const bool right = (globalPos.x() > rect.right() - border) && (globalPos.x() <= rect.right());
3515 const bool top = (globalPos.y() >= rect.top()) && (globalPos.y() < rect.top() + border);
3516 const bool bottom = (globalPos.y() > rect.bottom() - border) && (globalPos.y() <= rect.bottom());
3519 if (left || right || top || bottom) {
3521 *result = top ? HTTOPLEFT : (bottom ? HTBOTTOMLEFT : HTLEFT);
3523 *result = top ? HTTOPRIGHT : (bottom ? HTBOTTOMRIGHT : HTRIGHT);
3525 *result = top ? HTTOP : HTBOTTOM;
3533 if (!w->isTopLevel()
3534 || (m_windowState != Qt::WindowNoState)
3536 || (m_data.flags & Qt::FramelessWindowHint)) {
3539 const QSize minimumSize = w->minimumSize();
3540 if (minimumSize.isEmpty())
3542 const QSize maximumSize = w->maximumSize();
3543 const bool fixedWidth = minimumSize.width() == maximumSize.width();
3544 const bool fixedHeight = minimumSize.height() == maximumSize.height();
3545 if (!fixedWidth && !fixedHeight)
3547 const QSize size = w->size();
3549 if (localPos.y() >= size.height()) {
3553 if (localPos.y() < 0) {
3554 const int topResizeBarPos = invisibleMargins(m_data.hwnd).left() - frameMargins().top();
3555 if (localPos.y() < topResizeBarPos) {
3556 *result = HTCAPTION;
3561 if (fixedWidth && (localPos.x() < 0 || localPos.x() >= size.width())) {
3573 if (m_data.flags & Qt::FramelessWindowHint) {
3582 HWND hwnd = m_data.hwndTitlebar;
3583 QWindow *wnd = window();
3586 GetWindowRect(hwnd, &windowRect);
3588 const int titleBarHeight = getTitleBarHeight_sys(savedDpi());
3589 const int titleButtonWidth = titleBarHeight * 1.5;
3590 const qreal factor = QHighDpiScaling::factor(wnd);
3591 const int windowWidth = windowRect.right - windowRect.left;
3594 GetCursorPos(&localPos);
3595 MapWindowPoints(HWND_DESKTOP, m_data.hwnd, &localPos, 1);
3597 const bool isDarkmode = QWindowsIntegration::instance()->darkModeHandling().testFlags(QWindowsApplication::DarkModeWindowFrames) &&
3598 qApp->styleHints()->colorScheme() == Qt::ColorScheme::Dark;
3599 const bool isWindows11orAbove = QOperatingSystemVersion::current() >= QOperatingSystemVersion::Windows11;
3601 const QBrush closeButtonBrush(QColor(0xC4, 0x2C, 0x1E, 255));
3602 const QBrush minMaxButtonBrush = QBrush(isDarkmode ? QColor(0xFF, 0xFF, 0xFF, 0x40) : QColor(0x00, 0x00, 0x00, 0x20));
3603 const QBrush titleBarBackgroundColor = QBrush(isDarkmode ? QColor(0x1F, 0x1F, 0x1F, 0xFF) : QColor(0xF3, 0xF3, 0xF3, 0xFF));
3604 const QPen textPen = QPen(isDarkmode ? QColor(0xFF, 0xFF, 0xFD, 0xFF) : QColor(0x00, 0x00, 0x00, 0xFF));
3606 QImage image(windowWidth, titleBarHeight, QImage::Format_ARGB32);
3608 p.setCompositionMode(QPainter::CompositionMode_Clear);
3609 p.fillRect(0, 0, windowWidth, titleBarHeight, Qt::transparent);
3611 p.setCompositionMode(QPainter::CompositionMode_SourceOver);
3613 p.setBrush(titleBarBackgroundColor);
3614 p.setPen(Qt::NoPen);
3615 if (!wnd->flags().testFlags(Qt::NoTitleBarBackgroundHint)) {
3617 titleRect.setWidth(windowWidth);
3618 titleRect.setHeight(titleBarHeight);
3619 p.drawRect(titleRect);
3622 if (wnd->flags().testFlags(Qt::WindowTitleHint | Qt::CustomizeWindowHint) || !wnd->flags().testFlag(Qt::CustomizeWindowHint)) {
3626 titleRect.setWidth(windowWidth);
3627 titleRect.setHeight(titleBarHeight);
3629 titleRect.adjust(factor * 4, 0, 0, 0);
3630 QRect iconRect(titleRect.x(), titleRect.y() + factor * 8, factor * 16, factor * 16);
3631 if (wnd->icon().isNull()) {
3632 static QIcon defaultIcon;
3633 if (defaultIcon.isNull()) {
3634 const QImage defaultIconImage = QImage::fromHICON(LoadIcon(0, IDI_APPLICATION));
3635 defaultIcon = QIcon(QPixmap::fromImage(defaultIconImage));
3637 defaultIcon.paint(&p, iconRect);
3639 wnd->icon().paint(&p, iconRect);
3641 titleRect.adjust(factor * 24, 0, 0, 0);
3645 titleFont.setPointSize(factor * 9);
3646 titleFont.setWeight(QFont::Thin);
3647 titleFont.setHintingPreference(QFont::PreferFullHinting);
3648 p.setFont(titleFont);
3649 const QString title = wnd->title().isEmpty() ? qApp->applicationName() : wnd->title();
3650 p.drawText(titleRect, title, QTextOption(Qt::AlignVCenter));
3654 const QString assetFontName = isWindows11orAbove ? QStringLiteral(
"Segoe Fluent Icons") : QStringLiteral(
"Segoe MDL2 Assets");
3655 QFont assetFont = QFont(assetFontName, factor * 7);
3656 assetFont.setWeight(QFont::Thin);
3657 assetFont.setHintingPreference(QFont::PreferFullHinting);
3658 p.setFont(assetFont);
3659 p.setBrush(closeButtonBrush);
3660 p.setPen(Qt::NoPen);
3661 if (wnd->flags().testFlags(Qt::WindowCloseButtonHint | Qt::CustomizeWindowHint) || !wnd->flags().testFlag(Qt::CustomizeWindowHint)) {
3664 rect.setX(windowWidth - titleButtonWidth * buttons);
3665 rect.setWidth(titleButtonWidth);
3666 rect.setHeight(titleBarHeight);
3667 if (localPos.x > (windowWidth - buttons * titleButtonWidth) &&
3668 localPos.x < (windowWidth - (buttons - 1) * titleButtonWidth) &&
3669 localPos.y > rect.y() && localPos.y < rect.y() + rect.height()) {
3671 const QPen closeButtonHoveredPen = QPen(QColor(0xFF, 0xFF, 0xFD, 0xFF));
3672 p.setPen(closeButtonHoveredPen);
3676 p.drawText(rect, QStringLiteral(
"\uE8BB"), QTextOption(Qt::AlignVCenter | Qt::AlignHCenter));
3680 p.setBrush(minMaxButtonBrush);
3681 p.setPen(Qt::NoPen);
3682 if (wnd->flags().testFlags(Qt::WindowMaximizeButtonHint | Qt::CustomizeWindowHint) || !wnd->flags().testFlag(Qt::CustomizeWindowHint)) {
3685 rect.setX(windowWidth - titleButtonWidth * buttons);
3686 rect.setWidth(titleButtonWidth);
3687 rect.setHeight(titleBarHeight);
3688 if (localPos.x > (windowWidth - buttons * titleButtonWidth) &&
3689 localPos.x < (windowWidth - (buttons - 1) * titleButtonWidth) &&
3690 localPos.y > rect.y() && localPos.y < rect.y() + rect.height()) {
3695 const QString maximizeGlyph = IsZoomed(m_data.hwnd) ? QStringLiteral(
"\uE923")
3696 : QStringLiteral(
"\uE922");
3697 p.drawText(rect, maximizeGlyph, QTextOption(Qt::AlignVCenter | Qt::AlignHCenter));
3701 p.setBrush(minMaxButtonBrush);
3702 p.setPen(Qt::NoPen);
3703 if (wnd->flags().testFlags(Qt::WindowMinimizeButtonHint | Qt::CustomizeWindowHint) || !wnd->flags().testFlag(Qt::CustomizeWindowHint)) {
3706 rect.setX(windowWidth - titleButtonWidth * buttons);
3707 rect.setWidth(titleButtonWidth);
3708 rect.setHeight(titleBarHeight);
3709 if (localPos.x > (windowWidth - buttons * titleButtonWidth) &&
3710 localPos.x < (windowWidth - (buttons - 1) * titleButtonWidth) &&
3711 localPos.y > rect.y() && localPos.y < rect.y() + rect.height()) {
3715 p.drawText(rect,QStringLiteral(
"\uE921"), QTextOption(Qt::AlignVCenter | Qt::AlignHCenter));
3721 HBITMAP bmp = image.toHBITMAP();
3723 HDC hdc = GetDC(hwnd);
3725 HDC memdc = CreateCompatibleDC(hdc);
3726 HGDIOBJ original = SelectObject(memdc, bmp);
3729 BLENDFUNCTION blend = {AC_SRC_OVER, 0, 255, AC_SRC_ALPHA};
3730 POINT ptLocation = { 0, 0 };
3731 SIZE szWnd = { windowWidth, titleBarHeight };
3732 POINT ptSrc = { 0, 0 };
3733 UpdateLayeredWindow(hwnd, hdc, &ptLocation, &szWnd, memdc, &ptSrc, 0, &blend, ULW_ALPHA);
3734 SelectObject(hdc, original);
3737 DeleteObject(memdc);
3738 ReleaseDC(hwnd,hdc);
3745 if (QScreen *screen = w->screen())
3746 if (
const QPlatformScreen *platformScreen = screen->handle())
3747 if (QPlatformCursor *cursor = platformScreen->cursor())
3748 return static_cast<QWindowsCursor *>(cursor)->standardWindowCursor(Qt::ArrowCursor);
3749 return CursorHandlePtr(
new CursorHandle(QWindowsCursor::createCursorFromShape(Qt::ArrowCursor)));
3758 if (underMouse == w)
3760 for (
const QWindow *p = underMouse; p ; p = p->parent()) {
3763 const QWindowsWindow *platformWindow = QWindowsWindow::windowsWindowOf(p);
3764 if (platformWindow && !platformWindow->cursor()->isNull())
3772
3773
3774
3775
3785 if (m_cursor->isNull()) {
3786 if (
const QWindow *p = window()->parent()) {
3787 if (
QWindowsWindow *platformWindow = QWindowsWindow::windowsWindowOf(p))
3790 SetCursor(defaultCursor(window())->handle());
3793 SetCursor(m_cursor->handle());
3801 bool changed = c->handle() != m_cursor->handle();
3809 const bool apply = applyNewCursor(window());
3810 qCDebug(lcQpaWindow) << window() <<
__FUNCTION__
3811 << c->handle() <<
" doApply=" << apply;
3834 UINT timeOutMs = GetCaretBlinkTime();
3835 if (!timeOutMs || timeOutMs == INFINITE)
3839 info.cbSize =
sizeof(info);
3840 info.hwnd = m_data.hwnd;
3841 info.dwFlags = FLASHW_TRAY;
3842 info.dwTimeout = timeOutMs;
3843 info.uCount = durationMs == 0 ? 10 : UINT(durationMs) / timeOutMs;
3844 FlashWindowEx(&info);
3850 info.cbSize =
sizeof(info);
3851 info.hwnd = m_data.hwnd;
3852 info.dwFlags = FLASHW_STOP;
3855 FlashWindowEx(&info);
3860 return (style() & WS_DISABLED) == 0;
3865 const unsigned oldStyle =
style();
3866 unsigned newStyle = oldStyle;
3868 newStyle &= ~WS_DISABLED;
3870 newStyle |= WS_DISABLED;
3872 if (newStyle != oldStyle)
3879 const POINT origin{0, 0};
3880 if (
const HMONITOR monitor = MonitorFromPoint(origin, MONITOR_DEFAULTTOPRIMARY)) {
3883 if (SUCCEEDED(GetDpiForMonitor(monitor, MDT_EFFECTIVE_DPI, &dpiX, &dpiY)))
3886 return GetDpiForSystem();
3891 if (!icon.isNull()) {
3899 const QSize physicalSize(GetSystemMetricsForDpi(xSizeMetric, dpi),
3900 GetSystemMetricsForDpi(ySizeMetric, dpi));
3901 const QPixmap pm = icon.pixmap(icon.actualSize(physicalSize / dpr), dpr);
3903 return qt_pixmapToWinHICON(pm);
3917 const UINT windowDpi = GetDpiForWindow(m_data.hwnd);
3919 m_iconSmall = createHIcon(icon, titleBarDpi, SM_CXSMICON, SM_CYSMICON);
3926 m_iconBig = createHIcon(icon, primaryScreenDpi(), SM_CXICON, SM_CYICON);
3929 SendMessage(m_data.hwnd, WM_SETICON, 0 , LPARAM(m_iconSmall));
3930 SendMessage(m_data.hwnd, WM_SETICON, 1 , LPARAM(m_iconBig));
3932 SendMessage(m_data.hwnd, WM_SETICON, 0 , LPARAM(m_iconSmall));
3933 SendMessage(m_data.hwnd, WM_SETICON, 1 , LPARAM(m_iconSmall));
3940 return window()->isTopLevel() && !m_data.embedded;
3950 const BOOL darkBorder = d ? TRUE : FALSE;
3955 qCWarning(lcQpaWindow,
"%s: Unable to set %s window border.",
__FUNCTION__, d ?
"dark" :
"light");
3966 d = d && shouldApplyDarkFrame(window());
3968 setDarkBorderToWindow(m_data.hwnd, d);
3973 return m_menuBar.data();
3983 if (m_data.flags & Qt::FramelessWindowHint)
3985 return m_data.customMargins;
3989
3990
3991
3992
3993
3994
3995
3996
4000 if (m_data.flags & Qt::FramelessWindowHint) {
4001 qCWarning(lcQpaWindow) <<
"You should not set custom margins for a frameless window.";
4004 if (newCustomMargins != m_data.customMargins) {
4005 const QMargins oldCustomMargins = m_data.customMargins;
4006 m_data.customMargins = newCustomMargins;
4008 const QRect currentFrameGeometry = frameGeometry_sys();
4009 const QPoint topLeft = currentFrameGeometry.topLeft();
4010 QRect newFrame = currentFrameGeometry.marginsRemoved(oldCustomMargins) + m_data.customMargins;
4011 newFrame.moveTo(topLeft);
4012 qCDebug(lcQpaWindow) <<
__FUNCTION__ << oldCustomMargins <<
"->" << newCustomMargins
4013 << currentFrameGeometry <<
"->" << newFrame;
4014 SetWindowPos(m_data.hwnd,
nullptr, newFrame.x(), newFrame.y(), newFrame.width(), newFrame.height(), SWP_NOZORDER | SWP_FRAMECHANGED | SWP_NOACTIVATE);
4020#if QT_CONFIG(vulkan)
4021 Q_UNUSED(nativeConfig);
4023 if (window()->surfaceType() == QSurface::VulkanSurface) {
4025 QVulkanInstance *inst = window()->vulkanInstance();
4027 m_vkSurface =
static_cast<QWindowsVulkanInstance *>(inst->handle())->createSurface(handle());
4029 qWarning(
"Attempted to create Vulkan surface without an instance; was QWindow::setVulkanInstance() called?");
4033 return &m_vkSurface;
4035#elif defined(QT_NO_OPENGL)
4037 Q_UNUSED(nativeConfig);
4054#if QT_CONFIG(vulkan)
4056 QVulkanInstance *inst = window()->vulkanInstance();
4058 static_cast<QWindowsVulkanInstance *>(inst->handle())->destroySurface(m_vkSurface);
4059 m_vkSurface = VK_NULL_HANDLE;
4066 m_surface =
nullptr;
4079 const auto currentTouchTypes = touchWindowTouchTypes_sys();
4080 if (currentTouchTypes.has_value() && currentTouchTypes.value() == touchTypes)
4084 ULONG touchFlags = 0;
4085 if (touchTypes.testFlag(TouchWindowTouchType::FineTouch))
4086 touchFlags |= TWF_FINETOUCH;
4087 if (touchTypes.testFlag(TouchWindowTouchType::WantPalmTouch))
4088 touchFlags |= TWF_WANTPALM;
4089 if (RegisterTouchWindow(m_data.hwnd, touchFlags))
4092 qErrnoWarning(
"RegisterTouchWindow() failed for window '%s'.", qPrintable(window()->objectName()));
4097 if (QPlatformWindow *handle = window->handle())
4098 static_cast<QWindowsWindow *>(handle)->setHasBorderInFullScreen(border);
4105 m_borderInFullScreenDefault = border;
4122 if (m_windowState == Qt::WindowFullScreen) {
4123 LONG_PTR style = GetWindowLongPtr(handle(), GWL_STYLE);
4127 style &= ~WS_BORDER;
4128 SetWindowLongPtr(handle(), GWL_STYLE, style);
4134 return QPlatformWindow::formatWindowTitle(title, QStringLiteral(
" - "));
4144 QWindow *w = window();
4145 QDxgiVSyncService *vs = QDxgiVSyncService::instance();
4146 if (vs->supportsWindow(w)) {
4151 QPlatformWindow::d_ptr->updateTimer.stop();
4152 if (m_vsyncServiceCallbackId == 0) {
4153 m_vsyncServiceCallbackId = vs->registerCallback([
this, w](
const QDxgiVSyncService::CallbackWindowList &windowList, qint64) {
4154 if (windowList.contains(w)) {
4159 if (m_vsyncUpdatePending.testAndSetAcquire(UpdateState::Requested, UpdateState::Posted)) {
4160 QWindowsWindow *oldSelf =
this;
4161 qsizetype oldCallbackId = m_vsyncServiceCallbackId;
4162 QMetaObject::invokeMethod(w, [w, oldSelf, oldCallbackId] {
4164 auto *self =
static_cast<QWindowsWindow *>(w->handle());
4167 if (self && self == oldSelf && self->m_vsyncServiceCallbackId == oldCallbackId) {
4169 self->m_vsyncUpdatePending.storeRelease(UpdateState::Ready);
4170 self->deliverUpdateRequest();
4172 }, Qt::QueuedConnection);
4177 m_vsyncUpdatePending.testAndSetRelease(UpdateState::Ready, UpdateState::Requested);
4179 QPlatformWindow::requestUpdate();
\inmodule QtCore\reentrant
Base class for QWindowsForeignWindow, QWindowsWindow.
QMargins frameMargins_sys() const
bool isTopLevel_sys() const
void setHasBorderInFullScreen(bool border) override
QMargins customMargins() const override
bool windowEvent(QEvent *event) override
Reimplement this method to be able to do any platform specific event handling.
bool hasBorderInFullScreen() const override
bool hasMaximumWidth() const
std::optional< TouchWindowTouchTypes > touchWindowTouchTypes_sys() const
bool hasMaximumHeight() const
QRect frameGeometry_sys() const
QRect geometry_sys() const
void setCustomMargins(const QMargins &margins) override
void setGeometry_sys(const QRect &rect) const
bool hasMaximumSize() const
void setWindowTitle_sys(const QString &title)
Singleton container for all relevant information.
QWindowsScreenManager & screenManager()
void clearWindowUnderMouse()
unsigned systemInfo() const
static QWindowsContext * instance()
Platform cursor implementation.
static bool hasOverrideCursor()
static void enforceOverrideCursor()
Window wrapping a foreign native window.
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
static QWindowsStaticOpenGLContext * staticOpenGLContext()
static QWindowsIntegration * instance()
Manages a list of QWindowsScreen.
const QWindowsScreen * screenAtDp(const QPoint &p) const
static bool isSingleScreen()
virtual void * createWindowSurface(void *, void *, int *)
virtual void destroyWindowSurface(void *)
static QWindowsWindowClassRegistry * instance()
void alertWindow(int durationMs=0)
void setWindowFlags(Qt::WindowFlags flags) override
Requests setting the window flags of this surface to flags.
void setCustomMargins(const QMargins &m) override
Sets custom margins to be added to the default margins determined by the windows style in the handlin...
void setMenuBar(QWindowsMenuBar *mb)
void invalidateSurface() override
Invalidates the window's surface by releasing its surface buffers.
HDC getDC()
Allocates a HDC for the window or returns the temporary one obtained from WinAPI BeginPaint within a ...
QMargins fullFrameMargins() const override
void checkForScreenChanged(ScreenChangeMode mode=FromGeometryChange, const RECT *suggestedRect=nullptr)
void initialize() override
Called as part of QWindow::create(), after constructing the window.
void handleDpiChangedAfterParent(HWND hwnd)
void requestUpdate() override
Requests an QEvent::UpdateRequest event.
bool testFlag(unsigned f) const
void setFlag(unsigned f) const
void clearFlag(unsigned f) const
void setFrameStrutEventsEnabled(bool enabled) override
Reimplement this method to set whether frame strut events should be sent to enabled.
static void settingsChanged()
void getSizeHints(MINMAXINFO *mmi) const
static void setHasBorderInFullScreenDefault(bool border)
~QWindowsWindow() override
bool handleWmPaint(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam, LRESULT *result)
bool setMouseGrabEnabled(bool grab) override
void propagateSizeHints() override
Reimplement to propagate the size hints of the QWindow.
void applyCursor()
Applies to cursor property set on the window to the global cursor.
bool handleGeometryChanging(MSG *message) const
bool isActive() const override
Returns true if the window should appear active from a style perspective.
void setStyle(unsigned s) const
QString windowTitle() const override
Reimplement to return the actual window title used in the underlying windowing system unless the titl...
static void displayChanged()
bool setKeyboardGrabEnabled(bool grab) override
bool windowEvent(QEvent *event) override
Reimplement this method to be able to do any platform specific event handling.
void setGeometry(const QRect &rect) override
This function is called by Qt whenever a window is moved or resized using the QWindow API.
void setEnabled(bool enabled)
void setVisible(bool visible) override
Reimplemented in subclasses to show the surface if visible is true, and hide it if visible is false.
QSurfaceFormat format() const override
Returns the actual surface format of the window.
static const char * embeddedNativeParentHandleProperty
QWindowsMenuBar * menuBar() const
void handleDpiChanged(HWND hwnd, WPARAM wParam, LPARAM lParam)
void registerTouchWindow()
QMargins frameMargins() const override
void setWindowIcon(const QIcon &icon) override
Reimplement to set the window icon to icon.
bool isClientAreaExpanded() const
void handleResized(int wParam, LPARAM lParam)
void setOpacity(qreal level) override
Reimplement to be able to let Qt set the opacity level of a window.
bool isEmbedded() const override
Returns true if the window is a child of a non-Qt window.
QMargins customMargins() const override
bool handleNonClientActivate(LRESULT *result) const
QRect normalGeometry() const override
Returns the geometry of a window in 'normal' state (neither maximized, fullscreen nor minimized) for ...
void setExStyle(unsigned s) const
qreal dpiRelativeScale(const UINT dpi) const
QMargins safeAreaMargins() const override
The safe area margins of a window represent the area that is safe to place content within,...
void setSavedDpi(int dpi)
void requestActivateWindow() override
Reimplement to let Qt be able to request activation/focus for a window.
void handleDpiScaledSize(WPARAM wParam, LPARAM lParam, LRESULT *result)
void updateFullFrameMargins()
@ SynchronousGeometryChangeEvent
@ WithinSetParent
Automatic mouse capture on button press.
@ FrameStrutEventsEnabled
static const char * hasBorderInFullScreenProperty
bool startSystemMove() override
Reimplement this method to start a system move operation if the system supports it and return true to...
bool isTopLevel() const override
void releaseDC()
Releases the HDC for the window or does nothing in case it was obtained from WinAPI BeginPaint within...
void updateRestoreGeometry()
void setWindowState(Qt::WindowStates state) override
Requests setting the window state of this surface to type.
void setCursor(const CursorHandlePtr &c)
void updateCustomTitlebar()
bool hasBorderInFullScreen() const override
bool hasMouseCapture() const
void * surface(void *nativeConfig, int *err)
void setHasBorderInFullScreen(bool border) override
void handleCompositionSettingsChanged()
void setWindowTitle(const QString &title) override
Reimplement to set the window title to title.
void setDarkBorder(bool d)
bool startSystemResize(Qt::Edges edges) override
Reimplement this method to start a system resize operation if the system supports it and return true ...
void setFullFrameMargins(const QMargins &newMargins)
void setMask(const QRegion ®ion) override
Reimplement to be able to let Qt set the mask of a window.
void setAlertState(bool enabled) override
Reimplement this method to set whether the window demands attention (for example, by flashing the tas...
bool isAlertState() const override
Reimplement this method return whether the window is in an alert state.
Combined button and popup list for selecting options.
static HICON createHIcon(const QIcon &icon, UINT dpi, int xSizeMetric, int ySizeMetric)
static QSize toNativeSizeConstrained(QSize dip, const QScreen *s)
static void fixTopLevelWindowFlags(Qt::WindowFlags &flags)
static QString msgUnableToSetGeometry(const QWindowsWindow *platformWindow, const QRect &requestedRect, const QRect &obtainedRect, const QMargins &fullMargins, const QMargins &customMargins)
static bool shouldOmitFrameAdjustment(const Qt::WindowFlags flags, DWORD style)
static QRect normalFrameGeometry(HWND hwnd)
static void formatBriefRectangle(QDebug &d, const QRect &r)
static bool testShowWithoutActivating(const QWindow *window)
static bool shouldShowMaximizeButton(const QWindow *w, Qt::WindowFlags flags)
static void setMinimizedGeometry(HWND hwnd, const QRect &r)
static bool applyNewCursor(const QWindow *w)
static bool isSoftwareGl()
static void addRectToWinRegion(const QRect &rect, HRGN *winRegion)
static QByteArray debugWinSwpPos(UINT flags)
static HRGN createRectRegion(const QRect &r)
static QByteArray debugWinStyle(DWORD style)
static QScreen * screenForDeviceName(const QWindow *w, const QString &name)
static QPoint windowPlacementOffset(HWND hwnd, const QPoint &point)
static bool applyBlurBehindWindow(HWND hwnd)
static void setRestoreMaximizedFlag(HWND hwnd, bool set=true)
static RECT RECTfromQRect(const QRect &rect)
static QMargins invisibleMargins(const HWND hwnd)
static QRect frameGeometry(HWND hwnd, bool topLevel)
static void setWindowOpacity(HWND hwnd, Qt::WindowFlags flags, bool hasAlpha, bool accelerated, qreal level)
static QMargins invisibleMargins(QPoint screenPoint)
Calculates the dimensions of the invisible borders within the window frames which only exist on Windo...
static int getResizeBorderThickness(const UINT dpi)
static bool windowIsAccelerated(const QWindow *w)
static bool equalDpi(const QDpi &d1, const QDpi &d2)
static bool isResize(const WINDOWPOS *windowPos)
static void formatBriefMargins(QDebug &d, const QMargins &m)
static int getTitleBarHeight_sys(const UINT dpi)
static QByteArray debugWindowPlacementFlags(const UINT flags)
static QSize qSizeOfRect(const RECT &rect)
static DWORD edgesToWinOrientation(Qt::Edges edges)
static bool shouldApplyDarkFrame(const QWindow *w)
static QByteArray debugWinExStyle(DWORD exStyle)
static CursorHandlePtr defaultCursor(const QWindow *w)
static QByteArray debugShowWindowCmd(const UINT cmd)
static UINT primaryScreenDpi()
static HRGN qRegionToWinRegion(const QRegion ®ion)
static QPoint calcPosition(const QWindow *w, const QWindowCreationContextPtr &context, const QMargins &invMargins)
@ DwmwaUseImmersiveDarkMode
@ DwmwaUseImmersiveDarkModeBefore20h1
static QRect qrectFromRECT(const RECT &rect)
static QWindow::Visibility windowVisibility_sys(HWND hwnd)
static GpuDescription detect()
Active Context for creating windows.
void applyToMinMaxInfo(MINMAXINFO *mmi) const
Stores geometry constraints and provides utility functions.
void applyWindowFlags(HWND hwnd) const
void initialize(const QWindow *w, HWND h, bool frameChange, qreal opacityLevel) const
QWindowsWindowData WindowData
WindowData create(const QWindow *w, const WindowData &data, QString title) const
void fromWindow(const QWindow *w, const Qt::WindowFlags flags, unsigned creationFlags=0)