Qt 4.8
qmousevfb_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 #ifndef QT_NO_QWS_MOUSE_QVFB
43 
44 #include <stdlib.h>
45 #include <sys/types.h>
46 #include <unistd.h>
47 #include <fcntl.h>
48 #include <errno.h>
49 #include <stdio.h>
50 
51 #include <qvfbhdr.h>
52 #include <qmousevfb_qws.h>
53 #include <qwindowsystem_qws.h>
54 #include <qsocketnotifier.h>
55 #include <qapplication.h>
56 #include <qtimer.h>
57 #include <private/qcore_unix_p.h> // overrides QT_OPEN
58 
60 
61 QVFbMouseHandler::QVFbMouseHandler(const QString &driver, const QString &device)
62  : QObject(), QWSMouseHandler(driver, device)
63 {
64  QString mouseDev = device;
65  if (device.isEmpty())
66  mouseDev = QLatin1String("/dev/vmouse");
67 
68  mouseFD = QT_OPEN(mouseDev.toLatin1().constData(), O_RDWR | O_NDELAY);
69  if (mouseFD == -1) {
70  perror("QVFbMouseHandler::QVFbMouseHandler");
71  qWarning("QVFbMouseHander: Unable to open device %s",
72  qPrintable(mouseDev));
73  return;
74  }
75 
76  // Clear pending input
77  char buf[2];
78  while (QT_READ(mouseFD, buf, 1) > 0) { }
79 
80  mouseIdx = 0;
81 
83  connect(mouseNotifier, SIGNAL(activated(int)),this, SLOT(readMouseData()));
84 }
85 
87 {
88  if (mouseFD >= 0)
90 }
91 
93 {
95 }
96 
98 {
99  mouseNotifier->setEnabled(false);
100 }
101 
103 {
104  int n;
105  do {
107  if (n > 0)
108  mouseIdx += n;
109  } while (n > 0);
110 
111  int idx = 0;
112  static const int packetsize = sizeof(QPoint) + 2*sizeof(int);
113  while (mouseIdx-idx >= packetsize) {
114  uchar *mb = mouseBuf+idx;
115  QPoint mousePos = *reinterpret_cast<QPoint *>(mb);
116  mb += sizeof(QPoint);
117  int bstate = *reinterpret_cast<int *>(mb);
118  mb += sizeof(int);
119  int wheel = *reinterpret_cast<int *>(mb);
120 // limitToScreen(mousePos);
121  mouseChanged(mousePos, bstate, wheel);
122  idx += packetsize;
123  }
124 
125  int surplus = mouseIdx - idx;
126  for (int i = 0; i < surplus; i++)
127  mouseBuf[i] = mouseBuf[idx+i];
128  mouseIdx = surplus;
129 }
130 
132 
133 #endif // QT_NO_QWS_MOUSE_QVFB
void resume()
Implement this function to resume reading and handling mouse events, e.
#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
QPoint & mousePos
Definition: qmouse_qws.h:87
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
uchar mouseBuf[mouseBufSize]
Definition: qmousevfb_qws.h:71
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
QVFbMouseHandler(const QString &driver=QString(), const QString &device=QString())
#define QT_READ
Definition: qcore_unix_p.h:280
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
#define SIGNAL(a)
Definition: qobjectdefs.h:227
unsigned char uchar
Definition: qglobal.h:994
#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
Q_CORE_EXPORT void qWarning(const char *,...)
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
#define QT_OPEN
Definition: qcore_unix_p.h:186
void suspend()
Implement this function to suspend reading and handling of mouse events, e.
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
QSocketNotifier * mouseNotifier
Definition: qmousevfb_qws.h:72
void setEnabled(bool)
If enable is true, the notifier is enabled; otherwise the notifier is disabled.
#define qPrintable(string)
Definition: qglobal.h:1750
#define O_RDWR
#define QT_CLOSE
Definition: qcore_unix_p.h:304