Qt 4.8
Public Functions | Private Slots | Private Functions | Properties | List of all members
QLinuxInputMouseHandler Class Reference

#include <qlinuxinput.h>

Inheritance diagram for QLinuxInputMouseHandler:
QObject

Public Functions

 QLinuxInputMouseHandler (const QString &key, const QString &specification)
 
 ~QLinuxInputMouseHandler ()
 
- Public Functions inherited from QObject
bool blockSignals (bool b)
 If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke anything connected to it). More...
 
const QObjectListchildren () const
 Returns a list of child objects. More...
 
bool connect (const QObject *sender, const char *signal, const char *member, Qt::ConnectionType type=Qt::AutoConnection) const
 
bool disconnect (const char *signal=0, const QObject *receiver=0, const char *member=0)
 
bool disconnect (const QObject *receiver, const char *member=0)
 
void dumpObjectInfo ()
 Dumps information about signal connections, etc. More...
 
void dumpObjectTree ()
 Dumps a tree of children to the debug output. More...
 
QList< QByteArraydynamicPropertyNames () const
 Returns the names of all properties that were dynamically added to the object using setProperty(). More...
 
virtual bool event (QEvent *)
 This virtual function receives events to an object and should return true if the event e was recognized and processed. More...
 
virtual bool eventFilter (QObject *, QEvent *)
 Filters events if this object has been installed as an event filter for the watched object. More...
 
template<typename T >
findChild (const QString &aName=QString()) const
 Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. More...
 
template<typename T >
QList< T > findChildren (const QString &aName=QString()) const
 Returns all children of this object with the given name that can be cast to type T, or an empty list if there are no such objects. More...
 
template<typename T >
QList< T > findChildren (const QRegExp &re) const
 
bool inherits (const char *classname) const
 Returns true if this object is an instance of a class that inherits className or a QObject subclass that inherits className; otherwise returns false. More...
 
void installEventFilter (QObject *)
 Installs an event filter filterObj on this object. More...
 
bool isWidgetType () const
 Returns true if the object is a widget; otherwise returns false. More...
 
void killTimer (int id)
 Kills the timer with timer identifier, id. More...
 
virtual const QMetaObjectmetaObject () const
 Returns a pointer to the meta-object of this object. More...
 
void moveToThread (QThread *thread)
 Changes the thread affinity for this object and its children. More...
 
QString objectName () const
 
QObjectparent () const
 Returns a pointer to the parent object. More...
 
QVariant property (const char *name) const
 Returns the value of the object's name property. More...
 
Q_INVOKABLE QObject (QObject *parent=0)
 Constructs an object with parent object parent. More...
 
void removeEventFilter (QObject *)
 Removes an event filter object obj from this object. More...
 
void setObjectName (const QString &name)
 
void setParent (QObject *)
 Makes the object a child of parent. More...
 
bool setProperty (const char *name, const QVariant &value)
 Sets the value of the object's name property to value. More...
 
void setUserData (uint id, QObjectUserData *data)
 
bool signalsBlocked () const
 Returns true if signals are blocked; otherwise returns false. More...
 
int startTimer (int interval)
 Starts a timer and returns a timer identifier, or returns zero if it could not start a timer. More...
 
QThreadthread () const
 Returns the thread in which the object lives. More...
 
QObjectUserDatauserData (uint id) const
 
virtual ~QObject ()
 Destroys the object, deleting all its child objects. More...
 

Private Slots

void readMouseData ()
 

Private Functions

void sendMouseEvent (int x, int y, Qt::MouseButtons buttons)
 

Properties

QLinuxInputMouseHandlerData * d
 
Qt::MouseButtons m_buttons
 
bool m_compression
 
int m_fd
 
int m_jitterLimitSquared
 
QSocketNotifierm_notify
 
int m_prevx
 
int m_prevy
 
bool m_smooth
 
int m_smoothx
 
int m_smoothy
 
int m_x
 
int m_xoffset
 
int m_y
 
int m_yoffset
 

Additional Inherited Members

