v4 / vlib / sokol / sapp / sapp_linux.c.v
1182 lines · 1000 sloc · 35.97 KB · badd3466fd7ddc8a543badb4ecda4d999770ff91
Raw
1@[has_globals]
2module sapp
3
4$if linux_wayland_session ? {
5 $if !sokol_wayland ? {
6 $compile_error('`gg`/`sokol.sapp` cannot run in a Wayland-only Linux session without `-d sokol_wayland`.')
7 }
8}
9
10#preinclude <X11/Xlib.h>
11#preinclude <X11/Xatom.h>
12#preinclude <X11/Xutil.h>
13#preinclude <X11/Xresource.h>
14#preinclude <X11/keysym.h>
15#preinclude <X11/XKBlib.h>
16#preinclude <X11/Xcursor/Xcursor.h>
17#preinclude <X11/extensions/XInput2.h>
18
19// C library bindings for Linux Wayland/X11 backends.
20// These declare the external C types and functions from:
21// - wayland-client, wayland-egl, wayland-cursor (when SOKOL_WAYLAND is defined)
22// - xkbcommon
23// - EGL
24// - Wayland protocol generated headers (when SOKOL_WAYLAND is defined)
25// - Linux syscalls (timerfd, mmap)
26
27$if sokol_wayland ? {
28 // === wayland-client core types ===
29
30 pub struct C.wl_display {}
31
32 pub struct C.wl_registry {}
33
34 pub struct C.wl_compositor {}
35
36 pub struct C.wl_surface {}
37
38 pub struct C.wl_seat {}
39
40 pub struct C.wl_pointer {}
41
42 pub struct C.wl_keyboard {}
43
44 pub struct C.wl_touch {}
45
46 pub struct C.wl_shm {}
47
48 pub struct C.wl_output {}
49
50 pub struct C.wl_data_device_manager {}
51
52 pub struct C.wl_data_device {}
53
54 pub struct C.wl_data_source {}
55
56 pub struct C.wl_data_offer {}
57
58 pub struct C.wl_proxy {}
59
60 pub struct C.wl_interface {}
61
62 pub struct C.wl_array {
63 size usize
64 alloc usize
65 data voidptr
66 }
67
68 // === wayland-client functions ===
69
70 fn C.wl_display_connect(name &char) &C.wl_display
71 fn C.wl_display_disconnect(display &C.wl_display)
72 fn C.wl_display_dispatch(display &C.wl_display) int
73 fn C.wl_display_dispatch_pending(display &C.wl_display) int
74 fn C.wl_display_roundtrip(display &C.wl_display) int
75 fn C.wl_display_flush(display &C.wl_display) int
76 fn C.wl_display_get_registry(display &C.wl_display) &C.wl_registry
77
78 fn C.wl_registry_bind(registry &C.wl_registry, name u32, iface &C.wl_interface, version u32) voidptr
79 fn C.wl_registry_destroy(registry &C.wl_registry)
80
81 fn C.wl_compositor_create_surface(compositor &C.wl_compositor) &C.wl_surface
82 fn C.wl_compositor_destroy(compositor &C.wl_compositor)
83
84 fn C.wl_surface_destroy(surface &C.wl_surface)
85 fn C.wl_surface_commit(surface &C.wl_surface)
86 fn C.wl_surface_set_buffer_scale(surface &C.wl_surface, scale i32)
87
88 fn C.wl_seat_get_pointer(seat &C.wl_seat) &C.wl_pointer
89 fn C.wl_seat_get_keyboard(seat &C.wl_seat) &C.wl_keyboard
90 fn C.wl_seat_get_touch(seat &C.wl_seat) &C.wl_touch
91 fn C.wl_seat_destroy(seat &C.wl_seat)
92
93 fn C.wl_pointer_destroy(pointer &C.wl_pointer)
94 fn C.wl_keyboard_destroy(keyboard &C.wl_keyboard)
95 fn C.wl_touch_destroy(touch &C.wl_touch)
96 fn C.wl_shm_destroy(shm &C.wl_shm)
97
98 fn C.wl_data_device_manager_get_data_device(manager &C.wl_data_device_manager, seat &C.wl_seat) &C.wl_data_device
99 fn C.wl_data_device_manager_create_data_source(manager &C.wl_data_device_manager) &C.wl_data_source
100 fn C.wl_data_device_destroy(device &C.wl_data_device)
101 fn C.wl_data_source_destroy(source &C.wl_data_source)
102 fn C.wl_data_source_offer(source &C.wl_data_source, mime_type &char)
103 fn C.wl_data_offer_destroy(offer &C.wl_data_offer)
104 fn C.wl_data_offer_receive(offer &C.wl_data_offer, mime_type &char, fd int)
105 fn C.wl_data_offer_accept(offer &C.wl_data_offer, serial u32, mime_type &char)
106 fn C.wl_data_offer_set_actions(offer &C.wl_data_offer, dnd_actions u32, preferred_action u32)
107 fn C.wl_data_offer_finish(offer &C.wl_data_offer)
108 fn C.wl_data_device_manager_destroy(manager &C.wl_data_device_manager)
109
110 fn C.wl_proxy_add_listener(proxy &C.wl_proxy, implementation voidptr, data voidptr) int
111 fn C.wl_proxy_get_version(proxy &C.wl_proxy) u32
112
113 fn C.wl_fixed_to_double(f i32) f64
114
115 // wl_registry_add_listener, wl_seat_add_listener, etc. are static inline functions
116 // that call wl_proxy_add_listener. We declare them as C functions since they're
117 // in the included headers.
118 fn C.wl_registry_add_listener(registry &C.wl_registry, listener voidptr, data voidptr) int
119 fn C.wl_seat_add_listener(seat &C.wl_seat, listener voidptr, data voidptr) int
120 fn C.wl_pointer_add_listener(pointer &C.wl_pointer, listener voidptr, data voidptr) int
121 fn C.wl_keyboard_add_listener(keyboard &C.wl_keyboard, listener voidptr, data voidptr) int
122 fn C.wl_data_device_add_listener(device &C.wl_data_device, listener voidptr, data voidptr) int
123 fn C.wl_data_offer_add_listener(offer &C.wl_data_offer, listener voidptr, data voidptr) int
124
125 // === wayland-egl ===
126
127 pub struct C.wl_egl_window {}
128
129 fn C.wl_egl_window_create(surface &C.wl_surface, width int, height int) &C.wl_egl_window
130 fn C.wl_egl_window_destroy(window &C.wl_egl_window)
131 fn C.wl_egl_window_resize(window &C.wl_egl_window, width int, height int, dx int, dy int)
132
133 // === wayland-cursor ===
134
135 pub struct C.wl_cursor_theme {}
136
137 pub struct C.wl_cursor {
138 image_count u32
139 images &&C.wl_cursor_image
140 name &char
141 }
142
143 pub struct C.wl_cursor_image {
144 width u32
145 height u32
146 hotspot_x u32
147 hotspot_y u32
148 delay u32
149 }
150
151 fn C.wl_cursor_theme_load(name &char, size int, shm &C.wl_shm) &C.wl_cursor_theme
152 fn C.wl_cursor_theme_destroy(theme &C.wl_cursor_theme)
153 fn C.wl_cursor_theme_get_cursor(theme &C.wl_cursor_theme, name &char) &C.wl_cursor
154 fn C.wl_cursor_image_get_buffer(image &C.wl_cursor_image) &C.wl_buffer
155
156 pub struct C.wl_buffer {}
157
158 fn C.wl_surface_attach(surface &C.wl_surface, buffer &C.wl_buffer, x i32, y i32)
159
160 // === Wayland protocol interfaces (extern globals from generated .c files) ===
161
162 #include "xdg-shell-client-protocol.h"
163 #include "fractional-scale-v1-client-protocol.h"
164 #include "cursor-shape-v1-client-protocol.h"
165 #include "pointer-constraints-unstable-v1-client-protocol.h"
166 #include "relative-pointer-unstable-v1-client-protocol.h"
167 #include "viewporter-client-protocol.h"
168 #include "xdg-decoration-unstable-v1-client-protocol.h"
169
170 // Protocol object types
171 pub struct C.xdg_wm_base {}
172
173 pub struct C.xdg_surface {}
174
175 pub struct C.xdg_toplevel {}
176
177 pub struct C.wp_fractional_scale_manager_v1 {}
178
179 pub struct C.wp_fractional_scale_v1 {}
180
181 pub struct C.wp_viewporter {}
182
183 pub struct C.wp_viewport {}
184
185 pub struct C.wp_cursor_shape_manager_v1 {}
186
187 pub struct C.wp_cursor_shape_device_v1 {}
188
189 pub struct C.zwp_pointer_constraints_v1 {}
190
191 pub struct C.zwp_locked_pointer_v1 {}
192
193 pub struct C.zwp_relative_pointer_manager_v1 {}
194
195 pub struct C.zwp_relative_pointer_v1 {}
196
197 pub struct C.zxdg_decoration_manager_v1 {}
198
199 pub struct C.zxdg_toplevel_decoration_v1 {}
200
201 // Protocol interface globals (extern const struct wl_interface defined in generated .c and system headers)
202 __global C.wl_compositor_interface C.wl_interface
203 __global C.wl_seat_interface C.wl_interface
204 __global C.wl_shm_interface C.wl_interface
205 __global C.wl_output_interface C.wl_interface
206 __global C.wl_data_device_manager_interface C.wl_interface
207 __global C.xdg_wm_base_interface C.wl_interface
208 __global C.xdg_surface_interface C.wl_interface
209 __global C.wp_fractional_scale_manager_v1_interface C.wl_interface
210 __global C.wp_viewporter_interface C.wl_interface
211 __global C.wp_cursor_shape_manager_v1_interface C.wl_interface
212 __global C.zwp_pointer_constraints_v1_interface C.wl_interface
213 __global C.zwp_relative_pointer_manager_v1_interface C.wl_interface
214 __global C.zxdg_decoration_manager_v1_interface C.wl_interface
215
216 // Protocol functions (static inline in generated headers)
217 fn C.xdg_wm_base_get_xdg_surface(wm_base &C.xdg_wm_base, surface &C.wl_surface) &C.xdg_surface
218 fn C.xdg_wm_base_destroy(wm_base &C.xdg_wm_base)
219 fn C.xdg_wm_base_pong(wm_base &C.xdg_wm_base, serial u32)
220
221 fn C.xdg_surface_get_toplevel(xdg_surface &C.xdg_surface) &C.xdg_toplevel
222 fn C.xdg_surface_ack_configure(xdg_surface &C.xdg_surface, serial u32)
223 fn C.xdg_surface_destroy(xdg_surface &C.xdg_surface)
224 fn C.xdg_surface_add_listener(xdg_surface &C.xdg_surface, listener voidptr, data voidptr) int
225
226 fn C.xdg_toplevel_set_title(toplevel &C.xdg_toplevel, title &char)
227 fn C.xdg_toplevel_set_app_id(toplevel &C.xdg_toplevel, app_id &char)
228 fn C.xdg_toplevel_set_fullscreen(toplevel &C.xdg_toplevel, output &C.wl_output)
229 fn C.xdg_toplevel_unset_fullscreen(toplevel &C.xdg_toplevel)
230 fn C.xdg_toplevel_set_min_size(toplevel &C.xdg_toplevel, width i32, height i32)
231 fn C.xdg_toplevel_set_max_size(toplevel &C.xdg_toplevel, width i32, height i32)
232 fn C.xdg_toplevel_destroy(toplevel &C.xdg_toplevel)
233 fn C.xdg_toplevel_add_listener(toplevel &C.xdg_toplevel, listener voidptr, data voidptr) int
234
235 fn C.wp_fractional_scale_manager_v1_get_fractional_scale(manager &C.wp_fractional_scale_manager_v1, surface &C.wl_surface) &C.wp_fractional_scale_v1
236 fn C.wp_fractional_scale_manager_v1_destroy(manager &C.wp_fractional_scale_manager_v1)
237 fn C.wp_fractional_scale_v1_add_listener(scale &C.wp_fractional_scale_v1, listener voidptr, data voidptr) int
238 fn C.wp_fractional_scale_v1_destroy(scale &C.wp_fractional_scale_v1)
239
240 fn C.wp_viewporter_get_viewport(viewporter &C.wp_viewporter, surface &C.wl_surface) &C.wp_viewport
241 fn C.wp_viewporter_destroy(viewporter &C.wp_viewporter)
242 fn C.wp_viewport_set_destination(viewport &C.wp_viewport, width i32, height i32)
243 fn C.wp_viewport_destroy(viewport &C.wp_viewport)
244
245 fn C.wp_cursor_shape_manager_v1_get_pointer(manager &C.wp_cursor_shape_manager_v1, pointer &C.wl_pointer) &C.wp_cursor_shape_device_v1
246 fn C.wp_cursor_shape_manager_v1_destroy(manager &C.wp_cursor_shape_manager_v1)
247 fn C.wp_cursor_shape_device_v1_set_shape(device &C.wp_cursor_shape_device_v1, serial u32, shape u32)
248 fn C.wp_cursor_shape_device_v1_destroy(device &C.wp_cursor_shape_device_v1)
249
250 fn C.zwp_pointer_constraints_v1_lock_pointer(constraints &C.zwp_pointer_constraints_v1, surface &C.wl_surface, pointer &C.wl_pointer, region voidptr, lifetime u32) &C.zwp_locked_pointer_v1
251 fn C.zwp_pointer_constraints_v1_destroy(constraints &C.zwp_pointer_constraints_v1)
252 fn C.zwp_locked_pointer_v1_destroy(locked &C.zwp_locked_pointer_v1)
253
254 fn C.zwp_relative_pointer_manager_v1_get_relative_pointer(manager &C.zwp_relative_pointer_manager_v1, pointer &C.wl_pointer) &C.zwp_relative_pointer_v1
255 fn C.zwp_relative_pointer_manager_v1_destroy(manager &C.zwp_relative_pointer_manager_v1)
256 fn C.zwp_relative_pointer_v1_destroy(rp &C.zwp_relative_pointer_v1)
257 fn C.zwp_relative_pointer_v1_add_listener(rp &C.zwp_relative_pointer_v1, listener voidptr, data voidptr) int
258
259 fn C.zxdg_decoration_manager_v1_get_toplevel_decoration(manager &C.zxdg_decoration_manager_v1, toplevel &C.xdg_toplevel) &C.zxdg_toplevel_decoration_v1
260 fn C.zxdg_decoration_manager_v1_destroy(manager &C.zxdg_decoration_manager_v1)
261 fn C.zxdg_toplevel_decoration_v1_set_mode(decoration &C.zxdg_toplevel_decoration_v1, mode u32)
262 fn C.zxdg_toplevel_decoration_v1_destroy(decoration &C.zxdg_toplevel_decoration_v1)
263
264 // === xkbcommon ===
265
266 pub struct C.xkb_context {}
267
268 pub struct C.xkb_keymap {}
269
270 pub struct C.xkb_state {}
271
272 pub struct C.xkb_compose_table {}
273
274 pub struct C.xkb_compose_state {}
275
276 pub type Xkb_keysym_t = u32
277
278 fn C.xkb_context_new(flags int) &C.xkb_context
279 fn C.xkb_context_unref(ctx &C.xkb_context)
280
281 fn C.xkb_keymap_new_from_string(ctx &C.xkb_context, str &char, format int, flags int) &C.xkb_keymap
282 fn C.xkb_keymap_unref(keymap &C.xkb_keymap)
283
284 fn C.xkb_state_new(keymap &C.xkb_keymap) &C.xkb_state
285 fn C.xkb_state_unref(state &C.xkb_state)
286 fn C.xkb_state_key_get_one_sym(state &C.xkb_state, key u32) Xkb_keysym_t
287 fn C.xkb_state_key_get_utf8(state &C.xkb_state, key u32, buf &char, size usize) int
288 fn C.xkb_state_update_mask(state &C.xkb_state, depressed u32, latched u32, locked u32, dep_group u32, lat_group u32, lock_group u32) int
289 fn C.xkb_state_mod_name_is_active(state &C.xkb_state, name &char, @type int) int
290
291 fn C.xkb_compose_table_new_from_locale(ctx &C.xkb_context, locale &char, flags int) &C.xkb_compose_table
292 fn C.xkb_compose_table_unref(table &C.xkb_compose_table)
293 fn C.xkb_compose_state_new(table &C.xkb_compose_table, flags int) &C.xkb_compose_state
294 fn C.xkb_compose_state_unref(state &C.xkb_compose_state)
295
296 // xkbcommon constants
297 const xkb_context_no_flags = 0
298 const xkb_keymap_format_text_v1 = 1
299 const xkb_keymap_compile_no_flags = 0
300 const xkb_state_mods_effective = 8
301 const xkb_mod_name_shift = c'Shift'
302 const xkb_mod_name_ctrl = c'Control'
303 const xkb_mod_name_alt = c'Mod1'
304 const xkb_mod_name_logo = c'Mod4'
305
306 // Wayland keyboard state constants
307 const wl_keyboard_keymap_format_xkb_v1 = u32(1)
308 const wl_keyboard_key_state_pressed = u32(1)
309 const wl_keyboard_key_state_released = u32(0)
310 const wl_pointer_button_state_pressed = u32(1)
311 const wl_pointer_button_state_released = u32(0)
312 const wl_pointer_axis_vertical_scroll = u32(0)
313 const wl_pointer_axis_horizontal_scroll = u32(1)
314
315 // wl_seat capabilities
316 const wl_seat_capability_pointer = u32(1)
317 const wl_seat_capability_keyboard = u32(2)
318 const wl_seat_capability_touch = u32(4)
319
320 // XDG toplevel states
321 const xdg_toplevel_state_maximized = u32(1)
322 const xdg_toplevel_state_fullscreen = u32(2)
323 const xdg_toplevel_state_resizing = u32(3)
324 const xdg_toplevel_state_activated = u32(4)
325
326 // zxdg_toplevel_decoration_v1 modes
327 const zxdg_toplevel_decoration_v1_mode_client_side = u32(1)
328 const zxdg_toplevel_decoration_v1_mode_server_side = u32(2)
329
330 // zwp_pointer_constraints_v1 lifetime
331 const zwp_pointer_constraints_v1_lifetime_persistent = u32(2)
332
333 // wl_data_device_manager DND actions
334 const wl_data_device_manager_dnd_action_copy = u32(1)
335
336 // wp_cursor_shape constants (matching sapp MouseCursor values)
337 const wp_cursor_shape_device_v1_shape_default = u32(1)
338 const wp_cursor_shape_device_v1_shape_text = u32(5)
339 const wp_cursor_shape_device_v1_shape_crosshair = u32(3)
340 const wp_cursor_shape_device_v1_shape_pointer = u32(29)
341 const wp_cursor_shape_device_v1_shape_ew_resize = u32(17)
342 const wp_cursor_shape_device_v1_shape_ns_resize = u32(19)
343 const wp_cursor_shape_device_v1_shape_nwse_resize = u32(14)
344 const wp_cursor_shape_device_v1_shape_nesw_resize = u32(12)
345 const wp_cursor_shape_device_v1_shape_all_scroll = u32(21)
346 const wp_cursor_shape_device_v1_shape_not_allowed = u32(25)
347
348 // MAP_FAILED
349 const map_failed = voidptr(usize(~u64(0)))
350
351 // Linux input event codes (from linux/input-event-codes.h)
352 const btn_left = 0x110
353 const btn_right = 0x111
354 const btn_middle = 0x112
355
356 // timerfd
357 #include <sys/timerfd.h>
358
359 pub struct C.itimerspec {
360 it_interval C.timespec
361 it_value C.timespec
362 }
363
364 pub struct C.timespec {
365 tv_sec i64
366 tv_nsec i64
367 }
368
369 fn C.timerfd_create(clockid int, flags int) int
370 fn C.timerfd_settime(fd int, flags int, new_value &C.itimerspec, old_value &C.itimerspec) int
371
372 const clock_monotonic = 1
373 const tfd_cloexec = 0o2000000
374 const tfd_nonblock = 0o4000
375}
376
377// === EGL (shared between Wayland and X11) ===
378
379pub type EGLDisplay = voidptr
380pub type EGLContext = voidptr
381pub type EGLSurface = voidptr
382pub type EGLConfig = voidptr
383pub type EGLNativeWindowType = voidptr
384pub type EGLint = i32
385
386fn C.eglGetDisplay(native_display voidptr) EGLDisplay
387fn C.eglInitialize(display EGLDisplay, major &EGLint, minor &EGLint) int
388fn C.eglTerminate(display EGLDisplay) int
389fn C.eglChooseConfig(display EGLDisplay, attribs &EGLint, configs &EGLConfig, config_size EGLint, num_configs &EGLint) int
390fn C.eglCreateContext(display EGLDisplay, config EGLConfig, share_ctx EGLContext, attribs &EGLint) EGLContext
391fn C.eglDestroyContext(display EGLDisplay, ctx EGLContext) int
392fn C.eglCreateWindowSurface(display EGLDisplay, config EGLConfig, window EGLNativeWindowType, attribs &EGLint) EGLSurface
393fn C.eglDestroySurface(display EGLDisplay, surface EGLSurface) int
394fn C.eglMakeCurrent(display EGLDisplay, draw EGLSurface, read EGLSurface, ctx EGLContext) int
395fn C.eglSwapBuffers(display EGLDisplay, surface EGLSurface) int
396fn C.eglSwapInterval(display EGLDisplay, interval EGLint) int
397fn C.eglGetError() EGLint
398fn C.eglBindAPI(api u32) int
399fn C.eglGetConfigAttrib(display EGLDisplay, config EGLConfig, attribute EGLint, value &EGLint) int
400
401// OpenGL
402fn C.glGetIntegerv(pname u32, data &i32)
403
404// EGL constants
405const egl_opengl_api = u32(0x30A2)
406const egl_opengl_es_api = u32(0x30A0)
407const egl_no_display = EGLDisplay(0)
408const egl_no_context = EGLContext(0)
409const egl_no_surface = EGLSurface(0)
410const egl_none = EGLint(0x3038)
411const egl_red_size = EGLint(0x3024)
412const egl_green_size = EGLint(0x3023)
413const egl_blue_size = EGLint(0x3022)
414const egl_alpha_size = EGLint(0x3021)
415const egl_depth_size = EGLint(0x3025)
416const egl_stencil_size = EGLint(0x3026)
417const egl_sample_buffers = EGLint(0x3032)
418const egl_samples = EGLint(0x3031)
419const egl_surface_type = EGLint(0x3033)
420const egl_window_bit = EGLint(0x0004)
421const egl_renderable_type = EGLint(0x3040)
422const egl_opengl_bit = EGLint(0x0008)
423const egl_opengl_es3_bit = EGLint(0x0040)
424const egl_context_major_version = EGLint(0x3098)
425const egl_context_minor_version = EGLint(0x30FB)
426const egl_context_opengl_profile_mask = EGLint(0x30FD)
427const egl_context_opengl_core_profile_bit = EGLint(0x00000001)
428const egl_true = 1
429const egl_false = 0
430
431// GL constants
432const gl_framebuffer_binding = u32(0x8CA6)
433
434// === Linux syscalls (shared) ===
435
436fn C.mmap(addr voidptr, length usize, prot int, flags int, fd int, offset i64) voidptr
437fn C.munmap(addr voidptr, length usize) int
438fn C.close(fd int) int
439fn C.read(fd int, buf voidptr, count usize) isize
440fn C.pipe(fds &int) int
441fn C.strcmp(s1 &char, s2 &char) int
442fn C.strncmp(s1 &char, s2 &char, n usize) int
443fn C.strlen(s &char) usize
444fn C.strtok(str &char, delim &char) &char
445fn C.strtol(str &char, endptr &&char, base int) i64
446fn C.memset(s voidptr, c int, n usize) voidptr
447fn C.atof(s &char) f64
448
449// mmap constants
450const prot_read = 1
451const map_private = 2
452
453// === X11 / Xlib types and functions ===
454
455#include <X11/Xlib.h>
456#include <X11/Xutil.h>
457#include <X11/Xresource.h>
458#include <X11/Xatom.h>
459#include <X11/keysym.h>
460#include <X11/XKBlib.h>
461#include <X11/extensions/XInput2.h>
462#include <X11/Xcursor/Xcursor.h>
463
464// X11 C typedefs are unsigned long based. Define them locally so V1 can
465// type-check scalar operations while keeping the public aliases C-backed.
466pub type C.XID = usize
467pub type C.Atom = C.XID
468pub type C.Window = C.XID
469pub type C.Colormap = C.XID
470pub type C.Cursor = C.XID
471pub type C.KeySym = C.XID
472pub type C.Time = C.XID
473pub type C.VisualID = C.XID
474
475// X11 types
476pub type XID = C.XID
477pub type Atom = C.Atom
478pub type Window = C.Window
479pub type Colormap = C.Colormap
480pub type Cursor = C.Cursor
481pub type KeySym = C.KeySym
482pub type Time = C.Time
483pub type VisualID = C.VisualID
484pub type XlibULong = C.XID
485
486// X11 types are defined by X11 headers (#preinclude above)
487// Forward declarations for V type checking only
488@[typedef]
489pub struct C.Display {
490pub mut:
491 _ int // opaque - actual definition from X11 headers
492}
493
494@[typedef]
495pub struct C.Visual {
496pub mut:
497 _ int // opaque - actual definition from X11 headers
498}
499
500@[typedef]
501pub struct C.Screen {
502pub mut:
503 _ int // opaque - actual definition from X11 headers
504}
505
506@[typedef]
507pub struct C.XSelectionEvent {
508pub mut:
509 type int
510 display &C.Display = unsafe { nil }
511 requestor Window
512 selection Atom
513 target Atom
514 property Atom
515 time int
516}
517
518@[typedef]
519pub struct C.XSelectionClearEvent {
520pub mut:
521 window Window
522 selection Atom
523}
524
525@[typedef]
526pub struct C.XSelectionRequestEvent {
527pub mut:
528 display &C.Display = unsafe { nil }
529 owner Window
530 requestor Window
531 selection Atom
532 target Atom
533 property Atom
534 time int
535}
536
537@[typedef]
538pub struct C.XDestroyWindowEvent {
539pub mut:
540 window Window
541}
542
543@[typedef]
544pub struct C.XPropertyEvent {
545pub mut:
546 state int
547 atom Atom
548}
549
550@[typedef]
551pub struct C.XClientMessageEvent {
552pub mut:
553 window Window
554 format int
555 message_type Atom
556 data C.XClientMessageData
557}
558
559@[typedef]
560pub union C.XClientMessageData {
561pub mut:
562 b [20]u8
563 s [10]i16
564 l [5]i64
565}
566
567@[typedef]
568pub struct C.XGenericEventCookie {
569pub mut:
570 extension int
571 evtype int
572 data voidptr
573}
574
575@[typedef]
576pub struct C.XKeyEvent {
577pub mut:
578 keycode u32
579 state u32
580}
581
582@[typedef]
583pub struct C.XButtonEvent {
584pub mut:
585 button u32
586 state u32
587 x int
588 y int
589}
590
591@[typedef]
592pub struct C.XMotionEvent {
593pub mut:
594 x int
595 y int
596 state u32
597}
598
599@[typedef]
600pub struct C.XCrossingEvent {
601pub mut:
602 x int
603 y int
604 state u32
605}
606
607@[typedef]
608pub struct C.XFocusChangeEvent {
609pub mut:
610 mode int
611}
612
613@[typedef]
614pub union C.XEvent {
615pub mut:
616 type int
617 xclient C.XClientMessageEvent
618 xkey C.XKeyEvent
619 xbutton C.XButtonEvent
620 xmotion C.XMotionEvent
621 xcrossing C.XCrossingEvent
622 xfocus C.XFocusChangeEvent
623 xproperty C.XPropertyEvent
624 xselection C.XSelectionEvent
625 xselectionrequest C.XSelectionRequestEvent
626 xselectionclear C.XSelectionClearEvent
627 xdestroywindow C.XDestroyWindowEvent
628 xcookie C.XGenericEventCookie
629}
630
631pub struct C.XrmDatabase__rec {}
632
633pub type XrmDatabase = &C.XrmDatabase__rec
634
635pub struct C.XSetWindowAttributes {
636mut:
637 colormap Colormap
638 border_pixel u64
639 event_mask u64
640}
641
642@[typedef]
643pub struct C.XWindowAttributes {
644mut:
645 width int
646 height int
647 map_state int
648}
649
650pub struct C.XSizeHintsAspect {
651mut:
652 x int
653 y int
654}
655
656@[typedef]
657pub struct C.XSizeHints {
658mut:
659 flags i64
660 x int
661 y int
662 width int
663 height int
664 min_width int
665 min_height int
666 max_width int
667 max_height int
668 width_inc int
669 height_inc int
670 min_aspect C.XSizeHintsAspect
671 max_aspect C.XSizeHintsAspect
672 base_width int
673 base_height int
674 win_gravity int
675}
676
677pub struct C.XVisualInfo {
678mut:
679 visual &C.Visual = unsafe { nil }
680 visualid VisualID
681 depth int
682}
683
684// X11 event types are defined in vlib/x/x11/x11.v
685// XEvent union is defined here since it's used extensively in sokol
686
687pub union C.XEvent {
688pub mut:
689 @type int
690 xclient C.XClientMessageEvent
691 xkey C.XKeyEvent
692 xbutton C.XButtonEvent
693 xmotion C.XMotionEvent
694 xcrossing C.XCrossingEvent
695 xfocus C.XFocusChangeEvent
696 xproperty C.XPropertyEvent
697 xselection C.XSelectionEvent
698 xselectionrequest C.XSelectionRequestEvent
699 xselectionclear C.XSelectionClearEvent
700 xdestroywindow C.XDestroyWindowEvent
701 xcookie C.XGenericEventCookie
702}
703
704pub struct C.XKeyEvent {
705pub mut:
706 keycode u32
707 state u32
708}
709
710pub struct C.XButtonEvent {
711pub mut:
712 button u32
713 state u32
714 x int
715 y int
716}
717
718pub struct C.XMotionEvent {
719pub mut:
720 x int
721 y int
722 state u32
723}
724
725pub struct C.XCrossingEvent {
726pub mut:
727 x int
728 y int
729 state u32
730}
731
732pub struct C.XFocusChangeEvent {
733pub mut:
734 mode int
735}
736
737pub struct C.XPropertyEvent {
738pub mut:
739 state int
740 atom Atom
741}
742
743// XSelection* structs are forward-declared above
744// Full definitions come from X11 headers or clipboard module
745
746pub struct C.XClientMessageEvent {
747pub mut:
748 window Window
749 format int
750 message_type Atom
751 data C.XClientMessageData
752}
753
754pub union C.XClientMessageData {
755pub mut:
756 l [5]i64
757}
758
759pub struct C.XGenericEventCookie {
760pub mut:
761 extension int
762 evtype int
763 data voidptr
764}
765
766pub struct C.XrmValue {
767 addr &char = unsafe { nil }
768}
769
770// XKB types
771pub struct C.XkbDescRec {
772mut:
773 min_key_code u8
774 max_key_code u8
775 names &C.XkbNamesRec = unsafe { nil }
776}
777
778pub type XkbDescPtr = &C.XkbDescRec
779
780pub struct C.XkbNamesRec {
781mut:
782 keys &C.XkbKeyNameRec = unsafe { nil }
783 key_aliases &C.XkbKeyAliasRec = unsafe { nil }
784 num_key_aliases u8
785}
786
787pub struct C.XkbKeyNameRec {
788mut:
789 name [4]u8
790}
791
792pub struct C.XkbKeyAliasRec {
793mut:
794 real [4]u8
795 alias [4]u8
796}
797
798// XInput2 types
799pub struct C.XIEventMask {
800mut:
801 deviceid int
802 mask_len int
803 mask &u8 = unsafe { nil }
804}
805
806pub struct C.XIRawEvent {
807mut:
808 valuators C.XIValuatorState
809 raw_values &f64 = unsafe { nil }
810}
811
812pub struct C.XIValuatorState {
813mut:
814 mask_len int
815 mask &u8 = unsafe { nil }
816}
817
818// Xcursor types
819pub struct C.XcursorImage {
820mut:
821 width u32
822 height u32
823 xhot u32
824 yhot u32
825 pixels &u32 = unsafe { nil }
826}
827
828pub type XcursorPixel = u32
829
830// === Xlib functions ===
831
832fn C.XOpenDisplay(name &char) &C.Display
833fn C.XCloseDisplay(display &C.Display) int
834fn C.XDefaultScreen(display &C.Display) int
835fn C.XDefaultRootWindow(display &C.Display) Window
836fn C.XDefaultVisual(display &C.Display, screen int) &C.Visual
837fn C.XDefaultDepth(display &C.Display, screen int) int
838fn C.XDisplayWidth(display &C.Display, screen int) int
839fn C.XDisplayHeight(display &C.Display, screen int) int
840fn C.XDisplayWidthMM(display &C.Display, screen int) int
841fn C.XInternAtom(display &C.Display, name &char, only_if_exists int) Atom
842fn C.XCreateColormap(display &C.Display, window Window, visual &C.Visual, alloc int) Colormap
843fn C.XFreeColormap(display &C.Display, colormap Colormap) int
844fn C.XCreateWindow(display &C.Display, parent Window, x int, y int, width u32, height u32, border_width u32, depth int, class_ u32, visual &C.Visual, valuemask u64, attributes &C.XSetWindowAttributes) Window
845fn C.XDestroyWindow(display &C.Display, window Window) int
846fn C.XMapWindow(display &C.Display, window Window) int
847fn C.XUnmapWindow(display &C.Display, window Window) int
848fn C.XRaiseWindow(display &C.Display, window Window) int
849fn C.XFlush(display &C.Display) int
850fn C.XSync(display &C.Display, discard int) int
851fn C.XPending(display &C.Display) int
852fn C.XNextEvent(display &C.Display, event &C.XEvent) int
853fn C.XCheckTypedWindowEvent(display &C.Display, window Window, event_type int, event &C.XEvent) int
854fn C.XSendEvent(display &C.Display, window Window, propagate int, event_mask i64, event &C.XEvent) int
855fn C.XFilterEvent(event &C.XEvent, window Window) int
856fn C.XSetWMProtocols(display &C.Display, window Window, protocols &Atom, count int) int
857fn C.XSetWMNormalHints(display &C.Display, window Window, hints &C.XSizeHints) int
858fn C.XAllocSizeHints() &C.XSizeHints
859fn C.XGetWindowAttributes(display &C.Display, window Window, attrs &C.XWindowAttributes) int
860fn C.XGetWindowProperty(display &C.Display, window Window, property Atom, long_offset i64, long_length i64, delete int, req_type Atom, actual_type &Atom, actual_format &int, nitems &XlibULong, bytes_after &XlibULong, prop &&u8) int
861fn C.XChangeProperty(display &C.Display, window Window, property Atom, @type Atom, format int, mode int, data &u8, nelements int) int
862fn C.Xutf8SetWMProperties(display &C.Display, window Window, window_name &char, icon_name &char, argv &&char, argc int, normal_hints voidptr, wm_hints voidptr, class_hints voidptr)
863fn C.XSetSelectionOwner(display &C.Display, selection Atom, owner Window, time Time)
864fn C.XGetSelectionOwner(display &C.Display, selection Atom) Window
865fn C.XConvertSelection(display &C.Display, selection Atom, target Atom, property Atom, requestor Window, time Time)
866fn C.XFree(data voidptr) int
867fn C.XDefineCursor(display &C.Display, window Window, cursor Cursor) int
868fn C.XUndefineCursor(display &C.Display, window Window) int
869fn C.XCreateFontCursor(display &C.Display, shape u32) Cursor
870fn C.XFreeCursor(display &C.Display, cursor Cursor) int
871fn C.XGrabPointer(display &C.Display, grab_window Window, owner_events int, event_mask u32, pointer_mode int, keyboard_mode int, confine_to Window, cursor Cursor, time Time) int
872fn C.XUngrabPointer(display &C.Display, time Time) int
873fn C.XWarpPointer(display &C.Display, src_w Window, dst_w Window, src_x int, src_y int, src_width u32, src_height u32, dst_x int, dst_y int) int
874fn C.XSetErrorHandler(handler voidptr) voidptr
875fn C.XGetKeyboardMapping(display &C.Display, first_keycode u8, keycode_count int, keysyms_per_keycode &int) &KeySym
876fn C.XLookupString(event &C.XKeyEvent, buf &char, buf_len int, keysym &KeySym, status voidptr) int
877fn C.XQueryExtension(display &C.Display, name &char, major_opcode &int, first_event &int, first_error &int) int
878fn C.XResourceManagerString(display &C.Display) &char
879fn C.XGetVisualInfo(display &C.Display, vinfo_mask i64, vinfo_template &C.XVisualInfo, nitems &int) &C.XVisualInfo
880fn C.XInitThreads() int
881fn C.XrmInitialize()
882fn C.XrmGetStringDatabase(data &char) XrmDatabase
883fn C.XrmDestroyDatabase(db XrmDatabase)
884fn C.XrmGetResource(db XrmDatabase, str_name &char, str_class &char, str_type &&char, value &C.XrmValue) int
885fn C.XGetEventData(display &C.Display, cookie &C.XGenericEventCookie) int
886fn C.XFreeEventData(display &C.Display, cookie &C.XGenericEventCookie)
887
888// XKB functions
889fn C.XkbGetMap(display &C.Display, which u32, device_spec u32) XkbDescPtr
890fn C.XkbGetNames(display &C.Display, which u32, desc XkbDescPtr) int
891fn C.XkbFreeNames(desc XkbDescPtr, which u32, free_map int) int
892fn C.XkbFreeKeyboard(desc XkbDescPtr, which u32, free_all int) int
893fn C.XkbSetDetectableAutoRepeat(display &C.Display, detectable int, supported &int) int
894
895// XInput2 functions
896fn C.XIQueryVersion(display &C.Display, major &int, minor &int) int
897fn C.XISelectEvents(display &C.Display, window Window, masks &C.XIEventMask, num_masks int) int
898
899// Xcursor functions
900fn C.XcursorImageCreate(width int, height int) &C.XcursorImage
901fn C.XcursorImageDestroy(image &C.XcursorImage)
902fn C.XcursorImageLoadCursor(display &C.Display, image &C.XcursorImage) Cursor
903fn C.XcursorLibraryLoadImage(name &char, theme &char, size int) &C.XcursorImage
904fn C.XcursorGetTheme(display &C.Display) &char
905fn C.XcursorGetDefaultSize(display &C.Display) int
906
907// poll
908#include <poll.h>
909
910pub struct C.pollfd {
911mut:
912 fd int
913 events i16
914 revents i16
915}
916
917fn C.poll(fds &C.pollfd, nfds u64, timeout int) int
918
919fn C.ConnectionNumber(display &C.Display) int
920
921fn C.atof(str &char) f64
922fn C.strncmp(s1 &char, s2 &char, n usize) int
923
924// X11 constants
925const x_false = 0
926const x_true = 1
927const x_none = Atom(0)
928const x_window_none = Window(0)
929const x_colormap_none = Colormap(0)
930const x_cursor_none = Cursor(0)
931const xa_atom = Atom(4)
932const xa_cardinal = Atom(6)
933const alloc_none = 0
934const cw_border_pixel = u64(1 << 11)
935const cw_colormap = u64(1 << 13)
936const cw_event_mask = u64(1 << 11) // this is actually CWEventMask
937const input_output = u32(1)
938const structure_notify_mask = i64(1 << 17)
939const key_press_mask = i64(1 << 0)
940const key_release_mask = i64(1 << 1)
941const pointer_motion_mask = i64(1 << 6)
942const button_press_mask = i64(1 << 2)
943const button_release_mask = i64(1 << 3)
944const exposure_mask = i64(1 << 15)
945const focus_change_mask = i64(1 << 21)
946const visibility_change_mask = i64(1 << 16)
947const enter_window_mask = i64(1 << 4)
948const leave_window_mask = i64(1 << 5)
949const property_change_mask = i64(1 << 22)
950const substructure_notify_mask = i64(1 << 19)
951const substructure_redirect_mask = i64(1 << 20)
952const no_event_mask = i64(0)
953
954const prop_mode_replace = 0
955const pw_gravity = i64(1 << 9) // PWinGravity flag
956const center_gravity = 5
957
958const is_viewable = 2
959const visibility_notify = 15
960const normal_state = 1
961const iconic_state = 3
962const withdrawn_state = 0
963
964const current_time = Time(0)
965const grab_mode_async = 1
966
967// Event types
968const x_generic_event = 35
969const x_focus_in = 9
970const x_focus_out = 10
971const x_key_press = 2
972const x_key_release = 3
973const x_button_press = 4
974const x_button_release = 5
975const x_enter_notify = 7
976const x_leave_notify = 8
977const x_motion_notify = 6
978const x_property_notify = 28
979const x_selection_notify = 31
980const x_selection_request = 30
981const x_destroy_notify = 17
982const x_client_message = 33
983const property_new_value = 0
984
985const notify_grab = 1
986const notify_ungrab = 2
987
988// Mouse buttons
989const x_button1 = u32(1)
990const x_button2 = u32(2)
991const x_button3 = u32(3)
992
993// Modifier masks
994const shift_mask = u32(1 << 0)
995const control_mask = u32(1 << 2)
996const mod1_mask = u32(1 << 3) // Alt
997const mod4_mask = u32(1 << 6) // Super
998const button1_mask = u32(1 << 8)
999const button2_mask = u32(1 << 9)
1000const button3_mask = u32(1 << 10)
1001
1002// Cursor shapes for XCreateFontCursor
1003const xc_left_ptr = u32(68)
1004const xc_xterm = u32(152)
1005const xc_crosshair = u32(34)
1006const xc_hand2 = u32(60)
1007const xc_sb_h_double_arrow = u32(108)
1008const xc_sb_v_double_arrow = u32(116)
1009const xc_fleur = u32(52)
1010
1011// XKB constants
1012const xkb_use_core_kbd = u32(0x0100)
1013const xkb_key_names_mask = u32(1 << 9)
1014const xkb_key_aliases_mask = u32(1 << 10)
1015const xkb_key_name_length = 4
1016
1017// XInput2 constants
1018const xi_all_master_devices = -1
1019const xi_raw_motion = 17
1020const pollin = i16(0x001)
1021
1022// XDnD
1023const x11_xdnd_version = 5
1024
1025// KeySym constants
1026const xk_escape = KeySym(0xff1b)
1027const xk_tab = KeySym(0xff09)
1028const xk_shift_l = KeySym(0xffe1)
1029const xk_shift_r = KeySym(0xffe2)
1030const xk_control_l = KeySym(0xffe3)
1031const xk_control_r = KeySym(0xffe4)
1032const xk_meta_l = KeySym(0xffe7)
1033const xk_alt_l = KeySym(0xffe9)
1034const xk_mode_switch = KeySym(0xff7e)
1035const xk_iso_level3_shift = KeySym(0xfe03)
1036const xk_meta_r = KeySym(0xffe8)
1037const xk_alt_r = KeySym(0xffea)
1038const xk_super_l = KeySym(0xffeb)
1039const xk_super_r = KeySym(0xffec)
1040const xk_menu = KeySym(0xff67)
1041const xk_num_lock = KeySym(0xff7f)
1042const xk_caps_lock = KeySym(0xffe5)
1043const xk_print = KeySym(0xff61)
1044const xk_scroll_lock = KeySym(0xff14)
1045const xk_pause = KeySym(0xff13)
1046const xk_delete = KeySym(0xffff)
1047const xk_backspace = KeySym(0xff08)
1048const xk_return = KeySym(0xff0d)
1049const xk_home = KeySym(0xff50)
1050const xk_end = KeySym(0xff57)
1051const xk_page_up = KeySym(0xff55)
1052const xk_page_down = KeySym(0xff56)
1053const xk_insert = KeySym(0xff63)
1054const xk_left = KeySym(0xff51)
1055const xk_right = KeySym(0xff53)
1056const xk_down = KeySym(0xff54)
1057const xk_up = KeySym(0xff52)
1058const xk_f1 = KeySym(0xffbe)
1059const xk_f2 = KeySym(0xffbf)
1060const xk_f3 = KeySym(0xffc0)
1061const xk_f4 = KeySym(0xffc1)
1062const xk_f5 = KeySym(0xffc2)
1063const xk_f6 = KeySym(0xffc3)
1064const xk_f7 = KeySym(0xffc4)
1065const xk_f8 = KeySym(0xffc5)
1066const xk_f9 = KeySym(0xffc6)
1067const xk_f10 = KeySym(0xffc7)
1068const xk_f11 = KeySym(0xffc8)
1069const xk_f12 = KeySym(0xffc9)
1070const xk_f13 = KeySym(0xffca)
1071const xk_f14 = KeySym(0xffcb)
1072const xk_f15 = KeySym(0xffcc)
1073const xk_f16 = KeySym(0xffcd)
1074const xk_f17 = KeySym(0xffce)
1075const xk_f18 = KeySym(0xffcf)
1076const xk_f19 = KeySym(0xffd0)
1077const xk_f20 = KeySym(0xffd1)
1078const xk_f21 = KeySym(0xffd2)
1079const xk_f22 = KeySym(0xffd3)
1080const xk_f23 = KeySym(0xffd4)
1081const xk_f24 = KeySym(0xffd5)
1082const xk_f25 = KeySym(0xffd6)
1083const xk_kp_divide = KeySym(0xffaf)
1084const xk_kp_multiply = KeySym(0xffaa)
1085const xk_kp_subtract = KeySym(0xffad)
1086const xk_kp_add = KeySym(0xffab)
1087const xk_kp_0 = KeySym(0xffb0)
1088const xk_kp_1 = KeySym(0xffb1)
1089const xk_kp_2 = KeySym(0xffb2)
1090const xk_kp_3 = KeySym(0xffb3)
1091const xk_kp_4 = KeySym(0xffb4)
1092const xk_kp_5 = KeySym(0xffb5)
1093const xk_kp_6 = KeySym(0xffb6)
1094const xk_kp_7 = KeySym(0xffb7)
1095const xk_kp_8 = KeySym(0xffb8)
1096const xk_kp_9 = KeySym(0xffb9)
1097const xk_kp_separator = KeySym(0xffac)
1098const xk_kp_decimal = KeySym(0xffae)
1099const xk_kp_equal = KeySym(0xffbd)
1100const xk_kp_enter = KeySym(0xff8d)
1101const xk_kp_insert = KeySym(0xff9e)
1102const xk_kp_end = KeySym(0xff9c)
1103const xk_kp_down = KeySym(0xff99)
1104const xk_kp_page_down = KeySym(0xff9b)
1105const xk_kp_left = KeySym(0xff96)
1106const xk_kp_right = KeySym(0xff98)
1107const xk_kp_home = KeySym(0xff95)
1108const xk_kp_up = KeySym(0xff97)
1109const xk_kp_page_up = KeySym(0xff9a)
1110const xk_kp_delete = KeySym(0xff9f)
1111const xk_a = KeySym(0x0061)
1112const xk_b = KeySym(0x0062)
1113const xk_c = KeySym(0x0063)
1114const xk_d = KeySym(0x0064)
1115const xk_e = KeySym(0x0065)
1116const xk_f = KeySym(0x0066)
1117const xk_g = KeySym(0x0067)
1118const xk_h = KeySym(0x0068)
1119const xk_i = KeySym(0x0069)
1120const xk_j = KeySym(0x006a)
1121const xk_k = KeySym(0x006b)
1122const xk_l = KeySym(0x006c)
1123const xk_m = KeySym(0x006d)
1124const xk_n = KeySym(0x006e)
1125const xk_o = KeySym(0x006f)
1126const xk_p = KeySym(0x0070)
1127const xk_q = KeySym(0x0071)
1128const xk_r = KeySym(0x0072)
1129const xk_s = KeySym(0x0073)
1130const xk_t = KeySym(0x0074)
1131const xk_u = KeySym(0x0075)
1132const xk_v = KeySym(0x0076)
1133const xk_w = KeySym(0x0077)
1134const xk_x = KeySym(0x0078)
1135const xk_y = KeySym(0x0079)
1136const xk_z = KeySym(0x007a)
1137const xk_0 = KeySym(0x0030)
1138const xk_1 = KeySym(0x0031)
1139const xk_2 = KeySym(0x0032)
1140const xk_3 = KeySym(0x0033)
1141const xk_4 = KeySym(0x0034)
1142const xk_5 = KeySym(0x0035)
1143const xk_6 = KeySym(0x0036)
1144const xk_7 = KeySym(0x0037)
1145const xk_8 = KeySym(0x0038)
1146const xk_9 = KeySym(0x0039)
1147const xk_space = KeySym(0x0020)
1148const xk_minus = KeySym(0x002d)
1149const xk_equal = KeySym(0x003d)
1150const xk_bracketleft = KeySym(0x005b)
1151const xk_bracketright = KeySym(0x005d)
1152const xk_backslash = KeySym(0x005c)
1153const xk_semicolon = KeySym(0x003b)
1154const xk_apostrophe = KeySym(0x0027)
1155const xk_grave = KeySym(0x0060)
1156const xk_comma = KeySym(0x002c)
1157const xk_period = KeySym(0x002e)
1158const xk_slash = KeySym(0x002f)
1159const xk_less = KeySym(0x003c)
1160
1161// XIMaskLen macro equivalent
1162fn xi_mask_len(event int) int {
1163 return (event >> 3) + 1
1164}
1165
1166// XISetMask macro equivalent
1167fn xi_set_mask(mask &u8, event int) {
1168 unsafe {
1169 mut p := mask + (event >> 3)
1170 *p = *p | u8(1 << (event & 7))
1171 }
1172}
1173
1174// XIMaskIsSet macro equivalent
1175fn xi_mask_is_set(mask &u8, event int) bool {
1176 unsafe {
1177 return (mask[event >> 3] & u8(1 << (event & 7))) != 0
1178 }
1179}
1180
1181// VisualIDMask for XGetVisualInfo
1182const visual_id_mask = i64(0x1)
1183