46 #include <QSocketNotifier> 47 #include <QStringList> 49 #include <QWindowSystemInterface> 54 #include <qplatformdefs.h> 55 #include <private/qcore_unix_p.h> 61 #include <linux/input.h> 70 #ifdef QT_QPA_EXPERIMENTAL_TOUCHEVENT 71 class QLinuxInputMouseHandlerData
74 QLinuxInputMouseHandlerData() :seenMT(false), state(
QEvent::TouchBegin), currentIdx(0) {}
76 void ensureCurrentPoint() {
77 if (currentIdx >= touchPoints.size()) {
78 Q_ASSERT(currentIdx == touchPoints.size());
81 tp.isPrimary = (currentIdx == 0);
85 touchPoints.append(tp);
88 void setCurrentPoint(
int i) {
90 if (currentIdx < touchPoints.size()) {
91 currentX = int(touchPoints[currentIdx].
area.left());
92 currentY = int(touchPoints[currentIdx].
area.top());
94 currentY = currentX = -999;
97 void advanceCurrentPoint() {
98 setCurrentPoint(currentIdx + 1);
100 int currentPoint() {
return currentIdx; }
101 void setCurrentX(
int value) {
102 ensureCurrentPoint();
103 touchPoints[currentIdx].area.moveLeft(value);
105 bool currentMoved() {
106 return currentX != touchPoints[currentIdx].area.left() || currentY != touchPoints[currentIdx].area.top();
108 void updateCurrentPos() {
109 ensureCurrentPoint();
110 touchPoints[currentIdx].area.moveTopLeft(
QPointF(currentX, currentY));
113 ensureCurrentPoint();
114 touchPoints[currentIdx].state = state;
117 if (currentIdx < touchPoints.size())
118 return touchPoints[currentIdx].state;
134 : m_notify(0), m_x(0), m_y(0), m_prevx(0), m_prevy(0), m_xoffset(0), m_yoffset(0), m_buttons(0),
d(0)
136 qDebug() <<
"QLinuxInputMouseHandler" << key << specification;
147 foreach (
const QString &arg, args) {
148 if (arg ==
"nocompress")
169 #ifdef QT_QPA_EXPERIMENTAL_TOUCHEVENT 170 d =
new QLinuxInputMouseHandlerData;
179 #ifdef QT_QPA_EXPERIMENTAL_TOUCHEVENT 194 struct ::input_event buffer[32];
196 bool posChanged =
false;
197 bool pendingMouseEvent =
false;
198 int eventCompressCount = 0;
200 n =
QT_READ(
m_fd, reinterpret_cast<char *>(buffer) + n,
sizeof(buffer) - n);
203 qWarning(
"Got EOF from the input device.");
205 }
else if (n < 0 && (
errno != EINTR &&
errno != EAGAIN)) {
206 qWarning(
"Could not read from input device: %s", strerror(
errno));
208 }
else if (n %
sizeof(buffer[0]) == 0) {
213 n /=
sizeof(buffer[0]);
215 for (
int i = 0; i < n; ++i) {
216 struct ::input_event *
data = &buffer[i];
218 bool unknown =
false;
219 if (data->type == EV_ABS) {
220 if (data->code == ABS_X &&
m_x != data->value) {
223 }
else if (data->code == ABS_Y &&
m_y != data->value) {
226 }
else if (data->code == ABS_PRESSURE) {
228 }
else if (data->code == ABS_TOOL_WIDTH) {
230 }
else if (data->code == ABS_HAT0X) {
232 }
else if (data->code == ABS_HAT0Y) {
234 #ifdef QT_QPA_EXPERIMENTAL_TOUCHEVENT 235 }
else if (data->code == ABS_MT_POSITION_X) {
236 d->currentX = data->value;
238 }
else if (data->code == ABS_MT_POSITION_Y) {
239 d->currentY = data->value;
241 }
else if (data->code == ABS_MT_TOUCH_MAJOR) {
242 if (data->value == 0)
245 }
else if (data->code == ABS_MT_TOUCH_MINOR) {
251 }
else if (data->type == EV_REL) {
252 if (data->code == REL_X) {
255 }
else if (data->code == REL_Y) {
258 }
else if (data->code == ABS_WHEEL) {
260 int delta = 120 * data->value;
264 }
else if (data->code == ABS_THROTTLE) {
266 int delta = 120 * -data->value;
273 }
else if (data->type == EV_KEY && data->code == BTN_TOUCH) {
277 pendingMouseEvent =
false;
278 }
else if (data->type == EV_KEY && data->code >= BTN_LEFT && data->code <= BTN_MIDDLE) {
280 switch (data->code) {
290 pendingMouseEvent =
false;
291 }
else if (data->type == EV_SYN && data->code == SYN_REPORT) {
295 pendingMouseEvent =
true;
296 eventCompressCount++;
301 #ifdef QT_QPA_EXPERIMENTAL_TOUCHEVENT 308 for (
int i =
d->currentPoint(); i <
d->touchPoints.size(); ++i) {
309 d->touchPoints[i].pressure = 0;
318 d->touchPoints.clear();
320 d->setCurrentPoint(0);
323 }
else if (data->type == EV_SYN && data->code == SYN_MT_REPORT) {
329 d->updateCurrentPos();
331 }
else if (
d->currentMoved()) {
332 d->updateCurrentPos();
340 d->advanceCurrentPoint();
342 }
else if (data->type == EV_MSC && data->code == MSC_SCAN) {
348 #ifdef QLINUXINPUT_EXTRA_DEBUG 350 qWarning(
"unknown mouse event type=%x, code=%x, value=%x", data->type, data->code, data->value);
376 virtual bool filterInputEvent(
quint16 &input_code,
qint32 &input_value);
399 : m_handler(0),
m_fd(-1), m_tty_fd(-1), m_orig_kbmode(K_XLATE)
404 int repeat_delay = -1;
405 int repeat_rate = -1;
407 bool ttymode =
false;
410 foreach (
const QString &arg, args) {
425 if (repeat_delay > 0 && repeat_rate > 0) {
426 int kbdrep[2] = { repeat_delay, repeat_rate };
427 ::ioctl(
m_fd, EVIOCSREP, kbdrep);
442 struct ::termios termdata;
451 ::ioctl(
m_tty_fd, KDSKBMODE, K_MEDIUMRAW);
454 termdata.c_iflag = (IGNPAR | IGNBRK) & (~PARMRK) & (~ISTRIP);
455 termdata.c_oflag = 0;
456 termdata.c_cflag = CREAD | CS8;
457 termdata.c_lflag = 0;
458 termdata.c_cc[VTIME]=0;
459 termdata.c_cc[VMIN]=1;
460 cfsetispeed(&termdata, 9600);
461 cfsetospeed(&termdata, 9600);
462 tcsetattr(
m_tty_fd, TCSANOW, &termdata);
484 struct ::input_event led_ie;
485 ::gettimeofday(&led_ie.time, 0);
486 led_ie.type = EV_LED;
488 led_ie.value = state;
497 struct ::input_event buffer[32];
501 n =
QT_READ(
m_fd, reinterpret_cast<char *>(buffer) + n,
sizeof(buffer) - n);
504 qWarning(
"Got EOF from the input device.");
506 }
else if (n < 0 && (
errno != EINTR &&
errno != EAGAIN)) {
507 qWarning(
"Could not read from input device: %s", strerror(
errno));
509 }
else if (n %
sizeof(buffer[0]) == 0) {
514 n /=
sizeof(buffer[0]);
516 for (
int i = 0; i < n; ++i) {
517 if (buffer[i].
type != EV_KEY)
521 qint32 value = buffer[i].value;
The QWSKeyboardHandler class is a base class for keyboard drivers in Qt for Embedded Linux...
#define QT_END_NAMESPACE
This macro expands to.
int toInt(bool *ok=0, int base=10) const
Returns the string converted to an int using base base, which is 10 by default and must be between 2 ...
static void handleWheelEvent(QWidget *w, const QPoint &local, const QPoint &global, int d, Qt::Orientation o)
The QPointF class defines a point in the plane using floating point precision.
static Qt::MouseButtons buttons
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
void setObjectName(const QString &name)
static void handleTouchEvent(QWidget *w, QEvent::Type type, QTouchEvent::DeviceType devType, const QList< struct TouchPoint > &points)
Q_CORE_EXPORT void qDebug(const char *,...)
#define QT_BEGIN_NAMESPACE
This macro expands to.
The QRectF class defines a rectangle in the plane using floating point precision. ...
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
The QStringList class provides a list of strings.
static void handleMouseEvent(QWidget *w, const QPoint &local, const QPoint &global, Qt::MouseButtons b)
tlw == 0 means that ev is in global coords only
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
KeycodeAction
This enum describes the various special actions that actual QWSKeyboardHandler implementations have t...
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
const char * constData() const
Returns a pointer to the data stored in the byte array.
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Type
This enum type defines the valid event types in Qt.
The QPoint class defines a point in the plane using integer precision.
TouchPointState
This enum represents the state of a touch point at the time the QTouchEvent occurred.
QStringList split(const QString &sep, SplitBehavior behavior=KeepEmptyParts, Qt::CaseSensitivity cs=Qt::CaseSensitive) const Q_REQUIRED_RESULT
Splits the string into substrings wherever sep occurs, and returns the list of those strings...
The QEvent class is the base class of all event classes.
#define qPrintable(string)
KeycodeAction processKeycode(quint16 keycode, bool pressed, bool autorepeat)
Maps keycode according to a keymap and sends that key event to the Qt for Embedded Linux server appli...
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
The QList class is a template class that provides lists.
static int area(const QSize &s)
#define forever
This macro is provided for convenience for writing infinite loops.