1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the plugins of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#ifndef QXCBKEYBOARD_H
41#define QXCBKEYBOARD_H
42
43#include "qxcbobject.h"
44
45#include <xcb/xcb_keysyms.h>
46#define explicit dont_use_cxx_explicit
47#include <xcb/xkb.h>
48#undef explicit
49
50#include <QtXkbCommonSupport/private/qxkbcommon_p.h>
51#include <xkbcommon/xkbcommon-x11.h>
52
53#include <QEvent>
54
55QT_BEGIN_NAMESPACE
56
57class QXcbKeyboard : public QXcbObject
58{
59public:
60 QXcbKeyboard(QXcbConnection *connection);
61
62 ~QXcbKeyboard();
63
64 void initialize();
65 void selectEvents();
66
67 void handleKeyPressEvent(const xcb_key_press_event_t *event);
68 void handleKeyReleaseEvent(const xcb_key_release_event_t *event);
69
70 Qt::KeyboardModifiers translateModifiers(int s) const;
71 void updateKeymap(xcb_mapping_notify_event_t *event);
72 void updateKeymap(xcb_xkb_new_keyboard_notify_event_t *event);
73 void updateKeymap();
74 QList<int> possibleKeys(const QKeyEvent *event) const;
75
76 void updateXKBMods();
77 xkb_mod_mask_t xkbModMask(quint16 state);
78 void updateXKBStateFromCore(quint16 state);
79 void updateXKBStateFromXI(void *modInfo, void *groupInfo);
80
81 int coreDeviceId() const { return core_device_id; }
82 void updateXKBState(xcb_xkb_state_notify_event_t *state);
83
84 void handleStateChanges(xkb_state_component changedComponents);
85
86protected:
87 void handleKeyEvent(xcb_window_t sourceWindow, QEvent::Type type, xcb_keycode_t code,
88 quint16 state, xcb_timestamp_t time, bool fromSendEvent);
89
90 void resolveMaskConflicts();
91
92 typedef QMap<xcb_keysym_t, int> KeysymModifierMap;
93 struct xkb_keymap *keymapFromCore(const KeysymModifierMap &keysymMods);
94
95 void updateModifiers(const KeysymModifierMap &keysymMods);
96 KeysymModifierMap keysymsToModifiers();
97
98 void updateVModMapping();
99 void updateVModToRModMapping();
100
101private:
102 bool m_config = false;
103 bool m_isAutoRepeat = false;
104 xcb_keycode_t m_autoRepeatCode = 0;
105
106 struct _mod_masks {
107 uint alt;
108 uint altgr;
109 uint meta;
110 uint super;
111 uint hyper;
112 };
113
114 _mod_masks rmod_masks;
115
116 xcb_key_symbols_t *m_key_symbols = nullptr;
117 struct _xkb_mods {
118 xkb_mod_index_t shift;
119 xkb_mod_index_t lock;
120 xkb_mod_index_t control;
121 xkb_mod_index_t mod1;
122 xkb_mod_index_t mod2;
123 xkb_mod_index_t mod3;
124 xkb_mod_index_t mod4;
125 xkb_mod_index_t mod5;
126 };
127 _xkb_mods xkb_mods;
128
129 _mod_masks vmod_masks;
130 int core_device_id;
131
132 QXkbCommon::ScopedXKBState m_xkbState;
133 QXkbCommon::ScopedXKBKeymap m_xkbKeymap;
134 QXkbCommon::ScopedXKBContext m_xkbContext;
135
136 bool m_superAsMeta = false;
137 bool m_hyperAsMeta = false;
138};
139
140QT_END_NAMESPACE
141
142#endif
143

source code of qtbase/src/plugins/platforms/xcb/qxcbkeyboard.h