1 | // Copyright (C) 2016 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 QXCBKEYBOARD_H |
5 | #define QXCBKEYBOARD_H |
6 | |
7 | #include "qxcbobject.h" |
8 | |
9 | #include <xcb/xcb_keysyms.h> |
10 | #define explicit dont_use_cxx_explicit |
11 | #include <xcb/xkb.h> |
12 | #undef explicit |
13 | |
14 | #include <QtGui/private/qxkbcommon_p.h> |
15 | #include <xkbcommon/xkbcommon-x11.h> |
16 | |
17 | #include <qpa/qplatformkeymapper.h> |
18 | |
19 | #include <QEvent> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | class QXcbKeyboard : public QXcbObject, public QPlatformKeyMapper |
24 | { |
25 | public: |
26 | QXcbKeyboard(QXcbConnection *connection); |
27 | |
28 | ~QXcbKeyboard(); |
29 | |
30 | void initialize(); |
31 | void selectEvents(); |
32 | |
33 | void handleKeyPressEvent(const xcb_key_press_event_t *event); |
34 | void handleKeyReleaseEvent(const xcb_key_release_event_t *event); |
35 | |
36 | Qt::KeyboardModifiers translateModifiers(int s) const; |
37 | void updateKeymap(xcb_mapping_notify_event_t *event); |
38 | void updateKeymap(); |
39 | |
40 | QList<QKeyCombination> possibleKeyCombinations(const QKeyEvent *event) const override; |
41 | Qt::KeyboardModifiers queryKeyboardModifiers() const override; |
42 | |
43 | void updateXKBMods(); |
44 | xkb_mod_mask_t xkbModMask(quint16 state); |
45 | void updateXKBStateFromCore(quint16 state); |
46 | void updateXKBStateFromXI(void *modInfo, void *groupInfo); |
47 | |
48 | int coreDeviceId() const { return core_device_id; } |
49 | void updateXKBState(xcb_xkb_state_notify_event_t *state); |
50 | |
51 | void handleStateChanges(xkb_state_component changedComponents); |
52 | |
53 | protected: |
54 | void handleKeyEvent(xcb_window_t sourceWindow, QEvent::Type type, xcb_keycode_t code, |
55 | quint16 state, xcb_timestamp_t time, bool fromSendEvent); |
56 | |
57 | void resolveMaskConflicts(); |
58 | |
59 | typedef QMap<xcb_keysym_t, int> KeysymModifierMap; |
60 | struct xkb_keymap *keymapFromCore(const KeysymModifierMap &keysymMods); |
61 | |
62 | void updateModifiers(const KeysymModifierMap &keysymMods); |
63 | KeysymModifierMap keysymsToModifiers(); |
64 | |
65 | void updateVModMapping(); |
66 | void updateVModToRModMapping(); |
67 | |
68 | private: |
69 | bool m_config = false; |
70 | bool m_isAutoRepeat = false; |
71 | xcb_keycode_t m_autoRepeatCode = 0; |
72 | |
73 | struct _mod_masks { |
74 | uint alt; |
75 | uint altgr; |
76 | uint meta; |
77 | uint super; |
78 | uint hyper; |
79 | }; |
80 | |
81 | _mod_masks rmod_masks; |
82 | |
83 | xcb_key_symbols_t *m_key_symbols = nullptr; |
84 | struct _xkb_mods { |
85 | xkb_mod_index_t shift; |
86 | xkb_mod_index_t lock; |
87 | xkb_mod_index_t control; |
88 | xkb_mod_index_t mod1; |
89 | xkb_mod_index_t mod2; |
90 | xkb_mod_index_t mod3; |
91 | xkb_mod_index_t mod4; |
92 | xkb_mod_index_t mod5; |
93 | }; |
94 | _xkb_mods xkb_mods; |
95 | |
96 | _mod_masks vmod_masks; |
97 | int core_device_id; |
98 | |
99 | QXkbCommon::ScopedXKBState m_xkbState; |
100 | QXkbCommon::ScopedXKBKeymap m_xkbKeymap; |
101 | QXkbCommon::ScopedXKBContext m_xkbContext; |
102 | |
103 | bool m_superAsMeta = false; |
104 | bool m_hyperAsMeta = false; |
105 | }; |
106 | |
107 | QT_END_NAMESPACE |
108 | |
109 | #endif |
110 | |