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
qxkbcommon_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 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// Qt-Security score:significant reason:default
4
5#ifndef QXKBCOMMON_P_H
6#define QXKBCOMMON_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17//
18
19#include <QtGui/qtguiglobal.h>
20#include <QtCore/qstring.h>
21#include <QtCore/qloggingcategory.h>
22#include <QtCore/qlist.h>
23#include <QtCore/private/qglobal_p.h>
24
25#include <xkbcommon/xkbcommon.h>
26
27#include <qpa/qplatformkeymapper.h>
28
29#include <memory>
30
31QT_BEGIN_NAMESPACE
32
33class QEvent;
34class QKeyEvent;
35class QPlatformInputContext;
36
37class Q_GUI_EXPORT QXkbCommon
38{
39public:
40 static QString lookupString(struct xkb_state *state, xkb_keycode_t code);
41 static QString lookupStringNoKeysymTransformations(xkb_keysym_t keysym);
42
43 static QList<xkb_keysym_t> toKeysym(QKeyEvent *event);
44
45 static int keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers modifiers);
46 static int keysymToQtKey(xkb_keysym_t keysym, Qt::KeyboardModifiers modifiers,
47 xkb_state *state, xkb_keycode_t code,
48 bool superAsMeta = true, bool hyperAsMeta = true);
49
50 // xkbcommon_* API is part of libxkbcommon internals, with modifications as
51 // described in the header of the implementation file.
52 static void xkbcommon_XConvertCase(xkb_keysym_t sym, xkb_keysym_t *lower, xkb_keysym_t *upper);
53 static xkb_keysym_t qxkbcommon_xkb_keysym_to_upper(xkb_keysym_t ks);
54
55 static Qt::KeyboardModifiers modifiers(struct xkb_state *state, xkb_keysym_t keysym = XKB_KEY_VoidSymbol);
56
57 static QList<int> possibleKeys(xkb_state *state,
58 const QKeyEvent *event, bool superAsMeta = false, bool hyperAsMeta = false);
59 static QList<QKeyCombination> possibleKeyCombinations(xkb_state *state,
60 const QKeyEvent *event, bool superAsMeta = false, bool hyperAsMeta = false);
61
62 static void verifyHasLatinLayout(xkb_keymap *keymap);
63 static xkb_keysym_t lookupLatinKeysym(xkb_state *state, xkb_keycode_t keycode);
64
65 static bool isLatin1(xkb_keysym_t sym) {
66 return sym >= 0x20 && sym <= 0xff;
67 }
68 static bool isKeypad(xkb_keysym_t sym) {
69 switch (sym) {
70 case XKB_KEY_KP_Space:
71 case XKB_KEY_KP_Tab:
72 case XKB_KEY_KP_Enter:
73 case XKB_KEY_KP_F1:
74 case XKB_KEY_KP_F2:
75 case XKB_KEY_KP_F3:
76 case XKB_KEY_KP_F4:
77 case XKB_KEY_KP_Home:
78 case XKB_KEY_KP_Left:
79 case XKB_KEY_KP_Up:
80 case XKB_KEY_KP_Right:
81 case XKB_KEY_KP_Down:
82 case XKB_KEY_KP_Prior:
83 case XKB_KEY_KP_Next:
84 case XKB_KEY_KP_End:
85 case XKB_KEY_KP_Begin:
86 case XKB_KEY_KP_Insert:
87 case XKB_KEY_KP_Delete:
88 case XKB_KEY_KP_Equal:
89 case XKB_KEY_KP_Multiply:
90 case XKB_KEY_KP_Add:
91 case XKB_KEY_KP_Separator:
92 case XKB_KEY_KP_Subtract:
93 case XKB_KEY_KP_Decimal:
94 case XKB_KEY_KP_Divide:
95 case XKB_KEY_KP_0:
96 case XKB_KEY_KP_1:
97 case XKB_KEY_KP_2:
98 case XKB_KEY_KP_3:
99 case XKB_KEY_KP_4:
100 case XKB_KEY_KP_5:
101 case XKB_KEY_KP_6:
102 case XKB_KEY_KP_7:
103 case XKB_KEY_KP_8:
104 case XKB_KEY_KP_9:
105 return true;
106 default:
107 return false;
108 }
109 }
110
111 static void setXkbContext(QPlatformInputContext *inputContext, struct xkb_context *context);
112
113 struct XKBStateDeleter {
114 void operator()(struct xkb_state *state) const { return xkb_state_unref(state); }
115 };
116 struct XKBKeymapDeleter {
117 void operator()(struct xkb_keymap *keymap) const { return xkb_keymap_unref(keymap); }
118 };
119 struct XKBContextDeleter {
120 void operator()(struct xkb_context *context) const { return xkb_context_unref(context); }
121 };
122 using ScopedXKBState = std::unique_ptr<struct xkb_state, XKBStateDeleter>;
123 using ScopedXKBKeymap = std::unique_ptr<struct xkb_keymap, XKBKeymapDeleter>;
124 using ScopedXKBContext = std::unique_ptr<struct xkb_context, XKBContextDeleter>;
125};
126
127QT_END_NAMESPACE
128
129#endif // QXKBCOMMON_P_H
#define XKB_MOD_NAME_ALT
#define XKB_MOD_NAME_SHIFT
#define XKB_MOD_NAME_LOGO
#define XKB_MOD_NAME_CTRL
static const Qt::KeyboardModifiers ModsTbl[]
static QT_BEGIN_NAMESPACE int keysymToQtKey_internal(xkb_keysym_t keysym, Qt::KeyboardModifiers modifiers, xkb_state *state, xkb_keycode_t code, bool superAsMeta, bool hyperAsMeta)
static constexpr const auto KeyTbl
xkb2qt_t Type
static constexpr Type data() noexcept
constexpr bool operator<=(const xkb2qt &that) const noexcept
unsigned int xkb
constexpr bool operator<(const xkb2qt &that) const noexcept
unsigned int qt