diff options
Diffstat (limited to 'src/plugins/generic/touchscreen')
-rw-r--r-- | src/plugins/generic/touchscreen/70-qtouchscreen.rules | 1 | ||||
-rw-r--r-- | src/plugins/generic/touchscreen/README | 45 | ||||
-rw-r--r-- | src/plugins/generic/touchscreen/main.cpp | 80 | ||||
-rw-r--r-- | src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp | 116 | ||||
-rw-r--r-- | src/plugins/generic/touchscreen/qtoucheventsenderqpa.h | 77 | ||||
-rw-r--r-- | src/plugins/generic/touchscreen/qtouchscreen.cpp | 396 | ||||
-rw-r--r-- | src/plugins/generic/touchscreen/qtouchscreen.h | 104 | ||||
-rw-r--r-- | src/plugins/generic/touchscreen/touchscreen.pro | 18 |
8 files changed, 0 insertions, 837 deletions
diff --git a/src/plugins/generic/touchscreen/70-qtouchscreen.rules b/src/plugins/generic/touchscreen/70-qtouchscreen.rules deleted file mode 100644 index 2afde8f8a3..0000000000 --- a/src/plugins/generic/touchscreen/70-qtouchscreen.rules +++ /dev/null @@ -1 +0,0 @@ -KERNEL=="event*", ENV{ID_INPUT_TOUCHPAD}=="1", MODE="0644" diff --git a/src/plugins/generic/touchscreen/README b/src/plugins/generic/touchscreen/README deleted file mode 100644 index ac73f5f147..0000000000 --- a/src/plugins/generic/touchscreen/README +++ /dev/null @@ -1,45 +0,0 @@ -Generic plug-in for evdev touch events. - -Tested with the following drivers: bcm5974, hid_magicmouse. - -(1) Using as a QPA generic plug-in - -1. set up and connect the touch device -2. install libudev-dev or similar -3. build this plug-in (qmake && make) -4. sudo cp 70-qtouchscreen.rules /etc/udev/rules.d -5. sudo udevadm trigger --subsystem-match=input -6. ./fingerpaint -plugin LinuxTouchScreen:force_window - -If automatic detection does not work, use -plugin -LinuxTouchScreen:/dev/input/eventN to explicitly set the device file -name. - -By default the surface of the touch device is mapped to the entire -screen. If this is not desired, pass force_window in the plugin -specification as shown in the example above. This will cause mapping -the touch surface to the active window instead. - -Only touch events are generated, mouse events are not. Be aware however -that ignored touch events will generate a mouse event from the first -touch point by default. See AA_SynthesizeMouseForUnhandledTouchEvents. - -(2) Using in a compositor - -The classes (QTouchScreenHandler, QTouchScreenHandlerThread) are also -suitable for direct inclusion into an application, e.g. a Wayland -compositor. The compositor may then register its own -QTouchScreenObserver because relying on the QTouchEvents generated by -the QPA event sender may not always be satisfactory as some low-level -details get lost, and due to performance reasons. - -(3) Possible issues and solutions - -The udev rule matches any touchpad device. If there are multiple ones, -specify the device as described above. - -If no evdev events are read, remove 50-synaptics.conf (or similar) -from /usr/share/X11/xorg.conf.d and restart X. Or at least temporarily -disable the device by running xinput set-prop <device> <device enabled -property> 0. Use xinput list and xinput list-props to figure out the -values. diff --git a/src/plugins/generic/touchscreen/main.cpp b/src/plugins/generic/touchscreen/main.cpp deleted file mode 100644 index 1f438ef1e7..0000000000 --- a/src/plugins/generic/touchscreen/main.cpp +++ /dev/null @@ -1,80 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the plugins of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include <qgenericplugin_qpa.h> -#include "qtouchscreen.h" -#include "qtoucheventsenderqpa.h" - -QT_BEGIN_NAMESPACE - -class QTouchScreenPlugin : public QGenericPlugin -{ -public: - QTouchScreenPlugin(); - - QStringList keys() const; - QObject* create(const QString &key, const QString &specification); -}; - -QTouchScreenPlugin::QTouchScreenPlugin() -{ -} - -QStringList QTouchScreenPlugin::keys() const -{ - return QStringList() << "LinuxTouchScreen"; -} - -QObject* QTouchScreenPlugin::create(const QString &key, - const QString &spec) -{ - if (!key.compare(QLatin1String("LinuxTouchScreen"), Qt::CaseInsensitive)) { - QTouchScreenObserver *obs = new QTouchEventSenderQPA(spec); - QTouchScreenHandlerThread *h = new QTouchScreenHandlerThread(spec, obs); - return h; - } - - return 0; - } - -Q_EXPORT_PLUGIN2(qtouchscreenplugin, QTouchScreenPlugin) - -QT_END_NAMESPACE diff --git a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp deleted file mode 100644 index ac4a12c09a..0000000000 --- a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the plugins module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtoucheventsenderqpa.h" -#include <QGuiApplication> -#include <QScreen> -#include <QStringList> -#include <QDebug> - -QT_BEGIN_NAMESPACE - -QTouchEventSenderQPA::QTouchEventSenderQPA(const QString &spec) -{ - m_forceToActiveWindow = spec.split(QLatin1Char(':')).contains(QLatin1String("force_window")); - m_device = new QTouchDevice; - m_device->setType(QTouchDevice::TouchScreen); - m_device->setCapabilities(QTouchDevice::Position | QTouchDevice::Area); - QWindowSystemInterface::registerTouchDevice(m_device); -} - -void QTouchEventSenderQPA::touch_configure(int x_min, int x_max, int y_min, int y_max, - int pressure_min, int pressure_max, - const QString &dev_name) -{ - hw_range_x_min = x_min; - hw_range_x_max = x_max; - hw_range_y_min = y_min; - hw_range_y_max = y_max; - - hw_pressure_min = pressure_min; - hw_pressure_max = pressure_max; - - m_device->setName(dev_name); - - if (hw_pressure_max > hw_pressure_min) - m_device->setCapabilities(m_device->capabilities() | QTouchDevice::Pressure); -} - -void QTouchEventSenderQPA::touch_point(const QList<QWindowSystemInterface::TouchPoint> &points) -{ - QRect winRect; - if (m_forceToActiveWindow) { - QWindow *win = QGuiApplication::activeWindow(); - if (!win) - return; - winRect = win->geometry(); - } else { - winRect = QGuiApplication::primaryScreen()->geometry(); - } - - const int hw_w = hw_range_x_max - hw_range_x_min; - const int hw_h = hw_range_y_max - hw_range_y_min; - - QList<QWindowSystemInterface::TouchPoint> touchPoints = points; - // Map the coordinates based on the normalized position. QPA expects 'area' - // to be in screen coordinates. - for (int i = 0; i < touchPoints.size(); ++i) { - QWindowSystemInterface::TouchPoint &tp(touchPoints[i]); - - // Generate a screen position that is always inside the active window - // or the primary screen. - const int wx = winRect.left() + int(tp.normalPosition.x() * winRect.width()); - const int wy = winRect.top() + int(tp.normalPosition.y() * winRect.height()); - const qreal sizeRatio = (winRect.width() + winRect.height()) / qreal(hw_w + hw_h); - tp.area = QRect(0, 0, tp.area.width() * sizeRatio, tp.area.height() * sizeRatio); - tp.area.moveCenter(QPoint(wx, wy)); - - // Calculate normalized pressure. - if (!hw_pressure_min && !hw_pressure_max) - tp.pressure = tp.state == Qt::TouchPointReleased ? 0 : 1; - else - tp.pressure = (tp.pressure - hw_pressure_min) / qreal(hw_pressure_max - hw_pressure_min); - } - - QWindowSystemInterface::handleTouchEvent(0, m_device, touchPoints); -} - -QT_END_NAMESPACE diff --git a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h b/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h deleted file mode 100644 index 6b21dfe259..0000000000 --- a/src/plugins/generic/touchscreen/qtoucheventsenderqpa.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the plugins module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTOUCHEVENTSENDERQPA_H -#define QTOUCHEVENTSENDERQPA_H - -#include "qtouchscreen.h" - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QTouchDevice; - -class QTouchEventSenderQPA : public QTouchScreenObserver -{ -public: - QTouchEventSenderQPA(const QString &spec = QString()); - void touch_configure(int x_min, int x_max, int y_min, int y_max, - int pressure_min, int pressure_max, const QString &dev_name); - void touch_point(const QList<QWindowSystemInterface::TouchPoint> &points); - -private: - bool m_forceToActiveWindow; - int hw_range_x_min; - int hw_range_x_max; - int hw_range_y_min; - int hw_range_y_max; - int hw_pressure_min; - int hw_pressure_max; - QString hw_dev_name; - QTouchDevice *m_device; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QTOUCHEVENTSENDERQPA_H diff --git a/src/plugins/generic/touchscreen/qtouchscreen.cpp b/src/plugins/generic/touchscreen/qtouchscreen.cpp deleted file mode 100644 index 8e04c10b9f..0000000000 --- a/src/plugins/generic/touchscreen/qtouchscreen.cpp +++ /dev/null @@ -1,396 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the plugins module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include "qtouchscreen.h" -#include <QStringList> -#include <QHash> -#include <QSocketNotifier> -#include <QtCore/private/qcore_unix_p.h> -#include <linux/input.h> -#include <libudev.h> - -QT_BEGIN_NAMESPACE - -class QTouchScreenData -{ -public: - QTouchScreenData(QTouchScreenHandler *q_ptr, const QStringList &args); - - void processInputEvent(input_event *data); - void assignIds(); - - QTouchScreenHandler *q; - int m_lastEventType; - QList<QWindowSystemInterface::TouchPoint> m_touchPoints; - - struct Contact { - int trackingId; - int x; - int y; - int maj; - int pressure; - Qt::TouchPointState state; - QTouchEvent::TouchPoint::InfoFlags flags; - Contact() : trackingId(-1), - x(0), y(0), maj(1), pressure(0), - state(Qt::TouchPointPressed), flags(0) { } - }; - QHash<int, Contact> m_contacts, m_lastContacts; - Contact m_currentData; - - int findClosestContact(const QHash<int, Contact> &contacts, int x, int y, int *dist); - - int hw_range_x_min; - int hw_range_x_max; - int hw_range_y_min; - int hw_range_y_max; - int hw_pressure_min; - int hw_pressure_max; - QString hw_name; - - QList<QTouchScreenObserver *> m_observers; -}; - -QTouchScreenData::QTouchScreenData(QTouchScreenHandler *q_ptr, const QStringList &args) - : q(q_ptr), - m_lastEventType(-1), - hw_range_x_min(0), hw_range_x_max(0), - hw_range_y_min(0), hw_range_y_max(0), - hw_pressure_min(0), hw_pressure_max(0) -{ - Q_UNUSED(args); -} - -QTouchScreenHandler::QTouchScreenHandler(const QString &spec) - : m_notify(0), m_fd(-1), d(0) -{ - setObjectName(QLatin1String("Linux Touch Handler")); - - QString dev = QLatin1String("/dev/input/event5"); - try_udev(&dev); - - QStringList args = spec.split(QLatin1Char(':')); - for (int i = 0; i < args.count(); ++i) - if (args.at(i).startsWith(QLatin1String("/dev/"))) - dev = args.at(i); - - qDebug("Using device '%s'", qPrintable(dev)); - m_fd = QT_OPEN(dev.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0); - - if (m_fd >= 0) { - m_notify = new QSocketNotifier(m_fd, QSocketNotifier::Read, this); - connect(m_notify, SIGNAL(activated(int)), this, SLOT(readData())); - } else { - qWarning("Cannot open input device '%s': %s", qPrintable(dev), strerror(errno)); - return; - } - - d = new QTouchScreenData(this, args); - - input_absinfo absInfo; - memset(&absInfo, 0, sizeof(input_absinfo)); - if (ioctl(m_fd, EVIOCGABS(ABS_MT_POSITION_X), &absInfo) >= 0) { - qDebug("min X: %d max X: %d", absInfo.minimum, absInfo.maximum); - d->hw_range_x_min = absInfo.minimum; - d->hw_range_x_max = absInfo.maximum; - } - if (ioctl(m_fd, EVIOCGABS(ABS_MT_POSITION_Y), &absInfo) >= 0) { - qDebug("min Y: %d max Y: %d", absInfo.minimum, absInfo.maximum); - d->hw_range_y_min = absInfo.minimum; - d->hw_range_y_max = absInfo.maximum; - } - if (ioctl(m_fd, EVIOCGABS(ABS_PRESSURE), &absInfo) >= 0) { - qDebug("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; - } - } - char name[1024]; - if (ioctl(m_fd, EVIOCGNAME(sizeof(name) - 1), name) >= 0) { - d->hw_name = QString::fromLocal8Bit(name); - qDebug("device name: %s", name); - } -} - -QTouchScreenHandler::~QTouchScreenHandler() -{ - if (m_fd >= 0) - QT_CLOSE(m_fd); - - delete d; -} - -void QTouchScreenHandler::addObserver(QTouchScreenObserver *observer) -{ - if (!d || !observer) - return; - d->m_observers.append(observer); - observer->touch_configure(d->hw_range_x_min, d->hw_range_x_max, - d->hw_range_y_min, d->hw_range_y_max, - d->hw_pressure_min, d->hw_pressure_max, - d->hw_name); -} - -void QTouchScreenHandler::try_udev(QString *path) -{ - *path = QString(); - udev *u = udev_new(); - udev_enumerate *ue = udev_enumerate_new(u); - udev_enumerate_add_match_subsystem(ue, "input"); - udev_enumerate_add_match_property(ue, "ID_INPUT_TOUCHPAD", "1"); - udev_enumerate_scan_devices(ue); - udev_list_entry *entry; - udev_list_entry_foreach(entry, udev_enumerate_get_list_entry(ue)) { - const char *syspath = udev_list_entry_get_name(entry); - udev_device *udevice = udev_device_new_from_syspath(u, syspath); - QString candidate = QString::fromLocal8Bit(udev_device_get_devnode(udevice)); - udev_device_unref(udevice); - if (path->isEmpty() && candidate.startsWith("/dev/input/event")) - *path = candidate; - } - udev_enumerate_unref(ue); - udev_unref(u); -} - -void QTouchScreenHandler::readData() -{ - ::input_event buffer[32]; - int n = 0; - for (; ;) { - n = QT_READ(m_fd, reinterpret_cast<char*>(buffer) + n, sizeof(buffer) - n); - - if (!n) { - qWarning("Got EOF from input device"); - return; - } else if (n < 0 && (errno != EINTR && errno != EAGAIN)) { - qWarning("Could not read from input device: %s", strerror(errno)); - if (errno == ENODEV) { // device got disconnected -> stop reading - delete m_notify; - m_notify = 0; - QT_CLOSE(m_fd); - m_fd = -1; - } - return; - } else if (n % sizeof(::input_event) == 0) { - break; - } - } - - n /= sizeof(::input_event); - - for (int i = 0; i < n; ++i) - d->processInputEvent(&buffer[i]); -} - -void QTouchScreenData::processInputEvent(input_event *data) -{ - if (data->type == EV_ABS) { - - if (data->code == ABS_MT_POSITION_X) { - m_currentData.x = qBound(hw_range_x_min, data->value, hw_range_x_max); - } else if (data->code == ABS_MT_POSITION_Y) { - m_currentData.y = qBound(hw_range_y_min, data->value, hw_range_y_max); - } else if (data->code == ABS_MT_TRACKING_ID) { - m_currentData.trackingId = data->value; - } else if (data->code == ABS_MT_TOUCH_MAJOR) { - m_currentData.maj = data->value; - if (data->value == 0) - m_currentData.state = Qt::TouchPointReleased; - } else if (data->code == ABS_PRESSURE) { - m_currentData.pressure = qBound(hw_pressure_min, data->value, hw_pressure_max); - } - - } else if (data->type == EV_SYN && data->code == SYN_MT_REPORT && m_lastEventType != EV_SYN) { - - // If there is no tracking id, one will be generated later. - // Until that use a temporary key. - int key = m_currentData.trackingId; - if (key == -1) - key = m_contacts.count(); - - m_contacts.insert(key, m_currentData); - m_currentData = Contact(); - - } else if (data->type == EV_SYN && data->code == SYN_REPORT) { - - // Ensure valid IDs even when the driver does not report ABS_MT_TRACKING_ID. - if (!m_contacts.isEmpty() && m_contacts.constBegin().value().trackingId == -1) - assignIds(); - - m_touchPoints.clear(); - Qt::TouchPointStates combinedStates; - QMutableHashIterator<int, Contact> it(m_contacts); - while (it.hasNext()) { - it.next(); - QWindowSystemInterface::TouchPoint tp; - Contact &contact(it.value()); - tp.id = contact.trackingId; - tp.flags = contact.flags; - - if (m_lastContacts.contains(contact.trackingId)) { - const Contact &prev(m_lastContacts.value(contact.trackingId)); - if (contact.state == Qt::TouchPointReleased) { - // Copy over the previous values for released points, just in case. - contact.x = prev.x; - contact.y = prev.y; - contact.maj = prev.maj; - } else { - contact.state = (prev.x == contact.x && prev.y == contact.y) - ? Qt::TouchPointStationary : Qt::TouchPointMoved; - } - } - - // Avoid reporting a contact in released state more than once. - if (contact.state == Qt::TouchPointReleased - && !m_lastContacts.contains(contact.trackingId)) { - it.remove(); - continue; - } - - tp.state = contact.state; - combinedStates |= tp.state; - - // Store the HW coordinates. Observers can then map it to screen space or something else. - tp.area = QRectF(0, 0, contact.maj, contact.maj); - tp.area.moveCenter(QPoint(contact.x, contact.y)); - tp.pressure = contact.pressure; - - // Get a normalized position in range 0..1. - tp.normalPosition = QPointF((contact.x - hw_range_x_min) / qreal(hw_range_x_max - hw_range_x_min), - (contact.y - hw_range_y_min) / qreal(hw_range_y_max - hw_range_y_min)); - - m_touchPoints.append(tp); - - if (contact.state == Qt::TouchPointReleased) - it.remove(); - } - - m_lastContacts = m_contacts; - m_contacts.clear(); - - if (!m_touchPoints.isEmpty() && combinedStates != Qt::TouchPointStationary) { - for (int i = 0; i < m_observers.count(); ++i) - m_observers.at(i)->touch_point(m_touchPoints); - } - } - - m_lastEventType = data->type; -} - -int QTouchScreenData::findClosestContact(const QHash<int, Contact> &contacts, int x, int y, int *dist) -{ - int minDist = -1, id = -1; - for (QHash<int, Contact>::const_iterator it = contacts.constBegin(), ite = contacts.constEnd(); - it != ite; ++it) { - const Contact &contact(it.value()); - int dx = x - contact.x; - int dy = y - contact.y; - int dist = dx * dx + dy * dy; - if (minDist == -1 || dist < minDist) { - minDist = dist; - id = contact.trackingId; - } - } - if (dist) - *dist = minDist; - return id; -} - -void QTouchScreenData::assignIds() -{ - QHash<int, Contact> candidates = m_lastContacts, pending = m_contacts, newContacts; - int maxId = -1; - QHash<int, Contact>::iterator it, ite, bestMatch; - while (!pending.isEmpty() && !candidates.isEmpty()) { - int bestDist = -1, bestId; - for (it = pending.begin(), ite = pending.end(); it != ite; ++it) { - int dist; - int id = findClosestContact(candidates, it->x, it->y, &dist); - if (id >= 0 && (bestDist == -1 || dist < bestDist)) { - bestDist = dist; - bestId = id; - bestMatch = it; - } - } - if (bestDist >= 0) { - bestMatch->trackingId = bestId; - newContacts.insert(bestId, *bestMatch); - candidates.remove(bestId); - pending.erase(bestMatch); - if (bestId > maxId) - maxId = bestId; - } - } - if (candidates.isEmpty()) { - for (it = pending.begin(), ite = pending.end(); it != ite; ++it) { - it->trackingId = ++maxId; - newContacts.insert(it->trackingId, *it); - } - } - m_contacts = newContacts; -} - - -QTouchScreenHandlerThread::QTouchScreenHandlerThread(const QString &spec, - QTouchScreenObserver *observer) - : m_spec(spec), m_handler(0), m_observer(observer) -{ - start(); -} - -QTouchScreenHandlerThread::~QTouchScreenHandlerThread() -{ - quit(); - wait(); -} - -void QTouchScreenHandlerThread::run() -{ - m_handler = new QTouchScreenHandler(m_spec); - m_handler->addObserver(m_observer); - exec(); - delete m_handler; - m_handler = 0; -} - - -QT_END_NAMESPACE diff --git a/src/plugins/generic/touchscreen/qtouchscreen.h b/src/plugins/generic/touchscreen/qtouchscreen.h deleted file mode 100644 index 33a1b0ad2f..0000000000 --- a/src/plugins/generic/touchscreen/qtouchscreen.h +++ /dev/null @@ -1,104 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** Contact: http://www.qt-project.org/ -** -** This file is part of the plugins module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** This file may be used under the terms of the GNU Lesser General Public -** License version 2.1 as published by the Free Software Foundation and -** appearing in the file LICENSE.LGPL included in the packaging of this -** file. Please review the following information to ensure the GNU Lesser -** General Public License version 2.1 requirements will be met: -** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -** -** In addition, as a special exception, Nokia gives you certain additional -** rights. These rights are described in the Nokia Qt LGPL Exception -** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU General -** Public License version 3.0 as published by the Free Software Foundation -** and appearing in the file LICENSE.GPL included in the packaging of this -** file. Please review the following information to ensure the GNU General -** Public License version 3.0 requirements will be met: -** http://www.gnu.org/copyleft/gpl.html. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#ifndef QTOUCHSCREEN_H -#define QTOUCHSCREEN_H - -#include <QObject> -#include <QString> -#include <QList> -#include <QThread> -#include <QWindowSystemInterface> - -QT_BEGIN_HEADER - -QT_BEGIN_NAMESPACE - -class QSocketNotifier; -class QTouchScreenData; - -class QTouchScreenObserver -{ -public: - virtual void touch_configure(int x_min, int x_max, int y_min, int y_max, - int pressure_min, int pressure_max, const QString &dev_name) = 0; - virtual void touch_point(const QList<QWindowSystemInterface::TouchPoint> &points) = 0; -}; - -class QTouchScreenHandler : public QObject -{ - Q_OBJECT - -public: - QTouchScreenHandler(const QString &spec = QString()); - ~QTouchScreenHandler(); - void addObserver(QTouchScreenObserver *observer); - -private slots: - void readData(); - -private: - void try_udev(QString *path); - - QSocketNotifier *m_notify; - int m_fd; - QTouchScreenData *d; -}; - -class QTouchScreenHandlerThread : public QThread -{ -public: - QTouchScreenHandlerThread(const QString &spec, QTouchScreenObserver *observer); - ~QTouchScreenHandlerThread(); - void run(); - QTouchScreenHandler *handler() { return m_handler; } - -private: - QString m_spec; - QTouchScreenHandler *m_handler; - QTouchScreenObserver *m_observer; -}; - -QT_END_NAMESPACE - -QT_END_HEADER - -#endif // QTOUCHSCREEN_H diff --git a/src/plugins/generic/touchscreen/touchscreen.pro b/src/plugins/generic/touchscreen/touchscreen.pro deleted file mode 100644 index 60aa29c5ec..0000000000 --- a/src/plugins/generic/touchscreen/touchscreen.pro +++ /dev/null @@ -1,18 +0,0 @@ -TARGET = qtouchscreenplugin -load(qt_plugin) - -DESTDIR = $$QT.gui.plugins/generic -target.path = $$[QT_INSTALL_PLUGINS]/generic -INSTALLS += target - -HEADERS = \ - qtouchscreen.h \ - qtoucheventsenderqpa.h - -SOURCES = main.cpp \ - qtouchscreen.cpp \ - qtoucheventsenderqpa.cpp - -QT += core-private gui-private - -LIBS += -ludev |