Directory: | ./ |
---|---|
File: | src/client/keyboard.h |
Date: | 2024-01-22 17:25:27 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 1 | 1 | 100.0% |
Branches: | 3 | 6 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | /******************************************************************** | ||
2 | Copyright 2014 Martin Gräßlin <mgraesslin@kde.org> | ||
3 | |||
4 | This library is free software; you can redistribute it and/or | ||
5 | modify it under the terms of the GNU Lesser General Public | ||
6 | License as published by the Free Software Foundation; either | ||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||
8 | later version accepted by the membership of KDE e.V. (or its | ||
9 | successor approved by the membership of KDE e.V.), which shall | ||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||
11 | |||
12 | This library is distributed in the hope that it will be useful, | ||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | Lesser General Public License for more details. | ||
16 | |||
17 | You should have received a copy of the GNU Lesser General Public | ||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | *********************************************************************/ | ||
20 | #ifndef WAYLAND_KEYBOARD_H | ||
21 | #define WAYLAND_KEYBOARD_H | ||
22 | |||
23 | #include <QObject> | ||
24 | // STD | ||
25 | #include <memory> | ||
26 | |||
27 | #include <Wrapland/Client/wraplandclient_export.h> | ||
28 | |||
29 | struct wl_keyboard; | ||
30 | |||
31 | namespace Wrapland | ||
32 | { | ||
33 | namespace Client | ||
34 | { | ||
35 | |||
36 | class Surface; | ||
37 | |||
38 | /** | ||
39 | * @short Wrapper for the wl_keyboard interface. | ||
40 | * | ||
41 | * This class is a convenient wrapper for the wl_keyboard interface. | ||
42 | * | ||
43 | * To create an instance use Seat::createKeyboard. | ||
44 | * | ||
45 | * @see Seat | ||
46 | **/ | ||
47 | class WRAPLANDCLIENT_EXPORT Keyboard : public QObject | ||
48 | { | ||
49 | Q_OBJECT | ||
50 | public: | ||
51 | enum class KeyState { | ||
52 | Released, | ||
53 | Pressed, | ||
54 | }; | ||
55 | explicit Keyboard(QObject* parent = nullptr); | ||
56 | virtual ~Keyboard(); | ||
57 | |||
58 | /** | ||
59 | * @returns @c true if managing a wl_keyboard. | ||
60 | **/ | ||
61 | bool isValid() const; | ||
62 | /** | ||
63 | * Setup this Keyboard to manage the @p keyboard. | ||
64 | * When using Seat::createKeyboard there is no need to call this | ||
65 | * method. | ||
66 | **/ | ||
67 | void setup(wl_keyboard* keyboard); | ||
68 | /** | ||
69 | * Releases the wl_keyboard interface. | ||
70 | * After the interface has been released the Keyboard instance is no | ||
71 | * longer valid and can be setup with another wl_keyboard interface. | ||
72 | * | ||
73 | * This method is automatically invoked when the Seat which created this | ||
74 | * Keyboard gets released. | ||
75 | **/ | ||
76 | void release(); | ||
77 | |||
78 | /** | ||
79 | * @returns The Surface the Keyboard is on, may be @c null. | ||
80 | **/ | ||
81 | Surface* enteredSurface() const; | ||
82 | /** | ||
83 | * @overload | ||
84 | **/ | ||
85 | Surface* enteredSurface(); | ||
86 | |||
87 | /** | ||
88 | * @returns Whether key repeat is enabled on this keyboard | ||
89 | * @see keyRepeatRate | ||
90 | * @see keyRepeatDelay | ||
91 | * @see keyRepeatChanged | ||
92 | * @since 5.5 | ||
93 | **/ | ||
94 | bool isKeyRepeatEnabled() const; | ||
95 | /** | ||
96 | * @returns the key repeat rate in characters per second. | ||
97 | * @see isKeyRepeatEnabled | ||
98 | * @see keyRepeatDelay | ||
99 | * @see keyRepeatChanged | ||
100 | * @since 5.5 | ||
101 | **/ | ||
102 | qint32 keyRepeatRate() const; | ||
103 | /** | ||
104 | * @returns the delay in millisecond for key repeat after a press. | ||
105 | * @see isKeyRepeatEnabled | ||
106 | * @see keyRepeatRate | ||
107 | * @see keyRepeatChanged | ||
108 | * @since 5.5 | ||
109 | **/ | ||
110 | qint32 keyRepeatDelay() const; | ||
111 | |||
112 | operator wl_keyboard*(); | ||
113 | operator wl_keyboard*() const; | ||
114 | |||
115 | Q_SIGNALS: | ||
116 | /** | ||
117 | * Notification that this seat's Keyboard is focused on a certain surface. | ||
118 | * | ||
119 | * @param serial The serial for this enter | ||
120 | **/ | ||
121 | void entered(quint32 serial); | ||
122 | /** | ||
123 | * Notification that this seat's Keyboard is no longer focused on a certain surface. | ||
124 | * | ||
125 | * The leave notification is sent before the enter notification for the new focus. | ||
126 | * | ||
127 | * @param serial The serial of this enter | ||
128 | **/ | ||
129 | void left(quint32 serial); | ||
130 | /** | ||
131 | * This signal provides a file descriptor to the client which can | ||
132 | * be memory-mapped to provide a keyboard mapping description. | ||
133 | * | ||
134 | * The signal is only emitted if the keymap format is libxkbcommon compatible. | ||
135 | * | ||
136 | * @param fd file descriptor of the keymap | ||
137 | * @param size The size of the keymap | ||
138 | **/ | ||
139 | void keymapChanged(int fd, quint32 size); | ||
140 | /** | ||
141 | * A key was pressed or released. | ||
142 | * The time argument is a timestamp with millisecond granularity, with an undefined base. | ||
143 | * @param key The key which was pressed | ||
144 | * @param state Whether the key got @c Released or @c Pressed | ||
145 | * @param time The timestamp | ||
146 | **/ | ||
147 | void keyChanged(quint32 key, Wrapland::Client::Keyboard::KeyState state, quint32 time); | ||
148 | /** | ||
149 | * Notifies clients that the modifier and/or group state has changed, | ||
150 | * and it should update its local state. | ||
151 | **/ | ||
152 | void modifiersChanged(quint32 depressed, quint32 latched, quint32 locked, quint32 group); | ||
153 | /** | ||
154 | * Emitted whenever information on key repeat changed. | ||
155 | * @see isKeyRepeatEnabled | ||
156 | * @see keyRepeatRate | ||
157 | * @see keyRepeatDelay | ||
158 | * @since 5.5 | ||
159 | **/ | ||
160 | void keyRepeatChanged(); | ||
161 | |||
162 | private: | ||
163 | class Private; | ||
164 | std::unique_ptr<Private> d; | ||
165 | }; | ||
166 | |||
167 | } | ||
168 | } | ||
169 | |||
170 |
3/6✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
|
2 | Q_DECLARE_METATYPE(Wrapland::Client::Keyboard::KeyState) |
171 | |||
172 | #endif | ||
173 |