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 <joerg.bornemann@qt.io>
This commit is contained in:
Friedemann Kleint 2017-03-22 12:19:47 +01:00
parent e0becd6a8a
commit 7a902e86ce
3 changed files with 20 additions and 1 deletions

View File

@ -120,6 +120,7 @@ enum WindowsEventType // Simplify event types
QueryEndSessionApplicationEvent = ApplicationEventFlag + 4,
EndSessionApplicationEvent = ApplicationEventFlag + 5,
AppCommandEvent = ApplicationEventFlag + 6,
DeviceChangeEvent = ApplicationEventFlag + 7,
InputMethodStartCompositionEvent = InputMethodEventFlag + 1,
InputMethodCompositionEvent = InputMethodEventFlag + 2,
InputMethodEndCompositionEvent = InputMethodEventFlag + 3,
@ -271,6 +272,8 @@ inline QtWindows::WindowsEventType windowsEventType(UINT message, WPARAM wParamI
#endif
case WM_GESTURE:
return QtWindows::GestureEvent;
case WM_DEVICECHANGE:
return QtWindows::DeviceChangeEvent;
case WM_DPICHANGED:
return QtWindows::DpiChangedEvent;
default:

View File

@ -79,6 +79,7 @@
#include <stdio.h>
#include <windowsx.h>
#include <comdef.h>
#include <dbt.h>
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);

View File

@ -2411,7 +2411,8 @@ void QWindowsWindow::setTouchWindowTouchTypeStatic(QWindow *window, QWindowsWind
void QWindowsWindow::registerTouchWindow(QWindowsWindowFunctions::TouchWindowTouchTypes touchTypes)
{
if ((QWindowsContext::instance()->systemInfo() & QWindowsContext::SI_SupportsTouch)) {
if ((QWindowsContext::instance()->systemInfo() & QWindowsContext::SI_SupportsTouch)
&& !testFlag(TouchRegistered)) {
ULONG touchFlags = 0;
const bool ret = QWindowsContext::user32dll.isTouchWindow(m_data.hwnd, &touchFlags);
// Return if it is not a touch window or the flags are already set by a hook