- Public Slots inherited from QObject
void deleteLater ()
 Schedules this object for deletion. More...
 
- Signals inherited from QObject
void destroyed (QObject *=0)
 This signal is emitted immediately before the object obj is destroyed, and can not be blocked. More...
 
- Static Public Functions inherited from QObject
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 receiver object. More...
 
static bool connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type=Qt::AutoConnection)
 
static bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *member)
 Disconnects signal in object sender from method in object receiver. More...
 
static bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &member)
 
static uint registerUserData ()
 
static QString tr (const char *sourceText, const char *comment=0, int n=-1)
 
static QString trUtf8 (const char *sourceText, const char *comment=0, int n=-1)
 
- Static Public Variables inherited from QObject
static const QMetaObject staticMetaObject
 This variable stores the meta-object for the class. More...
 
- Protected Functions inherited from QObject
virtual void childEvent (QChildEvent *)
 This event handler can be reimplemented in a subclass to receive child events. More...
 
virtual void connectNotify (const char *signal)
 This virtual function is called when something has been connected to signal in this object. More...
 
virtual void customEvent (QEvent *)
 This event handler can be reimplemented in a subclass to receive custom events. More...
 
virtual void disconnectNotify (const char *signal)
 This virtual function is called when something has been disconnected from signal in this object. More...
 
 QObject (QObjectPrivate &dd, QObject *parent=0)
 
int receivers (const char *signal) const
 Returns the number of receivers connected to the signal. More...
 
QObjectsender () const
 Returns a pointer to the object that sent the signal, if called in a slot activated by a signal; otherwise it returns 0. More...
 
int senderSignalIndex () const
 
virtual void timerEvent (QTimerEvent *)
 This event handler can be reimplemented in a subclass to receive timer events for the object. More...
 
- Protected Variables inherited from QObject
QScopedPointer< QObjectDatad_ptr
 
- Static Protected Variables inherited from QObject
static const QMetaObject staticQtMetaObject
 

Detailed Description

Definition at line 57 of file qlinuxinput.h.

Constructors and Destructors

◆ QLinuxInputMouseHandler()

QLinuxInputMouseHandler::QLinuxInputMouseHandler ( const QString key,
const QString specification 
)

Definition at line 132 of file qlinuxinput.cpp.

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)
135 {
136  qDebug() << "QLinuxInputMouseHandler" << key << specification;
137 
138 
139  setObjectName(QLatin1String("LinuxInputSubsystem Mouse Handler"));
140 
141  QString dev = QLatin1String("/dev/input/event0");
142  m_compression = true;
143  m_smooth = false;
144  int jitterLimit = 0;
145 
146  QStringList args = specification.split(QLatin1Char(':'));
147  foreach (const QString &arg, args) {
148  if (arg == "nocompress")
149  m_compression = false;
150  else if (arg.startsWith("dejitter="))
151  jitterLimit = arg.mid(9).toInt();
152  else if (arg.startsWith("xoffset="))
153  m_xoffset = arg.mid(8).toInt();
154  else if (arg.startsWith("yoffset="))
155  m_yoffset = arg.mid(8).toInt();
156  else if (arg.startsWith(QLatin1String("/dev/")))
157  dev = arg;
158  }
159  m_jitterLimitSquared = jitterLimit*jitterLimit;
160 
161  m_fd = QT_OPEN(dev.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0);
162  if (m_fd >= 0) {
164  connect(m_notify, SIGNAL(activated(int)), this, SLOT(readMouseData()));
165  } else {
166  qWarning("Cannot open mouse input device '%s': %s", qPrintable(dev), strerror(errno));
167  return;
168  }
169 #ifdef QT_QPA_EXPERIMENTAL_TOUCHEVENT
170  d = new QLinuxInputMouseHandlerData;
171 #endif
172 }
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 ...
Definition: qstring.cpp:6090
#define SLOT(a)
Definition: qobjectdefs.h:226
#define O_RDONLY
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
Q_CORE_EXPORT void qDebug(const char *,...)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
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...
Definition: qobject.cpp:2580
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
Q_CORE_EXPORT void qWarning(const char *,...)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
Qt::MouseButtons m_buttons
Definition: qlinuxinput.h:75
QLinuxInputMouseHandlerData * d
Definition: qlinuxinput.h:79
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
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...
Definition: qstring.cpp:3706
#define QT_OPEN
Definition: qcore_unix_p.h:186
#define qPrintable(string)
Definition: qglobal.h:1750
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QSocketNotifier * m_notify
Definition: qlinuxinput.h:69
int errno

