12#if QT_CONFIG(directmanipulation)
13# include "qwindowsdirectmanipulation.h"
19#if QT_CONFIG(tabletevent)
20# include "qwindowstabletsupport.h"
23#include <private/qguiapplication_p.h>
24#if QT_CONFIG(accessibility)
25# include "uiautomation/qwindowsuiaaccessibility.h"
27#if QT_CONFIG(sessionmanager)
28# include <private/qsessionmanager_p.h>
29# include "qwindowssessionmanager.h"
35#include <QtGui/qwindow.h>
36#include <qpa/qwindowsysteminterface.h>
37#include <qpa/qwindowsysteminterface_p.h>
38#include <qpa/qplatformnativeinterface.h>
39#include <QtGui/qguiapplication.h>
40#include <QtGui/qopenglcontext.h>
41#include <QtGui/qpointingdevice.h>
43#include <QtCore/qhash.h>
44#include <QtCore/qstringlist.h>
45#include <QtCore/qdebug.h>
46#include <QtCore/qsysinfo.h>
47#include <QtCore/qscopedpointer.h>
48#include <QtCore/qscopeguard.h>
49#include <QtCore/private/qwinregistry_p.h>
50#if QT_CONFIG(cpp_winrt)
51# include <QtCore/private/qfactorycacheregistration_p.h>
53#include <QtCore/private/qsystemerror_p.h>
54#include <QtCore/private/quniquehandle_types_windows_p.h>
56#include <QtGui/private/qwindowsguieventdispatcher_p.h>
57#include <QtGui/private/qwindowsthemecache_p.h>
64#include <shellscalingapi.h>
68using namespace Qt::StringLiterals;
71Q_LOGGING_CATEGORY(lcQpaEvents,
"qt.qpa.events")
72Q_LOGGING_CATEGORY(lcQpaGl,
"qt.qpa.gl")
73Q_LOGGING_CATEGORY(lcQpaMime,
"qt.qpa.mime")
74Q_LOGGING_CATEGORY(lcQpaInputMethods,
"qt.qpa.input.methods")
75Q_LOGGING_CATEGORY(lcQpaDialogs,
"qt.qpa.dialogs")
76Q_LOGGING_CATEGORY(lcQpaMenus,
"qt.qpa.menus")
77Q_LOGGING_CATEGORY(lcQpaTablet,
"qt.qpa.input.tablet")
78Q_LOGGING_CATEGORY(lcQpaGestures,
"qt.qpa.input.gestures")
79Q_LOGGING_CATEGORY(lcQpaAccessibility,
"qt.qpa.accessibility")
80Q_LOGGING_CATEGORY(lcQpaUiAutomation,
"qt.qpa.uiautomation")
81Q_LOGGING_CATEGORY(lcQpaTrayIcon,
"qt.qpa.trayicon")
82Q_LOGGING_CATEGORY(lcQpaScreen,
"qt.qpa.screen")
83Q_LOGGING_CATEGORY(lcQpaTheme,
"qt.qpa.theme")
85int QWindowsContext::verbose = 0;
87#if !defined(LANG_SYRIAC)
88# define LANG_SYRIAC 0x5a
95 if (
const int nLayouts = GetKeyboardLayoutList(0,
nullptr)) {
96 QScopedArrayPointer<HKL> lpList(
new HKL[nLayouts]);
97 GetKeyboardLayoutList(nLayouts, lpList.data());
98 for (
int i = 0; i < nLayouts; ++i) {
99 switch (PRIMARYLANGID((quintptr)lpList[i])) {
113#if QT_CONFIG(sessionmanager)
114static inline QWindowsSessionManager *platformSessionManager()
116 auto *guiPrivate =
static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(qApp));
117 auto *managerPrivate =
static_cast<QSessionManagerPrivate*>(QObjectPrivate::get(guiPrivate->session_manager));
118 return static_cast<QWindowsSessionManager *>(managerPrivate->platformSessionManager);
121static inline bool sessionManagerInteractionBlocked()
123 return platformSessionManager()->isInteractionBlocked();
132
133
134
135
136
137
138
153#if QT_CONFIG(tabletevent)
156#if QT_CONFIG(directmanipulation)
172 if (m_pointerHandler.touchDevice())
174 m_displayContext.reset(GetDC(
nullptr));
175 m_defaultDPI = GetDeviceCaps(m_displayContext.get(), LOGPIXELSY);
178 m_keyMapper.setUseRTLExtensions(
true);
180 if (FAILED(m_oleInitializeResult)) {
181 qWarning() <<
"QWindowsContext: OleInitialize() failed: "
182 << QSystemError::windowsComString(m_oleInitializeResult);
184#if QT_CONFIG(directmanipulation)
186 m_directManipulation.reset(QWindowsDirectManipulation::create());
199#if QT_CONFIG(tabletevent)
200 d->m_tabletSupport.reset();
202#if QT_CONFIG(directmanipulation)
203 d->m_directManipulation.reset();
206 if (d->m_powerNotification)
207 UnregisterPowerSettingNotification(d->m_powerNotification);
209 if (d->m_powerDummyWindow)
210 DestroyWindow(d->m_powerDummyWindow);
213 theme->destroyThemeChangeWindow();
215 d->m_screenManager.destroyWindow();
217 if (d->m_oleInitializeResult == S_OK || d->m_oleInitializeResult == S_FALSE) {
218#ifdef QT_USE_FACTORY_CACHE_REGISTRATION
219 detail::QWinRTFactoryCacheRegistration::clearAllCaches();
224 d->m_screenManager.clearScreens();
225 m_instance =
nullptr;
235 if (d->m_systemInfo & QWindowsContext::SI_SupportsTouch)
237 auto touchDevice = d->m_pointerHandler.touchDevice();
238 if (touchDevice.isNull()) {
239 const bool mouseEmulation =
240 (integrationOptions & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch) == 0;
241 touchDevice = QWindowsPointerHandler::createTouchDevice(mouseEmulation);
243 if (touchDevice.isNull())
245 d->m_pointerHandler.setTouchDevice(touchDevice);
246 QWindowSystemInterface::registerInputDevice(touchDevice.data());
248 d->m_systemInfo |= QWindowsContext::SI_SupportsTouch;
258 if (QGuiApplicationPrivate::is_app_running
259 && (d->m_systemInfo & QWindowsContext::SI_SupportsTouch) != 0) {
260 for (QWindowsWindow *w : std::as_const(d->m_windows))
261 w->registerTouchWindow();
267#if QT_CONFIG(tabletevent)
268 d->m_tabletSupport.reset(QWindowsTabletSupport::create());
277#if QT_CONFIG(tabletevent)
278 d->m_tabletSupport.reset();
285LRESULT QT_WIN_CALLBACK qWindowsPowerWindowProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
287 if (message != WM_POWERBROADCAST || wParam != PBT_POWERSETTINGCHANGE)
288 return DefWindowProc(hwnd, message, wParam, lParam);
290 static bool initialized =
false;
293 return DefWindowProc(hwnd, message, wParam, lParam);
296 auto setting =
reinterpret_cast<
const POWERBROADCAST_SETTING *>(lParam);
298 auto data =
reinterpret_cast<
const DWORD *>(&setting->Data);
301 const auto tlw = QGuiApplication::topLevelWindows();
303 if (w->isVisible() && w->windowState() != Qt::WindowMinimized) {
304 if (
auto tw = QWindowsWindow::windowsWindowOf(w)) {
305 if (HWND hwnd = tw->handle()) {
306 InvalidateRect(hwnd,
nullptr,
false);
313 return DefWindowProc(hwnd, message, wParam, lParam);
318 if (d->m_powerNotification)
321 d->m_powerDummyWindow = createDummyWindow(QStringLiteral(
"PowerDummyWindow"), L"QtPowerDummyWindow", qWindowsPowerWindowProc);
322 if (!d->m_powerDummyWindow)
325 d->m_powerNotification = RegisterPowerSettingNotification(d->m_powerDummyWindow, &GUID_MONITOR_POWER_ON, DEVICE_NOTIFY_WINDOW_HANDLE);
326 if (!d->m_powerNotification) {
327 DestroyWindow(d->m_powerDummyWindow);
328 d->m_powerDummyWindow =
nullptr;
336#if QT_CONFIG(tabletevent)
337 QWindowsTabletSupport::setAbsoluteRange(a);
345 d->m_keyMapper.setDetectAltGrModifier(a);
352 if (!IsValidDpiAwarenessContext(context))
371 const auto context = GetWindowDpiAwarenessContext(hwnd);
372 return dpiAwarenessContextToQtDpiAwareness(context);
384 const auto context = GetThreadDpiAwarenessContext();
385 return dpiAwarenessContextToQtDpiAwareness(context);
391 switch (dpiAwareness) {
394 case QtWindows::DpiAwareness::Unaware:
396 case QtWindows::DpiAwareness::System:
398 case QtWindows::DpiAwareness::PerMonitor:
400 case QtWindows::DpiAwareness::PerMonitorVersion2:
402 case QtWindows::DpiAwareness::Unaware_GdiScaled:
408#ifndef QT_NO_DEBUG_STREAM
411 const QDebugStateSaver saver(d);
412 QString message = u"QtWindows::DpiAwareness::"_s;
413 switch (dpiAwareness) {
415 message += u"Invalid"_s;
418 message += u"Unaware"_s;
421 message += u"System"_s;
424 message += u"PerMonitor"_s;
427 message += u"PerMonitorVersion2"_s;
430 message += u"Unaware_GdiScaled"_s;
433 d.nospace().noquote() << message;
440 qCDebug(lcQpaWindow) <<
__FUNCTION__ << dpiAwareness;
441 [[maybe_unused]]
const auto updatePMv2Status = qScopeGuard([](){
447 const auto context = qtDpiAwarenessToDpiAwarenessContext(dpiAwareness);
448 if (!IsValidDpiAwarenessContext(context)) {
449 qCWarning(lcQpaWindow) << dpiAwareness <<
"is not supported by current system.";
452 if (!SetProcessDpiAwarenessContext(context)) {
453 qCWarning(lcQpaWindow).noquote().nospace()
454 <<
"SetProcessDpiAwarenessContext() failed: "
455 << QSystemError::windowsString()
456 <<
"\nQt's default DPI awareness context is "
457 <<
"DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2. If you know what you "
458 <<
"are doing, you can overwrite this default using qt.conf "
459 <<
"(https://doc.qt.io/qt-6/highdpi.html#configuring-windows).";
472 return d->m_systemInfo;
477 return d->m_keyMapper.useRTLExtensions();
482 return &d->m_keyMapper;
492 const QSharedPointer<QWindowCreationContext> old = d->m_creationContext;
493 d->m_creationContext = ctx;
499 return d->m_creationContext;
504 return d->m_defaultDPI;
509 return d->m_displayContext.get();
514 return d->m_keyMapper.keyGrabber();
519 d->m_keyMapper.setKeyGrabber(w);
524 return GetDeviceCaps(d->m_displayContext.get(), BITSPIXEL);
529 d->m_windows.insert(hwnd, w);
534 const HandleBaseWindowHash::iterator it = d->m_windows.find(hwnd);
535 if (it != d->m_windows.end()) {
536 if (d->m_keyMapper.keyGrabber() == it.value()->window())
537 d->m_keyMapper.setKeyGrabber(
nullptr);
538 d->m_windows.erase(it);
544 for (
auto it = d->m_windows.cbegin(), end = d->m_windows.cend(); it != end; ++it) {
545 if ((*it)->menuBar() == mb)
553 return d->m_windows.value(hwnd);
563 for (HWND w = hwnd; w; w = GetParent(w)) {
564 window = d->m_windows.value(w);
582 return d->m_pointerHandler.windowUnderMouse();
587 d->m_pointerHandler.clearWindowUnderMouse();
591
592
593
594
595
596
597
598
599
600
606 POINT point = screenPoint;
607 screenToClient(*hwnd, &point);
609 const HWND child = ChildWindowFromPointEx(*hwnd, point, cwexFlags);
610 if (!child || child == *hwnd)
623 if (!(cwexFlags & CWP_SKIPTRANSPARENT)
624 && (GetWindowLongPtr(child, GWL_EXSTYLE) & WS_EX_TRANSPARENT)) {
625 const HWND nonTransparentChild = ChildWindowFromPointEx(*hwnd, point, cwexFlags | CWP_SKIPTRANSPARENT);
626 if (!nonTransparentChild || nonTransparentChild == *hwnd)
629 *result = nonTransparentWindow;
630 *hwnd = nonTransparentChild;
639 const QPoint &screenPointIn,
640 unsigned cwex_flags)
const
643 const POINT screenPoint = { screenPointIn.x(), screenPointIn.y() };
644 while (findPlatformWindowHelper(screenPoint, cwex_flags,
this, &parent, &result)) {}
647 if (result ==
nullptr) {
648 if (
const HWND window = WindowFromPoint(screenPoint))
657 const DWORD sessionId = WTSGetActiveConsoleSessionId();
658 if (sessionId != 0xFFFFFFFF) {
659 LPTSTR buffer =
nullptr;
661#if !defined(Q_CC_MINGW)
662 if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, sessionId,
663 WTSSessionInfoEx, &buffer, &size) == TRUE
665 const WTSINFOEXW *info =
reinterpret_cast<WTSINFOEXW *>(buffer);
666 result = info->Level == 1 && info->Data.WTSInfoExLevel1.SessionFlags == WTS_SESSIONSTATE_LOCK;
667 WTSFreeMemory(buffer);
671 if (WTSQuerySessionInformation(WTS_CURRENT_SERVER_HANDLE, sessionId,
672 WTS_INFO_CLASS(25), &buffer, &size) == TRUE
674 const DWORD *p =
reinterpret_cast<DWORD *>(buffer);
675 const DWORD level = *p;
676 const DWORD sessionFlags = *(p + 4);
677 result = level == 1 && sessionFlags == 1;
678 WTSFreeMemory(buffer);
687 return d->m_mimeConverter;
692 return d->m_screenManager;
697#if QT_CONFIG(directmanipulation)
698 return d->m_directManipulation.data();
706#if QT_CONFIG(tabletevent)
707 return d->m_tabletSupport.data();
714
715
716
719 const wchar_t *windowName,
720 WNDPROC wndProc, DWORD style)
723 wndProc = DefWindowProc;
724 QString className = d->m_windowClassRegistry.registerWindowClass(classNameIn, wndProc);
725 return CreateWindowEx(0,
reinterpret_cast<LPCWSTR>(className.utf16()),
727 CW_USEDEFAULT, CW_USEDEFAULT,
728 CW_USEDEFAULT, CW_USEDEFAULT,
729 HWND_MESSAGE,
nullptr,
static_cast<HINSTANCE>(GetModuleHandle(
nullptr)),
nullptr);
735 SetWindowPos(hwnd,
nullptr, 0, 0, 0, 0,
736 SWP_FRAMECHANGED | SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
742 const BOOL result = dpi != 0
743 ? SystemParametersInfoForDpi(action, param, out, 0, dpi)
744 : SystemParametersInfo(action, param, out, 0);
745 return result == TRUE;
749 const QPlatformScreen *screen)
755 const QPlatformWindow *win)
762 memset(ncm, 0,
sizeof(NONCLIENTMETRICS));
763 ncm->cbSize =
sizeof(NONCLIENTMETRICS);
768 const QPlatformScreen *screen)
770 const int dpi = screen ? qRound(screen->logicalDpi().first) : 0;
771 return nonClientMetrics(ncm,
unsigned(dpi));
774bool QWindowsContext::nonClientMetricsForWindow(NONCLIENTMETRICS *ncm,
const QPlatformWindow *win)
776 return nonClientMetricsForScreen(ncm, win ? win->screen() :
nullptr);
790 return window->isTopLevel()
793 && (window->surfaceType() != QSurface::OpenGLSurface
794 || QOpenGLContext::openGLModuleType() != QOpenGLContext::LibGL)
802 case WM_IME_STARTCOMPOSITION:
803 case WM_IME_ENDCOMPOSITION:
804 case WM_IME_COMPOSITION:
809 case WM_NCMOUSEHOVER:
810 case WM_NCMOUSELEAVE:
815 case WM_DWMNCRENDERINGCHANGED:
821 return (m >= WM_MOUSEFIRST && m <= WM_MOUSELAST)
822 || (m >= WM_NCMOUSEMOVE && m <= WM_NCXBUTTONDBLCLK)
823 || (m >= WM_KEYFIRST && m <= WM_KEYLAST);
830 if (QWindowsContext::windowDpiAwareness(hwnd) == QtWindows::DpiAwareness::PerMonitor) {
831 result = EnableNonClientDpiScaling(hwnd) != FALSE;
833 const DWORD errorCode = GetLastError();
834 qErrnoWarning(
int(errorCode),
"EnableNonClientDpiScaling() failed for HWND %p (%lu)",
842
843
844
845
849 WPARAM wParam, LPARAM lParam,
857 msg.message = message;
860 msg.time = GetMessageTime();
861 msg.pt.x = msg.pt.y = 0;
863 msg.pt.x = GET_X_LPARAM(lParam);
864 msg.pt.y = GET_Y_LPARAM(lParam);
868 clientToScreen(msg.hwnd, &msg.pt);
871 GetCursorPos(&msg.pt);
875 *platformWindowPtr = platformWindow;
879 if (!isInputMessage(msg.message) && filterNativeEvent(&msg, result))
882 if (platformWindow && filterNativeEvent(platformWindow->window(), &msg, result))
889 if (!windowsInputContext) {
895 return windowsInputContext->startComposition(hwnd);
897 return windowsInputContext->composition(hwnd, lParam);
899 return windowsInputContext->endComposition(hwnd);
901 return windowsInputContext->handleIME_Request(wParam, lParam, result);
913#if QT_CONFIG(directmanipulation)
914 if (
auto *dm = d->m_directManipulation.data();
915 dm && !sessionManagerInteractionBlocked()) {
916 dm->handlePointerHitTest(hwnd, wParam);
926 qWarning() <<
"External WM_DESTROY received for " << platformWindow->window()
927 <<
", parent: " << platformWindow->window()->parent()
928 <<
", transient parent: " << platformWindow->window()->transientParent();
942#if QT_CONFIG(accessibility)
943 return QWindowsUiaAccessibility::handleWmGetObject(hwnd, wParam, lParam, result);
949 return d->m_screenManager.handleScreenChanges();
958 if (!platformWindow && !d->m_creationContext.isNull()) {
960 case QtWindows::QuerySizeHints:
961 d->m_creationContext->applyToMinMaxInfo(
reinterpret_cast<MINMAXINFO *>(lParam));
963 case QtWindows::ResizeEvent:
964 d->m_creationContext->obtainedSize = QSize(LOWORD(lParam), HIWORD(lParam));
966 case QtWindows::MoveEvent:
967 d->m_creationContext->obtainedPos = QPoint(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam));
970 if (shouldHaveNonClientDpiScaling(d->m_creationContext->window) &&
973 !QWindowsContextPrivate::m_v2DpiAware) {
974 enableNonClientDpiScaling(msg.hwnd);
978 return QWindowsGeometryHint::handleCalculateSize(d->m_creationContext->window, d->m_creationContext->customMargins, msg, result);
980 return QWindowsWindow::handleGeometryChangingMessage(&msg, d->m_creationContext->window,
981 d->m_creationContext->margins + d->m_creationContext->customMargins);
986 if (platformWindow) {
991 qCDebug(lcQpaEvents) <<
"Event window: " << platformWindow->window();
993 qWarning(
"%s: No Qt Window found for event 0x%x (%s), hwnd=0x%p.",
994 __FUNCTION__, message,
995 QWindowsGuiEventDispatcher::windowsMessageName(message), hwnd);
1001 if (d->m_systemInfo & QWindowsContext::SI_SupportsTouch)
1004 if (wParam == DBT_DEVNODES_CHANGED)
1009 wic->handleInputLanguageChanged(wParam, lParam);
1020 if (QWindowsPopupMenu::notifyAboutToShow(
reinterpret_cast<HMENU>(wParam)))
1022 if (platformWindow ==
nullptr || platformWindow
->menuBar() ==
nullptr)
1024 return platformWindow
->menuBar()->notifyAboutToShow(
reinterpret_cast<HMENU>(wParam));
1028 if (QWindowsPopupMenu::notifyTriggered(LOWORD(wParam)))
1030 if (platformWindow ==
nullptr || platformWindow
->menuBar() ==
nullptr)
1032 return platformWindow
->menuBar()->notifyTriggered(LOWORD(wParam));
1037 QWindow *window = platformWindow->window();
1038 platformWindow->handleResized(
static_cast<
int>(wParam), lParam);
1039 if (window->flags().testFlags(Qt::ExpandedClientAreaHint))
1044 platformWindow->getSizeHints(
reinterpret_cast<MINMAXINFO *>(lParam));
1047 return QWindowsGeometryHint::handleCalculateSize(platformWindow->window(), platformWindow->customMargins(), msg, result);
1049 QWindow *window = platformWindow->window();
1050 if (window->flags().testFlags(Qt::ExpandedClientAreaHint))
1052 return platformWindow->handleNonClientHitTest(
QPoint(msg.pt.x, msg.pt.y), result);
1055 return platformWindow->handleNonClientActivate(result);
1057 return platformWindow->handleGeometryChanging(&msg);
1059 QWindow *window = platformWindow->window();
1060 if (window->flags().testFlags(Qt::ExpandedClientAreaHint))
1062 return platformWindow->handleWmPaint(hwnd, message, wParam, lParam, result);
1074 if (!IsZoomed(hwnd))
1079 platformWindow->checkForScreenChanged();
1080 handleExitSizeMove(platformWindow->window());
1081 if (!IsZoomed(hwnd))
1091 QWindow *window = platformWindow->window();
1092 while (window && (window->flags() & Qt::WindowTransparentForInput))
1093 window = window->parent();
1105 if (platformWindow->window()->flags() & Qt::WindowDoesNotAcceptFocus)
1109 handleFocusEvent(et, platformWindow);
1112 if (!platformWindow->window()->isVisible()) {
1120 case QtWindows::CloseEvent:
1121 QWindowSystemInterface::handleCloseEvent(platformWindow->window());
1130 if (platformWindow->window()->flags() & Qt::WindowDoesNotAcceptFocus) {
1131 *result = LRESULT(MA_NOACTIVATE);
1134#if QT_CONFIG(tabletevent)
1135 if (!d->m_tabletSupport.isNull())
1136 d->m_tabletSupport->notifyActivate();
1139 if (
const QWindow *modalWindow = QGuiApplication::modalWindow()) {
1140 QWindowsWindow *platformWindow = QWindowsWindow::windowsWindowOf(modalWindow);
1141 Q_ASSERT(platformWindow);
1147 if (platformWindow->window()->flags() & Qt::WindowDoesNotAcceptFocus) {
1148 *result = LRESULT(MA_NOACTIVATE);
1152#ifndef QT_NO_CONTEXTMENU
1153 case QtWindows::ContextMenu:
1154 return handleContextMenuEvent(platformWindow->window(), msg);
1157#ifndef QT_NO_WHATSTHIS
1158 QWindowSystemInterface::handleEnterWhatsThisEvent();
1163 platformWindow->handleDpiScaledSize(wParam, lParam, result);
1166 platformWindow->handleDpiChanged(hwnd, wParam, lParam);
1169 platformWindow->handleDpiChangedAfterParent(hwnd);
1171#if QT_CONFIG(sessionmanager)
1172 case QtWindows::QueryEndSessionApplicationEvent: {
1173 QWindowsSessionManager *sessionManager = platformSessionManager();
1174 if (sessionManager->isActive()) {
1175 *result = sessionManager->wasCanceled() ? 0 : 1;
1179 sessionManager->setActive(
true);
1180 sessionManager->blocksInteraction();
1181 sessionManager->clearCancellation();
1183 auto *qGuiAppPriv =
static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(qApp));
1184 qGuiAppPriv->commitData();
1186 if (lParam & ENDSESSION_LOGOFF)
1189 *result = sessionManager->wasCanceled() ? 0 : 1;
1192 case QtWindows::EndSessionApplicationEvent: {
1193 QWindowsSessionManager *sessionManager = platformSessionManager();
1195 sessionManager->setActive(
false);
1196 sessionManager->allowsInteraction();
1197 const bool endsession = wParam != 0;
1201 auto *qGuiAppPriv =
static_cast<QGuiApplicationPrivate*>(QObjectPrivate::get(qApp));
1202 if (endsession && !qGuiAppPriv->aboutToQuitEmitted) {
1203 qGuiAppPriv->aboutToQuitEmitted =
true;
1204 int index = QGuiApplication::staticMetaObject.indexOfSignal(
"aboutToQuit()");
1205 qApp->qt_metacall(QMetaObject::InvokeMetaMethod, index,
nullptr);
1207 QGuiApplication::quit();
1224
1225
1226
1227
1231 QWindow *nextActiveWindow =
nullptr;
1233 QWindow *topWindow = QWindowsWindow::topLevelOf(platformWindow->window());
1234 QWindow *modalWindow =
nullptr;
1235 if (QGuiApplicationPrivate::instance()->isWindowBlocked(topWindow, &modalWindow) && topWindow != modalWindow) {
1236 modalWindow->requestActivate();
1242 QWindow *currentFocusWindow = QGuiApplication::focusWindow();
1243 if (currentFocusWindow && currentFocusWindow != platformWindow->window()) {
1244 currentFocusWindow->requestActivate();
1248 nextActiveWindow = platformWindow->window();
1252 if (
const HWND nextActiveHwnd = GetFocus())
1253 if (
QWindowsWindow *nextActivePlatformWindow = findClosestPlatformWindow(nextActiveHwnd))
1254 if (nextActivePlatformWindow != platformWindow)
1255 nextActiveWindow = nextActivePlatformWindow->window();
1257 if (nextActiveWindow != d->m_lastActiveWindow) {
1258 d->m_lastActiveWindow = nextActiveWindow;
1259 QWindowSystemInterface::handleFocusWindowChanged(nextActiveWindow, Qt::ActiveWindowFocusReason);
1263#ifndef QT_NO_CONTEXTMENU
1264bool QWindowsContext::handleContextMenuEvent(QWindow *window,
const MSG &msg)
1266 const QInputDevice *device = QInputDevice::primaryKeyboard();
1269 if (msg.lParam !=
int(0xffffffff)) {
1270 device = QPointingDevice::primaryPointingDevice();
1271 globalPos.setX(msg.pt.x);
1272 globalPos.setY(msg.pt.y);
1273 pos = QWindowsGeometryHint::mapFromGlobal(msg.hwnd, globalPos);
1276 if (GetClientRect(msg.hwnd, &clientRect)) {
1277 if (pos.x() < clientRect.left || pos.x() >= clientRect.right ||
1278 pos.y() < clientRect.top || pos.y() >= clientRect.bottom)
1288 QWindowSystemInterface::handleContextMenuEvent(window, device, pos, globalPos,
1289 keyMapper()->queryKeyboardModifiers());
1306 const Qt::MouseButtons currentButtons = QWindowsPointerHandler::queryMouseButtons();
1307 const Qt::MouseButtons appButtons = QGuiApplication::mouseButtons();
1308 if (currentButtons == appButtons)
1310 const Qt::KeyboardModifiers keyboardModifiers =
keyMapper()->queryKeyboardModifiers();
1311 const QPoint globalPos = QWindowsCursor::mousePosition();
1312 const QPlatformWindow *platWin = window->handle();
1313 const QPoint localPos = platWin->mapFromGlobal(globalPos);
1314 const QEvent::Type type = platWin->geometry().contains(globalPos)
1315 ? QEvent::MouseButtonRelease : QEvent::NonClientAreaMouseButtonRelease;
1316 for (Qt::MouseButton button : {Qt::LeftButton, Qt::RightButton, Qt::MiddleButton}) {
1317 if (appButtons.testFlag(button) && !currentButtons.testFlag(button)) {
1318 QWindowSystemInterface::handleMouseEvent(window, localPos, globalPos,
1319 currentButtons, button, type, keyboardModifiers);
1322 d->m_pointerHandler.clearEvents();
1327 return d->m_asyncExpose;
1332 d->m_asyncExpose = value;
1335DWORD
QWindowsContext::readAdvancedExplorerSettings(
const wchar_t *subKey, DWORD defaultValue)
1337 const auto advancedSettings = QWinRegistryKey(
1338 HKEY_CURRENT_USER, LR"(Software\Microsoft\Windows\CurrentVersion\Explorer\Advanced)");
1339 return advancedSettings.value<DWORD>(subKey).value_or(defaultValue);
1344 return rect.right - rect.left == 0 && rect.bottom - rect.top == 0;
1349 return QMargins(client.left - frame.left, client.top - frame.top,
1350 frame.right - client.right, frame.bottom - client.bottom);
1355 RECT result = {0, 0, 0, 0};
1356 if (message == WM_NCCALCSIZE && wParam)
1357 result =
reinterpret_cast<
const NCCALCSIZE_PARAMS *>(lParam)->rgrc[n];
1363 WINDOWPLACEMENT windowPlacement;
1364 windowPlacement.length =
sizeof(WINDOWPLACEMENT);
1365 return GetWindowPlacement(hwnd, &windowPlacement) && windowPlacement.showCmd == SW_SHOWMINIMIZED;
1370 return (GetWindowLongPtr(hwnd, GWL_STYLE) & WS_CHILD) == 0;
1374
1375
1376
1377
1378
1379
1381LRESULT QT_WIN_CALLBACK qWindowsWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
1384 const QtWindows::WindowsEventType et = windowsEventType(message, wParam, lParam);
1385 QWindowsWindow *platformWindow =
nullptr;
1386 const RECT ncCalcSizeFrame = rectFromNcCalcSize(message, wParam, lParam, 0);
1387 const bool handled = QWindowsContext::instance()->windowsProc(hwnd, message, et, wParam, lParam, &result, &platformWindow);
1388 if (QWindowsContext::verbose > 1 && lcQpaEvents().isDebugEnabled()) {
1389 if (
const char *eventName = QWindowsGuiEventDispatcher::windowsMessageName(message)) {
1390 qCDebug(lcQpaEvents).nospace() <<
"EVENT: hwd=" << hwnd <<
' ' << eventName
1391 <<
" msg=0x" << Qt::hex << message <<
" et=0x" << et << Qt::dec <<
" wp="
1392 <<
int(wParam) <<
" at " << GET_X_LPARAM(lParam) <<
','
1393 << GET_Y_LPARAM(lParam) <<
" handled=" << handled;
1397 result = DefWindowProc(hwnd, message, wParam, lParam);
1403 if (message == WM_NCCALCSIZE && !isEmptyRect(ncCalcSizeFrame) && isTopLevel(hwnd) && !isMinimized(hwnd)) {
1404 const QMargins margins =
1405 marginsFromRects(ncCalcSizeFrame, rectFromNcCalcSize(message, wParam, lParam, 0));
1406 if (margins.left() >= 0) {
1407 if (platformWindow) {
1408 qCDebug(lcQpaWindow) <<
__FUNCTION__ <<
"WM_NCCALCSIZE for" << hwnd << margins;
1409 platformWindow->setFullFrameMargins(margins);
1411 const QSharedPointer<QWindowCreationContext> ctx = QWindowsContext::instance()->windowCreationContext();
1413 ctx->margins = margins;
1426 QAbstractEventDispatcher *dispatcher = QAbstractEventDispatcher::instance();
1427 qintptr filterResult = 0;
1428 if (dispatcher && dispatcher->filterNativeEvent(nativeEventType(), msg, &filterResult)) {
1429 *result = LRESULT(filterResult);
1438 qintptr filterResult = 0;
1439 if (QWindowSystemInterface::handleNativeEvent(window, nativeEventType(), msg, &filterResult)) {
1440 *result = LRESULT(filterResult);
\inmodule QtCore\reentrant
Singleton container for all relevant information.
QSharedPointer< QWindowCreationContext > windowCreationContext() const
QWindowsScreenManager & screenManager()
QWindowsWindow * findClosestPlatformWindow(HWND) const
QWindow * findWindow(HWND) const
void addWindow(HWND, QWindowsWindow *w)
static bool systemParametersInfoForScreen(unsigned action, unsigned param, void *out, const QPlatformScreen *screen=nullptr)
static bool setProcessDpiAwareness(QtWindows::DpiAwareness dpiAwareness)
void clearWindowUnderMouse()
HDC displayContext() const
QWindowsTabletSupport * tabletSupport() const
static bool systemParametersInfoForWindow(unsigned action, unsigned param, void *out, const QPlatformWindow *win=nullptr)
static void setTabletAbsoluteRange(int a)
QWindowsDirectManipulation * directManipulation() const
void registerTouchWindows()
QWindowsWindow * findPlatformWindowAt(HWND parent, const QPoint &screenPoint, unsigned cwex_flags) const
bool initTouch(unsigned integrationOptions)
HWND createDummyWindow(const QString &classNameIn, const wchar_t *windowName, WNDPROC wndProc=nullptr, DWORD style=WS_OVERLAPPED)
Convenience to create a non-visible, message-only dummy window for example used as clipboard watcher ...
void setAsyncExpose(bool value)
QSharedPointer< QWindowCreationContext > setWindowCreationContext(const QSharedPointer< QWindowCreationContext > &ctx)
bool windowsProc(HWND hwnd, UINT message, QtWindows::WindowsEventType et, WPARAM wParam, LPARAM lParam, LRESULT *result, QWindowsWindow **platformWindowPtr)
Main windows procedure registered for windows.
unsigned systemInfo() const
static QtWindows::DpiAwareness processDpiAwareness()
QWindowsWindow * findPlatformWindow(HWND) const
QWindow * keyGrabber() const
QWindowsWindow * findPlatformWindow(const QWindowsMenuBar *mb) const
QWindow * windowUnderMouse() const
QPlatformKeyMapper * keyMapper() const
bool useRTLExtensions() const
static bool systemParametersInfo(unsigned action, unsigned param, void *out, unsigned dpi=0)
QWindowsMimeRegistry & mimeConverter() const
static bool isSessionLocked()
bool initPowerNotificationHandler()
HandleBaseWindowHash & windows()
static QWindowsContext * instance()
void setDetectAltGrModifier(bool a)
Platform cursor implementation.
static bool hasOverrideCursor()
static void enforceOverrideCursor()
Windows Input context implementation.
static void setWindowsImeEnabled(QWindowsWindow *platformWindow, bool enabled)
void updateApplicationBadge()
static QWindowsIntegration * instance()
Translates Windows keys to QWindowSystemInterface events.
Manages the list of QWindowsMimeConverter instances.
Manages a list of QWindowsScreen.
Tablet support for Windows.
static QWindowsTheme * instance()
void alertWindow(int durationMs=0)
bool testFlag(unsigned f) const
void setFlag(unsigned f) const
void clearFlag(unsigned f) const
static void settingsChanged()
static const char * embeddedNativeParentHandleProperty
QWindowsMenuBar * menuBar() const
bool frameStrutEventsEnabled() const override
Reimplement this method to return whether frame strut events are enabled.
@ WithinSetParent
Automatic mouse capture on button press.
void updateRestoreGeometry()
void updateCustomTitlebar()
void handleCompositionSettingsChanged()
WindowsEventType
Enumerations for WM_XX events.
@ PointerActivateWindowEvent
@ InputMethodEndCompositionEvent
@ InputLanguageChangeEvent
@ ShowEventOnParentRestoring
@ InputMethodCompositionEvent
@ InputMethodOpenCandidateWindowEvent
@ MouseActivateWindowEvent
@ DpiChangedAfterParentEvent
@ InputMethodStartCompositionEvent
@ InputMethodKeyDownEvent
@ CompositionSettingsChanged
@ InputMethodCloseCandidateWindowEvent
@ DirectManipulationHitTestEvent
@ AccessibleObjectFromWindowRequest
Q_LOGGING_CATEGORY(lcEventDispatcher, "qt.eventdispatcher")
#define DPI_AWARENESS_CONTEXT_UNAWARE
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
#define DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2
#define DPI_AWARENESS_CONTEXT_SYSTEM_AWARE
#define DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED
static bool isTopLevel(HWND hwnd)
static RECT rectFromNcCalcSize(UINT message, WPARAM wParam, LPARAM lParam, int n)
static bool enableNonClientDpiScaling(HWND hwnd)
static bool isInputMessage(UINT m)
static DPI_AWARENESS_CONTEXT qtDpiAwarenessToDpiAwarenessContext(QtWindows::DpiAwareness dpiAwareness)
static bool isMinimized(HWND hwnd)
static QMargins marginsFromRects(const RECT &frame, const RECT &client)
static bool useRTL_Extensions()
static bool sessionManagerInteractionBlocked()
static QWindowsInputContext * windowsInputContext()
static QtWindows::DpiAwareness dpiAwarenessContextToQtDpiAwareness(DPI_AWARENESS_CONTEXT context)
static QByteArray nativeEventType()
static bool isEmptyRect(const RECT &rect)
static bool findPlatformWindowHelper(const POINT &screenPoint, unsigned cwexFlags, const QWindowsContext *context, HWND *hwnd, QWindowsWindow **result)
Find a child window at a screen point.
const HRESULT m_oleInitializeResult
QWindowsKeyMapper m_keyMapper
QWindowsWindowClassRegistry m_windowClassRegistry
QWindowsPointerHandler m_pointerHandler
QUniqueHDCHandle m_displayContext
QWindowsScreenManager m_screenManager
QWindow * m_lastActiveWindow
QWindowsMimeRegistry m_mimeConverter
QWindowsContext::HandleBaseWindowHash m_windows
QSharedPointer< QWindowCreationContext > m_creationContext
HPOWERNOTIFY m_powerNotification