1 | // Copyright (C) 2017 The Qt Company Ltd. |
2 | // Copyright (C) 2017 Klarälvdalens Datakonsult AB (KDAB). |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
4 | |
5 | #ifndef QTWAYLAND_QWLKEYBOARD_P_H |
6 | #define QTWAYLAND_QWLKEYBOARD_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 | #include <QtWaylandCompositor/private/qwaylandcompositor_p.h> |
19 | |
20 | #include <QtWaylandCompositor/private/qtwaylandcompositorglobal_p.h> |
21 | #include <QtWaylandCompositor/qwaylandseat.h> |
22 | #include <QtWaylandCompositor/qwaylandkeyboard.h> |
23 | #include <QtWaylandCompositor/qwaylanddestroylistener.h> |
24 | |
25 | #include <QtCore/private/qobject_p.h> |
26 | #include <QtWaylandCompositor/private/qwayland-server-wayland.h> |
27 | |
28 | #include <QtCore/QList> |
29 | |
30 | #if QT_CONFIG(xkbcommon) |
31 | #include <xkbcommon/xkbcommon.h> |
32 | #include <QtGui/private/qxkbcommon_p.h> |
33 | #endif |
34 | |
35 | |
36 | QT_BEGIN_NAMESPACE |
37 | |
38 | class Q_WAYLANDCOMPOSITOR_EXPORT QWaylandKeyboardPrivate : public QObjectPrivate |
39 | , public QtWaylandServer::wl_keyboard |
40 | { |
41 | public: |
42 | Q_DECLARE_PUBLIC(QWaylandKeyboard) |
43 | |
44 | static QWaylandKeyboardPrivate *get(QWaylandKeyboard *keyboard); |
45 | |
46 | QWaylandKeyboardPrivate(QWaylandSeat *seat); |
47 | ~QWaylandKeyboardPrivate() override; |
48 | |
49 | QWaylandCompositor *compositor() const { return seat->compositor(); } |
50 | |
51 | void focused(QWaylandSurface* surface); |
52 | |
53 | #if QT_CONFIG(xkbcommon) |
54 | struct xkb_state *xkbState() const { return mXkbState.get(); } |
55 | struct xkb_context *xkbContext() const { |
56 | return QWaylandCompositorPrivate::get(compositor: seat->compositor())->xkbContext(); |
57 | } |
58 | uint32_t xkbModsMask() const { return modsDepressed | modsLatched | modsLocked; } |
59 | void maybeUpdateXkbScanCodeTable(); |
60 | void resetKeyboardState(); |
61 | #endif |
62 | |
63 | void keyEvent(uint code, uint32_t state); |
64 | void sendKeyEvent(uint code, uint32_t state); |
65 | void updateModifierState(uint code, uint32_t state); |
66 | void checkAndRepairModifierState(QKeyEvent *ke); |
67 | void maybeUpdateKeymap(); |
68 | |
69 | void checkFocusResource(Resource *resource); |
70 | void sendEnter(QWaylandSurface *surface, Resource *resource); |
71 | |
72 | protected: |
73 | void keyboard_bind_resource(Resource *resource) override; |
74 | void keyboard_destroy_resource(Resource *resource) override; |
75 | void keyboard_release(Resource *resource) override; |
76 | |
77 | private: |
78 | #if QT_CONFIG(xkbcommon) |
79 | void createXKBKeymap(); |
80 | void createXKBState(xkb_keymap *keymap); |
81 | #endif |
82 | static uint toWaylandKey(const uint nativeScanCode); |
83 | static uint fromWaylandKey(const uint key); |
84 | |
85 | void sendRepeatInfo(); |
86 | |
87 | QWaylandSeat *seat = nullptr; |
88 | |
89 | QWaylandSurface *focus = nullptr; |
90 | Resource *focusResource = nullptr; |
91 | QWaylandDestroyListener focusDestroyListener; |
92 | |
93 | QList<uint32_t> keys; |
94 | uint32_t modsDepressed = 0; |
95 | uint32_t modsLatched = 0; |
96 | uint32_t modsLocked = 0; |
97 | uint32_t group = 0; |
98 | |
99 | uint32_t shiftIndex = 0; |
100 | uint32_t controlIndex = 0; |
101 | uint32_t altIndex = 0; |
102 | |
103 | Qt::KeyboardModifiers currentModifierState; |
104 | |
105 | bool pendingKeymap = false; |
106 | #if QT_CONFIG(xkbcommon) |
107 | size_t keymap_size; |
108 | int keymap_fd = -1; |
109 | char *keymap_area = nullptr; |
110 | using ScanCodeKey = std::pair<uint,int>; // group/layout and QtKey |
111 | QMap<ScanCodeKey, uint> scanCodesByQtKey; |
112 | QXkbCommon::ScopedXKBState mXkbState; |
113 | #endif |
114 | |
115 | quint32 repeatRate = 40; |
116 | quint32 repeatDelay = 400; |
117 | }; |
118 | |
119 | QT_END_NAMESPACE |
120 | |
121 | #endif // QTWAYLAND_QWLKEYBOARD_P_H |
122 | |