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
qvxkeyboardhandler_p.h
Go to the documentation of this file.
1// Copyright (C) 2024 The Qt Company Ltd.
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 QVXKEYBOARDHANDLER_P_H
5#define QVXKEYBOARDHANDLER_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <qobject.h>
19#include <qloggingcategory.h>
20#include <QtInputSupport/private/qfdcontainer_p.h>
21#include <QtInputSupport/private/qkeyboardmap_p.h>
22#include <QtInputSupport/private/qkeycodeaction_p.h>
23
24#include <QDataStream>
25#include <private/qglobal_p.h>
26
27#include <memory>
28
29QT_BEGIN_NAMESPACE
30
32
33class QSocketNotifier;
34
35namespace QVxKeyboardMap {
36 const quint32 FileMagic = 0x514d4150; // 'QMAP'
37
47
48 enum Flags {
49 IsDead = 0x01,
50 IsLetter = 0x02,
51 IsModifier = 0x04,
52 IsSystem = 0x08
53 };
54
64
70
71 enum Modifiers {
72 ModPlain = 0x00,
73 ModShift = 0x01,
74 ModAltGr = 0x02,
75 ModControl = 0x04,
76 ModAlt = 0x08,
77 ModShiftL = 0x10,
78 ModShiftR = 0x20,
79 ModCtrlL = 0x40,
80 ModCtrlR = 0x80
81 // ModCapsShift = 0x100, // not supported!
82 };
83}
84
85inline QDataStream &operator>>(QDataStream &ds, QVxKeyboardMap::Mapping &m)
86{
87 return ds >> m.keycode >> m.unicode >> m.qtcode >> m.modifiers >> m.flags >> m.special;
88}
89
90inline QDataStream &operator<<(QDataStream &ds, const QVxKeyboardMap::Mapping &m)
91{
92 return ds << m.keycode << m.unicode << m.qtcode << m.modifiers << m.flags << m.special;
93}
94
95inline QDataStream &operator>>(QDataStream &ds, QVxKeyboardMap::Composing &c)
96{
97 return ds >> c.first >> c.second >> c.result;
98}
99
100inline QDataStream &operator<<(QDataStream &ds, const QVxKeyboardMap::Composing &c)
101{
102 return ds << c.first << c.second << c.result;
103}
104
106{
107public:
108 QVxKeyboardHandler(const QString &device, QFdContainer &fd, bool disableZap, bool enableCompose, const QString &keymapFile);
110
111 static std::unique_ptr<QVxKeyboardHandler> create(const QString &device,
112 const QString &specification,
113 const QString &defaultKeymapFile = QString());
114
116 {
117 Qt::KeyboardModifiers qtmod = Qt::NoModifier;
118
119 if (mod & (QVxKeyboardMap::ModShift | QVxKeyboardMap::ModShiftL | QVxKeyboardMap::ModShiftR))
120 qtmod |= Qt::ShiftModifier;
121 if (mod & (QVxKeyboardMap::ModControl | QVxKeyboardMap::ModCtrlL | QVxKeyboardMap::ModCtrlR))
122 qtmod |= Qt::ControlModifier;
123 if (mod & QVxKeyboardMap::ModAlt)
124 qtmod |= Qt::AltModifier;
125
126 return qtmod;
127 }
128
129 bool loadKeymap(const QString &file);
130 void unloadKeymap();
131
132 void readKeycode();
133 QKeycodeAction processKeycode(quint16 keycode, bool pressed, bool autorepeat);
134
135 void switchLang();
136
137private:
138 void processKeyEvent(int nativecode, int unicode, int qtcode,
139 Qt::KeyboardModifiers modifiers, bool isPress, bool autoRepeat);
140
141 QString m_device;
142 QFdContainer m_fd;
143 QSocketNotifier *m_notify;
144
145 // keymap handling
146 quint8 m_modifiers;
147 quint8 m_locks[3];
148 int m_composing;
149 quint16 m_dead_unicode;
150 quint8 m_langLock;
151
152 bool m_no_zap;
153 bool m_do_compose;
154
155 const QKeyboardMap::Mapping *m_keymap;
156 int m_keymap_size;
157 const QKeyboardMap::Composing *m_keycompose;
158 int m_keycompose_size;
159
160 static const QKeyboardMap::Mapping s_keymap_default[];
161 static const QKeyboardMap::Composing s_keycompose_default[];
162};
163
164
165QT_END_NAMESPACE
166
167#endif // QVXKEYBOARDHANDLER_P_H
QKeycodeAction processKeycode(quint16 keycode, bool pressed, bool autorepeat)
static Qt::KeyboardModifiers toQtModifiers(quint8 mod)
static std::unique_ptr< QVxKeyboardHandler > create(const QString &device, const QString &specification, const QString &defaultKeymapFile=QString())
QVxKeyboardHandler(const QString &device, QFdContainer &fd, bool disableZap, bool enableCompose, const QString &keymapFile)
bool loadKeymap(const QString &file)
const quint32 FileMagic
Definition qcompare.h:76
@ Key_Tab
Definition qnamespace.h:681
@ Key_Right
Definition qnamespace.h:696
@ Key_PageUp
Definition qnamespace.h:698
@ Key_Backtab
Definition qnamespace.h:682
@ Key_Insert
Definition qnamespace.h:686
@ Key_Left
Definition qnamespace.h:694
@ Key_Up
Definition qnamespace.h:695
@ Key_Down
Definition qnamespace.h:697
@ Key_Delete
Definition qnamespace.h:687
@ Key_Multi_key
Definition qnamespace.h:757
@ Key_ScrollLock
Definition qnamespace.h:706
@ Key_PageDown
Definition qnamespace.h:699
@ Key_Home
Definition qnamespace.h:692
@ Key_Clear
Definition qnamespace.h:691
@ Key_CapsLock
Definition qnamespace.h:704
@ Key_unknown
@ Key_End
Definition qnamespace.h:693
@ ShiftModifier
@ ControlModifier
@ MetaModifier
@ KeypadModifier
@ AltModifier
#define Q_LOGGING_CATEGORY(name,...)
#define qCDebug(category,...)
#define Q_STATIC_LOGGING_CATEGORY(name,...)
#define Q_DECLARE_LOGGING_CATEGORY(name)
QDataStream & operator<<(QDataStream &ds, const QVxKeyboardMap::Composing &c)
QDataStream & operator>>(QDataStream &ds, QVxKeyboardMap::Composing &c)
QDataStream & operator<<(QDataStream &ds, const QVxKeyboardMap::Mapping &m)
QDataStream & operator>>(QDataStream &ds, QVxKeyboardMap::Mapping &m)