diff options
Diffstat (limited to 'src/platformsupport/input')
12 files changed, 73 insertions, 32 deletions
diff --git a/src/platformsupport/input/CMakeLists.txt b/src/platformsupport/input/CMakeLists.txt index 3ad593e17f..b7ff09d827 100644 --- a/src/platformsupport/input/CMakeLists.txt +++ b/src/platformsupport/input/CMakeLists.txt @@ -1,9 +1,10 @@ -# Generated from input.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause -qt_find_package(Libinput) # special case -qt_find_package(XKB) # special case -qt_find_package(Tslib) # special case -qt_find_package(Mtdev) # special case +qt_find_package(Libinput) +qt_find_package(XKB) +qt_find_package(Tslib) +qt_find_package(Mtdev) ##################################################################### ## InputSupportPrivate Module: @@ -21,11 +22,9 @@ qt_internal_add_module(InputSupportPrivate Qt::GuiPrivate PRECOMPILED_HEADER "../../corelib/global/qt_pch.h" + NO_GENERATE_CPP_EXPORTS ) -#### Keys ignored in scope 2:.:.:input-support.pro:<TRUE>: -# MODULE = "input_support" - ## Scopes: ##################################################################### diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h index ed437c0060..1d991e2ba5 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler_p.h @@ -101,7 +101,7 @@ class QFdContainer int m_fd; Q_DISABLE_COPY_MOVE(QFdContainer); public: - explicit QFdContainer(int fd = -1) noexcept : m_fd(fd) {} + Q_NODISCARD_CTOR explicit QFdContainer(int fd = -1) noexcept : m_fd(fd) {} ~QFdContainer() { reset(); } int get() const noexcept { return m_fd; } diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp index 2888ff06b3..43717c4e81 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp @@ -33,7 +33,7 @@ QEvdevKeyboardManager::QEvdevKeyboardManager(const QString &key, const QString & m_spec = std::move(parsed.spec); // add all keyboards for devices specified in the argument list - for (const QString &device : qAsConst(parsed.devices)) + for (const QString &device : std::as_const(parsed.devices)) addKeyboard(device); if (parsed.devices.isEmpty()) { diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp index 32db2e897c..55b127ef17 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp +++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp @@ -34,7 +34,7 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif auto parsed = QEvdevUtil::parseSpecification(spec); m_spec = std::move(parsed.spec); - for (const auto &arg : qAsConst(parsed.args)) { + for (const auto &arg : std::as_const(parsed.args)) { if (arg.startsWith("xoffset="_L1)) { m_xoffset = arg.mid(8).toInt(); } else if (arg.startsWith("yoffset="_L1)) { @@ -43,7 +43,7 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif } // add all mice for devices specified in the argument list - for (const QString &device : qAsConst(parsed.devices)) + for (const QString &device : std::as_const(parsed.devices)) addMouse(device); if (parsed.devices.isEmpty()) { @@ -62,7 +62,7 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif } QInputDeviceManager *manager = QGuiApplicationPrivate::inputDeviceManager(); - connect(manager, &QInputDeviceManager::cursorPositionChangeRequested, [this](const QPoint &pos) { + connect(manager, &QInputDeviceManager::cursorPositionChangeRequested, this, [this](const QPoint &pos) { m_x = pos.x(); m_y = pos.y(); clampPosition(); diff --git a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp index d4bb9edc92..a270f9700d 100644 --- a/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp +++ b/src/platformsupport/input/evdevtablet/qevdevtabletmanager.cpp @@ -33,7 +33,7 @@ QEvdevTabletManager::QEvdevTabletManager(const QString &key, const QString &spec auto parsed = QEvdevUtil::parseSpecification(spec); m_spec = std::move(parsed.spec); - for (const QString &device : qAsConst(parsed.devices)) + for (const QString &device : std::as_const(parsed.devices)) addDevice(device); // when no devices specified, use device discovery to scan and monitor diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp index fbf483087e..1b0da6297b 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouchhandler.cpp @@ -15,6 +15,8 @@ #include <QtGui/private/qguiapplication_p.h> #include <QtGui/private/qpointingdevice_p.h> +#include <QtCore/qpointer.h> + #include <mutex> #ifdef Q_OS_FREEBSD @@ -150,12 +152,12 @@ QEvdevTouchScreenData::QEvdevTouchScreenData(QEvdevTouchScreenHandler *q_ptr, co m_filtered(false), m_prediction(0) { for (const QString &arg : args) { - if (arg == QStringLiteral("force_window")) + if (arg == u"force_window") m_forceToActiveWindow = true; - else if (arg == QStringLiteral("filtered")) + else if (arg == u"filtered") m_filtered = true; - else if (arg.startsWith(QStringLiteral("prediction="))) - m_prediction = arg.mid(11).toInt(); + else if (const QStringView prefix = u"prediction="; arg.startsWith(prefix)) + m_prediction = QStringView(arg).mid(prefix.size()).toInt(); } } @@ -181,7 +183,7 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const int rotationAngle = 0; bool invertx = false; bool inverty = false; - for (int i = 0; i < args.count(); ++i) { + for (int i = 0; i < args.size(); ++i) { if (args.at(i).startsWith("rotate"_L1)) { QString rotateArg = args.at(i).section(u'=', 1, 1); bool ok; @@ -192,6 +194,7 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &device, const case 180: case 270: rotationAngle = argValue; + break; default: break; } @@ -565,7 +568,7 @@ void QEvdevTouchScreenData::processInputEvent(input_event *data) // Until that use a temporary key. int key = m_currentData.trackingId; if (key == -1) - key = m_contacts.count(); + key = m_contacts.size(); m_contacts.insert(key, m_currentData); m_currentData = Contact(); @@ -774,7 +777,7 @@ void QEvdevTouchScreenData::reportPoints() // Map the coordinates based on the normalized position. QPA expects 'area' // to be in screen coordinates. - const int pointCount = m_touchPoints.count(); + const int pointCount = m_touchPoints.size(); for (int i = 0; i < pointCount; ++i) { QWindowSystemInterface::TouchPoint &tp(m_touchPoints[i]); @@ -901,7 +904,7 @@ void QEvdevTouchScreenHandlerThread::filterAndSendTouchPoints() } else { // Update our estimate for the touch rate. We're making the assumption - // that this value will be mostly accurate with the occational bump, + // that this value will be mostly accurate with the occasional bump, // so we're weighting the existing value high compared to the update. const double ratio = 0.9; m_touchRate = sqrt(m_touchRate * m_touchRate * ratio + touchDelta * touchDelta * (1.0 - ratio)); diff --git a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp index ce885d0a3b..f2a652c254 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouchmanager.cpp @@ -33,7 +33,7 @@ QEvdevTouchManager::QEvdevTouchManager(const QString &key, const QString &specif auto parsed = QEvdevUtil::parseSpecification(spec); m_spec = std::move(parsed.spec); - for (const QString &device : qAsConst(parsed.devices)) + for (const QString &device : std::as_const(parsed.devices)) addDevice(device); // when no devices specified, use device discovery to scan and monitor diff --git a/src/platformsupport/input/libinput/qlibinputhandler.cpp b/src/platformsupport/input/libinput/qlibinputhandler.cpp index 3b49438d0a..ef45533f1a 100644 --- a/src/platformsupport/input/libinput/qlibinputhandler.cpp +++ b/src/platformsupport/input/libinput/qlibinputhandler.cpp @@ -79,7 +79,7 @@ QLibInputHandler::QLibInputHandler(const QString &key, const QString &spec) m_touch.reset(new QLibInputTouch); QInputDeviceManager *manager = QGuiApplicationPrivate::inputDeviceManager(); - connect(manager, &QInputDeviceManager::cursorPositionChangeRequested, [this](const QPoint &pos) { + connect(manager, &QInputDeviceManager::cursorPositionChangeRequested, this, [this](const QPoint &pos) { m_pointer->setPos(pos); }); diff --git a/src/platformsupport/input/libinput/qlibinputkeyboard.cpp b/src/platformsupport/input/libinput/qlibinputkeyboard.cpp index f6640171eb..25939cd510 100644 --- a/src/platformsupport/input/libinput/qlibinputkeyboard.cpp +++ b/src/platformsupport/input/libinput/qlibinputkeyboard.cpp @@ -79,7 +79,7 @@ void QLibInputKeyboard::processKey(libinput_event_keyboard *e) xkb_state_update_key(m_state, keycode, pressed ? XKB_KEY_DOWN : XKB_KEY_UP); - Qt::KeyboardModifiers modifiersAfterStateChange = QXkbCommon::modifiers(m_state); + Qt::KeyboardModifiers modifiersAfterStateChange = QXkbCommon::modifiers(m_state, sym); QGuiApplicationPrivate::inputDeviceManager()->setKeyboardModifiers(modifiersAfterStateChange); QWindowSystemInterface::handleExtendedKeyEvent(nullptr, diff --git a/src/platformsupport/input/libinput/qlibinputtouch.cpp b/src/platformsupport/input/libinput/qlibinputtouch.cpp index 84a05f565e..e3a483dc84 100644 --- a/src/platformsupport/input/libinput/qlibinputtouch.cpp +++ b/src/platformsupport/input/libinput/qlibinputtouch.cpp @@ -14,12 +14,13 @@ QT_BEGIN_NAMESPACE Q_DECLARE_LOGGING_CATEGORY(qLcLibInput) +Q_LOGGING_CATEGORY(qLcLibInputEvents, "qt.qpa.input.events") QWindowSystemInterface::TouchPoint *QLibInputTouch::DeviceState::point(int32_t slot) { const int id = qMax(0, slot); - for (int i = 0; i < m_points.count(); ++i) + for (int i = 0; i < m_points.size(); ++i) if (m_points.at(i).id == id) return &m_points[i]; @@ -60,6 +61,33 @@ QPointF QLibInputTouch::getPos(libinput_event_touch *e) return geom.topLeft() + QPointF(x, y); } +static void setMatrix(libinput_device *dev) +{ + if (libinput_device_config_calibration_has_matrix(dev)) { + QByteArray env = qgetenv("QT_QPA_LIBINPUT_TOUCH_MATRIX"); + env = env.simplified(); + if (env.size()) { + float matrix[6]; + QList<QByteArray> list = env.split(' '); + if (list.length() != 6) { + qCWarning(qLcLibInput, "matrix length %lld wrong, should be 6", list.length()); + return; + } + for (int i = 0; i < 6; i++) { + bool ok = true; + matrix[i] = list[i].toFloat(&ok); + if (!ok) { + qCWarning(qLcLibInput, "Invalid matrix entry %d %s ", i, list[i].constData()); + return; + } + } + if (libinput_device_config_calibration_set_matrix(dev, matrix) != LIBINPUT_CONFIG_STATUS_SUCCESS) + qCWarning(qLcLibInput, "Failed to set libinput calibration matrix "); + } + } else { + qCWarning(qLcLibInput, "Touch device doesn't support matrix"); + } +} void QLibInputTouch::registerDevice(libinput_device *dev) { struct udev_device *udev_device; @@ -91,6 +119,7 @@ void QLibInputTouch::registerDevice(libinput_device *dev) if (!geom.isNull()) devPriv->setAvailableVirtualGeometry(geom); QWindowSystemInterface::registerInputDevice(td); + setMatrix(dev); } void QLibInputTouch::unregisterDevice(libinput_device *dev) @@ -113,6 +142,7 @@ void QLibInputTouch::processTouchDown(libinput_event_touch *e) newTp.area = QRect(0, 0, 8, 8); newTp.area.moveCenter(getPos(e)); state->m_points.append(newTp); + qCDebug(qLcLibInputEvents) << "touch down" << newTp; } } @@ -132,6 +162,7 @@ void QLibInputTouch::processTouchMotion(libinput_event_touch *e) // Handle this by compressing and keeping the Pressed state until the 'frame'. if (tp->state != QEventPoint::State::Pressed && tp->state != QEventPoint::State::Released) tp->state = tmpState; + qCDebug(qLcLibInputEvents) << "touch move" << tp; } else { qWarning("Inconsistent touch state (got 'motion' without 'down')"); } @@ -146,10 +177,13 @@ void QLibInputTouch::processTouchUp(libinput_event_touch *e) tp->state = QEventPoint::State::Released; // There may not be a Frame event after the last Up. Work this around. QEventPoint::States s; - for (int i = 0; i < state->m_points.count(); ++i) + for (int i = 0; i < state->m_points.size(); ++i) s |= state->m_points.at(i).state; + qCDebug(qLcLibInputEvents) << "touch up" << s << tp; if (s == QEventPoint::State::Released) processTouchFrame(e); + else + qCDebug(qLcLibInputEvents, "waiting for all points to be released"); } else { qWarning("Inconsistent touch state (got 'up' without 'down')"); } @@ -158,6 +192,7 @@ void QLibInputTouch::processTouchUp(libinput_event_touch *e) void QLibInputTouch::processTouchCancel(libinput_event_touch *e) { DeviceState *state = deviceState(e); + qCDebug(qLcLibInputEvents) << "touch cancel" << state->m_points; if (state->m_touchDevice) QWindowSystemInterface::handleTouchCancelEvent(nullptr, state->m_touchDevice, QGuiApplication::keyboardModifiers()); else @@ -171,13 +206,14 @@ void QLibInputTouch::processTouchFrame(libinput_event_touch *e) qWarning("TouchFrame without registered device"); return; } + qCDebug(qLcLibInputEvents) << "touch frame" << state->m_points; if (state->m_points.isEmpty()) return; QWindowSystemInterface::handleTouchEvent(nullptr, state->m_touchDevice, state->m_points, QGuiApplication::keyboardModifiers()); - for (int i = 0; i < state->m_points.count(); ++i) { + for (int i = 0; i < state->m_points.size(); ++i) { QWindowSystemInterface::TouchPoint &tp(state->m_points[i]); if (tp.state == QEventPoint::State::Released) state->m_points.removeAt(i--); diff --git a/src/platformsupport/input/shared/qevdevutil.cpp b/src/platformsupport/input/shared/qevdevutil.cpp index 4557ac9def..c1ebb9ada0 100644 --- a/src/platformsupport/input/shared/qevdevutil.cpp +++ b/src/platformsupport/input/shared/qevdevutil.cpp @@ -15,7 +15,7 @@ ParsedSpecification parseSpecification(const QString &specification) result.args = QStringView{specification}.split(u':'); - for (const auto &arg : qAsConst(result.args)) { + for (const auto &arg : std::as_const(result.args)) { if (arg.startsWith("/dev/"_L1)) { // if device is specified try to use it result.devices.append(arg.toString()); diff --git a/src/platformsupport/input/tslib/qtslib.cpp b/src/platformsupport/input/tslib/qtslib.cpp index 299d7801ec..a84cc90dc2 100644 --- a/src/platformsupport/input/tslib/qtslib.cpp +++ b/src/platformsupport/input/tslib/qtslib.cpp @@ -79,9 +79,12 @@ void QTsLibMouseHandler::readMouseData() } QPoint pos(x, y); - QWindowSystemInterface::handleMouseEvent(nullptr, pos, pos, - pressed ? Qt::LeftButton : Qt::NoButton, - Qt::NoButton, QEvent::None); + Qt::MouseButton button = pressed ^ m_pressed ? Qt::LeftButton : Qt::NoButton; + Qt::MouseButtons state = pressed ? Qt::LeftButton : Qt::NoButton; + QEvent::Type type = pressed ? (m_pressed ? QEvent::MouseMove : QEvent::MouseButtonPress) + : QEvent::MouseButtonRelease; + + QWindowSystemInterface::handleMouseEvent(nullptr, pos, pos, state, button, type); m_x = x; m_y = y; |