Qt 4.8
qkbdum_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 "qkbdum_qws.h"
43 
44 #if !defined(QT_NO_QWS_KEYBOARD) && !defined(QT_NO_QWS_KBD_UM)
45 
46 #include <stdlib.h>
47 #include <sys/types.h>
48 #include <sys/stat.h>
49 #include <unistd.h>
50 #include <fcntl.h>
51 #include <errno.h>
52 
53 #include <qstring.h>
54 #include <qwindowsystem_qws.h>
55 #include <qsocketnotifier.h>
56 #include "qplatformdefs.h"
57 #include "qvfbhdr.h"
58 
60 
62 {
63  Q_OBJECT
64 
65 public:
68 
69 private slots:
70  void readKeyboardData();
71 
72 private:
73  int kbdFD;
74  int kbdIdx;
75  const int kbdBufferLen;
76  unsigned char *kbdBuffer;
78 };
79 
81  : kbdFD(-1), kbdIdx(0), kbdBufferLen(sizeof(QVFbKeyData)*5)
82 {
83  kbdBuffer = new unsigned char [kbdBufferLen];
84 
85  if ((kbdFD = QT_OPEN((const char *)device.toLocal8Bit(), O_RDONLY | O_NDELAY, 0)) < 0) {
86  qDebug("Cannot open %s (%s)", (const char *)device.toLocal8Bit(),
87  strerror(errno));
88  } else {
89  // Clear pending input
90  char buf[2];
91  while (QT_READ(kbdFD, buf, 1) > 0) { }
92 
94  connect(notifier, SIGNAL(activated(int)),this, SLOT(readKeyboardData()));
95  }
96 }
97 
99 {
100  if (kbdFD >= 0)
101  QT_CLOSE(kbdFD);
102  delete [] kbdBuffer;
103 }
104 
105 
107 {
108  int n;
109  do {
111  if (n > 0)
112  kbdIdx += n;
113  } while (n > 0);
114 
115  int idx = 0;
116  while (kbdIdx - idx >= (int)sizeof(QVFbKeyData)) {
117  QVFbKeyData *kd = (QVFbKeyData *)(kbdBuffer + idx);
118  // Qtopia Key filters must still work.
120  idx += sizeof(QVFbKeyData);
121  }
122 
123  int surplus = kbdIdx - idx;
124  for (int i = 0; i < surplus; i++)
125  kbdBuffer[i] = kbdBuffer[idx+i];
126  kbdIdx = surplus;
127 }
128 
131 {
132  d = new QWSUmKeyboardHandlerPrivate(device);
133 }
134 
136 {
137  delete d;
138 }
139 
141 
142 #include "qkbdum_qws.moc"
143 
144 #endif // QT_NO_QWS_KEYBOARD && QT_NO_QWS_KBD_UM
bool repeat
Definition: qvfbhdr.h:112
The QWSKeyboardHandler class is a base class for keyboard drivers in Qt for Embedded Linux...
Definition: qkbd_qws.h:57
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QWSUmKeyboardHandlerPrivate(const QString &)
Definition: qkbdum_qws.cpp:80
QSocketNotifier * notifier
Definition: qkbdum_qws.cpp:77
#define SLOT(a)
Definition: qobjectdefs.h:226
#define O_RDONLY
QWSUmKeyboardHandler(const QString &)
Definition: qkbdum_qws.cpp:129
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
virtual ~QWSUmKeyboardHandler()
Definition: qkbdum_qws.cpp:135
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
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
unsigned int keycode
Definition: qvfbhdr.h:108
QByteArray toLocal8Bit() const Q_REQUIRED_RESULT
Returns the local 8-bit representation of the string as a QByteArray.
Definition: qstring.cpp:4049
#define Q_OBJECT
Definition: qobjectdefs.h:157
unsigned char * kbdBuffer
Definition: qkbdum_qws.cpp:76
#define QT_OPEN
Definition: qcore_unix_p.h:186
unsigned short int unicode
Definition: qvfbhdr.h:110
QWSUmKeyboardHandlerPrivate * d
Definition: qkbdum_qws.h:67
#define slots
Definition: qobjectdefs.h:68
Qt::KeyboardModifiers modifiers
Definition: qvfbhdr.h:109
int errno
#define QT_CLOSE
Definition: qcore_unix_p.h:304