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