◆ ~QLinuxInputMouseHandler()

QLinuxInputMouseHandler::~QLinuxInputMouseHandler ( )

Definition at line 175 of file qlinuxinput.cpp.

176 {
177  if (m_fd >= 0)
178  QT_CLOSE(m_fd);
179 #ifdef QT_QPA_EXPERIMENTAL_TOUCHEVENT
180  delete d;
181 #endif
182 }
QLinuxInputMouseHandlerData * d
Definition: qlinuxinput.h:79
#define QT_CLOSE
Definition: qcore_unix_p.h:304

Functions

◆ readMouseData

void QLinuxInputMouseHandler::readMouseData ( )
privateslot

Definition at line 192 of file qlinuxinput.cpp.

Referenced by QLinuxInputMouseHandler().

193 {
194  struct ::input_event buffer[32];
195  int n = 0;
196  bool posChanged = false;
197  bool pendingMouseEvent = false;
198  int eventCompressCount = 0;
199  forever {
200  n = QT_READ(m_fd, reinterpret_cast<char *>(buffer) + n, sizeof(buffer) - n);
201 
202  if (n == 0) {
203  qWarning("Got EOF from the input device.");
204  return;
205  } else if (n < 0 && (errno != EINTR && errno != EAGAIN)) {
206  qWarning("Could not read from input device: %s", strerror(errno));
207  return;
208  } else if (n % sizeof(buffer[0]) == 0) {
209  break;
210  }
211  }
212 
213  n /= sizeof(buffer[0]);
214 
215  for (int i = 0; i < n; ++i) {
216  struct ::input_event *data = &buffer[i];
217  //qDebug() << ">>" << hex << data->type << data->code << dec << data->value;
218  bool unknown = false;
219  if (data->type == EV_ABS) {
220  if (data->code == ABS_X && m_x != data->value) {
221  m_x = data->value;
222  posChanged = true;
223  } else if (data->code == ABS_Y && m_y != data->value) {
224  m_y = data->value;
225  posChanged = true;
226  } else if (data->code == ABS_PRESSURE) {
227  //ignore for now...
228  } else if (data->code == ABS_TOOL_WIDTH) {
229  //ignore for now...
230  } else if (data->code == ABS_HAT0X) {
231  //ignore for now...
232  } else if (data->code == ABS_HAT0Y) {
233  //ignore for now...
234 #ifdef QT_QPA_EXPERIMENTAL_TOUCHEVENT
235  } else if (data->code == ABS_MT_POSITION_X) {
236  d->currentX = data->value;
237  d->seenMT = true;
238  } else if (data->code == ABS_MT_POSITION_Y) {
239  d->currentY = data->value;
240  d->seenMT = true;
241  } else if (data->code == ABS_MT_TOUCH_MAJOR) {
242  if (data->value == 0)
243  d->setCurrentState(Qt::TouchPointReleased);
244  //otherwise, ignore for now...
245  } else if (data->code == ABS_MT_TOUCH_MINOR) {
246  //ignore for now...
247 #endif
248  } else {
249  unknown = true;
250  }
251  } else if (data->type == EV_REL) {
252  if (data->code == REL_X) {
253  m_x += data->value;
254  posChanged = true;
255  } else if (data->code == REL_Y) {
256  m_y += data->value;
257  posChanged = true;
258  } else if (data->code == ABS_WHEEL) { // vertical scroll
259  // data->value: 1 == up, -1 == down
260  int delta = 120 * data->value;
262  QPoint(m_x, m_y),
263  delta, Qt::Vertical);
264  } else if (data->code == ABS_THROTTLE) { // horizontal scroll
265  // data->value: 1 == right, -1 == left
266  int delta = 120 * -data->value;
268  QPoint(m_x, m_y),
269  delta, Qt::Horizontal);
270  } else {
271  unknown = true;
272  }
273  } else if (data->type == EV_KEY && data->code == BTN_TOUCH) {
274  m_buttons = data->value ? Qt::LeftButton : Qt::NoButton;
275 
276  posChanged = true;
277  pendingMouseEvent = false;
278  } else if (data->type == EV_KEY && data->code >= BTN_LEFT && data->code <= BTN_MIDDLE) {
279  Qt::MouseButton button = Qt::NoButton;
280  switch (data->code) {
281  case BTN_LEFT: button = Qt::LeftButton; break;
282  case BTN_MIDDLE: button = Qt::MidButton; break;
283  case BTN_RIGHT: button = Qt::RightButton; break;
284  }
285  if (data->value)
286  m_buttons |= button;
287  else
288  m_buttons &= ~button;
290  pendingMouseEvent = false;
291  } else if (data->type == EV_SYN && data->code == SYN_REPORT) {
292  if (posChanged) {
293  posChanged = false;
294  if (m_compression) {
295  pendingMouseEvent = true;
296  eventCompressCount++;
297  } else {
299  }
300  }
301 #ifdef QT_QPA_EXPERIMENTAL_TOUCHEVENT
302  if (d->state == QEvent::TouchBegin && !d->seenMT) {
303  //no multipoint-touch events to send
304  } else {
305  if (!d->seenMT)
306  d->state = QEvent::TouchEnd;
307 
308  for (int i = d->currentPoint(); i < d->touchPoints.size(); ++i) {
309  d->touchPoints[i].pressure = 0;
310  d->touchPoints[i].state = Qt::TouchPointReleased;
311  }
312  //qDebug() << "handleTouchEvent" << d->state << d->touchPoints.size() << d->touchPoints[0].state;
314  if (d->seenMT) {
315  d->state = QEvent::TouchUpdate;
316  } else {
317  d->state = QEvent::TouchBegin;
318  d->touchPoints.clear();
319  }
320  d->setCurrentPoint(0);
321  d->seenMT = false;
322  }
323  } else if (data->type == EV_SYN && data->code == SYN_MT_REPORT) {
324  //store data for this touch point
325 
326  if (!d->seenMT) {
327  d->setCurrentState(Qt::TouchPointReleased);
328  } else if (d->currentState() == Qt::TouchPointReleased) {
329  d->updateCurrentPos();
330  d->setCurrentState(Qt::TouchPointPressed);
331  } else if (d->currentMoved()) {
332  d->updateCurrentPos();
333  d->setCurrentState(Qt::TouchPointMoved);
334  } else {
335  d->setCurrentState(Qt::TouchPointStationary);
336  }
337  //qDebug() << "end of point" << d->currentPoint() << d->currentX << d->currentY << d->currentState();
338 
339  //advance to next tp:
340  d->advanceCurrentPoint();
341 #endif
342  } else if (data->type == EV_MSC && data->code == MSC_SCAN) {
343  // kernel encountered an unmapped key - just ignore it
344  continue;
345  } else {
346  unknown = true;
347  }
348 #ifdef QLINUXINPUT_EXTRA_DEBUG
349  if (unknown) {
350  qWarning("unknown mouse event type=%x, code=%x, value=%x", data->type, data->code, data->value);
351  }
352 #endif
353  }
354  if (m_compression && pendingMouseEvent) {
355  int distanceSquared = (m_x - m_prevx)*(m_x - m_prevx) + (m_y - m_prevy)*(m_y - m_prevy);
356  if (distanceSquared > m_jitterLimitSquared)
358  }
359 }
static void handleWheelEvent(QWidget *w, const QPoint &local, const QPoint &global, int d, Qt::Orientation o)
#define QT_READ
Definition: qcore_unix_p.h:280
static void handleTouchEvent(QWidget *w, QEvent::Type type, QTouchEvent::DeviceType devType, const QList< struct TouchPoint > &points)
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
Qt::MouseButtons m_buttons
Definition: qlinuxinput.h:75
QLinuxInputMouseHandlerData * d
Definition: qlinuxinput.h:79
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
int errno
void sendMouseEvent(int x, int y, Qt::MouseButtons buttons)
MouseButton
Definition: qnamespace.h:150
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452

