Qt 4.8
Public Functions | Private Slots | Properties | List of all members
QWSLinuxInputMousePrivate Class Reference
Inheritance diagram for QWSLinuxInputMousePrivate:
QObject

Public Functions

void enable (bool on)
 
 QWSLinuxInputMousePrivate (QWSLinuxInputMouseHandler *, const QString &)
 
 ~QWSLinuxInputMousePrivate ()
 
- 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 ()
 

Properties

int m_buttons
 
int m_fd
 
QWSLinuxInputMouseHandlerm_handler
 
QSocketNotifierm_notify
 
int m_x
 
int m_y
 

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 58 of file qmouselinuxinput_qws.cpp.

Constructors and Destructors

◆ QWSLinuxInputMousePrivate()

QWSLinuxInputMousePrivate::QWSLinuxInputMousePrivate ( QWSLinuxInputMouseHandler h,
const QString device 
)

Definition at line 99 of file qmouselinuxinput_qws.cpp.

100  : m_handler(h), m_notify(0), m_x(0), m_y(0), m_buttons(0)
101 {
102  setObjectName(QLatin1String("LinuxInputSubsystem Mouse Handler"));
103 
104  QString dev = QLatin1String("/dev/input/event0");
105  int grab = 0;
106 
107  QStringList args = device.split(QLatin1Char(':'));
108  foreach (const QString &arg, args) {
109  if (arg.startsWith(QLatin1String("grab=")))
110  grab = arg.mid(5).toInt();
111  else if (arg.startsWith(QLatin1String("/dev/")))
112  dev = arg;
113  }
114 
115  m_fd = QT_OPEN(dev.toLocal8Bit().constData(), O_RDONLY | O_NDELAY, 0);
116  if (m_fd >= 0) {
117  ::ioctl(m_fd, EVIOCGRAB, grab);
119  connect(m_notify, SIGNAL(activated(int)), this, SLOT(readMouseData()));
120  } else {
121  qWarning("Cannot open mouse input device '%s': %s", qPrintable(dev), strerror(errno));
122  return;
123  }
124 }
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
QWSLinuxInputMouseHandler * m_handler
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
#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
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
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...
Definition: qstring.cpp:6526
#define qPrintable(string)
Definition: qglobal.h:1750
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
int errno

◆ ~QWSLinuxInputMousePrivate()

QWSLinuxInputMousePrivate::~QWSLinuxInputMousePrivate ( )

Definition at line 126 of file qmouselinuxinput_qws.cpp.

127 {
128  if (m_fd >= 0)
129  QT_CLOSE(m_fd);
130 }
#define QT_CLOSE
Definition: qcore_unix_p.h:304

Functions

◆ enable()

void QWSLinuxInputMousePrivate::enable ( bool  on)

Definition at line 132 of file qmouselinuxinput_qws.cpp.

Referenced by QWSLinuxInputMouseHandler::resume(), and QWSLinuxInputMouseHandler::suspend().

133 {
134  if (m_notify)
135  m_notify->setEnabled(on);
136 }
void setEnabled(bool)
If enable is true, the notifier is enabled; otherwise the notifier is disabled.

◆ readMouseData

void QWSLinuxInputMousePrivate::readMouseData ( )
privateslot

Definition at line 138 of file qmouselinuxinput_qws.cpp.

Referenced by QWSLinuxInputMousePrivate().

