Clean up tslib plugin

The code is now cleaned up, properly divided between platformsupport and
the actual plugin (like evdev) and categorized logging is in use.

This will allow us to use tslib as a built-in input handler in eglfs in
the future.

Change-Id: Ic87cdcfe8049bb98530e7f26ffa7a77611a8ede3
Reviewed-by: Oswald Buddenhagen <oswald.buddenhagen@theqtcompany.com>
Reviewed-by: Andy Nichols <andy.nichols@digia.com>
bb10
Laszlo Agocs 2014-10-13 13:50:49 +02:00
parent 5cd6cd198c
commit cf046ccec0
6 changed files with 35 additions and 36 deletions

View File

@ -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)
}

View File

@ -3,7 +3,7 @@
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui module of the Qt Toolkit.
** This file is part of the plugins module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
@ -31,32 +31,32 @@
**
****************************************************************************/
#include "qtslib.h"
#include "qtslib_p.h"
#include <QSocketNotifier>
#include <QStringList>
#include <QPoint>
#include <QLoggingCategory>
#include <qpa/qwindowsysteminterface.h>
#include <errno.h>
#include <tslib.h>
#include <qdebug.h>
QT_BEGIN_NAMESPACE
Q_LOGGING_CATEGORY(qLcTsLib, "qt.qpa.input")
QTsLibMouseHandler::QTsLibMouseHandler(const QString &key,
const QString &specification)
const QString &specification)
: m_notify(0), m_x(0), m_y(0), m_pressed(0), m_rawMode(false)
{
qDebug() << "QTsLibMouseHandler" << key << specification;
qCDebug(qLcTsLib) << "Initializing tslib plugin" << key << specification;
setObjectName(QLatin1String("TSLib Mouse Handler"));
QByteArray device = qgetenv("TSLIB_TSDEVICE");
if (specification.startsWith("/dev/"))
if (specification.startsWith(QStringLiteral("/dev/")))
device = specification.toLocal8Bit();
if (device.isEmpty())
@ -69,27 +69,26 @@ QTsLibMouseHandler::QTsLibMouseHandler(const QString &key,
}
if (ts_config(m_dev))
perror("Error configuring\n");
qErrnoWarning(errno, "ts_config() failed");
m_rawMode = !key.compare(QLatin1String("TslibRaw"), Qt::CaseInsensitive);
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 {
qWarning("Cannot open mouse input device '%s': %s", device.constData(), strerror(errno));
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)
@ -98,7 +97,6 @@ static bool get_sample(struct tsdev *dev, struct ts_sample *sample, bool rawMode
return (ts_read(dev, sample, 1) == 1);
}
void QTsLibMouseHandler::readMouseData()
{
ts_sample sample;
@ -123,8 +121,6 @@ void QTsLibMouseHandler::readMouseData()
}
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;

View File

@ -3,7 +3,7 @@
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of the QtGui module of the Qt Toolkit.
** This file is part of the plugins module of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL21$
** Commercial License Usage
@ -34,13 +34,13 @@
#ifndef QTSLIB_H
#define QTSLIB_H
#include <qobject.h>
//#include <Qt>
#include <QObject>
struct tsdev;
QT_BEGIN_NAMESPACE
class QSocketNotifier;
struct tsdev;
class QTsLibMouseHandler : public QObject
{

View File

@ -0,0 +1,7 @@
HEADERS += \
$$PWD/qtslib_p.h
SOURCES += \
$$PWD/qtslib.cpp
LIBS += -lts

View File

@ -32,7 +32,7 @@
****************************************************************************/
#include <QtGui/qgenericplugin.h>
#include "qtslib.h"
#include <QtPlatformSupport/private/qtslib_p.h>
QT_BEGIN_NAMESPACE
@ -42,21 +42,16 @@ class QTsLibPlugin : public QGenericPlugin
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QGenericPluginFactoryInterface" FILE "tslib.json")
public:
QTsLibPlugin();
QObject* create(const QString &key, const QString &specification);
};
QTsLibPlugin::QTsLibPlugin()
: QGenericPlugin()
{
}
QObject* QTsLibPlugin::create(const QString &key,
const QString &specification)
const QString &specification)
{
if (!key.compare(QLatin1String("Tslib"), Qt::CaseInsensitive) || !key.compare(QLatin1String("TslibRaw"), Qt::CaseInsensitive))
if (!key.compare(QLatin1String("Tslib"), Qt::CaseInsensitive)
|| !key.compare(QLatin1String("TslibRaw"), Qt::CaseInsensitive))
return new QTsLibMouseHandler(key, specification);
return 0;
}

View File

@ -5,12 +5,9 @@ PLUGIN_EXTENDS = -
PLUGIN_CLASS_NAME = QTsLibPlugin
load(qt_plugin)
HEADERS = qtslib.h
SOURCES = main.cpp
SOURCES = main.cpp \
qtslib.cpp
QT += gui-private
QT += gui-private platformsupport-private
LIBS += -lts