Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qbsdkeyboard.h
Go to the documentation of this file.
1// Copyright (C) 2015-2016 Oleksandr Tymoshenko <gonzo@bluezbox.com>
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#ifndef QBSDKEYBOARD_H
5#define QBSDKEYBOARD_H
6
7#include <qobject.h>
8#include <QDataStream>
9#include <QList>
10
12
13class QSocketNotifier;
14
15struct termios;
16
17enum {
19};
20
21namespace QBsdKeyboardMap {
22 const quint32 FileMagic = 0x514d4150; // 'QMAP'
23
33
34 enum Flags {
35 NoFlags = 0x00,
36 IsLetter = 0x01,
38 };
39
40 enum Modifiers {
41 ModPlain = 0x00,
42 ModShift = 0x01,
43 ModAltGr = 0x02,
44 ModControl = 0x04,
45 ModAlt = 0x08,
46 ModShiftL = 0x10,
47 ModShiftR = 0x20,
48 ModCtrlL = 0x40,
49 ModCtrlR = 0x80
50 // ModCapsShift = 0x100, // not supported!
51 };
52}
53
54inline QDataStream &operator>>(QDataStream &ds, QBsdKeyboardMap::Mapping &m)
55{
56 return ds >> m.keycode >> m.unicode >> m.qtcode >> m.modifiers >> m.flags >> m.special;
57}
58
60{
62
63public:
66
68 {
69 Qt::KeyboardModifiers qtmod = Qt::NoModifier;
70
71 if (mod & (QBsdKeyboardMap::ModShift | QBsdKeyboardMap::ModShiftL | QBsdKeyboardMap::ModShiftR))
72 qtmod |= Qt::ShiftModifier;
73 if (mod & (QBsdKeyboardMap::ModControl | QBsdKeyboardMap::ModCtrlL | QBsdKeyboardMap::ModCtrlR))
74 qtmod |= Qt::ControlModifier;
75 if (mod & QBsdKeyboardMap::ModAlt)
76 qtmod |= Qt::AltModifier;
77
78 return qtmod;
79 }
80
81protected:
82 void switchLed(int led, bool state);
83 void processKeycode(quint16 keycode, bool pressed, bool autorepeat);
84 void processKeyEvent(int nativecode, int unicode, int qtcode,
85 Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat);
86 void revertTTYSettings();
87 void resetKeymap();
88 void readKeyboardData();
89
90private:
91 QScopedPointer<QSocketNotifier> m_notifier;
92 QScopedPointer<termios> m_kbdOrigTty;
93 int m_origKbdMode = Bsd_NoKeyMode;
94 int m_fd = -1;
95 bool m_shouldClose = false;
96 QString m_spec;
97
98 // keymap handling
99 quint8 m_modifiers = 0;
100 bool m_capsLock = false;
101 bool m_numLock = false;
102 bool m_scrollLock = false;
103
104 QList<QBsdKeyboardMap::Mapping> m_keymap;
105};
106
107QT_END_NAMESPACE
108
109#endif // QBSDKEYBOARD_H
void processKeycode(quint16 keycode, bool pressed, bool autorepeat)
static Qt::KeyboardModifiers toQtModifiers(quint8 mod)
void switchLed(int led, bool state)
void processKeyEvent(int nativecode, int unicode, int qtcode, Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat)
~QBsdKeyboardHandler() override
const quint32 FileMagic
QDataStream & operator>>(QDataStream &ds, QBsdKeyboardMap::Mapping &m)
@ Bsd_NoKeyMode