Windows QPA: Use a QSharedPointer for the touch device

For reasons of symmetry with the tablet devices.

As a drive by, give it more distinct IDs.

Task-number: QTBUG-46412
Change-Id: Ie667621246b26db6fdda84c5ff2455fe38633cb3
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
Friedemann Kleint 2020-10-16 11:50:27 +02:00
parent d9edad8117
commit e3470a98e9
6 changed files with 27 additions and 32 deletions

View File

@ -349,19 +349,16 @@ bool QWindowsContext::initTouch(unsigned integrationOptions)
return true; return true;
const bool usePointerHandler = (d->m_systemInfo & QWindowsContext::SI_SupportsPointer) != 0; const bool usePointerHandler = (d->m_systemInfo & QWindowsContext::SI_SupportsPointer) != 0;
auto touchDevice = usePointerHandler ? d->m_pointerHandler.touchDevice() : d->m_mouseHandler.touchDevice(); auto touchDevice = usePointerHandler ? d->m_pointerHandler.touchDevice() : d->m_mouseHandler.touchDevice();
if (!touchDevice) { if (touchDevice.isNull()) {
const bool mouseEmulation = const bool mouseEmulation =
(integrationOptions & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch) == 0; (integrationOptions & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch) == 0;
touchDevice = QWindowsPointerHandler::createTouchDevice(mouseEmulation); touchDevice = QWindowsPointerHandler::createTouchDevice(mouseEmulation);
} }
if (!touchDevice) if (touchDevice.isNull())
return false; return false;
if (usePointerHandler) d->m_pointerHandler.setTouchDevice(touchDevice);
d->m_pointerHandler.setTouchDevice(touchDevice); d->m_mouseHandler.setTouchDevice(touchDevice);
else QWindowSystemInterface::registerInputDevice(touchDevice.data());
d->m_mouseHandler.setTouchDevice(touchDevice);
QWindowSystemInterface::registerInputDevice(touchDevice);
d->m_systemInfo |= QWindowsContext::SI_SupportsTouch; d->m_systemInfo |= QWindowsContext::SI_SupportsTouch;
@ -1637,12 +1634,6 @@ void QWindowsContext::setAsyncExpose(bool value)
d->m_asyncExpose = value; d->m_asyncExpose = value;
} }
QPointingDevice *QWindowsContext::touchDevice() const
{
return (d->m_systemInfo & QWindowsContext::SI_SupportsPointer) ?
d->m_pointerHandler.touchDevice() : d->m_mouseHandler.touchDevice();
}
DWORD QWindowsContext::readAdvancedExplorerSettings(const wchar_t *subKey, DWORD defaultValue) DWORD QWindowsContext::readAdvancedExplorerSettings(const wchar_t *subKey, DWORD defaultValue)
{ {
const auto value = const auto value =

View File

@ -266,8 +266,6 @@ public:
static DWORD readAdvancedExplorerSettings(const wchar_t *subKey, DWORD defaultValue); static DWORD readAdvancedExplorerSettings(const wchar_t *subKey, DWORD defaultValue);
QPointingDevice *touchDevice() const;
static bool filterNativeEvent(MSG *msg, LRESULT *result); static bool filterNativeEvent(MSG *msg, LRESULT *result);
static bool filterNativeEvent(QWindow *window, MSG *msg, LRESULT *result); static bool filterNativeEvent(QWindow *window, MSG *msg, LRESULT *result);

View File

@ -652,7 +652,7 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND,
m_touchInputIDToTouchPointID.clear(); m_touchInputIDToTouchPointID.clear();
QWindowSystemInterface::handleTouchEvent(window, QWindowSystemInterface::handleTouchEvent(window,
m_touchDevice, m_touchDevice.data(),
touchPoints, touchPoints,
QWindowsKeyMapper::queryKeyboardModifiers()); QWindowsKeyMapper::queryKeyboardModifiers());
return true; return true;

View File

@ -45,6 +45,7 @@
#include <QtCore/qpointer.h> #include <QtCore/qpointer.h>
#include <QtCore/qhash.h> #include <QtCore/qhash.h>
#include <QtCore/qsharedpointer.h>
#include <QtGui/qevent.h> #include <QtGui/qevent.h>
QT_BEGIN_NAMESPACE QT_BEGIN_NAMESPACE
@ -56,10 +57,12 @@ class QWindowsMouseHandler
{ {
Q_DISABLE_COPY_MOVE(QWindowsMouseHandler) Q_DISABLE_COPY_MOVE(QWindowsMouseHandler)
public: public:
using QPointingDevicePtr = QSharedPointer<QPointingDevice>;
QWindowsMouseHandler(); QWindowsMouseHandler();
QPointingDevice *touchDevice() const { return m_touchDevice; } const QPointingDevicePtr &touchDevice() const { return m_touchDevice; }
void setTouchDevice(QPointingDevice *d) { m_touchDevice = d; } void setTouchDevice(const QPointingDevicePtr &d) { m_touchDevice = d; }
bool translateMouseEvent(QWindow *widget, HWND hwnd, bool translateMouseEvent(QWindow *widget, HWND hwnd,
QtWindows::WindowsEventType t, MSG msg, QtWindows::WindowsEventType t, MSG msg,
@ -90,7 +93,7 @@ private:
QPointer<QWindow> m_trackedWindow; QPointer<QWindow> m_trackedWindow;
QHash<DWORD, int> m_touchInputIDToTouchPointID; QHash<DWORD, int> m_touchInputIDToTouchPointID;
QHash<int, QPointF> m_lastTouchPositions; QHash<int, QPointF> m_lastTouchPositions;
QPointingDevice *m_touchDevice = nullptr; QPointingDevicePtr m_touchDevice;
bool m_leftButtonDown = false; bool m_leftButtonDown = false;
QWindow *m_previousCaptureWindow = nullptr; QWindow *m_previousCaptureWindow = nullptr;
QEvent::Type m_lastEventType = QEvent::None; QEvent::Type m_lastEventType = QEvent::None;

View File

@ -82,7 +82,6 @@ qint64 QWindowsPointerHandler::m_nextInputDeviceId = 1;
QWindowsPointerHandler::~QWindowsPointerHandler() QWindowsPointerHandler::~QWindowsPointerHandler()
{ {
delete m_touchDevice;
} }
bool QWindowsPointerHandler::translatePointerEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType et, MSG msg, LRESULT *result) bool QWindowsPointerHandler::translatePointerEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType et, MSG msg, LRESULT *result)
@ -320,7 +319,7 @@ static bool isValidWheelReceiver(QWindow *candidate)
return false; return false;
} }
QPointingDevice *QWindowsPointerHandler::createTouchDevice(bool mouseEmulation) QWindowsPointerHandler::QPointingDevicePtr QWindowsPointerHandler::createTouchDevice(bool mouseEmulation)
{ {
const int digitizers = GetSystemMetrics(SM_DIGITIZER); const int digitizers = GetSystemMetrics(SM_DIGITIZER);
if (!(digitizers & (NID_INTEGRATED_TOUCH | NID_EXTERNAL_TOUCH))) if (!(digitizers & (NID_INTEGRATED_TOUCH | NID_EXTERNAL_TOUCH)))
@ -339,15 +338,19 @@ QPointingDevice *QWindowsPointerHandler::createTouchDevice(bool mouseEmulation)
capabilities.setFlag(QInputDevice::Capability::MouseEmulation); capabilities.setFlag(QInputDevice::Capability::MouseEmulation);
} }
qCDebug(lcQpaEvents) << "Digitizers:" << Qt::hex << Qt::showbase << (digitizers & ~NID_READY) const int flags = digitizers & ~NID_READY;
qCDebug(lcQpaEvents) << "Digitizers:" << Qt::hex << Qt::showbase << flags
<< "Ready:" << (digitizers & NID_READY) << Qt::dec << Qt::noshowbase << "Ready:" << (digitizers & NID_READY) << Qt::dec << Qt::noshowbase
<< "Tablet PC:" << tabletPc << "Max touch points:" << maxTouchPoints << "Capabilities:" << capabilities; << "Tablet PC:" << tabletPc << "Max touch points:" << maxTouchPoints << "Capabilities:" << capabilities;
const int buttonCount = type == QInputDevice::DeviceType::TouchScreen ? 1 : 3; const int buttonCount = type == QInputDevice::DeviceType::TouchScreen ? 1 : 3;
// TODO: use system-provided name and device ID rather than empty-string and m_nextInputDeviceId // TODO: use system-provided name and device ID rather than empty-string and m_nextInputDeviceId
return new QPointingDevice(QString(), m_nextInputDeviceId++, const qint64 systemId = m_nextInputDeviceId++ | (qint64(flags << 2));
type, QPointingDevice::PointerType::Finger, auto d = new QPointingDevice(QString(), systemId, type,
capabilities, maxTouchPoints, buttonCount); QPointingDevice::PointerType::Finger,
capabilities, maxTouchPoints, buttonCount,
QString(), QPointingDeviceUniqueId::fromNumericId(systemId));
return QPointingDevicePtr(d);
} }
void QWindowsPointerHandler::clearEvents() void QWindowsPointerHandler::clearEvents()
@ -466,7 +469,7 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd,
return false; return false;
if (msg.message == WM_POINTERCAPTURECHANGED) { if (msg.message == WM_POINTERCAPTURECHANGED) {
QWindowSystemInterface::handleTouchCancelEvent(window, m_touchDevice, QWindowSystemInterface::handleTouchCancelEvent(window, m_touchDevice.data(),
QWindowsKeyMapper::queryKeyboardModifiers()); QWindowsKeyMapper::queryKeyboardModifiers());
m_lastTouchPositions.clear(); m_lastTouchPositions.clear();
return true; return true;
@ -550,7 +553,7 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd,
if (allStates == QEventPoint::State::Released) if (allStates == QEventPoint::State::Released)
m_touchInputIDToTouchPointID.clear(); m_touchInputIDToTouchPointID.clear();
QWindowSystemInterface::handleTouchEvent(window, m_touchDevice, touchPoints, QWindowSystemInterface::handleTouchEvent(window, m_touchDevice.data(), touchPoints,
QWindowsKeyMapper::queryKeyboardModifiers()); QWindowsKeyMapper::queryKeyboardModifiers());
return false; // Allow mouse messages to be generated. return false; // Allow mouse messages to be generated.
} }