◆ sendMouseEvent()

void QLinuxInputMouseHandler::sendMouseEvent ( int  x,
int  y,
Qt::MouseButtons  buttons 
)
private

Definition at line 184 of file qlinuxinput.cpp.

Referenced by readMouseData().

185 {
186  QPoint pos(x+m_xoffset, y+m_yoffset);
188  m_prevx = x;
189  m_prevy = y;
190 }
static void handleMouseEvent(QWidget *w, const QPoint &local, const QPoint &global, Qt::MouseButtons b)
tlw == 0 means that ev is in global coords only
Qt::MouseButtons m_buttons
Definition: qlinuxinput.h:75
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53

Properties

◆ d

QLinuxInputMouseHandlerData* QLinuxInputMouseHandler::d
private

Definition at line 79 of file qlinuxinput.h.

Referenced by QLinuxInputMouseHandler(), readMouseData(), and ~QLinuxInputMouseHandler().

◆ m_buttons

Qt::MouseButtons QLinuxInputMouseHandler::m_buttons
private

Definition at line 75 of file qlinuxinput.h.

Referenced by readMouseData(), and sendMouseEvent().

◆ m_compression

bool QLinuxInputMouseHandler::m_compression
private

Definition at line 76 of file qlinuxinput.h.

Referenced by QLinuxInputMouseHandler(), and readMouseData().

