Skip to content

Commit

Permalink
Windows QPA: Use a QSharedPointer for the touch device
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
FriedemannKleint committed Oct 26, 2020
1 parent d9edad8 commit e3470a9
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 32 deletions.
19 changes: 5 additions & 14 deletions src/plugins/platforms/windows/qwindowscontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 =
Expand Down
2 changes: 0 additions & 2 deletions src/plugins/platforms/windows/qwindowscontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,6 @@ class QWindowsContext

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);

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/platforms/windows/qwindowsmousehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions src/plugins/platforms/windows/qwindowsmousehandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@

#include <QtCore/qpointer.h>
#include <QtCore/qhash.h>
#include <QtCore/qsharedpointer.h>
#include <QtGui/qevent.h>

QT_BEGIN_NAMESPACE
Expand All @@ -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,
Expand Down Expand Up @@ -90,7 +93,7 @@ class QWindowsMouseHandler
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;
Expand Down
19 changes: 11 additions & 8 deletions src/plugins/platforms/windows/qwindowspointerhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)))
Expand All @@ -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()
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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.
}
Expand Down
8 changes: 4 additions & 4 deletions src/plugins/platforms/windows/qwindowspointerhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class QWindowsPointerHandler
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; }
Expand All @@ -83,7 +83,7 @@ class QWindowsPointerHandler
QPointingDevicePtr findTabletDevice(QPointingDevice::PointerType pointerType) const;
#endif

QPointingDevice *m_touchDevice = nullptr;
QPointingDevicePtr m_touchDevice;
#if QT_CONFIG(tabletevent)
QList<QPointingDevicePtr> m_tabletDevices;
#endif
Expand Down

0 comments on commit e3470a9

Please sign in to comment.