View File

@ -65,9 +65,9 @@ public:
bool translatePointerEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType et, MSG msg, LRESULT *result); bool translatePointerEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType et, MSG msg, LRESULT *result);
bool translateMouseEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType et, MSG msg, LRESULT *result); bool translateMouseEvent(QWindow *window, HWND hwnd, QtWindows::WindowsEventType et, MSG msg, LRESULT *result);
QPointingDevice *touchDevice() const { return m_touchDevice; } const QPointingDevicePtr &touchDevice() const { return m_touchDevice; }
void setTouchDevice(QPointingDevice *d) { m_touchDevice = d; } void setTouchDevice(const QPointingDevicePtr &d) { m_touchDevice = d; }
static QPointingDevice *createTouchDevice(bool mouseEmulation); static QPointingDevicePtr createTouchDevice(bool mouseEmulation);
QWindow *windowUnderMouse() const { return m_windowUnderPointer.data(); } QWindow *windowUnderMouse() const { return m_windowUnderPointer.data(); }
void clearWindowUnderMouse() { m_windowUnderPointer = nullptr; } void clearWindowUnderMouse() { m_windowUnderPointer = nullptr; }
@ -83,7 +83,7 @@ private:
QPointingDevicePtr findTabletDevice(QPointingDevice::PointerType pointerType) const; QPointingDevicePtr findTabletDevice(QPointingDevice::PointerType pointerType) const;
#endif #endif
QPointingDevice *m_touchDevice = nullptr; QPointingDevicePtr m_touchDevice;
#if QT_CONFIG(tabletevent) #if QT_CONFIG(tabletevent)
QList<QPointingDevicePtr> m_tabletDevices; QList<QPointingDevicePtr> m_tabletDevices;
#endif #endif