◆ m_fd

int QLinuxInputMouseHandler::m_fd
private

Definition at line 70 of file qlinuxinput.h.

Referenced by QLinuxInputMouseHandler(), readMouseData(), and ~QLinuxInputMouseHandler().

◆ m_jitterLimitSquared

int QLinuxInputMouseHandler::m_jitterLimitSquared
private

Definition at line 78 of file qlinuxinput.h.

Referenced by QLinuxInputMouseHandler(), and readMouseData().

◆ m_notify

QSocketNotifier* QLinuxInputMouseHandler::m_notify
private

Definition at line 69 of file qlinuxinput.h.

Referenced by QLinuxInputMouseHandler().

◆ m_prevx

int QLinuxInputMouseHandler::m_prevx
private

Definition at line 72 of file qlinuxinput.h.

Referenced by readMouseData(), and sendMouseEvent().

◆ m_prevy

int QLinuxInputMouseHandler::m_prevy
private

Definition at line 72 of file qlinuxinput.h.

Referenced by readMouseData(), and sendMouseEvent().

◆ m_smooth

bool QLinuxInputMouseHandler::m_smooth
private

Definition at line 77 of file qlinuxinput.h.

Referenced by QLinuxInputMouseHandler().

◆ m_smoothx

int QLinuxInputMouseHandler::m_smoothx
private

Definition at line 74 of file qlinuxinput.h.

◆ m_smoothy

int QLinuxInputMouseHandler::m_smoothy
private

Definition at line 74 of file qlinuxinput.h.

◆ m_x

int QLinuxInputMouseHandler::m_x
private

Definition at line 71 of file qlinuxinput.h.

Referenced by readMouseData().

◆ m_xoffset

int QLinuxInputMouseHandler::m_xoffset
private

Definition at line 73 of file qlinuxinput.h.

Referenced by QLinuxInputMouseHandler(), and sendMouseEvent().

◆ m_y

int QLinuxInputMouseHandler::m_y
private

Definition at line 71 of file qlinuxinput.h.

Referenced by readMouseData().

◆ m_yoffset

int QLinuxInputMouseHandler::m_yoffset
private

Definition at line 73 of file qlinuxinput.h.

Referenced by QLinuxInputMouseHandler(), and sendMouseEvent().


The documentation for this class was generated from the following files: