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:
parent
d9edad8117
commit
e3470a98e9
@ -349,19 +349,16 @@ bool QWindowsContext::initTouch(unsigned integrationOptions)
|
||||
return true;
|
||||
const bool usePointerHandler = (d->m_systemInfo & QWindowsContext::SI_SupportsPointer) != 0;
|
||||
auto touchDevice = usePointerHandler ? d->m_pointerHandler.touchDevice() : d->m_mouseHandler.touchDevice();
|
||||
if (!touchDevice) {
|
||||
if (touchDevice.isNull()) {
|
||||
const bool mouseEmulation =
|
||||
(integrationOptions & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch) == 0;
|
||||
touchDevice = QWindowsPointerHandler::createTouchDevice(mouseEmulation);
|
||||
}
|
||||
if (!touchDevice)
|
||||
if (touchDevice.isNull())
|
||||
return false;
|
||||
if (usePointerHandler)
|
||||
d->m_pointerHandler.setTouchDevice(touchDevice);
|
||||
else
|
||||
d->m_mouseHandler.setTouchDevice(touchDevice);
|
||||
|
||||
QWindowSystemInterface::registerInputDevice(touchDevice);
|
||||
d->m_pointerHandler.setTouchDevice(touchDevice);
|
||||
d->m_mouseHandler.setTouchDevice(touchDevice);
|
||||
QWindowSystemInterface::registerInputDevice(touchDevice.data());
|
||||
|
||||
d->m_systemInfo |= QWindowsContext::SI_SupportsTouch;
|
||||
|
||||
@ -1637,12 +1634,6 @@ void QWindowsContext::setAsyncExpose(bool 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)
|
||||
{
|
||||
const auto value =
|
||||
|
@ -266,8 +266,6 @@ public:
|
||||
|
||||
static DWORD readAdvancedExplorerSettings(const wchar_t *subKey, DWORD defaultValue);
|
||||
|
||||
QPointingDevice *touchDevice() const;
|
||||
|
||||
static bool filterNativeEvent(MSG *msg, LRESULT *result);
|
||||
static bool filterNativeEvent(QWindow *window, MSG *msg, LRESULT *result);
|
||||
|
||||
|
@ -652,7 +652,7 @@ bool QWindowsMouseHandler::translateTouchEvent(QWindow *window, HWND,
|
||||
m_touchInputIDToTouchPointID.clear();
|
||||
|
||||
QWindowSystemInterface::handleTouchEvent(window,
|
||||
m_touchDevice,
|
||||
m_touchDevice.data(),
|
||||
touchPoints,
|
||||
QWindowsKeyMapper::queryKeyboardModifiers());
|
||||
return true;
|
||||
|
@ -45,6 +45,7 @@
|
||||
|
||||
#include <QtCore/qpointer.h>
|
||||
#include <QtCore/qhash.h>
|
||||
#include <QtCore/qsharedpointer.h>
|
||||
#include <QtGui/qevent.h>
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
@ -56,10 +57,12 @@ class QWindowsMouseHandler
|
||||
{
|
||||
Q_DISABLE_COPY_MOVE(QWindowsMouseHandler)
|
||||
public:
|
||||
using QPointingDevicePtr = QSharedPointer<QPointingDevice>;
|
||||
|
||||
QWindowsMouseHandler();
|
||||
|
||||
QPointingDevice *touchDevice() const { return m_touchDevice; }
|
||||
void setTouchDevice(QPointingDevice *d) { m_touchDevice = d; }
|
||||
const QPointingDevicePtr &touchDevice() const { return m_touchDevice; }
|
||||
void setTouchDevice(const QPointingDevicePtr &d) { m_touchDevice = d; }
|
||||
|
||||
bool translateMouseEvent(QWindow *widget, HWND hwnd,
|
||||
QtWindows::WindowsEventType t, MSG msg,
|
||||
@ -90,7 +93,7 @@ private:
|
||||
QPointer<QWindow> m_trackedWindow;
|
||||
QHash<DWORD, int> m_touchInputIDToTouchPointID;
|
||||
QHash<int, QPointF> m_lastTouchPositions;
|
||||
QPointingDevice *m_touchDevice = nullptr;
|
||||
QPointingDevicePtr m_touchDevice;
|
||||
bool m_leftButtonDown = false;
|
||||
QWindow *m_previousCaptureWindow = nullptr;
|
||||
QEvent::Type m_lastEventType = QEvent::None;
|
||||
|
@ -82,7 +82,6 @@ qint64 QWindowsPointerHandler::m_nextInputDeviceId = 1;
|
||||
|
||||
QWindowsPointerHandler::~QWindowsPointerHandler()
|
||||
{
|
||||
delete m_touchDevice;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
QPointingDevice *QWindowsPointerHandler::createTouchDevice(bool mouseEmulation)
|
||||
QWindowsPointerHandler::QPointingDevicePtr QWindowsPointerHandler::createTouchDevice(bool mouseEmulation)
|
||||
{
|
||||
const int digitizers = GetSystemMetrics(SM_DIGITIZER);
|
||||
if (!(digitizers & (NID_INTEGRATED_TOUCH | NID_EXTERNAL_TOUCH)))
|
||||
@ -339,15 +338,19 @@ QPointingDevice *QWindowsPointerHandler::createTouchDevice(bool 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
|
||||
<< "Tablet PC:" << tabletPc << "Max touch points:" << maxTouchPoints << "Capabilities:" << capabilities;
|
||||
|
||||
const int buttonCount = type == QInputDevice::DeviceType::TouchScreen ? 1 : 3;
|
||||
// TODO: use system-provided name and device ID rather than empty-string and m_nextInputDeviceId
|
||||
return new QPointingDevice(QString(), m_nextInputDeviceId++,
|
||||
type, QPointingDevice::PointerType::Finger,
|
||||
capabilities, maxTouchPoints, buttonCount);
|
||||
const qint64 systemId = m_nextInputDeviceId++ | (qint64(flags << 2));
|
||||
auto d = new QPointingDevice(QString(), systemId, type,
|
||||
QPointingDevice::PointerType::Finger,
|
||||
capabilities, maxTouchPoints, buttonCount,
|
||||
QString(), QPointingDeviceUniqueId::fromNumericId(systemId));
|
||||
return QPointingDevicePtr(d);
|
||||
}
|
||||
|
||||
void QWindowsPointerHandler::clearEvents()
|
||||
@ -466,7 +469,7 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd,
|
||||
return false;
|
||||
|
||||
if (msg.message == WM_POINTERCAPTURECHANGED) {
|
||||
QWindowSystemInterface::handleTouchCancelEvent(window, m_touchDevice,
|
||||
QWindowSystemInterface::handleTouchCancelEvent(window, m_touchDevice.data(),
|
||||
QWindowsKeyMapper::queryKeyboardModifiers());
|
||||
m_lastTouchPositions.clear();
|
||||
return true;
|
||||
@ -550,7 +553,7 @@ bool QWindowsPointerHandler::translateTouchEvent(QWindow *window, HWND hwnd,
|
||||
if (allStates == QEventPoint::State::Released)
|
||||
m_touchInputIDToTouchPointID.clear();
|
||||
|
||||
QWindowSystemInterface::handleTouchEvent(window, m_touchDevice, touchPoints,
|
||||
QWindowSystemInterface::handleTouchEvent(window, m_touchDevice.data(), touchPoints,
|
||||
QWindowsKeyMapper::queryKeyboardModifiers());
|
||||
return false; // Allow mouse messages to be generated.
|
||||
}
|
||||
|
@ -65,9 +65,9 @@ public:
|
||||
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);
|
||||
|
||||
QPointingDevice *touchDevice() const { return m_touchDevice; }
|
||||
void setTouchDevice(QPointingDevice *d) { m_touchDevice = d; }
|
||||
static QPointingDevice *createTouchDevice(bool mouseEmulation);
|
||||
const QPointingDevicePtr &touchDevice() const { return m_touchDevice; }
|
||||
void setTouchDevice(const QPointingDevicePtr &d) { m_touchDevice = d; }
|
||||
static QPointingDevicePtr createTouchDevice(bool mouseEmulation);
|
||||
|
||||
QWindow *windowUnderMouse() const { return m_windowUnderPointer.data(); }
|
||||
void clearWindowUnderMouse() { m_windowUnderPointer = nullptr; }
|
||||
@ -83,7 +83,7 @@ private:
|
||||
QPointingDevicePtr findTabletDevice(QPointingDevice::PointerType pointerType) const;
|
||||
#endif
|
||||
|
||||
QPointingDevice *m_touchDevice = nullptr;
|
||||
QPointingDevicePtr m_touchDevice;
|
||||
#if QT_CONFIG(tabletevent)
|
||||
QList<QPointingDevicePtr> m_tabletDevices;
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user