Qt 4.8
qkbdvfb_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 <stdlib.h>
43 #include <sys/types.h>
44 #include <sys/stat.h>
45 #include <unistd.h>
46 #include <fcntl.h>
47 #include <errno.h>
48 
49 #include <qvfbhdr.h>
50 #include <qkbdvfb_qws.h>
51 
52 #ifndef QT_NO_QWS_KEYBOARD
53 #ifndef QT_NO_QWS_KBD_QVFB
54 
55 #include <qwindowsystem_qws.h>
56 #include <qsocketnotifier.h>
57 #include <qapplication.h>
58 #include <private/qcore_unix_p.h> // overrides QT_OPEN
59 
61 
63  : QObject()
64 {
65  terminalName = device;
66  if (terminalName.isEmpty())
67  terminalName = QLatin1String("/dev/vkdb");
68  kbdFD = -1;
69  kbdIdx = 0;
70  kbdBufferLen = sizeof(QVFbKeyData) * 5;
71  kbdBuffer = new unsigned char [kbdBufferLen];
72 
73  if ((kbdFD = QT_OPEN(terminalName.toLatin1().constData(), O_RDONLY | O_NDELAY)) < 0) {
74  qWarning("Cannot open %s (%s)", terminalName.toLatin1().constData(),
75  strerror(errno));
76  } else {
77  // Clear pending input
78  char buf[2];
79  while (QT_READ(kbdFD, buf, 1) > 0) { }
80 
82  connect(notifier, SIGNAL(activated(int)),this, SLOT(readKeyboardData()));
83  }
84 }
85 
87 {
88  if (kbdFD >= 0)
89  QT_CLOSE(kbdFD);
90  delete [] kbdBuffer;
91 }
92 
93 
95 {
96  int n;
97  do {
99  if (n > 0)
100  kbdIdx += n;
101  } while (n > 0);
102 
103  int idx = 0;
104  while (kbdIdx - idx >= (int)sizeof(QVFbKeyData)) {
105  QVFbKeyData *kd = (QVFbKeyData *)(kbdBuffer + idx);
106  if (kd->unicode == 0 && kd->keycode == 0 && kd->modifiers == 0 && kd->press) {
107  // magic exit key
108  qWarning("Instructed to quit by Virtual Keyboard");
109  qApp->quit();
110  }
111  QWSServer::processKeyEvent(kd->unicode ? kd->unicode : 0xffff, kd->keycode, kd->modifiers, kd->press, kd->repeat);
112  idx += sizeof(QVFbKeyData);
113  }
114 
115  int surplus = kbdIdx - idx;
116  for (int i = 0; i < surplus; i++)
117  kbdBuffer[i] = kbdBuffer[idx+i];
118  kbdIdx = surplus;
119 }
120 
122 
123 #endif // QT_NO_QWS_KBD_QVFB
124 #endif // QT_NO_QWS_KEYBOARD
bool repeat
Definition: qvfbhdr.h:112
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
#define SLOT(a)
Definition: qobjectdefs.h:226
#define O_RDONLY
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
The QString class provides a Unicode character string.
Definition: qstring.h:83
The QObject class is the base class of all Qt objects.
Definition: qobject.h:111
static void processKeyEvent(int unicode, int keycode, Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat)
Processes the given key event.
#define QT_READ
Definition: qcore_unix_p.h:280
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
bool press
Definition: qvfbhdr.h:111
#define SIGNAL(a)
Definition: qobjectdefs.h:227
unsigned char * kbdBuffer
Definition: qkbdvfb_qws.h:74
#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
#define qApp
Q_CORE_EXPORT void qWarning(const char *,...)
unsigned int keycode
Definition: qvfbhdr.h:108
QByteArray toLatin1() const Q_REQUIRED_RESULT
Returns a Latin-1 representation of the string as a QByteArray.
Definition: qstring.cpp:3993
QSocketNotifier * notifier
Definition: qkbdvfb_qws.h:75
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
QVFbKeyboardHandler(const QString &device)
Definition: qkbdvfb_qws.cpp:62
unsigned short int unicode
Definition: qvfbhdr.h:110
virtual ~QVFbKeyboardHandler()
Definition: qkbdvfb_qws.cpp:86
Qt::KeyboardModifiers modifiers
Definition: qvfbhdr.h:109
int errno
#define QT_CLOSE
Definition: qcore_unix_p.h:304