Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtslib.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qtslib_p.h"
5
6#include <QSocketNotifier>
7#include <QStringList>
8#include <QPoint>
9#include <QLoggingCategory>
10
11#include <qpa/qwindowsysteminterface.h>
12
13#include <errno.h>
14#include <tslib.h>
15
17
18using namespace Qt::StringLiterals;
19
20Q_LOGGING_CATEGORY(qLcTsLib, "qt.qpa.input")
21
23 const QString &specification,
24 QObject *parent)
25 : QObject(parent),
26 m_rawMode(!key.compare("TslibRaw"_L1, Qt::CaseInsensitive))
27{
28 qCDebug(qLcTsLib) << "Initializing tslib plugin" << key << specification;
29 setObjectName("TSLib Mouse Handler"_L1);
30
31 m_dev = ts_setup(nullptr, 1);
32 if (!m_dev) {
33 qErrnoWarning(errno, "ts_setup() failed");
34 return;
35 }
36
37#ifdef TSLIB_VERSION_EVENTPATH /* also introduced in 1.15 */
38 qCDebug(qLcTsLib) << "tslib device is" << ts_get_eventpath(m_dev);
39#endif
40 m_notify = new QSocketNotifier(ts_fd(m_dev), QSocketNotifier::Read, this);
41 connect(m_notify, &QSocketNotifier::activated, this, &QTsLibMouseHandler::readMouseData);
42}
43
45{
46 if (m_dev)
47 ts_close(m_dev);
48}
49
50static bool get_sample(struct tsdev *dev, struct ts_sample *sample, bool rawMode)
51{
52 if (rawMode)
53 return (ts_read_raw(dev, sample, 1) == 1);
54 else
55 return (ts_read(dev, sample, 1) == 1);
56}
57
58void QTsLibMouseHandler::readMouseData()
59{
60 ts_sample sample;
61
62 while (get_sample(m_dev, &sample, m_rawMode)) {
63 bool pressed = sample.pressure;
64 int x = sample.x;
65 int y = sample.y;
66
67 // coordinates on release events can contain arbitrary values, just ignore them
68 if (sample.pressure == 0) {
69 x = m_x;
70 y = m_y;
71 }
72
73 if (!m_rawMode) {
74 //filtering: ignore movements of 2 pixels or less
75 int dx = x - m_x;
76 int dy = y - m_y;
77 if (dx*dx <= 4 && dy*dy <= 4 && pressed == m_pressed)
78 continue;
79 }
80 QPoint pos(x, y);
81
82 Qt::MouseButton button = pressed ^ m_pressed ? Qt::LeftButton : Qt::NoButton;
83 Qt::MouseButtons state = pressed ? Qt::LeftButton : Qt::NoButton;
85 : QEvent::MouseButtonRelease;
86
88
89 m_x = x;
90 m_y = y;
91 m_pressed = pressed;
92 }
93}
94
96
97#include "moc_qtslib_p.cpp"
\inmodule QtCore
Definition qcoreevent.h:45
Type
This enum type defines the valid event types in Qt.
Definition qcoreevent.h:51
@ MouseMove
Definition qcoreevent.h:63
@ MouseButtonPress
Definition qcoreevent.h:60
\inmodule QtCore
Definition qobject.h:103
\inmodule QtCore\reentrant
Definition qpoint.h:25
\inmodule QtCore
void activated(QSocketDescriptor socket, QSocketNotifier::Type activationEvent, QPrivateSignal)
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static bool handleMouseEvent(QWindow *window, const QPointF &local, const QPointF &global, Qt::MouseButtons state, Qt::MouseButton button, QEvent::Type type, Qt::KeyboardModifiers mods=Qt::NoModifier, Qt::MouseEventSource source=Qt::MouseEventNotSynthesized)
QPushButton * button
[2]
object setObjectName("A new object name")
else opt state
[0]
void qErrnoWarning(const char *msg,...)
Combined button and popup list for selecting options.
Definition qcompare.h:63
MouseButton
Definition qnamespace.h:56
@ LeftButton
Definition qnamespace.h:58
@ NoButton
Definition qnamespace.h:57
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
GLint GLint GLint GLint GLint x
[0]
GLuint64 key
GLenum type
GLint y
static int compare(quint64 a, quint64 b)
static bool get_sample(struct tsdev *dev, struct ts_sample *sample, bool rawMode)
Definition qtslib.cpp:50
connect(quitButton, &QPushButton::clicked, &app, &QCoreApplication::quit, Qt::QueuedConnection)