1 | /* |
2 | SPDX-FileCopyrightText: 2014 Martin Gräßlin <mgraesslin@kde.org> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL |
5 | */ |
6 | #ifndef WAYLAND_KEYBOARD_H |
7 | #define WAYLAND_KEYBOARD_H |
8 | |
9 | #include <QObject> |
10 | |
11 | #include "KWayland/Client/kwaylandclient_export.h" |
12 | |
13 | struct wl_keyboard; |
14 | |
15 | namespace KWayland |
16 | { |
17 | namespace Client |
18 | { |
19 | class Surface; |
20 | |
21 | /** |
22 | * @short Wrapper for the wl_keyboard interface. |
23 | * |
24 | * This class is a convenient wrapper for the wl_keyboard interface. |
25 | * |
26 | * To create an instance use Seat::createKeyboard. |
27 | * |
28 | * @see Seat |
29 | **/ |
30 | class KWAYLANDCLIENT_EXPORT Keyboard : public QObject |
31 | { |
32 | Q_OBJECT |
33 | public: |
34 | enum class KeyState { |
35 | Released, |
36 | Pressed, |
37 | }; |
38 | explicit Keyboard(QObject *parent = nullptr); |
39 | ~Keyboard() override; |
40 | |
41 | /** |
42 | * @returns @c true if managing a wl_keyboard. |
43 | **/ |
44 | bool isValid() const; |
45 | /** |
46 | * Setup this Keyboard to manage the @p keyboard. |
47 | * When using Seat::createKeyboard there is no need to call this |
48 | * method. |
49 | **/ |
50 | void setup(wl_keyboard *keyboard); |
51 | /** |
52 | * Releases the wl_keyboard interface. |
53 | * After the interface has been released the Keyboard instance is no |
54 | * longer valid and can be setup with another wl_keyboard interface. |
55 | * |
56 | * This method is automatically invoked when the Seat which created this |
57 | * Keyboard gets released. |
58 | **/ |
59 | void release(); |
60 | /** |
61 | * Destroys the data held by this Keyboard. |
62 | * This method is supposed to be used when the connection to the Wayland |
63 | * server goes away. If the connection is not valid anymore, it's not |
64 | * possible to call release anymore as that calls into the Wayland |
65 | * connection and the call would fail. This method cleans up the data, so |
66 | * that the instance can be deleted or set up to a new wl_keyboard interface |
67 | * once there is a new connection available. |
68 | * |
69 | * This method is automatically invoked when the Seat which created this |
70 | * Keyboard gets destroyed. |
71 | * |
72 | * @see release |
73 | **/ |
74 | void destroy(); |
75 | |
76 | /** |
77 | * @returns The Surface the Keyboard is on, may be @c null. |
78 | **/ |
79 | Surface *enteredSurface() const; |
80 | /** |
81 | * @overload |
82 | **/ |
83 | Surface *enteredSurface(); |
84 | |
85 | /** |
86 | * @returns The keys that were reported in the enter event. |
87 | **/ |
88 | QList<quint32> enteredKeys() const; |
89 | |
90 | /** |
91 | * @returns Whether key repeat is enabled on this keyboard |
92 | * @see keyRepeatRate |
93 | * @see keyRepeatDelay |
94 | * @see keyRepeatChanged |
95 | * @since 5.5 |
96 | **/ |
97 | bool isKeyRepeatEnabled() const; |
98 | /** |
99 | * @returns the key repeat rate in characters per second. |
100 | * @see isKeyRepeatEnabled |
101 | * @see keyRepeatDelay |
102 | * @see keyRepeatChanged |
103 | * @since 5.5 |
104 | **/ |
105 | qint32 keyRepeatRate() const; |
106 | /** |
107 | * @returns the delay in millisecond for key repeat after a press. |
108 | * @see isKeyRepeatEnabled |
109 | * @see keyRepeatRate |
110 | * @see keyRepeatChanged |
111 | * @since 5.5 |
112 | **/ |
113 | qint32 keyRepeatDelay() const; |
114 | |
115 | operator wl_keyboard *(); |
116 | operator wl_keyboard *() const; |
117 | |
118 | Q_SIGNALS: |
119 | /** |
120 | * Notification that this seat's Keyboard is focused on a certain surface. |
121 | * |
122 | * @param serial The serial for this enter |
123 | **/ |
124 | void entered(quint32 serial); |
125 | /** |
126 | * Notification that this seat's Keyboard is no longer focused on a certain surface. |
127 | * |
128 | * The leave notification is sent before the enter notification for the new focus. |
129 | * |
130 | * @param serial The serial of this enter |
131 | **/ |
132 | void left(quint32 serial); |
133 | /** |
134 | * This signal provides a file descriptor to the client which can |
135 | * be memory-mapped to provide a keyboard mapping description. |
136 | * |
137 | * The signal is only emitted if the keymap format is libxkbcommon compatible. |
138 | * |
139 | * @param fd file descriptor of the keymap |
140 | * @param size The size of the keymap |
141 | **/ |
142 | void keymapChanged(int fd, quint32 size); |
143 | /** |
144 | * A key was pressed or released. |
145 | * The time argument is a timestamp with millisecond granularity, with an undefined base. |
146 | * @param key The key which was pressed |
147 | * @param state Whether the key got @c Released or @c Pressed |
148 | * @param time The timestamp |
149 | **/ |
150 | void keyChanged(quint32 key, KWayland::Client::Keyboard::KeyState state, quint32 time); |
151 | /** |
152 | * Notifies clients that the modifier and/or group state has changed, |
153 | * and it should update its local state. |
154 | **/ |
155 | void modifiersChanged(quint32 depressed, quint32 latched, quint32 locked, quint32 group); |
156 | /** |
157 | * Emitted whenever information on key repeat changed. |
158 | * @see isKeyRepeatEnabled |
159 | * @see keyRepeatRate |
160 | * @see keyRepeatDelay |
161 | * @since 5.5 |
162 | **/ |
163 | void keyRepeatChanged(); |
164 | |
165 | private: |
166 | class Private; |
167 | QScopedPointer<Private> d; |
168 | }; |
169 | |
170 | } |
171 | } |
172 | |
173 | Q_DECLARE_METATYPE(KWayland::Client::Keyboard::KeyState) |
174 | |
175 | #endif |
176 | |