1 /*
2  * This an unstable interface of wlroots. No guarantees are made regarding the
3  * future consistency of this API.
4  */
5 #ifndef WLR_USE_UNSTABLE
6 #error "Add -DWLR_USE_UNSTABLE to enable unstable wlroots features"
7 #endif
8 
9 #ifndef WLR_TYPES_WLR_TABLET_V2_H
10 #define WLR_TYPES_WLR_TABLET_V2_H
11 
12 #include <wayland-server-core.h>
13 #include <wlr/types/wlr_seat.h>
14 #include <wlr/types/wlr_input_device.h>
15 
16 #include "tablet-unstable-v2-protocol.h"
17 
18 /* This can probably be even lower,the tools don't have a lot of buttons */
19 #define WLR_TABLET_V2_TOOL_BUTTONS_CAP 16
20 
21 struct wlr_tablet_pad_v2_grab_interface;
22 
23 struct wlr_tablet_pad_v2_grab {
24 	const struct wlr_tablet_pad_v2_grab_interface *interface;
25 	struct wlr_tablet_v2_tablet_pad *pad;
26 	void *data;
27 };
28 
29 struct wlr_tablet_tool_v2_grab_interface;
30 
31 struct wlr_tablet_tool_v2_grab {
32 	const struct wlr_tablet_tool_v2_grab_interface *interface;
33 	struct wlr_tablet_v2_tablet_tool *tool;
34 	void *data;
35 };
36 
37 struct wlr_tablet_client_v2;
38 struct wlr_tablet_tool_client_v2;
39 struct wlr_tablet_pad_client_v2;
40 
41 struct wlr_tablet_manager_v2 {
42 	struct wl_global *wl_global;
43 	struct wl_list clients; // wlr_tablet_manager_client_v2::link
44 	struct wl_list seats; // wlr_tablet_seat_v2::link
45 
46 	struct wl_listener display_destroy;
47 
48 	struct {
49 		struct wl_signal destroy;
50 	} events;
51 
52 	void *data;
53 };
54 
55 struct wlr_tablet_v2_tablet {
56 	struct wl_list link; // wlr_tablet_seat_v2::tablets
57 	struct wlr_tablet *wlr_tablet;
58 	struct wlr_input_device *wlr_device;
59 	struct wl_list clients; // wlr_tablet_client_v2::tablet_link
60 
61 	struct wl_listener tool_destroy;
62 
63 	struct wlr_tablet_client_v2 *current_client;
64 };
65 
66 struct wlr_tablet_v2_tablet_tool {
67 	struct wl_list link; // wlr_tablet_seat_v2::tablets
68 	struct wlr_tablet_tool *wlr_tool;
69 	struct wl_list clients; // wlr_tablet_tool_client_v2::tool_link
70 
71 	struct wl_listener tool_destroy;
72 
73 	struct wlr_tablet_tool_client_v2 *current_client;
74 	struct wlr_surface *focused_surface;
75 	struct wl_listener surface_destroy;
76 
77 	struct wlr_tablet_tool_v2_grab *grab;
78 	struct wlr_tablet_tool_v2_grab default_grab;
79 
80 	uint32_t proximity_serial;
81 	bool is_down;
82 	uint32_t down_serial;
83 	size_t num_buttons;
84 	uint32_t pressed_buttons[WLR_TABLET_V2_TOOL_BUTTONS_CAP];
85 	uint32_t pressed_serials[WLR_TABLET_V2_TOOL_BUTTONS_CAP];
86 
87 	struct {
88 		struct wl_signal set_cursor; // struct wlr_tablet_v2_event_cursor
89 	} events;
90 };
91 
92 struct wlr_tablet_v2_tablet_pad {
93 	struct wl_list link; // wlr_tablet_seat_v2::pads
94 	struct wlr_tablet_pad *wlr_pad;
95 	struct wlr_input_device *wlr_device;
96 	struct wl_list clients; // wlr_tablet_pad_client_v2::pad_link
97 
98 	size_t group_count;
99 	uint32_t *groups;
100 
101 	struct wl_listener pad_destroy;
102 
103 	struct wlr_tablet_pad_client_v2 *current_client;
104 	struct wlr_tablet_pad_v2_grab *grab;
105 	struct wlr_tablet_pad_v2_grab default_grab;
106 
107 	struct {
108 		struct wl_signal button_feedback; // struct wlr_tablet_v2_event_feedback
109 		struct wl_signal strip_feedback; // struct wlr_tablet_v2_event_feedback
110 		struct wl_signal ring_feedback; // struct wlr_tablet_v2_event_feedback
111 	} events;
112 };
113 
114 struct wlr_tablet_v2_event_cursor {
115 	struct wlr_surface *surface;
116 	uint32_t serial;
117 	int32_t hotspot_x;
118 	int32_t hotspot_y;
119 	struct wlr_seat_client *seat_client;
120 };
121 
122 struct wlr_tablet_v2_event_feedback {
123 	const char *description;
124 	size_t index;
125 	uint32_t serial;
126 };
127 
128 struct wlr_tablet_v2_tablet *wlr_tablet_create(
129 	struct wlr_tablet_manager_v2 *manager,
130 	struct wlr_seat *wlr_seat,
131 	struct wlr_input_device *wlr_device);
132 
133 struct wlr_tablet_v2_tablet_pad *wlr_tablet_pad_create(
134 	struct wlr_tablet_manager_v2 *manager,
135 	struct wlr_seat *wlr_seat,
136 	struct wlr_input_device *wlr_device);
137 
138 struct wlr_tablet_v2_tablet_tool *wlr_tablet_tool_create(
139 	struct wlr_tablet_manager_v2 *manager,
140 	struct wlr_seat *wlr_seat,
141 	struct wlr_tablet_tool *wlr_tool);
142 
143 struct wlr_tablet_manager_v2 *wlr_tablet_v2_create(struct wl_display *display);
144 
145 void wlr_send_tablet_v2_tablet_tool_proximity_in(
146 	struct wlr_tablet_v2_tablet_tool *tool,
147 	struct wlr_tablet_v2_tablet *tablet,
148 	struct wlr_surface *surface);
149 
150 void wlr_send_tablet_v2_tablet_tool_down(struct wlr_tablet_v2_tablet_tool *tool);
151 void wlr_send_tablet_v2_tablet_tool_up(struct wlr_tablet_v2_tablet_tool *tool);
152 
153 void wlr_send_tablet_v2_tablet_tool_motion(
154 	struct wlr_tablet_v2_tablet_tool *tool, double x, double y);
155 
156 void wlr_send_tablet_v2_tablet_tool_pressure(
157 	struct wlr_tablet_v2_tablet_tool *tool, double pressure);
158 
159 void wlr_send_tablet_v2_tablet_tool_distance(
160 	struct wlr_tablet_v2_tablet_tool *tool, double distance);
161 
162 void wlr_send_tablet_v2_tablet_tool_tilt(
163 	struct wlr_tablet_v2_tablet_tool *tool, double x, double y);
164 
165 void wlr_send_tablet_v2_tablet_tool_rotation(
166 	struct wlr_tablet_v2_tablet_tool *tool, double degrees);
167 
168 void wlr_send_tablet_v2_tablet_tool_slider(
169 	struct wlr_tablet_v2_tablet_tool *tool, double position);
170 
171 void wlr_send_tablet_v2_tablet_tool_wheel(
172 	struct wlr_tablet_v2_tablet_tool *tool, double degrees, int32_t clicks);
173 
174 void wlr_send_tablet_v2_tablet_tool_proximity_out(
175 	struct wlr_tablet_v2_tablet_tool *tool);
176 
177 void wlr_send_tablet_v2_tablet_tool_button(
178 	struct wlr_tablet_v2_tablet_tool *tool, uint32_t button,
179 	enum zwp_tablet_pad_v2_button_state state);
180 
181 
182 
183 void wlr_tablet_v2_tablet_tool_notify_proximity_in(
184 	struct wlr_tablet_v2_tablet_tool *tool,
185 	struct wlr_tablet_v2_tablet *tablet,
186 	struct wlr_surface *surface);
187 
188 void wlr_tablet_v2_tablet_tool_notify_down(struct wlr_tablet_v2_tablet_tool *tool);
189 void wlr_tablet_v2_tablet_tool_notify_up(struct wlr_tablet_v2_tablet_tool *tool);
190 
191 void wlr_tablet_v2_tablet_tool_notify_motion(
192 	struct wlr_tablet_v2_tablet_tool *tool, double x, double y);
193 
194 void wlr_tablet_v2_tablet_tool_notify_pressure(
195 	struct wlr_tablet_v2_tablet_tool *tool, double pressure);
196 
197 void wlr_tablet_v2_tablet_tool_notify_distance(
198 	struct wlr_tablet_v2_tablet_tool *tool, double distance);
199 
200 void wlr_tablet_v2_tablet_tool_notify_tilt(
201 	struct wlr_tablet_v2_tablet_tool *tool, double x, double y);
202 
203 void wlr_tablet_v2_tablet_tool_notify_rotation(
204 	struct wlr_tablet_v2_tablet_tool *tool, double degrees);
205 
206 void wlr_tablet_v2_tablet_tool_notify_slider(
207 	struct wlr_tablet_v2_tablet_tool *tool, double position);
208 
209 void wlr_tablet_v2_tablet_tool_notify_wheel(
210 	struct wlr_tablet_v2_tablet_tool *tool, double degrees, int32_t clicks);
211 
212 void wlr_tablet_v2_tablet_tool_notify_proximity_out(
213 	struct wlr_tablet_v2_tablet_tool *tool);
214 
215 void wlr_tablet_v2_tablet_tool_notify_button(
216 	struct wlr_tablet_v2_tablet_tool *tool, uint32_t button,
217 	enum zwp_tablet_pad_v2_button_state state);
218 
219 
220 struct wlr_tablet_tool_v2_grab_interface {
221 	void (*proximity_in)(
222 		struct wlr_tablet_tool_v2_grab *grab,
223 		struct wlr_tablet_v2_tablet *tablet,
224 		struct wlr_surface *surface);
225 
226 	void (*down)(struct wlr_tablet_tool_v2_grab *grab);
227 	void (*up)(struct wlr_tablet_tool_v2_grab *grab);
228 
229 	void (*motion)(struct wlr_tablet_tool_v2_grab *grab, double x, double y);
230 
231 	void (*pressure)(struct wlr_tablet_tool_v2_grab *grab, double pressure);
232 
233 	void (*distance)(struct wlr_tablet_tool_v2_grab *grab, double distance);
234 
235 	void (*tilt)(struct wlr_tablet_tool_v2_grab *grab, double x, double y);
236 
237 	void (*rotation)(struct wlr_tablet_tool_v2_grab *grab, double degrees);
238 
239 	void (*slider)(struct wlr_tablet_tool_v2_grab *grab, double position);
240 
241 	void (*wheel)(struct wlr_tablet_tool_v2_grab *grab, double degrees, int32_t clicks);
242 
243 	void (*proximity_out)(struct wlr_tablet_tool_v2_grab *grab);
244 
245 	void (*button)(
246 		struct wlr_tablet_tool_v2_grab *grab, uint32_t button,
247 		enum zwp_tablet_pad_v2_button_state state);
248 	void (*cancel)(struct wlr_tablet_tool_v2_grab *grab);
249 };
250 
251 void wlr_tablet_tool_v2_start_grab(struct wlr_tablet_v2_tablet_tool *tool, struct wlr_tablet_tool_v2_grab *grab);
252 void wlr_tablet_tool_v2_end_grab(struct wlr_tablet_v2_tablet_tool *tool);
253 
254 void wlr_tablet_tool_v2_start_implicit_grab(struct wlr_tablet_v2_tablet_tool *tool);
255 
256 bool wlr_tablet_tool_v2_has_implicit_grab(
257 	struct wlr_tablet_v2_tablet_tool *tool);
258 
259 uint32_t wlr_send_tablet_v2_tablet_pad_enter(
260 	struct wlr_tablet_v2_tablet_pad *pad,
261 	struct wlr_tablet_v2_tablet *tablet,
262 	struct wlr_surface *surface);
263 
264 void wlr_send_tablet_v2_tablet_pad_button(
265 	struct wlr_tablet_v2_tablet_pad *pad, size_t button,
266 	uint32_t time, enum zwp_tablet_pad_v2_button_state state);
267 
268 void wlr_send_tablet_v2_tablet_pad_strip(struct wlr_tablet_v2_tablet_pad *pad,
269 	uint32_t strip, double position, bool finger, uint32_t time);
270 void wlr_send_tablet_v2_tablet_pad_ring(struct wlr_tablet_v2_tablet_pad *pad,
271 	uint32_t ring, double position, bool finger, uint32_t time);
272 
273 uint32_t wlr_send_tablet_v2_tablet_pad_leave(struct wlr_tablet_v2_tablet_pad *pad,
274 	struct wlr_surface *surface);
275 
276 uint32_t wlr_send_tablet_v2_tablet_pad_mode(struct wlr_tablet_v2_tablet_pad *pad,
277 	size_t group, uint32_t mode, uint32_t time);
278 
279 
280 uint32_t wlr_tablet_v2_tablet_pad_notify_enter(
281 	struct wlr_tablet_v2_tablet_pad *pad,
282 	struct wlr_tablet_v2_tablet *tablet,
283 	struct wlr_surface *surface);
284 
285 void wlr_tablet_v2_tablet_pad_notify_button(
286 	struct wlr_tablet_v2_tablet_pad *pad, size_t button,
287 	uint32_t time, enum zwp_tablet_pad_v2_button_state state);
288 
289 void wlr_tablet_v2_tablet_pad_notify_strip(
290 	struct wlr_tablet_v2_tablet_pad *pad,
291 	uint32_t strip, double position, bool finger, uint32_t time);
292 void wlr_tablet_v2_tablet_pad_notify_ring(
293 	struct wlr_tablet_v2_tablet_pad *pad,
294 	uint32_t ring, double position, bool finger, uint32_t time);
295 
296 uint32_t wlr_tablet_v2_tablet_pad_notify_leave(
297 	struct wlr_tablet_v2_tablet_pad *pad, struct wlr_surface *surface);
298 
299 uint32_t wlr_tablet_v2_tablet_pad_notify_mode(
300 	struct wlr_tablet_v2_tablet_pad *pad,
301 	size_t group, uint32_t mode, uint32_t time);
302 
303 struct wlr_tablet_pad_v2_grab_interface {
304 	uint32_t (*enter)(
305 		struct wlr_tablet_pad_v2_grab *grab,
306 		struct wlr_tablet_v2_tablet *tablet,
307 		struct wlr_surface *surface);
308 
309 	void (*button)(struct wlr_tablet_pad_v2_grab *grab,size_t button,
310 		uint32_t time, enum zwp_tablet_pad_v2_button_state state);
311 
312 	void (*strip)(struct wlr_tablet_pad_v2_grab *grab,
313 		uint32_t strip, double position, bool finger, uint32_t time);
314 	void (*ring)(struct wlr_tablet_pad_v2_grab *grab,
315 		uint32_t ring, double position, bool finger, uint32_t time);
316 
317 	uint32_t (*leave)(struct wlr_tablet_pad_v2_grab *grab,
318 		struct wlr_surface *surface);
319 
320 	uint32_t (*mode)(struct wlr_tablet_pad_v2_grab *grab,
321 		size_t group, uint32_t mode, uint32_t time);
322 
323 	void (*cancel)(struct wlr_tablet_pad_v2_grab *grab);
324 };
325 
326 void wlr_tablet_v2_end_grab(struct wlr_tablet_v2_tablet_pad *pad);
327 void wlr_tablet_v2_start_grab(struct wlr_tablet_v2_tablet_pad *pad, struct wlr_tablet_pad_v2_grab *grab);
328 
329 bool wlr_surface_accepts_tablet_v2(struct wlr_tablet_v2_tablet *tablet,
330 	struct wlr_surface *surface);
331 #endif /* WLR_TYPES_WLR_TABLET_V2_H */
332