From 7daae2c2c706fd5d1c1ae44ace6847bc297803a0 Mon Sep 17 00:00:00 2001 From: Friedemann Kleint Date: Mon, 19 Oct 2015 14:25:37 +0200 Subject: Windows: Delay-initialize pluggable touch devices. Move touch device initialization code to QWindowsContext and replace the assert on the touch device in QWindowsMouseHandler by a call to the initTouch(). Task-number: QTBUG-48849 Change-Id: If8573b8283ef94e7fd015f6edc626e3c8cc0b139 Reviewed-by: Joni Poikelin Reviewed-by: Oliver Wolff Reviewed-by: Andreas Holzammer Reviewed-by: Friedemann Kleint --- src/plugins/platforms/windows/qwindowscontext.cpp | 45 +++++++++++++++++++--- src/plugins/platforms/windows/qwindowscontext.h | 3 ++ .../platforms/windows/qwindowsintegration.cpp | 12 +----- .../platforms/windows/qwindowsmousehandler.cpp | 17 ++++++-- .../platforms/windows/qwindowsmousehandler.h | 1 + 5 files changed, 57 insertions(+), 21 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowscontext.cpp b/src/plugins/platforms/windows/qwindowscontext.cpp index 3f355db607..00049bd0d6 100644 --- a/src/plugins/platforms/windows/qwindowscontext.cpp +++ b/src/plugins/platforms/windows/qwindowscontext.cpp @@ -33,6 +33,7 @@ ****************************************************************************/ #include "qwindowscontext.h" +#include "qwindowsintegration.h" #include "qwindowswindow.h" #include "qwindowskeymapper.h" #include "qwindowsguieventdispatcher.h" @@ -201,12 +202,14 @@ void QWindowsUser32DLL::init() bool QWindowsUser32DLL::initTouch() { - QSystemLibrary library(QStringLiteral("user32")); - isTouchWindow = (IsTouchWindow)(library.resolve("IsTouchWindow")); - registerTouchWindow = (RegisterTouchWindow)(library.resolve("RegisterTouchWindow")); - unregisterTouchWindow = (UnregisterTouchWindow)(library.resolve("UnregisterTouchWindow")); - getTouchInputInfo = (GetTouchInputInfo)(library.resolve("GetTouchInputInfo")); - closeTouchInputHandle = (CloseTouchInputHandle)(library.resolve("CloseTouchInputHandle")); + if (!isTouchWindow && QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7) { + QSystemLibrary library(QStringLiteral("user32")); + isTouchWindow = (IsTouchWindow)(library.resolve("IsTouchWindow")); + registerTouchWindow = (RegisterTouchWindow)(library.resolve("RegisterTouchWindow")); + unregisterTouchWindow = (UnregisterTouchWindow)(library.resolve("UnregisterTouchWindow")); + getTouchInputInfo = (GetTouchInputInfo)(library.resolve("GetTouchInputInfo")); + closeTouchInputHandle = (CloseTouchInputHandle)(library.resolve("CloseTouchInputHandle")); + } return isTouchWindow && registerTouchWindow && unregisterTouchWindow && getTouchInputInfo && closeTouchInputHandle; } @@ -359,6 +362,36 @@ QWindowsContext::~QWindowsContext() m_instance = 0; } +bool QWindowsContext::initTouch() +{ + return initTouch(QWindowsIntegration::instance()->options()); +} + +bool QWindowsContext::initTouch(unsigned integrationOptions) +{ + if (d->m_systemInfo & QWindowsContext::SI_SupportsTouch) + return true; + + QTouchDevice *touchDevice = d->m_mouseHandler.ensureTouchDevice(); + if (!touchDevice) + return false; + +#ifndef Q_OS_WINCE + if (!QWindowsContext::user32dll.initTouch()) { + delete touchDevice; + return false; + } +#endif // !Q_OS_WINCE + + if (!(integrationOptions & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch)) + touchDevice->setCapabilities(touchDevice->capabilities() | QTouchDevice::MouseEmulation); + + QWindowSystemInterface::registerTouchDevice(touchDevice); + + d->m_systemInfo |= QWindowsContext::SI_SupportsTouch; + return true; +} + void QWindowsContext::setTabletAbsoluteRange(int a) { #if !defined(QT_NO_TABLETEVENT) && !defined(Q_OS_WINCE) diff --git a/src/plugins/platforms/windows/qwindowscontext.h b/src/plugins/platforms/windows/qwindowscontext.h index d2a3481b28..641e3ed41f 100644 --- a/src/plugins/platforms/windows/qwindowscontext.h +++ b/src/plugins/platforms/windows/qwindowscontext.h @@ -170,6 +170,9 @@ public: explicit QWindowsContext(); ~QWindowsContext(); + bool initTouch(); + bool initTouch(unsigned integrationOptions); // For calls from QWindowsIntegration::QWindowsIntegration() only. + int defaultDPI() const; QString registerWindowClass(const QWindow *w); diff --git a/src/plugins/platforms/windows/qwindowsintegration.cpp b/src/plugins/platforms/windows/qwindowsintegration.cpp index 79df6ce720..089c3cd0fe 100644 --- a/src/plugins/platforms/windows/qwindowsintegration.cpp +++ b/src/plugins/platforms/windows/qwindowsintegration.cpp @@ -230,17 +230,7 @@ QWindowsIntegrationPrivate::QWindowsIntegrationPrivate(const QStringList ¶mL << __FUNCTION__ << "DpiAwareness=" << dpiAwareness <<",Scaling=" << QWindowsScaling::factor(); - QTouchDevice *touchDevice = m_context.touchDevice(); - if (touchDevice) { -#ifdef Q_OS_WINCE - touchDevice->setCapabilities(touchDevice->capabilities() | QTouchDevice::MouseEmulation); -#else - if (!(m_options & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch)) { - touchDevice->setCapabilities(touchDevice->capabilities() | QTouchDevice::MouseEmulation); - } -#endif - QWindowSystemInterface::registerTouchDevice(touchDevice); - } + m_context.initTouch(m_options); } QWindowsIntegrationPrivate::~QWindowsIntegrationPrivate() diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.cpp b/src/plugins/platforms/windows/qwindowsmousehandler.cpp index e6b80f2b93..e83354157b 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.cpp +++ b/src/plugins/platforms/windows/qwindowsmousehandler.cpp @@ -150,12 +150,19 @@ static inline QTouchDevice *createTouchDevice() QWindowsMouseHandler::QWindowsMouseHandler() : m_windowUnderMouse(0), m_trackedWindow(0), - m_touchDevice(createTouchDevice()), + m_touchDevice(Q_NULLPTR), m_leftButtonDown(false), m_previousCaptureWindow(0) { } +QTouchDevice *QWindowsMouseHandler::ensureTouchDevice() +{ + if (!m_touchDevice) + m_touchDevice = createTouchDevice(); + return m_touchDevice; +} + Qt::MouseButtons QWindowsMouseHandler::queryMouseButtons() { Qt::MouseButtons result = 0; @@ -480,7 +487,11 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND, typedef QWindowSystemInterface::TouchPoint QTouchPoint; typedef QList QTouchPointList; - Q_ASSERT(m_touchDevice); + if (!QWindowsContext::instance()->initTouch()) { + qWarning("Unable to initialize touch handling."); + return true; + } + const QRect screenGeometry = window->screen()->geometry(); const int winTouchPointCount = msg.wParam; @@ -491,8 +502,6 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND, touchPoints.reserve(winTouchPointCount); Qt::TouchPointStates allStates = 0; - Q_ASSERT(QWindowsContext::user32dll.getTouchInputInfo); - QWindowsContext::user32dll.getTouchInputInfo((HANDLE) msg.lParam, msg.wParam, winTouchInputs.data(), sizeof(TOUCHINPUT)); const qreal screenPosFactor = 0.01 / qreal(QWindowsScaling::factor()); for (int i = 0; i < winTouchPointCount; ++i) { diff --git a/src/plugins/platforms/windows/qwindowsmousehandler.h b/src/plugins/platforms/windows/qwindowsmousehandler.h index 61aa8d6084..4b5078567d 100644 --- a/src/plugins/platforms/windows/qwindowsmousehandler.h +++ b/src/plugins/platforms/windows/qwindowsmousehandler.h @@ -52,6 +52,7 @@ public: QWindowsMouseHandler(); QTouchDevice *touchDevice() const { return m_touchDevice; } + QTouchDevice *ensureTouchDevice(); bool translateMouseEvent(QWindow *widget, HWND hwnd, QtWindows::WindowsEventType t, MSG msg, -- cgit v1.2.3