forked from colemickens/platform2-sommelier
-
Notifications
You must be signed in to change notification settings - Fork 3
/
sommelier.h
576 lines (501 loc) · 14.1 KB
/
sommelier.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
// Copyright 2018 The Chromium OS Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef VM_TOOLS_SOMMELIER_SOMMELIER_H_
#define VM_TOOLS_SOMMELIER_SOMMELIER_H_
#include <sys/types.h>
#include <wayland-server.h>
#include <wayland-util.h>
#include <xcb/xcb.h>
#include <xkbcommon/xkbcommon.h>
#define SOMMELIER_VERSION "0.20"
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
#define ARRAY_SIZE(a) (sizeof(a) / sizeof(a[0]))
#define UNUSED(x) ((void)(x))
#define CONTROL_MASK (1 << 0)
#define ALT_MASK (1 << 1)
#define SHIFT_MASK (1 << 2)
struct sl_global;
struct sl_compositor;
struct sl_shm;
struct sl_shell;
struct sl_data_device_manager;
struct sl_data_offer;
struct sl_data_source;
struct sl_xdg_shell;
struct sl_subcompositor;
struct sl_aura_shell;
struct sl_viewporter;
struct sl_linux_dmabuf;
struct sl_keyboard_extension;
struct sl_text_input_manager;
struct sl_relative_pointer_manager;
struct sl_pointer_constraints;
struct sl_window;
struct zaura_shell;
struct zcr_keyboard_extension_v1;
enum {
ATOM_WM_S0,
ATOM_WM_PROTOCOLS,
ATOM_WM_STATE,
ATOM_WM_CHANGE_STATE,
ATOM_WM_DELETE_WINDOW,
ATOM_WM_TAKE_FOCUS,
ATOM_WM_CLIENT_LEADER,
ATOM_WL_SURFACE_ID,
ATOM_UTF8_STRING,
ATOM_MOTIF_WM_HINTS,
ATOM_NET_ACTIVE_WINDOW,
ATOM_NET_FRAME_EXTENTS,
ATOM_NET_STARTUP_ID,
ATOM_NET_SUPPORTED,
ATOM_NET_SUPPORTING_WM_CHECK,
ATOM_NET_WM_NAME,
ATOM_NET_WM_MOVERESIZE,
ATOM_NET_WM_STATE,
ATOM_NET_WM_STATE_FULLSCREEN,
ATOM_NET_WM_STATE_MAXIMIZED_VERT,
ATOM_NET_WM_STATE_MAXIMIZED_HORZ,
ATOM_CLIPBOARD,
ATOM_CLIPBOARD_MANAGER,
ATOM_TARGETS,
ATOM_TIMESTAMP,
ATOM_TEXT,
ATOM_INCR,
ATOM_WL_SELECTION,
ATOM_GTK_THEME_VARIANT,
ATOM_LAST = ATOM_GTK_THEME_VARIANT,
};
enum {
SHM_DRIVER_NOOP,
SHM_DRIVER_DMABUF,
SHM_DRIVER_VIRTWL,
SHM_DRIVER_VIRTWL_DMABUF,
};
enum {
DATA_DRIVER_NOOP,
DATA_DRIVER_VIRTWL,
};
struct sl_context {
char** runprog;
struct wl_display* display;
struct wl_display* host_display;
struct wl_client* client;
struct sl_compositor* compositor;
struct sl_subcompositor* subcompositor;
struct sl_shm* shm;
struct sl_shell* shell;
struct sl_data_device_manager* data_device_manager;
struct sl_xdg_shell* xdg_shell;
struct sl_aura_shell* aura_shell;
struct sl_viewporter* viewporter;
struct sl_linux_dmabuf* linux_dmabuf;
struct sl_keyboard_extension* keyboard_extension;
struct sl_text_input_manager* text_input_manager;
struct sl_relative_pointer_manager* relative_pointer_manager;
struct sl_pointer_constraints* pointer_constraints;
struct wl_list outputs;
struct wl_list seats;
struct wl_event_source* display_event_source;
struct wl_event_source* display_ready_event_source;
struct wl_event_source* sigchld_event_source;
struct wl_array dpi;
int shm_driver;
int data_driver;
int wm_fd;
int virtwl_fd;
int virtwl_ctx_fd;
int virtwl_socket_fd;
struct wl_event_source* virtwl_ctx_event_source;
struct wl_event_source* virtwl_socket_event_source;
const char* drm_device;
struct gbm_device* gbm;
int xwayland;
pid_t xwayland_pid;
pid_t child_pid;
pid_t peer_pid;
struct xkb_context* xkb_context;
struct wl_list accelerators;
struct wl_list registries;
struct wl_list globals;
struct wl_list host_outputs;
int next_global_id;
xcb_connection_t* connection;
struct wl_event_source* connection_event_source;
const xcb_query_extension_reply_t* xfixes_extension;
xcb_screen_t* screen;
xcb_window_t window;
struct wl_list windows, unpaired_windows;
struct sl_window* host_focus_window;
int needs_set_input_focus;
double desired_scale;
double scale;
const char* application_id;
int exit_with_child;
const char* sd_notify;
int clipboard_manager;
uint32_t frame_color;
uint32_t dark_frame_color;
int fullscreen_mode;
const char* overridden_output_scales;
int pointer_scale;
struct sl_host_seat* default_seat;
xcb_window_t selection_window;
xcb_window_t selection_owner;
int selection_incremental_transfer;
xcb_selection_request_event_t selection_request;
xcb_timestamp_t selection_timestamp;
struct wl_data_device* selection_data_device;
struct sl_data_offer* selection_data_offer;
struct sl_data_source* selection_data_source;
int selection_data_source_send_fd;
struct wl_list selection_data_source_send_pending;
struct wl_event_source* selection_send_event_source;
xcb_get_property_reply_t* selection_property_reply;
int selection_property_offset;
struct wl_event_source* selection_event_source;
xcb_atom_t selection_data_type;
struct wl_array selection_data;
int selection_data_offer_receive_fd;
int selection_data_ack_pending;
union {
const char* name;
xcb_intern_atom_cookie_t cookie;
xcb_atom_t value;
} atoms[ATOM_LAST + 1];
xcb_visualid_t visual_ids[256];
xcb_colormap_t colormaps[256];
};
struct sl_compositor {
struct sl_context* ctx;
uint32_t id;
uint32_t version;
struct sl_global* host_global;
struct wl_compositor* internal;
};
struct sl_shm {
struct sl_context* ctx;
uint32_t id;
struct sl_global* host_global;
struct wl_shm* internal;
};
struct sl_seat {
struct sl_context* ctx;
uint32_t id;
uint32_t version;
struct sl_global* host_global;
uint32_t last_serial;
struct wl_list link;
};
struct sl_host_pointer {
struct sl_seat* seat;
struct wl_resource* resource;
struct wl_pointer* proxy;
struct wl_resource* focus_resource;
struct wl_listener focus_resource_listener;
uint32_t focus_serial;
uint32_t time;
wl_fixed_t axis_delta[2];
int32_t axis_discrete[2];
};
struct sl_relative_pointer_manager {
struct sl_context* ctx;
uint32_t id;
struct sl_global* host_global;
struct zwp_relative_pointer_manager_v1* internal;
};
struct sl_viewport {
struct wl_list link;
wl_fixed_t src_x;
wl_fixed_t src_y;
wl_fixed_t src_width;
wl_fixed_t src_height;
int32_t dst_width;
int32_t dst_height;
};
struct sl_host_callback {
struct wl_resource* resource;
struct wl_callback* proxy;
};
struct sl_host_surface {
struct sl_context* ctx;
struct wl_resource* resource;
struct wl_surface* proxy;
struct wp_viewport* viewport;
uint32_t contents_width;
uint32_t contents_height;
int32_t contents_scale;
struct wl_list contents_viewport;
struct sl_mmap* contents_shm_mmap;
int has_role;
int has_output;
uint32_t last_event_serial;
struct sl_output_buffer* current_buffer;
struct wl_list released_buffers;
struct wl_list busy_buffers;
int defer_commits_until_configure;
int is_pointer;
};
struct sl_host_region {
struct sl_context* ctx;
struct wl_resource* resource;
struct wl_region* proxy;
};
struct sl_host_buffer {
struct wl_resource* resource;
struct wl_buffer* proxy;
uint32_t width;
uint32_t height;
struct sl_mmap* shm_mmap;
uint32_t shm_format;
struct sl_sync_point* sync_point;
};
struct sl_data_source_send_request {
int fd;
xcb_intern_atom_cookie_t cookie;
struct sl_data_source* data_source;
struct wl_list link;
};
struct sl_subcompositor {
struct sl_context* ctx;
uint32_t id;
struct sl_global* host_global;
};
struct sl_shell {
struct sl_context* ctx;
uint32_t id;
struct sl_global* host_global;
};
struct sl_output {
struct sl_context* ctx;
uint32_t id;
uint32_t version;
struct sl_global* host_global;
struct wl_list link;
};
struct sl_host_output {
struct sl_context* ctx;
struct wl_resource* resource;
struct wl_output* proxy;
struct zaura_output* aura_output;
int internal;
int x;
int y;
int physical_width;
int physical_height;
int subpixel;
char* make;
char* model;
char* name;
int transform;
uint32_t flags;
int width;
int height;
int refresh;
int scale_factor;
int current_scale;
int preferred_scale;
int device_scale_factor;
int expecting_scale;
double applied_scale;
struct wl_list link;
};
struct sl_host_seat {
struct sl_seat* seat;
struct wl_resource* resource;
struct wl_seat* proxy;
};
struct sl_accelerator {
struct wl_list link;
uint32_t modifiers;
xkb_keysym_t symbol;
};
struct sl_keyboard_extension {
struct sl_context* ctx;
uint32_t id;
struct zcr_keyboard_extension_v1* internal;
};
struct sl_data_device_manager {
struct sl_context* ctx;
uint32_t id;
uint32_t version;
struct sl_global* host_global;
struct wl_data_device_manager* internal;
};
struct sl_data_offer {
struct sl_context* ctx;
struct wl_data_offer* internal;
struct wl_array atoms; // Contains xcb_atom_t
struct wl_array cookies; // Contains xcb_intern_atom_cookie_t
};
struct sl_text_input_manager {
struct sl_context* ctx;
uint32_t id;
struct sl_global* host_global;
struct zwp_text_input_manager_v1* internal;
};
struct sl_pointer_constraints {
struct sl_context* ctx;
uint32_t id;
struct sl_global* host_global;
struct zwp_pointer_constraints_v1* internal;
};
struct sl_viewporter {
struct sl_context* ctx;
uint32_t id;
struct sl_global* host_viewporter_global;
struct wp_viewporter* internal;
};
struct sl_xdg_shell {
struct sl_context* ctx;
uint32_t id;
struct sl_global* host_global;
struct xdg_wm_base* internal;
};
struct sl_aura_shell {
struct sl_context* ctx;
uint32_t id;
uint32_t version;
struct sl_global* host_gtk_shell_global;
struct zaura_shell* internal;
};
struct sl_linux_dmabuf {
struct sl_context* ctx;
uint32_t id;
uint32_t version;
struct sl_global* host_drm_global;
struct zwp_linux_dmabuf_v1* internal;
};
struct sl_global {
struct sl_context* ctx;
const struct wl_interface* interface;
uint32_t name;
uint32_t version;
void* data;
wl_global_bind_func_t bind;
struct wl_list link;
};
struct sl_host_registry {
struct sl_context* ctx;
struct wl_resource* resource;
struct wl_list link;
};
typedef void (*sl_begin_end_access_func_t)(int fd);
struct sl_mmap {
int refcount;
int fd;
void* addr;
size_t size;
size_t bpp;
size_t num_planes;
size_t offset[2];
size_t stride[2];
size_t y_ss[2];
sl_begin_end_access_func_t begin_write;
sl_begin_end_access_func_t end_write;
struct wl_resource* buffer_resource;
};
typedef void (*sl_sync_func_t)(struct sl_context* ctx,
struct sl_sync_point* sync_point);
struct sl_sync_point {
int fd;
sl_sync_func_t sync;
};
struct sl_config {
uint32_t serial;
uint32_t mask;
uint32_t values[5];
uint32_t states_length;
uint32_t states[3];
};
struct sl_window {
struct sl_context* ctx;
xcb_window_t id;
xcb_window_t frame_id;
uint32_t host_surface_id;
int unpaired;
int x;
int y;
int width;
int height;
int border_width;
int depth;
int managed;
int realized;
int activated;
int maximized;
int allow_resize;
xcb_window_t transient_for;
xcb_window_t client_leader;
int decorated;
char* name;
char* clazz;
char* startup_id;
int dark_frame;
uint32_t size_flags;
int focus_model_take_focus;
int min_width;
int min_height;
int max_width;
int max_height;
struct sl_config next_config;
struct sl_config pending_config;
struct xdg_surface* xdg_surface;
struct xdg_toplevel* xdg_toplevel;
struct xdg_popup* xdg_popup;
struct zaura_surface* aura_surface;
struct wl_list link;
};
struct sl_host_buffer* sl_create_host_buffer(struct wl_client* client,
uint32_t id,
struct wl_buffer* proxy,
int32_t width,
int32_t height);
struct sl_global* sl_global_create(struct sl_context* ctx,
const struct wl_interface* interface,
int version,
void* data,
wl_global_bind_func_t bind);
struct sl_global* sl_compositor_global_create(struct sl_context* ctx);
size_t sl_shm_bpp_for_shm_format(uint32_t format);
size_t sl_shm_num_planes_for_shm_format(uint32_t format);
struct sl_global* sl_shm_global_create(struct sl_context* ctx);
struct sl_global* sl_subcompositor_global_create(struct sl_context* ctx);
struct sl_global* sl_shell_global_create(struct sl_context* ctx);
double sl_output_aura_scale_factor_to_double(int scale_factor);
void sl_output_send_host_output_state(struct sl_host_output* host);
struct sl_global* sl_output_global_create(struct sl_output* output);
struct sl_global* sl_seat_global_create(struct sl_seat* seat);
struct sl_global* sl_relative_pointer_manager_global_create(
struct sl_context* ctx);
struct sl_global* sl_data_device_manager_global_create(struct sl_context* ctx);
struct sl_global* sl_viewporter_global_create(struct sl_context* ctx);
struct sl_global* sl_xdg_shell_global_create(struct sl_context* ctx);
struct sl_global* sl_gtk_shell_global_create(struct sl_context* ctx);
struct sl_global* sl_drm_global_create(struct sl_context* ctx);
struct sl_global* sl_text_input_manager_global_create(struct sl_context* ctx);
struct sl_global* sl_pointer_constraints_global_create(struct sl_context* ctx);
void sl_set_display_implementation(struct sl_context* ctx);
struct sl_mmap* sl_mmap_create(int fd,
size_t size,
size_t bpp,
size_t num_planes,
size_t offset0,
size_t stride0,
size_t offset1,
size_t stride1,
size_t y_ss0,
size_t y_ss1);
struct sl_mmap* sl_mmap_ref(struct sl_mmap* map);
void sl_mmap_unref(struct sl_mmap* map);
struct sl_sync_point* sl_sync_point_create(int fd);
void sl_sync_point_destroy(struct sl_sync_point* sync_point);
void sl_host_seat_added(struct sl_host_seat* host);
void sl_host_seat_removed(struct sl_host_seat* host);
void sl_restack_windows(struct sl_context* ctx, uint32_t focus_resource_id);
void sl_roundtrip(struct sl_context* ctx);
int sl_process_pending_configure_acks(struct sl_window* window,
struct sl_host_surface* host_surface);
void sl_window_update(struct sl_window* window);
#endif // VM_TOOLS_SOMMELIER_SOMMELIER_H_