Changeset View
Changeset View
Standalone View
Standalone View
keyboard_input.h
- This file was copied to xkb.h.
Show All 15 Lines | |||||
16 | 16 | | |||
17 | You should have received a copy of the GNU General Public License | 17 | You should have received a copy of the GNU General Public License | ||
18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | 19 | *********************************************************************/ | ||
20 | #ifndef KWIN_KEYBOARD_INPUT_H | 20 | #ifndef KWIN_KEYBOARD_INPUT_H | ||
21 | #define KWIN_KEYBOARD_INPUT_H | 21 | #define KWIN_KEYBOARD_INPUT_H | ||
22 | 22 | | |||
23 | #include "input.h" | 23 | #include "input.h" | ||
24 | #include "xkb.h" | ||||
24 | 25 | | |||
25 | #include <QObject> | 26 | #include <QObject> | ||
26 | #include <QPointer> | 27 | #include <QPointer> | ||
27 | #include <QPointF> | 28 | #include <QPointF> | ||
28 | 29 | | |||
29 | #include <QLoggingCategory> | | |||
30 | Q_DECLARE_LOGGING_CATEGORY(KWIN_XKB) | | |||
31 | | ||||
32 | #include <KSharedConfig> | 30 | #include <KSharedConfig> | ||
33 | 31 | | |||
34 | class QWindow; | 32 | class QWindow; | ||
35 | struct xkb_context; | 33 | struct xkb_context; | ||
36 | struct xkb_keymap; | 34 | struct xkb_keymap; | ||
37 | struct xkb_state; | 35 | struct xkb_state; | ||
38 | struct xkb_compose_table; | 36 | struct xkb_compose_table; | ||
39 | struct xkb_compose_state; | 37 | struct xkb_compose_state; | ||
Show All 10 Lines | |||||
50 | class ModifiersChangedSpy; | 48 | class ModifiersChangedSpy; | ||
51 | class Toplevel; | 49 | class Toplevel; | ||
52 | 50 | | |||
53 | namespace LibInput | 51 | namespace LibInput | ||
54 | { | 52 | { | ||
55 | class Device; | 53 | class Device; | ||
56 | } | 54 | } | ||
57 | 55 | | |||
58 | class KWIN_EXPORT Xkb | | |||
59 | { | | |||
60 | public: | | |||
61 | Xkb(InputRedirection *input); | | |||
62 | ~Xkb(); | | |||
63 | void setConfig(KSharedConfigPtr config) { | | |||
64 | m_config = config; | | |||
65 | } | | |||
66 | void reconfigure(); | | |||
67 | | ||||
68 | void installKeymap(int fd, uint32_t size); | | |||
69 | void updateModifiers(uint32_t modsDepressed, uint32_t modsLatched, uint32_t modsLocked, uint32_t group); | | |||
70 | void updateKey(uint32_t key, InputRedirection::KeyboardKeyState state); | | |||
71 | xkb_keysym_t toKeysym(uint32_t key); | | |||
72 | xkb_keysym_t currentKeysym() const { | | |||
73 | return m_keysym; | | |||
74 | } | | |||
75 | QString toString(xkb_keysym_t keysym); | | |||
76 | Qt::Key toQtKey(xkb_keysym_t keysym) const; | | |||
77 | Qt::KeyboardModifiers modifiers() const; | | |||
78 | Qt::KeyboardModifiers modifiersRelevantForGlobalShortcuts() const; | | |||
79 | bool shouldKeyRepeat(quint32 key) const; | | |||
80 | | ||||
81 | void switchToNextLayout(); | | |||
82 | void switchToPreviousLayout(); | | |||
83 | void switchToLayout(xkb_layout_index_t layout); | | |||
84 | | ||||
85 | enum class LED { | | |||
86 | NumLock = 1 << 0, | | |||
87 | CapsLock = 1 << 1, | | |||
88 | ScrollLock = 1 << 2 | | |||
89 | }; | | |||
90 | Q_DECLARE_FLAGS(LEDs, LED) | | |||
91 | LEDs leds() const { | | |||
92 | return m_leds; | | |||
93 | } | | |||
94 | | ||||
95 | xkb_keymap *keymap() const { | | |||
96 | return m_keymap; | | |||
97 | } | | |||
98 | | ||||
99 | xkb_state *state() const { | | |||
100 | return m_state; | | |||
101 | } | | |||
102 | | ||||
103 | quint32 currentLayout() const { | | |||
104 | return m_currentLayout; | | |||
105 | } | | |||
106 | QString layoutName() const; | | |||
107 | QMap<xkb_layout_index_t, QString> layoutNames() const; | | |||
108 | quint32 numberOfLayouts() const; | | |||
109 | | ||||
110 | private: | | |||
111 | xkb_keymap *loadKeymapFromConfig(); | | |||
112 | xkb_keymap *loadDefaultKeymap(); | | |||
113 | void updateKeymap(xkb_keymap *keymap); | | |||
114 | void createKeymapFile(); | | |||
115 | void updateModifiers(); | | |||
116 | void updateConsumedModifiers(uint32_t key); | | |||
117 | QString layoutName(xkb_layout_index_t layout) const; | | |||
118 | InputRedirection *m_input; | | |||
119 | xkb_context *m_context; | | |||
120 | xkb_keymap *m_keymap; | | |||
121 | xkb_state *m_state; | | |||
122 | xkb_mod_index_t m_shiftModifier; | | |||
123 | xkb_mod_index_t m_capsModifier; | | |||
124 | xkb_mod_index_t m_controlModifier; | | |||
125 | xkb_mod_index_t m_altModifier; | | |||
126 | xkb_mod_index_t m_metaModifier; | | |||
127 | xkb_led_index_t m_numLock; | | |||
128 | xkb_led_index_t m_capsLock; | | |||
129 | xkb_led_index_t m_scrollLock; | | |||
130 | Qt::KeyboardModifiers m_modifiers; | | |||
131 | Qt::KeyboardModifiers m_consumedModifiers; | | |||
132 | xkb_keysym_t m_keysym; | | |||
133 | quint32 m_currentLayout = 0; | | |||
134 | | ||||
135 | struct { | | |||
136 | xkb_compose_table *table = nullptr; | | |||
137 | xkb_compose_state *state = nullptr; | | |||
138 | } m_compose; | | |||
139 | LEDs m_leds; | | |||
140 | KSharedConfigPtr m_config; | | |||
141 | }; | | |||
142 | | ||||
143 | class KWIN_EXPORT KeyboardInputRedirection : public QObject | 56 | class KWIN_EXPORT KeyboardInputRedirection : public QObject | ||
144 | { | 57 | { | ||
145 | Q_OBJECT | 58 | Q_OBJECT | ||
146 | public: | 59 | public: | ||
147 | explicit KeyboardInputRedirection(InputRedirection *parent); | 60 | explicit KeyboardInputRedirection(InputRedirection *parent); | ||
148 | virtual ~KeyboardInputRedirection(); | 61 | virtual ~KeyboardInputRedirection(); | ||
149 | 62 | | |||
150 | void init(); | 63 | void init(); | ||
Show All 30 Lines | 93 | private: | |||
181 | InputRedirection *m_input; | 94 | InputRedirection *m_input; | ||
182 | bool m_inited = false; | 95 | bool m_inited = false; | ||
183 | QScopedPointer<Xkb> m_xkb; | 96 | QScopedPointer<Xkb> m_xkb; | ||
184 | QMetaObject::Connection m_activeClientSurfaceChangedConnection; | 97 | QMetaObject::Connection m_activeClientSurfaceChangedConnection; | ||
185 | ModifiersChangedSpy *m_modifiersChangedSpy = nullptr; | 98 | ModifiersChangedSpy *m_modifiersChangedSpy = nullptr; | ||
186 | KeyboardLayout *m_keyboardLayout = nullptr; | 99 | KeyboardLayout *m_keyboardLayout = nullptr; | ||
187 | }; | 100 | }; | ||
188 | 101 | | |||
189 | inline | | |||
190 | Qt::KeyboardModifiers Xkb::modifiers() const | | |||
191 | { | | |||
192 | return m_modifiers; | | |||
193 | } | 102 | } | ||
194 | 103 | | |||
195 | } | | |||
196 | | ||||
197 | Q_DECLARE_METATYPE(KWin::Xkb::LED) | | |||
198 | Q_DECLARE_METATYPE(KWin::Xkb::LEDs) | | |||
199 | | ||||
200 | #endif | 104 | #endif |