| 1 | @[has_globals] |
| 2 | module 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 | |
| 379 | pub type EGLDisplay = voidptr |
| 380 | pub type EGLContext = voidptr |
| 381 | pub type EGLSurface = voidptr |
| 382 | pub type EGLConfig = voidptr |
| 383 | pub type EGLNativeWindowType = voidptr |
| 384 | pub type EGLint = i32 |
| 385 | |
| 386 | fn C.eglGetDisplay(native_display voidptr) EGLDisplay |
| 387 | fn C.eglInitialize(display EGLDisplay, major &EGLint, minor &EGLint) int |
| 388 | fn C.eglTerminate(display EGLDisplay) int |
| 389 | fn C.eglChooseConfig(display EGLDisplay, attribs &EGLint, configs &EGLConfig, config_size EGLint, num_configs &EGLint) int |
| 390 | fn C.eglCreateContext(display EGLDisplay, config EGLConfig, share_ctx EGLContext, attribs &EGLint) EGLContext |
| 391 | fn C.eglDestroyContext(display EGLDisplay, ctx EGLContext) int |
| 392 | fn C.eglCreateWindowSurface(display EGLDisplay, config EGLConfig, window EGLNativeWindowType, attribs &EGLint) EGLSurface |
| 393 | fn C.eglDestroySurface(display EGLDisplay, surface EGLSurface) int |
| 394 | fn C.eglMakeCurrent(display EGLDisplay, draw EGLSurface, read EGLSurface, ctx EGLContext) int |
| 395 | fn C.eglSwapBuffers(display EGLDisplay, surface EGLSurface) int |
| 396 | fn C.eglSwapInterval(display EGLDisplay, interval EGLint) int |
| 397 | fn C.eglGetError() EGLint |
| 398 | fn C.eglBindAPI(api u32) int |
| 399 | fn C.eglGetConfigAttrib(display EGLDisplay, config EGLConfig, attribute EGLint, value &EGLint) int |
| 400 | |
| 401 | // OpenGL |
| 402 | fn C.glGetIntegerv(pname u32, data &i32) |
| 403 | |
| 404 | // EGL constants |
| 405 | const egl_opengl_api = u32(0x30A2) |
| 406 | const egl_opengl_es_api = u32(0x30A0) |
| 407 | const egl_no_display = EGLDisplay(0) |
| 408 | const egl_no_context = EGLContext(0) |
| 409 | const egl_no_surface = EGLSurface(0) |
| 410 | const egl_none = EGLint(0x3038) |
| 411 | const egl_red_size = EGLint(0x3024) |
| 412 | const egl_green_size = EGLint(0x3023) |
| 413 | const egl_blue_size = EGLint(0x3022) |
| 414 | const egl_alpha_size = EGLint(0x3021) |
| 415 | const egl_depth_size = EGLint(0x3025) |
| 416 | const egl_stencil_size = EGLint(0x3026) |
| 417 | const egl_sample_buffers = EGLint(0x3032) |
| 418 | const egl_samples = EGLint(0x3031) |
| 419 | const egl_surface_type = EGLint(0x3033) |
| 420 | const egl_window_bit = EGLint(0x0004) |
| 421 | const egl_renderable_type = EGLint(0x3040) |
| 422 | const egl_opengl_bit = EGLint(0x0008) |
| 423 | const egl_opengl_es3_bit = EGLint(0x0040) |
| 424 | const egl_context_major_version = EGLint(0x3098) |
| 425 | const egl_context_minor_version = EGLint(0x30FB) |
| 426 | const egl_context_opengl_profile_mask = EGLint(0x30FD) |
| 427 | const egl_context_opengl_core_profile_bit = EGLint(0x00000001) |
| 428 | const egl_true = 1 |
| 429 | const egl_false = 0 |
| 430 | |
| 431 | // GL constants |
| 432 | const gl_framebuffer_binding = u32(0x8CA6) |
| 433 | |
| 434 | // === Linux syscalls (shared) === |
| 435 | |
| 436 | fn C.mmap(addr voidptr, length usize, prot int, flags int, fd int, offset i64) voidptr |
| 437 | fn C.munmap(addr voidptr, length usize) int |
| 438 | fn C.close(fd int) int |
| 439 | fn C.read(fd int, buf voidptr, count usize) isize |
| 440 | fn C.pipe(fds &int) int |
| 441 | fn C.strcmp(s1 &char, s2 &char) int |
| 442 | fn C.strncmp(s1 &char, s2 &char, n usize) int |
| 443 | fn C.strlen(s &char) usize |
| 444 | fn C.strtok(str &char, delim &char) &char |
| 445 | fn C.strtol(str &char, endptr &&char, base int) i64 |
| 446 | fn C.memset(s voidptr, c int, n usize) voidptr |
| 447 | fn C.atof(s &char) f64 |
| 448 | |
| 449 | // mmap constants |
| 450 | const prot_read = 1 |
| 451 | const 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 types |
| 465 | pub type XID = u64 |
| 466 | pub type Atom = u64 |
| 467 | pub type Window = u64 |
| 468 | pub type Colormap = u64 |
| 469 | pub type Cursor = u64 |
| 470 | pub type KeySym = u64 |
| 471 | pub type Time = u64 |
| 472 | pub type VisualID = u64 |
| 473 | |
| 474 | // X11 types are defined by X11 headers (#preinclude above) |
| 475 | // Forward declarations for V type checking only |
| 476 | @[typedef] |
| 477 | pub struct C.Display { |
| 478 | pub mut: |
| 479 | _ int // opaque - actual definition from X11 headers |
| 480 | } |
| 481 | |
| 482 | @[typedef] |
| 483 | pub struct C.Visual { |
| 484 | pub mut: |
| 485 | _ int // opaque - actual definition from X11 headers |
| 486 | } |
| 487 | |
| 488 | @[typedef] |
| 489 | pub struct C.Screen { |
| 490 | pub mut: |
| 491 | _ int // opaque - actual definition from X11 headers |
| 492 | } |
| 493 | |
| 494 | @[typedef] |
| 495 | pub struct C.XSelectionEvent { |
| 496 | pub mut: |
| 497 | type int |
| 498 | display &C.Display = unsafe { nil } |
| 499 | requestor Window |
| 500 | selection Atom |
| 501 | target Atom |
| 502 | property Atom |
| 503 | time int |
| 504 | } |
| 505 | |
| 506 | @[typedef] |
| 507 | pub struct C.XSelectionClearEvent { |
| 508 | pub mut: |
| 509 | window Window |
| 510 | selection Atom |
| 511 | } |
| 512 | |
| 513 | @[typedef] |
| 514 | pub struct C.XSelectionRequestEvent { |
| 515 | pub mut: |
| 516 | display &C.Display = unsafe { nil } |
| 517 | owner Window |
| 518 | requestor Window |
| 519 | selection Atom |
| 520 | target Atom |
| 521 | property Atom |
| 522 | time int |
| 523 | } |
| 524 | |
| 525 | @[typedef] |
| 526 | pub struct C.XDestroyWindowEvent { |
| 527 | pub mut: |
| 528 | window Window |
| 529 | } |
| 530 | |
| 531 | @[typedef] |
| 532 | pub struct C.XPropertyEvent { |
| 533 | pub mut: |
| 534 | state int |
| 535 | atom Atom |
| 536 | } |
| 537 | |
| 538 | @[typedef] |
| 539 | pub struct C.XClientMessageEvent { |
| 540 | pub mut: |
| 541 | window Window |
| 542 | format int |
| 543 | message_type Atom |
| 544 | data C.XClientMessageData |
| 545 | } |
| 546 | |
| 547 | @[typedef] |
| 548 | pub union C.XClientMessageData { |
| 549 | pub mut: |
| 550 | b [20]u8 |
| 551 | s [10]i16 |
| 552 | l [5]i64 |
| 553 | } |
| 554 | |
| 555 | @[typedef] |
| 556 | pub struct C.XGenericEventCookie { |
| 557 | pub mut: |
| 558 | extension int |
| 559 | evtype int |
| 560 | data voidptr |
| 561 | } |
| 562 | |
| 563 | @[typedef] |
| 564 | pub struct C.XKeyEvent { |
| 565 | pub mut: |
| 566 | keycode u32 |
| 567 | state u32 |
| 568 | } |
| 569 | |
| 570 | @[typedef] |
| 571 | pub struct C.XButtonEvent { |
| 572 | pub mut: |
| 573 | button u32 |
| 574 | state u32 |
| 575 | x int |
| 576 | y int |
| 577 | } |
| 578 | |
| 579 | @[typedef] |
| 580 | pub struct C.XMotionEvent { |
| 581 | pub mut: |
| 582 | x int |
| 583 | y int |
| 584 | state u32 |
| 585 | } |
| 586 | |
| 587 | @[typedef] |
| 588 | pub struct C.XCrossingEvent { |
| 589 | pub mut: |
| 590 | x int |
| 591 | y int |
| 592 | state u32 |
| 593 | } |
| 594 | |
| 595 | @[typedef] |
| 596 | pub struct C.XFocusChangeEvent { |
| 597 | pub mut: |
| 598 | mode int |
| 599 | } |
| 600 | |
| 601 | @[typedef] |
| 602 | pub union C.XEvent { |
| 603 | pub mut: |
| 604 | type int |
| 605 | xclient C.XClientMessageEvent |
| 606 | xkey C.XKeyEvent |
| 607 | xbutton C.XButtonEvent |
| 608 | xmotion C.XMotionEvent |
| 609 | xcrossing C.XCrossingEvent |
| 610 | xfocus C.XFocusChangeEvent |
| 611 | xproperty C.XPropertyEvent |
| 612 | xselection C.XSelectionEvent |
| 613 | xselectionrequest C.XSelectionRequestEvent |
| 614 | xselectionclear C.XSelectionClearEvent |
| 615 | xdestroywindow C.XDestroyWindowEvent |
| 616 | xcookie C.XGenericEventCookie |
| 617 | } |
| 618 | |
| 619 | pub struct C.XrmDatabase__rec {} |
| 620 | |
| 621 | pub type XrmDatabase = &C.XrmDatabase__rec |
| 622 | |
| 623 | pub struct C.XSetWindowAttributes { |
| 624 | mut: |
| 625 | colormap Colormap |
| 626 | border_pixel u64 |
| 627 | event_mask u64 |
| 628 | } |
| 629 | |
| 630 | @[typedef] |
| 631 | pub struct C.XWindowAttributes { |
| 632 | mut: |
| 633 | width int |
| 634 | height int |
| 635 | map_state int |
| 636 | } |
| 637 | |
| 638 | pub struct C.XSizeHintsAspect { |
| 639 | mut: |
| 640 | x int |
| 641 | y int |
| 642 | } |
| 643 | |
| 644 | @[typedef] |
| 645 | pub struct C.XSizeHints { |
| 646 | mut: |
| 647 | flags i64 |
| 648 | x int |
| 649 | y int |
| 650 | width int |
| 651 | height int |
| 652 | min_width int |
| 653 | min_height int |
| 654 | max_width int |
| 655 | max_height int |
| 656 | width_inc int |
| 657 | height_inc int |
| 658 | min_aspect C.XSizeHintsAspect |
| 659 | max_aspect C.XSizeHintsAspect |
| 660 | base_width int |
| 661 | base_height int |
| 662 | win_gravity int |
| 663 | } |
| 664 | |
| 665 | pub struct C.XVisualInfo { |
| 666 | mut: |
| 667 | visual &C.Visual = unsafe { nil } |
| 668 | visualid VisualID |
| 669 | depth int |
| 670 | } |
| 671 | |
| 672 | // X11 event types are defined in vlib/x/x11/x11.v |
| 673 | // XEvent union is defined here since it's used extensively in sokol |
| 674 | |
| 675 | pub union C.XEvent { |
| 676 | pub mut: |
| 677 | @type int |
| 678 | xclient C.XClientMessageEvent |
| 679 | xkey C.XKeyEvent |
| 680 | xbutton C.XButtonEvent |
| 681 | xmotion C.XMotionEvent |
| 682 | xcrossing C.XCrossingEvent |
| 683 | xfocus C.XFocusChangeEvent |
| 684 | xproperty C.XPropertyEvent |
| 685 | xselection C.XSelectionEvent |
| 686 | xselectionrequest C.XSelectionRequestEvent |
| 687 | xselectionclear C.XSelectionClearEvent |
| 688 | xdestroywindow C.XDestroyWindowEvent |
| 689 | xcookie C.XGenericEventCookie |
| 690 | } |
| 691 | |
| 692 | pub struct C.XKeyEvent { |
| 693 | pub mut: |
| 694 | keycode u32 |
| 695 | state u32 |
| 696 | } |
| 697 | |
| 698 | pub struct C.XButtonEvent { |
| 699 | pub mut: |
| 700 | button u32 |
| 701 | state u32 |
| 702 | x int |
| 703 | y int |
| 704 | } |
| 705 | |
| 706 | pub struct C.XMotionEvent { |
| 707 | pub mut: |
| 708 | x int |
| 709 | y int |
| 710 | state u32 |
| 711 | } |
| 712 | |
| 713 | pub struct C.XCrossingEvent { |
| 714 | pub mut: |
| 715 | x int |
| 716 | y int |
| 717 | state u32 |
| 718 | } |
| 719 | |
| 720 | pub struct C.XFocusChangeEvent { |
| 721 | pub mut: |
| 722 | mode int |
| 723 | } |
| 724 | |
| 725 | pub struct C.XPropertyEvent { |
| 726 | pub mut: |
| 727 | state int |
| 728 | atom Atom |
| 729 | } |
| 730 | |
| 731 | // XSelection* structs are forward-declared above |
| 732 | // Full definitions come from X11 headers or clipboard module |
| 733 | |
| 734 | pub struct C.XClientMessageEvent { |
| 735 | pub mut: |
| 736 | window Window |
| 737 | format int |
| 738 | message_type Atom |
| 739 | data C.XClientMessageData |
| 740 | } |
| 741 | |
| 742 | pub union C.XClientMessageData { |
| 743 | pub mut: |
| 744 | l [5]i64 |
| 745 | } |
| 746 | |
| 747 | pub struct C.XGenericEventCookie { |
| 748 | pub mut: |
| 749 | extension int |
| 750 | evtype int |
| 751 | data voidptr |
| 752 | } |
| 753 | |
| 754 | pub struct C.XrmValue { |
| 755 | addr &char = unsafe { nil } |
| 756 | } |
| 757 | |
| 758 | // XKB types |
| 759 | pub struct C.XkbDescRec { |
| 760 | mut: |
| 761 | min_key_code u8 |
| 762 | max_key_code u8 |
| 763 | names &C.XkbNamesRec = unsafe { nil } |
| 764 | } |
| 765 | |
| 766 | pub type XkbDescPtr = &C.XkbDescRec |
| 767 | |
| 768 | pub struct C.XkbNamesRec { |
| 769 | mut: |
| 770 | keys &C.XkbKeyNameRec = unsafe { nil } |
| 771 | key_aliases &C.XkbKeyAliasRec = unsafe { nil } |
| 772 | num_key_aliases u8 |
| 773 | } |
| 774 | |
| 775 | pub struct C.XkbKeyNameRec { |
| 776 | mut: |
| 777 | name [4]u8 |
| 778 | } |
| 779 | |
| 780 | pub struct C.XkbKeyAliasRec { |
| 781 | mut: |
| 782 | real [4]u8 |
| 783 | alias [4]u8 |
| 784 | } |
| 785 | |
| 786 | // XInput2 types |
| 787 | pub struct C.XIEventMask { |
| 788 | mut: |
| 789 | deviceid int |
| 790 | mask_len int |
| 791 | mask &u8 = unsafe { nil } |
| 792 | } |
| 793 | |
| 794 | pub struct C.XIRawEvent { |
| 795 | mut: |
| 796 | valuators C.XIValuatorState |
| 797 | raw_values &f64 = unsafe { nil } |
| 798 | } |
| 799 | |
| 800 | pub struct C.XIValuatorState { |
| 801 | mut: |
| 802 | mask_len int |
| 803 | mask &u8 = unsafe { nil } |
| 804 | } |
| 805 | |
| 806 | // Xcursor types |
| 807 | pub struct C.XcursorImage { |
| 808 | mut: |
| 809 | width u32 |
| 810 | height u32 |
| 811 | xhot u32 |
| 812 | yhot u32 |
| 813 | pixels &u32 = unsafe { nil } |
| 814 | } |
| 815 | |
| 816 | pub type XcursorPixel = u32 |
| 817 | |
| 818 | // === Xlib functions === |
| 819 | |
| 820 | fn C.XOpenDisplay(name &char) &C.Display |
| 821 | fn C.XCloseDisplay(display &C.Display) int |
| 822 | fn C.XDefaultScreen(display &C.Display) int |
| 823 | fn C.XDefaultRootWindow(display &C.Display) Window |
| 824 | fn C.XDefaultVisual(display &C.Display, screen int) &C.Visual |
| 825 | fn C.XDefaultDepth(display &C.Display, screen int) int |
| 826 | fn C.XDisplayWidth(display &C.Display, screen int) int |
| 827 | fn C.XDisplayHeight(display &C.Display, screen int) int |
| 828 | fn C.XDisplayWidthMM(display &C.Display, screen int) int |
| 829 | fn C.XInternAtom(display &C.Display, name &char, only_if_exists int) Atom |
| 830 | fn C.XCreateColormap(display &C.Display, window Window, visual &C.Visual, alloc int) Colormap |
| 831 | fn C.XFreeColormap(display &C.Display, colormap Colormap) int |
| 832 | fn 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 |
| 833 | fn C.XDestroyWindow(display &C.Display, window Window) int |
| 834 | fn C.XMapWindow(display &C.Display, window Window) int |
| 835 | fn C.XUnmapWindow(display &C.Display, window Window) int |
| 836 | fn C.XRaiseWindow(display &C.Display, window Window) int |
| 837 | fn C.XFlush(display &C.Display) int |
| 838 | fn C.XSync(display &C.Display, discard int) int |
| 839 | fn C.XPending(display &C.Display) int |
| 840 | fn C.XNextEvent(display &C.Display, event &C.XEvent) int |
| 841 | fn C.XCheckTypedWindowEvent(display &C.Display, window Window, event_type int, event &C.XEvent) int |
| 842 | fn C.XSendEvent(display &C.Display, window Window, propagate int, event_mask i64, event &C.XEvent) int |
| 843 | fn C.XFilterEvent(event &C.XEvent, window Window) int |
| 844 | fn C.XSetWMProtocols(display &C.Display, window Window, protocols &Atom, count int) int |
| 845 | fn C.XSetWMNormalHints(display &C.Display, window Window, hints &C.XSizeHints) int |
| 846 | fn C.XAllocSizeHints() &C.XSizeHints |
| 847 | fn C.XGetWindowAttributes(display &C.Display, window Window, attrs &C.XWindowAttributes) int |
| 848 | fn 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 &u64, bytes_after &u64, prop &&&u8) int |
| 849 | fn C.XChangeProperty(display &C.Display, window Window, property Atom, @type Atom, format int, mode int, data &u8, nelements int) int |
| 850 | fn 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) |
| 851 | fn C.XSetSelectionOwner(display &C.Display, selection Atom, owner Window, time Time) |
| 852 | fn C.XGetSelectionOwner(display &C.Display, selection Atom) Window |
| 853 | fn C.XConvertSelection(display &C.Display, selection Atom, target Atom, property Atom, requestor Window, time Time) |
| 854 | fn C.XFree(data voidptr) int |
| 855 | fn C.XDefineCursor(display &C.Display, window Window, cursor Cursor) int |
| 856 | fn C.XUndefineCursor(display &C.Display, window Window) int |
| 857 | fn C.XCreateFontCursor(display &C.Display, shape u32) Cursor |
| 858 | fn C.XFreeCursor(display &C.Display, cursor Cursor) int |
| 859 | fn 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 |
| 860 | fn C.XUngrabPointer(display &C.Display, time Time) int |
| 861 | fn 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 |
| 862 | fn C.XSetErrorHandler(handler voidptr) voidptr |
| 863 | fn C.XGetKeyboardMapping(display &C.Display, first_keycode u8, keycode_count int, keysyms_per_keycode &int) &KeySym |
| 864 | fn C.XLookupString(event &C.XKeyEvent, buf &char, buf_len int, keysym &KeySym, status voidptr) int |
| 865 | fn C.XQueryExtension(display &C.Display, name &char, major_opcode &int, first_event &int, first_error &int) int |
| 866 | fn C.XResourceManagerString(display &C.Display) &char |
| 867 | fn C.XGetVisualInfo(display &C.Display, vinfo_mask i64, vinfo_template &C.XVisualInfo, nitems &int) &C.XVisualInfo |
| 868 | fn C.XInitThreads() int |
| 869 | fn C.XrmInitialize() |
| 870 | fn C.XrmGetStringDatabase(data &char) XrmDatabase |
| 871 | fn C.XrmDestroyDatabase(db XrmDatabase) |
| 872 | fn C.XrmGetResource(db XrmDatabase, str_name &char, str_class &char, str_type &&char, value &C.XrmValue) int |
| 873 | fn C.XGetEventData(display &C.Display, cookie &C.XGenericEventCookie) int |
| 874 | fn C.XFreeEventData(display &C.Display, cookie &C.XGenericEventCookie) |
| 875 | |
| 876 | // XKB functions |
| 877 | fn C.XkbGetMap(display &C.Display, which u32, device_spec u32) XkbDescPtr |
| 878 | fn C.XkbGetNames(display &C.Display, which u32, desc XkbDescPtr) int |
| 879 | fn C.XkbFreeNames(desc XkbDescPtr, which u32, free_map int) int |
| 880 | fn C.XkbFreeKeyboard(desc XkbDescPtr, which u32, free_all int) int |
| 881 | fn C.XkbSetDetectableAutoRepeat(display &C.Display, detectable int, supported &int) int |
| 882 | |
| 883 | // XInput2 functions |
| 884 | fn C.XIQueryVersion(display &C.Display, major &int, minor &int) int |
| 885 | fn C.XISelectEvents(display &C.Display, window Window, masks &C.XIEventMask, num_masks int) int |
| 886 | |
| 887 | // Xcursor functions |
| 888 | fn C.XcursorImageCreate(width int, height int) &C.XcursorImage |
| 889 | fn C.XcursorImageDestroy(image &C.XcursorImage) |
| 890 | fn C.XcursorImageLoadCursor(display &C.Display, image &C.XcursorImage) Cursor |
| 891 | fn C.XcursorLibraryLoadImage(name &char, theme &char, size int) &C.XcursorImage |
| 892 | fn C.XcursorGetTheme(display &C.Display) &char |
| 893 | fn C.XcursorGetDefaultSize(display &C.Display) int |
| 894 | |
| 895 | // poll |
| 896 | #include <poll.h> |
| 897 | |
| 898 | pub struct C.pollfd { |
| 899 | mut: |
| 900 | fd int |
| 901 | events i16 |
| 902 | revents i16 |
| 903 | } |
| 904 | |
| 905 | fn C.poll(fds &C.pollfd, nfds u64, timeout int) int |
| 906 | |
| 907 | fn C.ConnectionNumber(display &C.Display) int |
| 908 | |
| 909 | fn C.atof(str &char) f64 |
| 910 | fn C.strncmp(s1 &char, s2 &char, n usize) int |
| 911 | |
| 912 | // X11 constants |
| 913 | const x_false = 0 |
| 914 | const x_true = 1 |
| 915 | const x_none = Atom(0) |
| 916 | const xa_atom = Atom(4) |
| 917 | const xa_cardinal = Atom(6) |
| 918 | const alloc_none = 0 |
| 919 | const cw_border_pixel = u64(1 << 11) |
| 920 | const cw_colormap = u64(1 << 13) |
| 921 | const cw_event_mask = u64(1 << 11) // this is actually CWEventMask |
| 922 | const input_output = u32(1) |
| 923 | const structure_notify_mask = i64(1 << 17) |
| 924 | const key_press_mask = i64(1 << 0) |
| 925 | const key_release_mask = i64(1 << 1) |
| 926 | const pointer_motion_mask = i64(1 << 6) |
| 927 | const button_press_mask = i64(1 << 2) |
| 928 | const button_release_mask = i64(1 << 3) |
| 929 | const exposure_mask = i64(1 << 15) |
| 930 | const focus_change_mask = i64(1 << 21) |
| 931 | const visibility_change_mask = i64(1 << 16) |
| 932 | const enter_window_mask = i64(1 << 4) |
| 933 | const leave_window_mask = i64(1 << 5) |
| 934 | const property_change_mask = i64(1 << 22) |
| 935 | const substructure_notify_mask = i64(1 << 19) |
| 936 | const substructure_redirect_mask = i64(1 << 20) |
| 937 | const no_event_mask = i64(0) |
| 938 | |
| 939 | const prop_mode_replace = 0 |
| 940 | const pw_gravity = i64(1 << 9) // PWinGravity flag |
| 941 | const center_gravity = 5 |
| 942 | |
| 943 | const is_viewable = 2 |
| 944 | const visibility_notify = 15 |
| 945 | const normal_state = 1 |
| 946 | const iconic_state = 3 |
| 947 | const withdrawn_state = 0 |
| 948 | |
| 949 | const current_time = Time(0) |
| 950 | const grab_mode_async = 1 |
| 951 | |
| 952 | // Event types |
| 953 | const x_generic_event = 35 |
| 954 | const x_focus_in = 9 |
| 955 | const x_focus_out = 10 |
| 956 | const x_key_press = 2 |
| 957 | const x_key_release = 3 |
| 958 | const x_button_press = 4 |
| 959 | const x_button_release = 5 |
| 960 | const x_enter_notify = 7 |
| 961 | const x_leave_notify = 8 |
| 962 | const x_motion_notify = 6 |
| 963 | const x_property_notify = 28 |
| 964 | const x_selection_notify = 31 |
| 965 | const x_selection_request = 30 |
| 966 | const x_destroy_notify = 17 |
| 967 | const x_client_message = 33 |
| 968 | const property_new_value = 0 |
| 969 | |
| 970 | const notify_grab = 1 |
| 971 | const notify_ungrab = 2 |
| 972 | |
| 973 | // Mouse buttons |
| 974 | const x_button1 = u32(1) |
| 975 | const x_button2 = u32(2) |
| 976 | const x_button3 = u32(3) |
| 977 | |
| 978 | // Modifier masks |
| 979 | const shift_mask = u32(1 << 0) |
| 980 | const control_mask = u32(1 << 2) |
| 981 | const mod1_mask = u32(1 << 3) // Alt |
| 982 | const mod4_mask = u32(1 << 6) // Super |
| 983 | const button1_mask = u32(1 << 8) |
| 984 | const button2_mask = u32(1 << 9) |
| 985 | const button3_mask = u32(1 << 10) |
| 986 | |
| 987 | // Cursor shapes for XCreateFontCursor |
| 988 | const xc_left_ptr = u32(68) |
| 989 | const xc_xterm = u32(152) |
| 990 | const xc_crosshair = u32(34) |
| 991 | const xc_hand2 = u32(60) |
| 992 | const xc_sb_h_double_arrow = u32(108) |
| 993 | const xc_sb_v_double_arrow = u32(116) |
| 994 | const xc_fleur = u32(52) |
| 995 | |
| 996 | // XKB constants |
| 997 | const xkb_use_core_kbd = u32(0x0100) |
| 998 | const xkb_key_names_mask = u32(1 << 9) |
| 999 | const xkb_key_aliases_mask = u32(1 << 10) |
| 1000 | const xkb_key_name_length = 4 |
| 1001 | |
| 1002 | // XInput2 constants |
| 1003 | const xi_all_master_devices = -1 |
| 1004 | const xi_raw_motion = 17 |
| 1005 | const pollin = i16(0x001) |
| 1006 | |
| 1007 | // XDnD |
| 1008 | const x11_xdnd_version = 5 |
| 1009 | |
| 1010 | // KeySym constants |
| 1011 | const xk_escape = KeySym(0xff1b) |
| 1012 | const xk_tab = KeySym(0xff09) |
| 1013 | const xk_shift_l = KeySym(0xffe1) |
| 1014 | const xk_shift_r = KeySym(0xffe2) |
| 1015 | const xk_control_l = KeySym(0xffe3) |
| 1016 | const xk_control_r = KeySym(0xffe4) |
| 1017 | const xk_meta_l = KeySym(0xffe7) |
| 1018 | const xk_alt_l = KeySym(0xffe9) |
| 1019 | const xk_mode_switch = KeySym(0xff7e) |
| 1020 | const xk_iso_level3_shift = KeySym(0xfe03) |
| 1021 | const xk_meta_r = KeySym(0xffe8) |
| 1022 | const xk_alt_r = KeySym(0xffea) |
| 1023 | const xk_super_l = KeySym(0xffeb) |
| 1024 | const xk_super_r = KeySym(0xffec) |
| 1025 | const xk_menu = KeySym(0xff67) |
| 1026 | const xk_num_lock = KeySym(0xff7f) |
| 1027 | const xk_caps_lock = KeySym(0xffe5) |
| 1028 | const xk_print = KeySym(0xff61) |
| 1029 | const xk_scroll_lock = KeySym(0xff14) |
| 1030 | const xk_pause = KeySym(0xff13) |
| 1031 | const xk_delete = KeySym(0xffff) |
| 1032 | const xk_backspace = KeySym(0xff08) |
| 1033 | const xk_return = KeySym(0xff0d) |
| 1034 | const xk_home = KeySym(0xff50) |
| 1035 | const xk_end = KeySym(0xff57) |
| 1036 | const xk_page_up = KeySym(0xff55) |
| 1037 | const xk_page_down = KeySym(0xff56) |
| 1038 | const xk_insert = KeySym(0xff63) |
| 1039 | const xk_left = KeySym(0xff51) |
| 1040 | const xk_right = KeySym(0xff53) |
| 1041 | const xk_down = KeySym(0xff54) |
| 1042 | const xk_up = KeySym(0xff52) |
| 1043 | const xk_f1 = KeySym(0xffbe) |
| 1044 | const xk_f2 = KeySym(0xffbf) |
| 1045 | const xk_f3 = KeySym(0xffc0) |
| 1046 | const xk_f4 = KeySym(0xffc1) |
| 1047 | const xk_f5 = KeySym(0xffc2) |
| 1048 | const xk_f6 = KeySym(0xffc3) |
| 1049 | const xk_f7 = KeySym(0xffc4) |
| 1050 | const xk_f8 = KeySym(0xffc5) |
| 1051 | const xk_f9 = KeySym(0xffc6) |
| 1052 | const xk_f10 = KeySym(0xffc7) |
| 1053 | const xk_f11 = KeySym(0xffc8) |
| 1054 | const xk_f12 = KeySym(0xffc9) |
| 1055 | const xk_f13 = KeySym(0xffca) |
| 1056 | const xk_f14 = KeySym(0xffcb) |
| 1057 | const xk_f15 = KeySym(0xffcc) |
| 1058 | const xk_f16 = KeySym(0xffcd) |
| 1059 | const xk_f17 = KeySym(0xffce) |
| 1060 | const xk_f18 = KeySym(0xffcf) |
| 1061 | const xk_f19 = KeySym(0xffd0) |
| 1062 | const xk_f20 = KeySym(0xffd1) |
| 1063 | const xk_f21 = KeySym(0xffd2) |
| 1064 | const xk_f22 = KeySym(0xffd3) |
| 1065 | const xk_f23 = KeySym(0xffd4) |
| 1066 | const xk_f24 = KeySym(0xffd5) |
| 1067 | const xk_f25 = KeySym(0xffd6) |
| 1068 | const xk_kp_divide = KeySym(0xffaf) |
| 1069 | const xk_kp_multiply = KeySym(0xffaa) |
| 1070 | const xk_kp_subtract = KeySym(0xffad) |
| 1071 | const xk_kp_add = KeySym(0xffab) |
| 1072 | const xk_kp_0 = KeySym(0xffb0) |
| 1073 | const xk_kp_1 = KeySym(0xffb1) |
| 1074 | const xk_kp_2 = KeySym(0xffb2) |
| 1075 | const xk_kp_3 = KeySym(0xffb3) |
| 1076 | const xk_kp_4 = KeySym(0xffb4) |
| 1077 | const xk_kp_5 = KeySym(0xffb5) |
| 1078 | const xk_kp_6 = KeySym(0xffb6) |
| 1079 | const xk_kp_7 = KeySym(0xffb7) |
| 1080 | const xk_kp_8 = KeySym(0xffb8) |
| 1081 | const xk_kp_9 = KeySym(0xffb9) |
| 1082 | const xk_kp_separator = KeySym(0xffac) |
| 1083 | const xk_kp_decimal = KeySym(0xffae) |
| 1084 | const xk_kp_equal = KeySym(0xffbd) |
| 1085 | const xk_kp_enter = KeySym(0xff8d) |
| 1086 | const xk_kp_insert = KeySym(0xff9e) |
| 1087 | const xk_kp_end = KeySym(0xff9c) |
| 1088 | const xk_kp_down = KeySym(0xff99) |
| 1089 | const xk_kp_page_down = KeySym(0xff9b) |
| 1090 | const xk_kp_left = KeySym(0xff96) |
| 1091 | const xk_kp_right = KeySym(0xff98) |
| 1092 | const xk_kp_home = KeySym(0xff95) |
| 1093 | const xk_kp_up = KeySym(0xff97) |
| 1094 | const xk_kp_page_up = KeySym(0xff9a) |
| 1095 | const xk_kp_delete = KeySym(0xff9f) |
| 1096 | const xk_a = KeySym(0x0061) |
| 1097 | const xk_b = KeySym(0x0062) |
| 1098 | const xk_c = KeySym(0x0063) |
| 1099 | const xk_d = KeySym(0x0064) |
| 1100 | const xk_e = KeySym(0x0065) |
| 1101 | const xk_f = KeySym(0x0066) |
| 1102 | const xk_g = KeySym(0x0067) |
| 1103 | const xk_h = KeySym(0x0068) |
| 1104 | const xk_i = KeySym(0x0069) |
| 1105 | const xk_j = KeySym(0x006a) |
| 1106 | const xk_k = KeySym(0x006b) |
| 1107 | const xk_l = KeySym(0x006c) |
| 1108 | const xk_m = KeySym(0x006d) |
| 1109 | const xk_n = KeySym(0x006e) |
| 1110 | const xk_o = KeySym(0x006f) |
| 1111 | const xk_p = KeySym(0x0070) |
| 1112 | const xk_q = KeySym(0x0071) |
| 1113 | const xk_r = KeySym(0x0072) |
| 1114 | const xk_s = KeySym(0x0073) |
| 1115 | const xk_t = KeySym(0x0074) |
| 1116 | const xk_u = KeySym(0x0075) |
| 1117 | const xk_v = KeySym(0x0076) |
| 1118 | const xk_w = KeySym(0x0077) |
| 1119 | const xk_x = KeySym(0x0078) |
| 1120 | const xk_y = KeySym(0x0079) |
| 1121 | const xk_z = KeySym(0x007a) |
| 1122 | const xk_0 = KeySym(0x0030) |
| 1123 | const xk_1 = KeySym(0x0031) |
| 1124 | const xk_2 = KeySym(0x0032) |
| 1125 | const xk_3 = KeySym(0x0033) |
| 1126 | const xk_4 = KeySym(0x0034) |
| 1127 | const xk_5 = KeySym(0x0035) |
| 1128 | const xk_6 = KeySym(0x0036) |
| 1129 | const xk_7 = KeySym(0x0037) |
| 1130 | const xk_8 = KeySym(0x0038) |
| 1131 | const xk_9 = KeySym(0x0039) |
| 1132 | const xk_space = KeySym(0x0020) |
| 1133 | const xk_minus = KeySym(0x002d) |
| 1134 | const xk_equal = KeySym(0x003d) |
| 1135 | const xk_bracketleft = KeySym(0x005b) |
| 1136 | const xk_bracketright = KeySym(0x005d) |
| 1137 | const xk_backslash = KeySym(0x005c) |
| 1138 | const xk_semicolon = KeySym(0x003b) |
| 1139 | const xk_apostrophe = KeySym(0x0027) |
| 1140 | const xk_grave = KeySym(0x0060) |
| 1141 | const xk_comma = KeySym(0x002c) |
| 1142 | const xk_period = KeySym(0x002e) |
| 1143 | const xk_slash = KeySym(0x002f) |
| 1144 | const xk_less = KeySym(0x003c) |
| 1145 | |
| 1146 | // XIMaskLen macro equivalent |
| 1147 | fn xi_mask_len(event int) int { |
| 1148 | return (event >> 3) + 1 |
| 1149 | } |
| 1150 | |
| 1151 | // XISetMask macro equivalent |
| 1152 | fn xi_set_mask(mask &u8, event int) { |
| 1153 | unsafe { |
| 1154 | mut p := mask + (event >> 3) |
| 1155 | *p = *p | u8(1 << (event & 7)) |
| 1156 | } |
| 1157 | } |
| 1158 | |
| 1159 | // XIMaskIsSet macro equivalent |
| 1160 | fn xi_mask_is_set(mask &u8, event int) bool { |
| 1161 | unsafe { |
| 1162 | return (mask[event >> 3] & u8(1 << (event & 7))) != 0 |
| 1163 | } |
| 1164 | } |
| 1165 | |
| 1166 | // VisualIDMask for XGetVisualInfo |
| 1167 | const visual_id_mask = i64(0x1) |
| 1168 | |