diff options
Diffstat (limited to 'src/platformsupport/input')
12 files changed, 285 insertions, 139 deletions
diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp index 27d15dfafa..9ce97cf373 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardhandler.cpp @@ -37,20 +37,18 @@ #include <QSocketNotifier> #include <QStringList> -#include <qpa/qwindowsysteminterface.h> #include <QCoreApplication> +#include <QLoggingCategory> +#include <qpa/qwindowsysteminterface.h> #include <private/qcore_unix_p.h> #include <linux/input.h> -//#define QT_QPA_KEYMAP_DEBUG - -#ifdef QT_QPA_KEYMAP_DEBUG -#include <qdebug.h> -#endif - QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(qLcEvdevKey, "qt.qpa.input") +Q_LOGGING_CATEGORY(qLcEvdevKeyMap, "qt.qpa.input.keymap") + // simple builtin US keymap #include "qevdevkeyboard_defaultmap_p.h" @@ -60,9 +58,7 @@ QEvdevKeyboardHandler::QEvdevKeyboardHandler(const QString &device, int fd, bool m_no_zap(disableZap), m_do_compose(enableCompose), m_keymap(0), m_keymap_size(0), m_keycompose(0), m_keycompose_size(0) { -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning() << "Create keyboard handler with for device" << device; -#endif + qCDebug(qLcEvdevKey) << "Create keyboard handler with for device" << device; setObjectName(QLatin1String("LinuxInput Keyboard Handler")); @@ -89,9 +85,7 @@ QEvdevKeyboardHandler *QEvdevKeyboardHandler::create(const QString &device, const QString &specification, const QString &defaultKeymapFile) { -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning() << "Try to create keyboard handler for" << device << specification; -#endif + qCDebug(qLcEvdevKey) << "Try to create keyboard handler for" << device << specification; QString keymapFile = defaultKeymapFile; int repeatDelay = 400; @@ -116,9 +110,7 @@ QEvdevKeyboardHandler *QEvdevKeyboardHandler::create(const QString &device, grab = arg.mid(5).toInt(); } -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning() << "Opening keyboard at" << device; -#endif + qCDebug(qLcEvdevKey) << "Opening keyboard at" << device; int fd; fd = qt_safe_open(device.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); @@ -138,9 +130,7 @@ QEvdevKeyboardHandler *QEvdevKeyboardHandler::create(const QString &device, void QEvdevKeyboardHandler::switchLed(int led, bool state) { -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning() << "switchLed" << led << state; -#endif + qCDebug(qLcEvdevKey) << "switchLed" << led << state; struct ::input_event led_ie; ::gettimeofday(&led_ie.time, 0); @@ -153,10 +143,6 @@ void QEvdevKeyboardHandler::switchLed(int led, bool state) void QEvdevKeyboardHandler::readKeycode() { -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning() << "Read new keycode on" << m_device; -#endif - struct ::input_event buffer[32]; int n = 0; @@ -164,11 +150,11 @@ void QEvdevKeyboardHandler::readKeycode() int result = qt_safe_read(m_fd, reinterpret_cast<char *>(buffer) + n, sizeof(buffer) - n); if (result == 0) { - qWarning("Got EOF from the input device."); + qWarning("evdevkeyboard: Got EOF from the input device"); return; } else if (result < 0) { if (errno != EINTR && errno != EAGAIN) { - qWarning("Could not read from input device: %s", strerror(errno)); + qErrnoWarning(errno, "evdevkeyboard: Could not read from input device"); return; } } else { @@ -249,21 +235,17 @@ QEvdevKeyboardHandler::KeycodeAction QEvdevKeyboardHandler::processKeycode(quint if (m_locks[0] /*CapsLock*/ && map_withmod && (map_withmod->flags & QEvdevKeyboardMap::IsLetter)) modifiers ^= QEvdevKeyboardMap::ModShift; -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning("Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d | plain=%d, withmod=%d, size=%d", \ - keycode, modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0, \ - map_plain ? map_plain - m_keymap : -1, \ - map_withmod ? map_withmod - m_keymap : -1, \ - m_keymap_size); -#endif + qCDebug(qLcEvdevKeyMap, "Processing key event: keycode=%3d, modifiers=%02x pressed=%d, autorepeat=%d | plain=%d, withmod=%d, size=%d", + keycode, modifiers, pressed ? 1 : 0, autorepeat ? 1 : 0, + int(map_plain ? map_plain - m_keymap : -1), + int(map_withmod ? map_withmod - m_keymap : -1), + m_keymap_size); const QEvdevKeyboardMap::Mapping *it = map_withmod ? map_withmod : map_plain; if (!it) { -#ifdef QT_QPA_KEYMAP_DEBUG // we couldn't even find a plain mapping - qWarning("Could not find a suitable mapping for keycode: %3d, modifiers: %02x", keycode, modifiers); -#endif + qCDebug(qLcEvdevKeyMap, "Could not find a suitable mapping for keycode: %3d, modifiers: %02x", keycode, modifiers); return result; } @@ -397,9 +379,7 @@ QEvdevKeyboardHandler::KeycodeAction QEvdevKeyboardHandler::processKeycode(quint } if (!skip) { -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning("Processing: uni=%04x, qt=%08x, qtmod=%08x", unicode, qtcode & ~modmask, (qtcode & modmask)); -#endif + qCDebug(qLcEvdevKeyMap, "Processing: uni=%04x, qt=%08x, qtmod=%08x", unicode, qtcode & ~modmask, (qtcode & modmask)); //If NumLockOff and keypad key pressed remap event sent if (!m_locks[1] && (qtcode & Qt::KeypadModifier) && @@ -457,9 +437,7 @@ QEvdevKeyboardHandler::KeycodeAction QEvdevKeyboardHandler::processKeycode(quint void QEvdevKeyboardHandler::unloadKeymap() { -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning() << "Unload current keymap and restore built-in"; -#endif + qCDebug(qLcEvdevKey) << "Unload current keymap and restore built-in"; if (m_keymap && m_keymap != s_keymap_default) delete [] m_keymap; @@ -481,7 +459,7 @@ void QEvdevKeyboardHandler::unloadKeymap() quint16 ledbits[1]; memset(ledbits, 0, sizeof(ledbits)); if (::ioctl(m_fd, EVIOCGLED(sizeof(ledbits)), ledbits) < 0) { - qWarning("Failed to query led states. Settings numlock & capslock off"); + qWarning("evdevkeyboard: Failed to query led states"); switchLed(LED_NUML,false); switchLed(LED_CAPSL, false); switchLed(LED_SCROLLL,false); @@ -495,17 +473,13 @@ void QEvdevKeyboardHandler::unloadKeymap() //Scrollock if ((ledbits[0]&0x04) > 0) m_locks[2] = 1; -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning("numlock=%d , capslock=%d, scrolllock=%d",m_locks[1],m_locks[0],m_locks[2]); -#endif + qCDebug(qLcEvdevKey, "numlock=%d , capslock=%d, scrolllock=%d", m_locks[1], m_locks[0], m_locks[2]); } } bool QEvdevKeyboardHandler::loadKeymap(const QString &file) { -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning() << "Load keymap" << file; -#endif + qCDebug(qLcEvdevKey) << "Loading keymap" << file; QFile f(file); @@ -529,7 +503,7 @@ bool QEvdevKeyboardHandler::loadKeymap(const QString &file) ds >> qmap_magic >> qmap_version >> qmap_keymap_size >> qmap_keycompose_size; if (ds.status() != QDataStream::Ok || qmap_magic != QEvdevKeyboardMap::FileMagic || qmap_version != 1 || qmap_keymap_size == 0) { - qWarning("'%s' is ot a valid.qmap keymap file.", qPrintable(file)); + qWarning("'%s' is not a valid .qmap keymap file", qPrintable(file)); return false; } diff --git a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp index 3f8eb1bcd5..4614fbd499 100644 --- a/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp +++ b/src/platformsupport/input/evdevkeyboard/qevdevkeyboardmanager.cpp @@ -35,15 +35,12 @@ #include <QStringList> #include <QCoreApplication> - -//#define QT_QPA_KEYMAP_DEBUG - -#ifdef QT_QPA_KEYMAP_DEBUG -#include <QDebug> -#endif +#include <QLoggingCategory> QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(qLcEvdevKey) + QEvdevKeyboardManager::QEvdevKeyboardManager(const QString &key, const QString &specification, QObject *parent) : QObject(parent) { @@ -74,10 +71,7 @@ QEvdevKeyboardManager::QEvdevKeyboardManager(const QString &key, const QString & addKeyboard(device); if (devices.isEmpty()) { -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning() << "Use device discovery"; -#endif - + qCDebug(qLcEvdevKey) << "evdevkeyboard: Using device discovery"; m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Keyboard, this); if (m_deviceDiscovery) { // scan and add already connected keyboards @@ -100,24 +94,19 @@ QEvdevKeyboardManager::~QEvdevKeyboardManager() void QEvdevKeyboardManager::addKeyboard(const QString &deviceNode) { -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning() << "Adding keyboard at" << deviceNode; -#endif - + qCDebug(qLcEvdevKey) << "Adding keyboard at" << deviceNode; QEvdevKeyboardHandler *keyboard; keyboard = QEvdevKeyboardHandler::create(deviceNode, m_spec, m_defaultKeymapFile); if (keyboard) m_keyboards.insert(deviceNode, keyboard); else - qWarning("Failed to open keyboard"); + qWarning("Failed to open keyboard device %s", qPrintable(deviceNode)); } void QEvdevKeyboardManager::removeKeyboard(const QString &deviceNode) { if (m_keyboards.contains(deviceNode)) { -#ifdef QT_QPA_KEYMAP_DEBUG - qWarning() << "Removing keyboard at" << deviceNode; -#endif + qCDebug(qLcEvdevKey) << "Removing keyboard at" << deviceNode; QEvdevKeyboardHandler *keyboard = m_keyboards.value(deviceNode); m_keyboards.remove(deviceNode); delete keyboard; diff --git a/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp b/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp index 11db06680a..eddf180e4a 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp +++ b/src/platformsupport/input/evdevmouse/qevdevmousehandler.cpp @@ -38,6 +38,7 @@ #include <QPoint> #include <QGuiApplication> #include <QScreen> +#include <QLoggingCategory> #include <qpa/qwindowsysteminterface.h> #include <qplatformdefs.h> @@ -48,19 +49,15 @@ #include <linux/kd.h> #include <linux/input.h> -#include <qdebug.h> - -//#define QT_QPA_MOUSE_HANDLER_DEBUG - #define TEST_BIT(array, bit) (array[bit/8] & (1<<(bit%8))) QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(qLcEvdevMouse, "qt.qpa.input") + QEvdevMouseHandler *QEvdevMouseHandler::create(const QString &device, const QString &specification) { -#ifdef QT_QPA_MOUSE_HANDLER_DEBUG - qWarning() << "Try to create mouse handler for" << device << specification; -#endif + qCDebug(qLcEvdevMouse) << "create mouse handler for" << device << specification; bool compression = true; int jitterLimit = 0; @@ -85,7 +82,7 @@ QEvdevMouseHandler *QEvdevMouseHandler::create(const QString &device, const QStr ::ioctl(fd, EVIOCGRAB, grab); return new QEvdevMouseHandler(device, fd, abs, compression, jitterLimit); } else { - qWarning("Cannot open mouse input device '%s': %s", qPrintable(device), strerror(errno)); + qErrnoWarning(errno, "Cannot open mouse input device %s", qPrintable(device)); return 0; } } @@ -148,12 +145,10 @@ bool QEvdevMouseHandler::getHardwareMaximum() m_hardwareScalerX = static_cast<qreal>(m_hardwareWidth) / (g.right() - g.left()); m_hardwareScalerY = static_cast<qreal>(m_hardwareHeight) / (g.bottom() - g.top()); -#ifdef QT_QPA_MOUSE_HANDLER_DEBUG - qDebug() << "Absolute pointing device"; - qDebug() << "hardware max x" << m_hardwareWidth; - qDebug() << "hardware max y" << m_hardwareHeight; - qDebug() << "hardware scalers x" << m_hardwareScalerX << "y" << m_hardwareScalerY; -#endif + qCDebug(qLcEvdevMouse) << "Absolute pointing device" + << "hardware max x" << m_hardwareWidth + << "hardware max y" << m_hardwareHeight + << "hardware scalers x" << m_hardwareScalerX << "y" << m_hardwareScalerY; return true; } @@ -194,11 +189,11 @@ void QEvdevMouseHandler::readMouseData() int result = QT_READ(m_fd, reinterpret_cast<char *>(buffer) + n, sizeof(buffer) - n); if (result == 0) { - qWarning("Got EOF from the input device."); + qWarning("evdevmouse: Got EOF from the input device"); return; } else if (result < 0) { if (errno != EINTR && errno != EAGAIN) { - qWarning("Could not read from input device: %s", strerror(errno)); + qErrnoWarning(errno, "evdevmouse: Could not read from input device"); return; } } else { @@ -212,7 +207,6 @@ void QEvdevMouseHandler::readMouseData() for (int i = 0; i < n; ++i) { struct ::input_event *data = &buffer[i]; - //qDebug() << ">>" << hex << data->type << data->code << dec << data->value; if (data->type == EV_ABS) { // Touchpads: store the absolute position for now, will calculate a relative one later. if (data->code == ABS_X && m_x != data->value) { diff --git a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp index 2b52c4e995..a0c9c9f34d 100644 --- a/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp +++ b/src/platformsupport/input/evdevmouse/qevdevmousemanager.cpp @@ -36,16 +36,13 @@ #include <QStringList> #include <QGuiApplication> #include <QScreen> +#include <QLoggingCategory> #include <qpa/qwindowsysteminterface.h> -//#define QT_QPA_MOUSEMANAGER_DEBUG - -#ifdef QT_QPA_MOUSEMANAGER_DEBUG -#include <QDebug> -#endif - QT_BEGIN_NAMESPACE +Q_DECLARE_LOGGING_CATEGORY(qLcEvdevMouse) + QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specification, QObject *parent) : QObject(parent), m_x(0), m_y(0), m_xoffset(0), m_yoffset(0) { @@ -79,10 +76,7 @@ QEvdevMouseManager::QEvdevMouseManager(const QString &key, const QString &specif addMouse(device); if (devices.isEmpty()) { -#ifdef QT_QPA_MOUSEMANAGER_DEBUG - qWarning() << "Use device discovery"; -#endif - + qCDebug(qLcEvdevMouse) << "evdevmouse: Using device discovery"; m_deviceDiscovery = QDeviceDiscovery::create(QDeviceDiscovery::Device_Mouse | QDeviceDiscovery::Device_Touchpad, this); if (m_deviceDiscovery) { // scan and add already connected keyboards @@ -130,28 +124,17 @@ void QEvdevMouseManager::handleMouseEvent(int x, int y, bool abs, Qt::MouseButto // Cannot track the keyboard modifiers ourselves here. Instead, report the // modifiers from the last key event that has been seen by QGuiApplication. QWindowSystemInterface::handleMouseEvent(0, pos, pos, buttons, QGuiApplication::keyboardModifiers()); - -#ifdef QT_QPA_MOUSEMANAGER_DEBUG - qDebug("mouse event %d %d %d", pos.x(), pos.y(), int(buttons)); -#endif } void QEvdevMouseManager::handleWheelEvent(int delta, Qt::Orientation orientation) { QPoint pos(m_x + m_xoffset, m_y + m_yoffset); QWindowSystemInterface::handleWheelEvent(0, pos, pos, delta, orientation, QGuiApplication::keyboardModifiers()); - -#ifdef QT_QPA_MOUSEMANAGER_DEBUG - qDebug("mouse wheel event %dx%d %d %d", pos.x(), pos.y(), delta, int(orientation)); -#endif } void QEvdevMouseManager::addMouse(const QString &deviceNode) { -#ifdef QT_QPA_MOUSEMANAGER_DEBUG - qWarning() << "Adding mouse at" << deviceNode; -#endif - + qCDebug(qLcEvdevMouse) << "Adding mouse at" << deviceNode; QEvdevMouseHandler *handler; handler = QEvdevMouseHandler::create(deviceNode, m_spec); if (handler) { @@ -159,16 +142,14 @@ void QEvdevMouseManager::addMouse(const QString &deviceNode) connect(handler, SIGNAL(handleWheelEvent(int,Qt::Orientation)), this, SLOT(handleWheelEvent(int,Qt::Orientation))); m_mice.insert(deviceNode, handler); } else { - qWarning("Failed to open mouse"); + qWarning("evdevmouse: Failed to open mouse device %s", qPrintable(deviceNode)); } } void QEvdevMouseManager::removeMouse(const QString &deviceNode) { if (m_mice.contains(deviceNode)) { -#ifdef QT_QPA_MOUSEMANAGER_DEBUG - qWarning() << "Removing mouse at" << deviceNode; -#endif + qCDebug(qLcEvdevMouse) << "Removing mouse at" << deviceNode; QEvdevMouseHandler *handler = m_mice.value(deviceNode); m_mice.remove(deviceNode); delete handler; diff --git a/src/platformsupport/input/evdevtablet/qevdevtablet.cpp b/src/platformsupport/input/evdevtablet/qevdevtablet.cpp index 8d91c49488..8dbf5832d9 100644 --- a/src/platformsupport/input/evdevtablet/qevdevtablet.cpp +++ b/src/platformsupport/input/evdevtablet/qevdevtablet.cpp @@ -36,13 +36,15 @@ #include <QStringList> #include <QSocketNotifier> #include <QGuiApplication> -#include <QDebug> +#include <QLoggingCategory> #include <QtCore/private/qcore_unix_p.h> #include <QtPlatformSupport/private/qdevicediscovery_p.h> #include <linux/input.h> QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(qLcEvdevTablet, "qt.qpa.input") + class QEvdevTabletData { public: @@ -87,28 +89,28 @@ bool QEvdevTabletData::queryLimits() if (ok) { minValues.x = absInfo.minimum; maxValues.x = absInfo.maximum; - qDebug("evdevtablet: min X: %d max X: %d", minValues.x, maxValues.x); + qCDebug(qLcEvdevTablet, "evdevtablet: min X: %d max X: %d", minValues.x, maxValues.x); } ok &= ioctl(fd, EVIOCGABS(ABS_Y), &absInfo) >= 0; if (ok) { minValues.y = absInfo.minimum; maxValues.y = absInfo.maximum; - qDebug("evdevtablet: min Y: %d max Y: %d", minValues.y, maxValues.y); + qCDebug(qLcEvdevTablet, "evdevtablet: min Y: %d max Y: %d", minValues.y, maxValues.y); } if (ioctl(fd, EVIOCGABS(ABS_PRESSURE), &absInfo) >= 0) { minValues.p = absInfo.minimum; maxValues.p = absInfo.maximum; - qDebug("evdevtablet: min pressure: %d max pressure: %d", minValues.p, maxValues.p); + qCDebug(qLcEvdevTablet, "evdevtablet: min pressure: %d max pressure: %d", minValues.p, maxValues.p); } if (ioctl(fd, EVIOCGABS(ABS_DISTANCE), &absInfo) >= 0) { minValues.d = absInfo.minimum; maxValues.d = absInfo.maximum; - qDebug("evdevtablet: min distance: %d max distance: %d", minValues.d, maxValues.d); + qCDebug(qLcEvdevTablet, "evdevtablet: min distance: %d max distance: %d", minValues.d, maxValues.d); } char name[128]; if (ioctl(fd, EVIOCGNAME(sizeof(name) - 1), name) >= 0) { devName = QString::fromLocal8Bit(name); - qDebug("evdevtablet: device name: %s", name); + qCDebug(qLcEvdevTablet, "evdevtablet: device name: %s", name); } return ok; } @@ -232,7 +234,7 @@ QEvdevTabletHandler::QEvdevTabletHandler(const QString &spec, QObject *parent) } } if (!dev.isEmpty()) { - qDebug("evdevtablet: using %s", qPrintable(dev)); + qCDebug(qLcEvdevTablet, "evdevtablet: using %s", qPrintable(dev)); d->fd = QT_OPEN(dev.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); if (d->fd >= 0) { d->testGrab(); diff --git a/src/platformsupport/input/evdevtablet/qevdevtablet_p.h b/src/platformsupport/input/evdevtablet/qevdevtablet_p.h index c20ddec787..4778c85d21 100644 --- a/src/platformsupport/input/evdevtablet/qevdevtablet_p.h +++ b/src/platformsupport/input/evdevtablet/qevdevtablet_p.h @@ -73,7 +73,7 @@ class QEvdevTabletHandlerThread : public QThread public: explicit QEvdevTabletHandlerThread(const QString &spec, QObject *parent = 0); ~QEvdevTabletHandlerThread(); - void run(); + void run() Q_DECL_OVERRIDE; QEvdevTabletHandler *handler() { return m_handler; } private: diff --git a/src/platformsupport/input/evdevtouch/qevdevtouch.cpp b/src/platformsupport/input/evdevtouch/qevdevtouch.cpp index d0d8b783a4..dd831c9e82 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouch.cpp +++ b/src/platformsupport/input/evdevtouch/qevdevtouch.cpp @@ -36,7 +36,7 @@ #include <QHash> #include <QSocketNotifier> #include <QGuiApplication> -#include <QDebug> +#include <QLoggingCategory> #include <QtCore/private/qcore_unix_p.h> #include <QtPlatformSupport/private/qdevicediscovery_p.h> #include <linux/input.h> @@ -49,6 +49,8 @@ extern "C" { QT_BEGIN_NAMESPACE +Q_LOGGING_CATEGORY(qLcEvdevTouch, "qt.qpa.input") + /* android (and perhaps some other linux-derived stuff) don't define everything * in linux/input.h, so we'll need to do that ourselves. */ @@ -164,7 +166,8 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &specification, { setObjectName(QLatin1String("Evdev Touch Handler")); - bool printDeviceInfo = qgetenv("QT_QPA_EVDEV_DEBUG").toInt(); + if (qEnvironmentVariableIsSet("QT_QPA_EVDEV_DEBUG")) + ((QLoggingCategory &) qLcEvdevTouch()).setEnabled(QtDebugMsg, true); // only the first device argument is used for now QString spec = QString::fromLocal8Bit(qgetenv("QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS")); @@ -215,13 +218,11 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &specification, } if (dev.isEmpty()) { - if (printDeviceInfo) - qDebug("evdevtouch: No touch devices found"); + qCDebug(qLcEvdevTouch, "evdevtouch: No touch devices found"); return; } - if (printDeviceInfo) - qDebug("evdevtouch: Using device %s", qPrintable(dev)); + qCDebug(qLcEvdevTouch, "evdevtouch: Using device %s", qPrintable(dev)); m_fd = QT_OPEN(dev.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); @@ -257,25 +258,22 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &specification, } #endif - if (printDeviceInfo) - qDebug("evdevtouch: Protocol type %c %s (%s)", d->m_typeB ? 'B' : 'A', - mtdevStr, d->m_singleTouch ? "single" : "multi"); + qCDebug(qLcEvdevTouch, "evdevtouch: Protocol type %c %s (%s)", d->m_typeB ? 'B' : 'A', + mtdevStr, d->m_singleTouch ? "single" : "multi"); input_absinfo absInfo; memset(&absInfo, 0, sizeof(input_absinfo)); bool has_x_range = false, has_y_range = false; if (ioctl(m_fd, EVIOCGABS((d->m_singleTouch ? ABS_X : ABS_MT_POSITION_X)), &absInfo) >= 0) { - if (printDeviceInfo) - qDebug("evdevtouch: min X: %d max X: %d", absInfo.minimum, absInfo.maximum); + qCDebug(qLcEvdevTouch, "evdevtouch: min X: %d max X: %d", absInfo.minimum, absInfo.maximum); d->hw_range_x_min = absInfo.minimum; d->hw_range_x_max = absInfo.maximum; has_x_range = true; } if (ioctl(m_fd, EVIOCGABS((d->m_singleTouch ? ABS_Y : ABS_MT_POSITION_Y)), &absInfo) >= 0) { - if (printDeviceInfo) - qDebug("evdevtouch: min Y: %d max Y: %d", absInfo.minimum, absInfo.maximum); + qCDebug(qLcEvdevTouch, "evdevtouch: min Y: %d max Y: %d", absInfo.minimum, absInfo.maximum); d->hw_range_y_min = absInfo.minimum; d->hw_range_y_max = absInfo.maximum; has_y_range = true; @@ -285,8 +283,7 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &specification, qWarning("evdevtouch: Invalid ABS limits, behavior unspecified"); if (ioctl(m_fd, EVIOCGABS(ABS_PRESSURE), &absInfo) >= 0) { - if (printDeviceInfo) - qDebug("evdevtouch: min pressure: %d max pressure: %d", absInfo.minimum, absInfo.maximum); + qCDebug(qLcEvdevTouch, "evdevtouch: min pressure: %d max pressure: %d", absInfo.minimum, absInfo.maximum); if (absInfo.maximum > absInfo.minimum) { d->hw_pressure_min = absInfo.minimum; d->hw_pressure_max = absInfo.maximum; @@ -296,8 +293,7 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &specification, char name[1024]; if (ioctl(m_fd, EVIOCGNAME(sizeof(name) - 1), name) >= 0) { d->hw_name = QString::fromLocal8Bit(name); - if (printDeviceInfo) - qDebug("evdevtouch: device name: %s", name); + qCDebug(qLcEvdevTouch, "evdevtouch: device name: %s", name); } // Fix up the coordinate ranges for am335x in case the kernel driver does not have them fixed. @@ -310,9 +306,8 @@ QEvdevTouchScreenHandler::QEvdevTouchScreenHandler(const QString &specification, d->hw_range_y_min = 220; d->hw_range_y_max = 3907; } - if (printDeviceInfo) - qDebug("evdevtouch: found ti-tsc, overriding: min X: %d max X: %d min Y: %d max Y: %d", - d->hw_range_x_min, d->hw_range_x_max, d->hw_range_y_min, d->hw_range_y_max); + qCDebug(qLcEvdevTouch, "evdevtouch: found ti-tsc, overriding: min X: %d max X: %d min Y: %d max Y: %d", + d->hw_range_x_min, d->hw_range_x_max, d->hw_range_y_min, d->hw_range_y_max); } bool grabSuccess = !ioctl(m_fd, EVIOCGRAB, (void *) 1); diff --git a/src/platformsupport/input/evdevtouch/qevdevtouch_p.h b/src/platformsupport/input/evdevtouch/qevdevtouch_p.h index 31b2d86834..e7861f0360 100644 --- a/src/platformsupport/input/evdevtouch/qevdevtouch_p.h +++ b/src/platformsupport/input/evdevtouch/qevdevtouch_p.h @@ -85,7 +85,7 @@ class QEvdevTouchScreenHandlerThread : public QThread public: explicit QEvdevTouchScreenHandlerThread(const QString &spec, QObject *parent = 0); ~QEvdevTouchScreenHandlerThread(); - void run(); + void run() Q_DECL_OVERRIDE; QEvdevTouchScreenHandler *handler() { return m_handler; } private: diff --git a/src/platformsupport/input/input.pri b/src/platformsupport/input/input.pri index 1524eb454e..c1fd95703b 100644 --- a/src/platformsupport/input/input.pri +++ b/src/platformsupport/input/input.pri @@ -4,3 +4,7 @@ contains(QT_CONFIG, evdev) { include($$PWD/evdevtouch/evdevtouch.pri) include($$PWD/evdevtablet/evdevtablet.pri) } + +contains(QT_CONFIG, tslib) { + include($$PWD/tslib/tslib.pri) +} diff --git a/src/platformsupport/input/tslib/qtslib.cpp b/src/platformsupport/input/tslib/qtslib.cpp new file mode 100644 index 0000000000..e75fd9e691 --- /dev/null +++ b/src/platformsupport/input/tslib/qtslib.cpp @@ -0,0 +1,134 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qtslib_p.h" + +#include <QSocketNotifier> +#include <QStringList> +#include <QPoint> +#include <QLoggingCategory> + +#include <qpa/qwindowsysteminterface.h> + +#include <errno.h> +#include <tslib.h> + +QT_BEGIN_NAMESPACE + +Q_LOGGING_CATEGORY(qLcTsLib, "qt.qpa.input") + +QTsLibMouseHandler::QTsLibMouseHandler(const QString &key, + const QString &specification, + QObject *parent) + : QObject(parent), + m_notify(0), m_x(0), m_y(0), m_pressed(0), m_rawMode(false) +{ + qCDebug(qLcTsLib) << "Initializing tslib plugin" << key << specification; + setObjectName(QLatin1String("TSLib Mouse Handler")); + + QByteArray device = qgetenv("TSLIB_TSDEVICE"); + + if (specification.startsWith(QStringLiteral("/dev/"))) + device = specification.toLocal8Bit(); + + if (device.isEmpty()) + device = QByteArrayLiteral("/dev/input/event1"); + + m_dev = ts_open(device.constData(), 1); + if (!m_dev) { + qErrnoWarning(errno, "ts_open() failed"); + return; + } + + if (ts_config(m_dev)) + qErrnoWarning(errno, "ts_config() failed"); + + m_rawMode = !key.compare(QLatin1String("TslibRaw"), Qt::CaseInsensitive); + + int fd = ts_fd(m_dev); + if (fd >= 0) { + qCDebug(qLcTsLib) << "tslib device is" << device; + m_notify = new QSocketNotifier(fd, QSocketNotifier::Read, this); + connect(m_notify, SIGNAL(activated(int)), this, SLOT(readMouseData())); + } else { + qErrnoWarning(errno, "tslib: Cannot open input device %s", device.constData()); + } +} + +QTsLibMouseHandler::~QTsLibMouseHandler() +{ + if (m_dev) + ts_close(m_dev); +} + +static bool get_sample(struct tsdev *dev, struct ts_sample *sample, bool rawMode) +{ + if (rawMode) + return (ts_read_raw(dev, sample, 1) == 1); + else + return (ts_read(dev, sample, 1) == 1); +} + +void QTsLibMouseHandler::readMouseData() +{ + ts_sample sample; + + while (get_sample(m_dev, &sample, m_rawMode)) { + bool pressed = sample.pressure; + int x = sample.x; + int y = sample.y; + + // work around missing coordinates on mouse release + if (sample.pressure == 0 && sample.x == 0 && sample.y == 0) { + x = m_x; + y = m_y; + } + + if (!m_rawMode) { + //filtering: ignore movements of 2 pixels or less + int dx = x - m_x; + int dy = y - m_y; + if (dx*dx <= 4 && dy*dy <= 4 && pressed == m_pressed) + continue; + } + QPoint pos(x, y); + + QWindowSystemInterface::handleMouseEvent(0, pos, pos, pressed ? Qt::LeftButton : Qt::NoButton); + + m_x = x; + m_y = y; + m_pressed = pressed; + } +} + +QT_END_NAMESPACE diff --git a/src/platformsupport/input/tslib/qtslib_p.h b/src/platformsupport/input/tslib/qtslib_p.h new file mode 100644 index 0000000000..4bcefb6cb9 --- /dev/null +++ b/src/platformsupport/input/tslib/qtslib_p.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the plugins module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL21$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 or version 3 as published by the Free +** Software Foundation and appearing in the file LICENSE.LGPLv21 and +** LICENSE.LGPLv3 included in the packaging of this file. Please review the +** following information to ensure the GNU Lesser General Public License +** requirements will be met: https://www.gnu.org/licenses/lgpl.html and +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QTSLIB_H +#define QTSLIB_H + +#include <QObject> + +struct tsdev; + +QT_BEGIN_NAMESPACE + +class QSocketNotifier; + +class QTsLibMouseHandler : public QObject +{ + Q_OBJECT + +public: + QTsLibMouseHandler(const QString &key, const QString &specification, QObject *parent = 0); + ~QTsLibMouseHandler(); + +private slots: + void readMouseData(); + +private: + QSocketNotifier * m_notify; + tsdev *m_dev; + int m_x, m_y; + bool m_pressed; + bool m_rawMode; +}; + +QT_END_NAMESPACE + +#endif // QTSLIB_H diff --git a/src/platformsupport/input/tslib/tslib.pri b/src/platformsupport/input/tslib/tslib.pri new file mode 100644 index 0000000000..c9fef1ca8f --- /dev/null +++ b/src/platformsupport/input/tslib/tslib.pri @@ -0,0 +1,7 @@ +HEADERS += \ + $$PWD/qtslib_p.h + +SOURCES += \ + $$PWD/qtslib.cpp + +LIBS += -lts |