summaryrefslogtreecommitdiffstats
path: root/src/plugins/generic/tslib
diff options
context:
space:
mode:
authorQt by Nokia <qt-info@nokia.com>2011-04-27 12:05:43 +0200
committeraxis <qt-info@nokia.com>2011-04-27 12:05:43 +0200
commit38be0d13830efd2d98281c645c3a60afe05ffece (patch)
tree6ea73f3ec77f7d153333779883e8120f82820abe /src/plugins/generic/tslib
Initial import from the monolithic Qt.
This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12
Diffstat (limited to 'src/plugins/generic/tslib')
-rw-r--r--src/plugins/generic/tslib/main.cpp78
-rw-r--r--src/plugins/generic/tslib/qtslib.cpp144
-rw-r--r--src/plugins/generic/tslib/qtslib.h77
-rw-r--r--src/plugins/generic/tslib/tslib.pro13
4 files changed, 312 insertions, 0 deletions
diff --git a/src/plugins/generic/tslib/main.cpp b/src/plugins/generic/tslib/main.cpp
new file mode 100644
index 0000000000..3c2d21c6c8
--- /dev/null
+++ b/src/plugins/generic/tslib/main.cpp
@@ -0,0 +1,78 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qgenericplugin_qpa.h>
+#include "qtslib.h"
+
+QT_BEGIN_NAMESPACE
+
+class QTsLibPlugin : public QGenericPlugin
+{
+public:
+ QTsLibPlugin();
+
+ QStringList keys() const;
+ QObject* create(const QString &key, const QString &specification);
+};
+
+QTsLibPlugin::QTsLibPlugin()
+ : QGenericPlugin()
+{
+}
+
+QStringList QTsLibPlugin::keys() const
+{
+ return (QStringList()
+ << QLatin1String("Tslib")
+ << QLatin1String("TslibRaw"));
+}
+
+QObject* QTsLibPlugin::create(const QString &key,
+ const QString &specification)
+{
+ if (!key.compare(QLatin1String("Tslib"), Qt::CaseInsensitive) || !key.compare(QLatin1String("TslibRaw"), Qt::CaseInsensitive))
+ return new QTsLibMouseHandler(key, specification);
+ return 0;
+ }
+
+Q_EXPORT_PLUGIN2(qtslibplugin, QTsLibPlugin)
+
+QT_END_NAMESPACE
diff --git a/src/plugins/generic/tslib/qtslib.cpp b/src/plugins/generic/tslib/qtslib.cpp
new file mode 100644
index 0000000000..0143db411d
--- /dev/null
+++ b/src/plugins/generic/tslib/qtslib.cpp
@@ -0,0 +1,144 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+
+#include "qtslib.h"
+
+
+#include <QSocketNotifier>
+#include <QStringList>
+#include <QPoint>
+#include <QWindowSystemInterface>
+
+#include <Qt>
+
+#include <errno.h>
+#include <tslib.h>
+
+#include <qdebug.h>
+
+QT_BEGIN_NAMESPACE
+
+QTsLibMouseHandler::QTsLibMouseHandler(const QString &key,
+ const QString &specification)
+ : m_notify(0), m_x(0), m_y(0), m_pressed(0), m_rawMode(false)
+{
+ qDebug() << "QTsLibMouseHandler" << key << specification;
+ setObjectName(QLatin1String("TSLib Mouse Handler"));
+
+ QByteArray device = "/dev/input/event1";
+ if (specification.startsWith("/dev/"))
+ device = specification.toLocal8Bit();
+
+ m_dev = ts_open(device.constData(), 1);
+
+ if (ts_config(m_dev)) {
+ perror("Error configuring\n");
+ }
+
+
+ m_rawMode = !key.compare(QLatin1String("TslibRaw"), Qt::CaseInsensitive);
+
+ int fd = ts_fd(m_dev);
+ if (fd >= 0) {
+ m_notify = new QSocketNotifier(fd, QSocketNotifier::Read, this);
+ connect(m_notify, SIGNAL(activated(int)), this, SLOT(readMouseData()));
+ } else {
+ qWarning("Cannot open mouse input device '%s': %s", device.constData(), strerror(errno));
+ return;
+ }
+}
+
+
+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 {
+ int ret = ts_read(dev, sample, 1);
+ return ( ret == 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;
+
+
+ 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;
+ } else {
+ // work around missing coordinates on mouse release in raw mode
+ if (sample.pressure == 0 && sample.x == 0 && sample.y == 0) {
+ x = m_x;
+ y = m_y;
+ }
+ }
+ QPoint pos(x, y);
+
+ //printf("handleMouseEvent %d %d %d %ld\n", m_x, m_y, pressed, sample.tv.tv_usec);
+
+ 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/plugins/generic/tslib/qtslib.h b/src/plugins/generic/tslib/qtslib.h
new file mode 100644
index 0000000000..43091857bd
--- /dev/null
+++ b/src/plugins/generic/tslib/qtslib.h
@@ -0,0 +1,77 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the QtGui module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** 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 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.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QTSLIB_H
+#define QTSLIB_H
+
+#include <qobject.h>
+//#include <Qt>
+
+QT_BEGIN_HEADER
+
+QT_BEGIN_NAMESPACE
+
+class QSocketNotifier;
+struct tsdev;
+
+class QTsLibMouseHandler : public QObject
+{
+ Q_OBJECT
+public:
+ QTsLibMouseHandler(const QString &key, const QString &specification);
+ ~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
+
+QT_END_HEADER
+
+#endif // QTSLIB_H
diff --git a/src/plugins/generic/tslib/tslib.pro b/src/plugins/generic/tslib/tslib.pro
new file mode 100644
index 0000000000..74c7fd2b96
--- /dev/null
+++ b/src/plugins/generic/tslib/tslib.pro
@@ -0,0 +1,13 @@
+TARGET = qlinuxinputplugin
+include(../../qpluginbase.pri)
+
+QTDIR_build:DESTDIR = $$QT_BUILD_TREE/plugins/generic
+target.path = $$[QT_INSTALL_PLUGINS]/generic
+INSTALLS += target
+
+HEADERS = qtslib.h
+
+SOURCES = main.cpp \
+ qtslib.cpp
+
+LIBS += -lts