Qt 4.8
qmouseqnx_qws.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #include "qmouseqnx_qws.h"
43 #ifndef QT_NO_QWS_TRANSFORMED
44 #include "qscreen_qws.h"
45 #endif
46 
47 #include "qplatformdefs.h"
48 #include "qsocketnotifier.h"
49 #include "private/qcore_unix_p.h"
50 
51 #include <sys/dcmd_input.h>
52 #include <errno.h>
53 
55 
100 QQnxMouseHandler::QQnxMouseHandler(const QString & driver, const QString &device)
101  : QObject(), QWSMouseHandler(driver, device), mouseButtons(Qt::NoButton)
102 {
103  // open the mouse device with O_NONBLOCK so reading won't block when there's no data
104  mouseFD = QT_OPEN(device.isEmpty() ? "/dev/devi/mouse0" : device.toLatin1().constData(),
105  QT_OPEN_RDONLY | O_NONBLOCK);
106  if (mouseFD == -1) {
107  qErrnoWarning(errno, "QQnxMouseHandler: Unable to open mouse device");
108  } else {
109  struct _pointer_info data;
110  if (devctl(mouseFD, _POINTERGETINFO, &data, sizeof(data), NULL) == EOK)
111  absolutePositioning = (data.flags & _POINTER_FLAG_ABSOLUTE);
112  else
113  absolutePositioning = !device.isEmpty() && device.contains(QLatin1String("touch"));
114 
115  // register a socket notifier on the file descriptor so we'll wake up whenever
116  // there's a mouse move waiting for us.
118  connect(mouseNotifier, SIGNAL(activated(int)), SLOT(socketActivated()));
119 
120  qDebug("QQnxMouseHandler: connected.");
121  }
122 #ifndef QT_NO_QWS_TRANSFORMED
124 #endif
125 }
126 
131 {
132  if (mouseFD != -1)
133  QT_CLOSE(mouseFD);
134 }
135 
138 {
139  if (mouseNotifier)
140  mouseNotifier->setEnabled(true);
141 }
142 
145 {
146  if (mouseNotifier)
147  mouseNotifier->setEnabled(false);
148 }
149 
160 {
161 #ifndef QT_NO_QWS_TRANSFORMED
162  QPoint queuedPos = transformedMousePos;
163 #else
164  QPoint queuedPos = mousePos;
165 #endif
166 
167  // _mouse_packet is a QNX structure. devi-hid is nice enough to translate
168  // the raw byte data from mouse devices into generic format for us.
169  struct _mouse_packet buffer[32];
170  int n = 0;
171 
172  forever {
173  int bytesRead = QT_READ(mouseFD, reinterpret_cast<char *>(buffer) + n, sizeof(buffer) - n);
174  if (bytesRead == -1) {
175  // EAGAIN means that there are no more mouse events to read
176  if (errno != EAGAIN)
177  qErrnoWarning(errno, "QQnxMouseHandler: Could not read from input device");
178  break;
179  }
180 
181  n += bytesRead;
182  if (n % sizeof(buffer[0]) == 0)
183  break;
184  }
185  n /= sizeof(buffer[0]);
186 
187  for (int i = 0; i < n; ++i) {
188  const struct _mouse_packet &packet = buffer[i];
189 
190  // translate the coordinates from the QNX data structure to the Qt coordinates
191  if (absolutePositioning) {
192  queuedPos = QPoint(packet.dx, packet.dy);
193  } else {
194  // note the swapped y axis
195  queuedPos += QPoint(packet.dx, -packet.dy);
196 
197  // QNX only tells us relative mouse movements, not absolute ones, so
198  // limit the cursor position manually to the screen
199  limitToScreen(queuedPos);
200  }
201 
202  // translate the QNX mouse button bitmask to Qt buttons
203  int buttons = Qt::NoButton;
204  if (packet.hdr.buttons & _POINTER_BUTTON_LEFT)
205  buttons |= Qt::LeftButton;
206  if (packet.hdr.buttons & _POINTER_BUTTON_MIDDLE)
207  buttons |= Qt::MidButton;
208  if (packet.hdr.buttons & _POINTER_BUTTON_RIGHT)
209  buttons |= Qt::RightButton;
210 
211  if (buttons != mouseButtons) {
212  // send the MouseEvent to avoid missing any clicks
213  mouseChanged(queuedPos, buttons, 0);
214  // mousePos updated by the mouseChanged()
215 #ifndef QT_NO_QWS_TRANSFORMED
216  queuedPos = transformedMousePos;
217 #else
218  queuedPos = mousePos;
219 #endif
221  }
222  }
223 
224 #ifndef QT_NO_QWS_TRANSFORMED
225  if (queuedPos != transformedMousePos) {
226  mouseChanged(queuedPos, mouseButtons, 0);
227  transformedMousePos = queuedPos;
228  }
229 #else
230  if (queuedPos != mousePos)
231  mouseChanged(queuedPos, mouseButtons, 0);
232 #endif
233 }
234 
Q_GUI_EXPORT QScreen * qt_screen
Definition: qscreen_qws.cpp:69
QBool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.h:904
QPoint transformedMousePos
Definition: qmouseqnx_qws.h:76
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
The QWSMouseHandler class is a base class for mouse drivers in Qt for Embedded Linux.
Definition: qmouse_qws.h:66
#define SLOT(a)
Definition: qobjectdefs.h:226
static Qt::MouseButtons buttons
QPoint & mousePos
Definition: qmouse_qws.h:87
~QQnxMouseHandler()
Destroys this mouse handler and closes the connection to the mouse device.
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
int deviceWidth() const
Returns the physical width of the framebuffer device in pixels.
Definition: qscreen_qws.h:233
The QString class provides a Unicode character string.
Definition: qstring.h:83
void mouseChanged(const QPoint &pos, int bstate, int wheel=0)
Notifies the system of a new mouse event.
Definition: qmouse_qws.cpp:285
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
void socketActivated()
This function is called whenever there is activity on the mouse device.
#define QT_READ
Definition: qcore_unix_p.h:280
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
Q_CORE_EXPORT void qDebug(const char *,...)
#define SIGNAL(a)
Definition: qobjectdefs.h:227
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
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
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
Definition: qstring.h:704
void resume()
Reimplemented Function
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
QQnxMouseHandler(const QString &driver=QString(), const QString &device=QString())
Constructs a mouse handler for the specified device, defaulting to /dev/devi/mouse0.
#define QT_OPEN
Definition: qcore_unix_p.h:186
QSocketNotifier * mouseNotifier
Definition: qmouseqnx_qws.h:71
int deviceHeight() const
Returns the full height of the framebuffer device in pixels.
Definition: qscreen_qws.h:234
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
void setEnabled(bool)
If enable is true, the notifier is enabled; otherwise the notifier is disabled.
Definition: qnamespace.h:54
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
void suspend()
Reimplemented Function
int errno
void qErrnoWarning(const char *msg,...)
Definition: qglobal.cpp:2954
#define QT_CLOSE
Definition: qcore_unix_p.h:304
#define forever
This macro is provided for convenience for writing infinite loops.
Definition: qglobal.h:2452