mirror of https://github.com/qt/qtbase.git
Windows QPA: Refactor touch device creation
There was duplicated code in QWindowsMouseHandler::ensureTouchDevice() and QWindowsPointerHandler::ensureTouchDevice() which caused deprecation warnings since the setters of QInputDevice were deprecated. Join the 2 functions into a single creation function and add simple getters and setters. Fix deprecation warnings: qwindowscontext.cpp:357:108: warning: 'void QPointingDevice::setCapabilities(QInputDevice::Capabilities)' is deprecated: Use the constructor qwindowsmousehandler.cpp:132:97: warning: 'void QPointingDevice::setType(QInputDevice::DeviceType)' is deprecated: Use the constructor qwindowsmousehandler.cpp:136:41: warning: 'void QPointingDevice::setCapabilities(QInputDevice::Capabilities)' is deprecated: Use the constructor qwindowsmousehandler.cpp:137:49: warning: 'void QPointingDevice::setMaximumTouchPoints(int)' is deprecated: Use the constructor Change-Id: Iab5385e84d600e45b60f38225175f25ef043c3eb Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io> Reviewed-by: André de la Rocha <andre.rocha@qt.io> Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
This commit is contained in:
parent
39d99c714b
commit
3fb31819fd
|
@ -347,14 +347,19 @@ bool QWindowsContext::initTouch(unsigned integrationOptions)
|
|||
{
|
||||
if (d->m_systemInfo & QWindowsContext::SI_SupportsTouch)
|
||||
return true;
|
||||
|
||||
QPointingDevice *touchDevice = (d->m_systemInfo & QWindowsContext::SI_SupportsPointer) ?
|
||||
d->m_pointerHandler.ensureTouchDevice() : d->m_mouseHandler.ensureTouchDevice();
|
||||
const bool usePointerHandler = (d->m_systemInfo & QWindowsContext::SI_SupportsPointer) != 0;
|
||||
auto touchDevice = usePointerHandler ? d->m_pointerHandler.touchDevice() : d->m_mouseHandler.touchDevice();
|
||||
if (!touchDevice) {
|
||||
const bool mouseEmulation =
|
||||
(integrationOptions & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch) == 0;
|
||||
touchDevice = QWindowsPointerHandler::createTouchDevice(mouseEmulation);
|
||||
}
|
||||
if (!touchDevice)
|
||||
return false;
|
||||
|
||||
if (!(integrationOptions & QWindowsIntegration::DontPassOsMouseEventsSynthesizedFromTouch))
|
||||
touchDevice->setCapabilities(touchDevice->capabilities() | QInputDevice::Capability::MouseEmulation);
|
||||
if (usePointerHandler)
|
||||
d->m_pointerHandler.setTouchDevice(touchDevice);
|
||||
else
|
||||
d->m_mouseHandler.setTouchDevice(touchDevice);
|
||||
|
||||
QWindowSystemInterface::registerInputDevice(touchDevice);
|
||||
|
||||
|
|
|
@ -117,27 +117,6 @@ static inline void compressMouseMove(MSG *msg)
|
|||
}
|
||||
}
|
||||
|
||||
static inline QPointingDevice *createTouchDevice()
|
||||
{
|
||||
const int digitizers = GetSystemMetrics(SM_DIGITIZER);
|
||||
if (!(digitizers & (NID_INTEGRATED_TOUCH | NID_EXTERNAL_TOUCH)))
|
||||
return nullptr;
|
||||
const int tabletPc = GetSystemMetrics(SM_TABLETPC);
|
||||
const int maxTouchPoints = GetSystemMetrics(SM_MAXIMUMTOUCHES);
|
||||
qCDebug(lcQpaEvents) << "Digitizers:" << Qt::hex << Qt::showbase << (digitizers & ~NID_READY)
|
||||
<< "Ready:" << (digitizers & NID_READY) << Qt::dec << Qt::noshowbase
|
||||
<< "Tablet PC:" << tabletPc << "Max touch points:" << maxTouchPoints;
|
||||
auto *result = new QPointingDevice;
|
||||
result->setType(digitizers & NID_INTEGRATED_TOUCH
|
||||
? QInputDevice::DeviceType::TouchScreen : QInputDevice::DeviceType::TouchPad);
|
||||
QPointingDevice::Capabilities capabilities = QPointingDevice::Capability::Position | QPointingDevice::Capability::Area | QPointingDevice::Capability::NormalizedPosition;
|
||||
if (result->type() == QInputDevice::DeviceType::TouchPad)
|
||||
capabilities.setFlag(QInputDevice::Capability::MouseEmulation);
|
||||
result->setCapabilities(capabilities);
|
||||
result->setMaximumTouchPoints(maxTouchPoints);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*!
|
||||
\class QWindowsMouseHandler
|
||||
\brief Windows mouse handler
|
||||
|
@ -149,13 +128,6 @@ static inline QPointingDevice *createTouchDevice()
|
|||
|
||||
QWindowsMouseHandler::QWindowsMouseHandler() = default;
|
||||
|
||||
QPointingDevice *QWindowsMouseHandler::ensureTouchDevice()
|
||||
{
|
||||
if (!m_touchDevice)
|
||||
m_touchDevice = createTouchDevice();
|
||||
return m_touchDevice;
|
||||
}
|
||||
|
||||
void QWindowsMouseHandler::clearEvents()
|
||||
{
|
||||
m_lastEventType = QEvent::None;
|
||||
|
|
|
@ -59,7 +59,7 @@ public:
|
|||
QWindowsMouseHandler();
|
||||
|
||||
QPointingDevice *touchDevice() const { return m_touchDevice; }
|
||||
QPointingDevice *ensureTouchDevice();
|
||||
void setTouchDevice(QPointingDevice *d) { m_touchDevice = d; }
|
||||
|
||||
bool translateMouseEvent(QWindow *widget, HWND hwnd,
|
||||
QtWindows::WindowsEventType t, MSG msg,
|
||||
|
|
|
@ -317,31 +317,34 @@ static bool isValidWheelReceiver(QWindow *candidate)
|
|||
return false;
|
||||
}
|
||||
|
||||
QPointingDevice *QWindowsPointerHandler::ensureTouchDevice()
|
||||
QPointingDevice *QWindowsPointerHandler::createTouchDevice(bool mouseEmulation)
|
||||
{
|
||||
if (!m_touchDevice) {
|
||||
const int digitizers = GetSystemMetrics(SM_DIGITIZER);
|
||||
if (!(digitizers & (NID_INTEGRATED_TOUCH | NID_EXTERNAL_TOUCH)))
|
||||
return nullptr;
|
||||
const int tabletPc = GetSystemMetrics(SM_TABLETPC);
|
||||
const int maxTouchPoints = GetSystemMetrics(SM_MAXIMUMTOUCHES);
|
||||
const bool touchScreen = digitizers & NID_INTEGRATED_TOUCH;
|
||||
QPointingDevice::Capabilities capabilities = QPointingDevice::Capability::Position;
|
||||
if (!touchScreen) {
|
||||
capabilities.setFlag(QInputDevice::Capability::MouseEmulation);
|
||||
capabilities.setFlag(QInputDevice::Capability::Scroll);
|
||||
}
|
||||
qCDebug(lcQpaEvents) << "Digitizers:" << Qt::hex << Qt::showbase << (digitizers & ~NID_READY)
|
||||
<< "Ready:" << (digitizers & NID_READY) << Qt::dec << Qt::noshowbase
|
||||
<< "Tablet PC:" << tabletPc << "Max touch points:" << maxTouchPoints << "Capabilities:" << capabilities;
|
||||
// TODO: use system-provided name and device ID rather than empty-string and m_nextInputDeviceId
|
||||
m_touchDevice = new QPointingDevice(QString(), m_nextInputDeviceId++,
|
||||
(touchScreen ? QInputDevice::DeviceType::TouchScreen : QInputDevice::DeviceType::TouchPad),
|
||||
QPointingDevice::PointerType::Finger, capabilities, maxTouchPoints,
|
||||
// TODO: precise button count (detect whether the touchpad can emulate 3 or more buttons)
|
||||
(touchScreen ? 1 : 3));
|
||||
}
|
||||
return m_touchDevice;
|
||||
const int digitizers = GetSystemMetrics(SM_DIGITIZER);
|
||||
if (!(digitizers & (NID_INTEGRATED_TOUCH | NID_EXTERNAL_TOUCH)))
|
||||
return nullptr;
|
||||
const int tabletPc = GetSystemMetrics(SM_TABLETPC);
|
||||
const int maxTouchPoints = GetSystemMetrics(SM_MAXIMUMTOUCHES);
|
||||
const QPointingDevice::DeviceType type = (digitizers & NID_INTEGRATED_TOUCH)
|
||||
? QInputDevice::DeviceType::TouchScreen : QInputDevice::DeviceType::TouchPad;
|
||||
QInputDevice::Capabilities capabilities = QInputDevice::Capability::Position
|
||||
| QInputDevice::Capability::Area
|
||||
| QInputDevice::Capability::NormalizedPosition;
|
||||
if (type != QInputDevice::DeviceType::TouchScreen) {
|
||||
capabilities.setFlag(QInputDevice::Capability::MouseEmulation);
|
||||
capabilities.setFlag(QInputDevice::Capability::Scroll);
|
||||
} else if (mouseEmulation) {
|
||||
capabilities.setFlag(QInputDevice::Capability::MouseEmulation);
|
||||
}
|
||||
|
||||
qCDebug(lcQpaEvents) << "Digitizers:" << Qt::hex << Qt::showbase << (digitizers & ~NID_READY)
|
||||
<< "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);
|
||||
}
|
||||
|
||||
void QWindowsPointerHandler::clearEvents()
|
||||
|
|
|
@ -61,8 +61,11 @@ public:
|
|||
~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; }
|
||||
QPointingDevice *ensureTouchDevice();
|
||||
void setTouchDevice(QPointingDevice *d) { m_touchDevice = d; }
|
||||
static QPointingDevice *createTouchDevice(bool mouseEmulation);
|
||||
|
||||
QWindow *windowUnderMouse() const { return m_windowUnderPointer.data(); }
|
||||
void clearWindowUnderMouse() { m_windowUnderPointer = nullptr; }
|
||||
void clearEvents();
|
||||
|
|
Loading…
Reference in New Issue