From 7a902e86ceb392b8b6cd0b3119afa19ea619868d Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Wed, 22 Mar 2017 12:19:47 +0100 Subject: Windows: Register windows for touch when a device is plugged in Call QWindowsWindow::registerTouchWindow() for all windows when a device is plugged in while the application is running. Guard registerTouchWindow() against repetitive invocation and wrong window types. This amends the crash fix 7daae2c2c706fd5d1c1ae44ace6847bc297803a0 and touch should then work. Task-number: QTBUG-48849 Change-Id: I8b257dda144f28d60bcc5c4e369a413a90263998 Reviewed-by: Joerg Bornemann --- src/plugins/platforms/windows/qwindowscontext.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/plugins/platforms/windows/qwindowscontext.cpp') diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 5745fc6d19..b7a866679f 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -79,6 +79,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE @@ -322,6 +323,13 @@ bool QWindowsContext::initTouch(unsigned integrationOptions) QWindowSystemInterface::registerTouchDevice(touchDevice); d->m_systemInfo |= QWindowsContext::SI_SupportsTouch; + + // A touch device was plugged while the app is running. Register all windows for touch. + if (QGuiApplicationPrivate::is_app_running) { + for (QWindowsWindow *w : qAsConst(d->m_windows)) + w->registerTouchWindow(); + } + return true; } @@ -965,6 +973,13 @@ bool QWindowsContext::windowsProc(HWND hwnd, UINT message, } switch (et) { + case QtWindows::DeviceChangeEvent: + if (d->m_systemInfo & QWindowsContext::SI_SupportsTouch) + break; + // See if there are any touch devices added + if (wParam == DBT_DEVNODES_CHANGED) + initTouch(); + break; case QtWindows::KeyboardLayoutChangeEvent: if (QWindowsInputContext *wic = windowsInputContext()) wic->handleInputLanguageChanged(wParam, lParam); -- cgit v1.2.3