139 {
140  if (!qt_screen)
141  return;
142 
143  struct ::input_event buffer[32];
144  int n = 0;
145 
146  forever {
147  int bytesRead = QT_READ(m_fd, reinterpret_cast<char *>(buffer) + n, sizeof(buffer) - n);
148  if (bytesRead == 0) {
149  qWarning("Got EOF from the input device.");
150  return;
151  }
152  if (bytesRead == -1) {
153  if (errno != EAGAIN)
154  qWarning("Could not read from input device: %s", strerror(errno));
155  break;
156  }
157 
158  n += bytesRead;
159  if (n % sizeof(buffer[0]) == 0)
160  break;
161  }
162  n /= sizeof(buffer[0]);
163 
164  for (int i = 0; i < n; ++i) {
165  struct ::input_event *data = &buffer[i];
166 
167  bool unknown = false;
168  if (data->type == EV_ABS) {
169  if (data->code == ABS_X) {
170  m_x = data->value;
171  } else if (data->code == ABS_Y) {
172  m_y = data->value;
173  } else {
174  unknown = true;
175  }
176  } else if (data->type == EV_REL) {
177  if (data->code == REL_X) {
178  m_x += data->value;
179  } else if (data->code == REL_Y) {
180  m_y += data->value;
181  } else {
182  unknown = true;
183  }
184  } else if (data->type == EV_KEY && data->code == BTN_TOUCH) {
185  m_buttons = data->value ? Qt::LeftButton : 0;
186  } else if (data->type == EV_KEY) {
187  int button = 0;
188  switch (data->code) {
189  case BTN_LEFT: button = Qt::LeftButton; break;
190  case BTN_MIDDLE: button = Qt::MidButton; break;
191  case BTN_RIGHT: button = Qt::RightButton; break;
192  }
193  if (data->value)
194  m_buttons |= button;
195  else
196  m_buttons &= ~button;
197  } else if (data->type == EV_SYN && data->code == SYN_REPORT) {
198  QPoint pos(m_x, m_y);
199  pos = m_handler->transform(pos);
200  m_handler->limitToScreen(pos);
202  } else if (data->type == EV_MSC && data->code == MSC_SCAN) {
203  // kernel encountered an unmapped key - just ignore it
204  continue;
205  } else {
206  unknown = true;
207  }
208  if (unknown) {
209  qWarning("unknown mouse event type=%x, code=%x, value=%x", data->type, data->code, data->value);
210  }
211  }
212 }
QPoint transform(const QPoint &)
Transforms the given position from device coordinates to screen coordinates, and returns the transfor...
Definition: qmouse_qws.cpp:589
Q_GUI_EXPORT QScreen * qt_screen
Definition: qscreen_qws.cpp:69
QWSLinuxInputMouseHandler * m_handler
void mouseChanged(const QPoint &pos, int bstate, int wheel=0)
Notifies the system of a new mouse event.
Definition: qmouse_qws.cpp:285
#define QT_READ
Definition: qcore_unix_p.h:280
Q_CORE_EXPORT void qWarning(const char *,...)
static const char * data(const QByteArray &arr)
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void limitToScreen(QPoint &pt)
Ensures that the given position is within the screen&#39;s boundaries, changing the position if necessary...
Definition: qmouse_qws.cpp:248
int errno
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452

Properties

◆ m_buttons

int QWSLinuxInputMousePrivate::m_buttons
private

Definition at line 75 of file qmouselinuxinput_qws.cpp.

Referenced by readMouseData().

◆ m_fd

int QWSLinuxInputMousePrivate::m_fd
private

◆ m_handler

QWSLinuxInputMouseHandler* QWSLinuxInputMousePrivate::m_handler
private

Definition at line 71 of file qmouselinuxinput_qws.cpp.

Referenced by readMouseData().

◆ m_notify

QSocketNotifier* QWSLinuxInputMousePrivate::m_notify
private

Definition at line 72 of file qmouselinuxinput_qws.cpp.

Referenced by enable(), and QWSLinuxInputMousePrivate().

◆ m_x

int QWSLinuxInputMousePrivate::m_x
private

Definition at line 74 of file qmouselinuxinput_qws.cpp.

Referenced by readMouseData().

◆ m_y

int QWSLinuxInputMousePrivate::m_y
private

Definition at line 74 of file qmouselinuxinput_qws.cpp.

Referenced by readMouseData().


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