QtBase  v6.3.1
qevdevkeyboardhandler_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2016 The Qt Company Ltd.
4 ** Contact: https://www.qt.io/licensing/
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 The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/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 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QEVDEVKEYBOARDHANDLER_P_H
41 #define QEVDEVKEYBOARDHANDLER_P_H
42 
43 //
44 // W A R N I N G
45 // -------------
46 //
47 // This file is not part of the Qt API. It exists purely as an
48 // implementation detail. This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <qobject.h>
55 #include <QTimer>
56 #include <QDataStream>
57 
58 #include <memory>
59 
61 
62 class QSocketNotifier;
63 
64 namespace QEvdevKeyboardMap {
65  const quint32 FileMagic = 0x514d4150; // 'QMAP'
66 
67  struct Mapping {
74 
75  };
76 
77  enum Flags {
78  IsDead = 0x01,
79  IsLetter = 0x02,
80  IsModifier = 0x04,
81  IsSystem = 0x08
82  };
83 
84  enum System {
90  SystemReboot = 0x0200,
91  SystemZap = 0x0300
92  };
93 
94  struct Composing {
98  };
99 
100  enum Modifiers {
101  ModPlain = 0x00,
102  ModShift = 0x01,
103  ModAltGr = 0x02,
104  ModControl = 0x04,
105  ModAlt = 0x08,
106  ModShiftL = 0x10,
107  ModShiftR = 0x20,
108  ModCtrlL = 0x40,
109  ModCtrlR = 0x80
110  // ModCapsShift = 0x100, // not supported!
111  };
112 }
113 
115 {
116  return ds >> m.keycode >> m.unicode >> m.qtcode >> m.modifiers >> m.flags >> m.special;
117 }
118 
120 {
121  return ds << m.keycode << m.unicode << m.qtcode << m.modifiers << m.flags << m.special;
122 }
123 
125 {
126  return ds >> c.first >> c.second >> c.result;
127 }
128 
130 {
131  return ds << c.first << c.second << c.result;
132 }
133 
135 {
136  int m_fd;
137  Q_DISABLE_COPY_MOVE(QFdContainer);
138 public:
139  explicit QFdContainer(int fd = -1) noexcept : m_fd(fd) {}
141 
142  int get() const noexcept { return m_fd; }
143 
144  int release() noexcept { int result = m_fd; m_fd = -1; return result; }
145  void reset() noexcept;
146  void reset(int fd) { reset(); m_fd = fd; }
147 };
148 
150 {
151 public:
152  QEvdevKeyboardHandler(const QString &device, QFdContainer &fd, bool disableZap, bool enableCompose, const QString &keymapFile);
154 
156  None = 0,
157 
158  CapsLockOff = 0x01000000,
159  CapsLockOn = 0x01000001,
160  NumLockOff = 0x02000000,
161  NumLockOn = 0x02000001,
162  ScrollLockOff = 0x03000000,
163  ScrollLockOn = 0x03000001,
164 
165  Reboot = 0x04000000,
166 
167  PreviousConsole = 0x05000000,
168  NextConsole = 0x05000001,
169  SwitchConsoleFirst = 0x06000000,
170  SwitchConsoleLast = 0x0600007f,
171  SwitchConsoleMask = 0x0000007f
172  };
173 
174  static std::unique_ptr<QEvdevKeyboardHandler> create(const QString &device,
175  const QString &specification,
176  const QString &defaultKeymapFile = QString());
177 
178  static Qt::KeyboardModifiers toQtModifiers(quint8 mod)
179  {
180  Qt::KeyboardModifiers qtmod = Qt::NoModifier;
181 
183  qtmod |= Qt::ShiftModifier;
185  qtmod |= Qt::ControlModifier;
186  if (mod & QEvdevKeyboardMap::ModAlt)
187  qtmod |= Qt::AltModifier;
188 
189  return qtmod;
190  }
191 
192  bool loadKeymap(const QString &file);
193  void unloadKeymap();
194 
195  void readKeycode();
196  KeycodeAction processKeycode(quint16 keycode, bool pressed, bool autorepeat);
197 
198  void switchLang();
199 
200 private:
201  void processKeyEvent(int nativecode, int unicode, int qtcode,
202  Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat);
203  void switchLed(int, bool);
204 
205  QString m_device;
206  QFdContainer m_fd;
207  QSocketNotifier *m_notify;
208 
209  // keymap handling
210  quint8 m_modifiers;
211  quint8 m_locks[3];
212  int m_composing;
213  quint16 m_dead_unicode;
214  quint8 m_langLock;
215 
216  bool m_no_zap;
217  bool m_do_compose;
218 
219  const QEvdevKeyboardMap::Mapping *m_keymap;
220  int m_keymap_size;
221  const QEvdevKeyboardMap::Composing *m_keycompose;
222  int m_keycompose_size;
223 
224  static const QEvdevKeyboardMap::Mapping s_keymap_default[];
225  static const QEvdevKeyboardMap::Composing s_keycompose_default[];
226 };
227 
228 
230 
231 #endif // QEVDEVKEYBOARDHANDLER_P_H
The QDataStream class provides serialization of binary data to a QIODevice.
Definition: qdatastream.h:66
operator>>(QDataStream &ds, qfloat16 &f)
Definition: qfloat16.cpp:344
operator<<(QDataStream &ds, qfloat16 f)
Definition: qfloat16.cpp:327
QEvdevKeyboardHandler(const QString &device, QFdContainer &fd, bool disableZap, bool enableCompose, const QString &keymapFile)
static std::unique_ptr< QEvdevKeyboardHandler > create(const QString &device, const QString &specification, const QString &defaultKeymapFile=QString())
KeycodeAction processKeycode(quint16 keycode, bool pressed, bool autorepeat)
bool loadKeymap(const QString &file)
static Qt::KeyboardModifiers toQtModifiers(quint8 mod)
int release() noexcept
QFdContainer(int fd=-1) noexcept
int get() const noexcept
void reset() noexcept
The QObject class is the base class of all Qt objects.
Definition: qobject.h:125
The QSocketNotifier class provides support for monitoring activity on a file descriptor.
The QString class provides a Unicode character string.
Definition: qstring.h:388
auto it unsigned count const
Definition: hb-iter.hh:848
@ ShiftModifier
Definition: qnamespace.h:1075
@ ControlModifier
Definition: qnamespace.h:1076
@ NoModifier
Definition: qnamespace.h:1074
@ AltModifier
Definition: qnamespace.h:1077
#define QString()
Definition: parse-defines.h:51
unsigned int quint32
Definition: qglobal.h:288
unsigned short quint16
Definition: qglobal.h:286
unsigned char quint8
Definition: qglobal.h:284
const GLfloat * m
GLuint64 GLenum GLint fd
GLboolean reset
Definition: qopenglext.h:2748
const GLubyte * c
Definition: qopenglext.h:12701
GLuint64EXT * result
[6]
Definition: qopenglext.h:10932
int keycode
Definition: qvnc.cpp:176
QFile file
[0]