gioui.org/ui@v0.0.0-20190926171558-ce74bc0cbaea/app/os_wayland.c (about) 1 // SPDX-License-Identifier: Unlicense OR MIT 2 3 // +build linux,!android 4 5 #include <wayland-client.h> 6 #include "wayland_xdg_shell.h" 7 #include "wayland_text_input.h" 8 #include "os_wayland.h" 9 #include "_cgo_export.h" 10 11 static const struct wl_registry_listener registry_listener = { 12 // Cast away const parameter. 13 .global = (void (*)(void *, struct wl_registry *, uint32_t, const char *, uint32_t))gio_onRegistryGlobal, 14 .global_remove = gio_onRegistryGlobalRemove 15 }; 16 17 void gio_wl_registry_add_listener(struct wl_registry *reg) { 18 wl_registry_add_listener(reg, ®istry_listener, NULL); 19 } 20 21 static struct wl_surface_listener surface_listener = {.enter = gio_onSurfaceEnter, .leave = gio_onSurfaceLeave}; 22 23 void gio_wl_surface_add_listener(struct wl_surface *surface) { 24 wl_surface_add_listener(surface, &surface_listener, NULL); 25 } 26 27 static const struct xdg_surface_listener xdg_surface_listener = { 28 .configure = gio_onXdgSurfaceConfigure, 29 }; 30 31 void gio_xdg_surface_add_listener(struct xdg_surface *surface) { 32 xdg_surface_add_listener(surface, &xdg_surface_listener, NULL); 33 } 34 35 static const struct xdg_toplevel_listener xdg_toplevel_listener = { 36 .configure = gio_onToplevelConfigure, 37 .close = gio_onToplevelClose, 38 }; 39 40 void gio_xdg_toplevel_add_listener(struct xdg_toplevel *toplevel) { 41 xdg_toplevel_add_listener(toplevel, &xdg_toplevel_listener, NULL); 42 } 43 44 static void xdg_wm_base_handle_ping(void *data, struct xdg_wm_base *wm, uint32_t serial) { 45 xdg_wm_base_pong(wm, serial); 46 } 47 static const struct xdg_wm_base_listener xdg_wm_base_listener = { 48 .ping = xdg_wm_base_handle_ping, 49 }; 50 51 void gio_xdg_wm_base_add_listener(struct xdg_wm_base *wm) { 52 xdg_wm_base_add_listener(wm, &xdg_wm_base_listener, NULL); 53 } 54 55 static const struct wl_callback_listener wl_callback_listener = { 56 .done = gio_onFrameDone, 57 }; 58 59 void gio_wl_callback_add_listener(struct wl_callback *callback, void *data) { 60 wl_callback_add_listener(callback, &wl_callback_listener, data); 61 } 62 63 static const struct wl_output_listener wl_output_listener = { 64 // Cast away const parameter. 65 .geometry = (void (*)(void *, struct wl_output *, int32_t, int32_t, int32_t, int32_t, int32_t, const char *, const char *, int32_t))gio_onOutputGeometry, 66 .mode = gio_onOutputMode, 67 .done = gio_onOutputDone, 68 .scale = gio_onOutputScale, 69 }; 70 71 void gio_wl_output_add_listener(struct wl_output *output) { 72 wl_output_add_listener(output, &wl_output_listener, NULL); 73 } 74 75 static const struct wl_seat_listener wl_seat_listener = { 76 .capabilities = gio_onSeatCapabilities, 77 // Cast away const parameter. 78 .name = (void (*)(void *, struct wl_seat *, const char *))gio_onSeatName, 79 }; 80 81 void gio_wl_seat_add_listener(struct wl_seat *seat) { 82 wl_seat_add_listener(seat, &wl_seat_listener, NULL); 83 } 84 85 static const struct wl_pointer_listener wl_pointer_listener = { 86 .enter = gio_onPointerEnter, 87 .leave = gio_onPointerLeave, 88 .motion = gio_onPointerMotion, 89 .button = gio_onPointerButton, 90 .axis = gio_onPointerAxis, 91 .frame = gio_onPointerFrame, 92 .axis_source = gio_onPointerAxisSource, 93 .axis_stop = gio_onPointerAxisStop, 94 .axis_discrete = gio_onPointerAxisDiscrete, 95 }; 96 97 void gio_wl_pointer_add_listener(struct wl_pointer *pointer) { 98 wl_pointer_add_listener(pointer, &wl_pointer_listener, NULL); 99 } 100 101 static const struct wl_touch_listener wl_touch_listener = { 102 .down = gio_onTouchDown, 103 .up = gio_onTouchUp, 104 .motion = gio_onTouchMotion, 105 .frame = gio_onTouchFrame, 106 .cancel = gio_onTouchCancel, 107 }; 108 109 void gio_wl_touch_add_listener(struct wl_touch *touch) { 110 wl_touch_add_listener(touch, &wl_touch_listener, NULL); 111 } 112 113 static const struct wl_keyboard_listener wl_keyboard_listener = { 114 .keymap = gio_onKeyboardKeymap, 115 .enter = gio_onKeyboardEnter, 116 .leave = gio_onKeyboardLeave, 117 .key = gio_onKeyboardKey, 118 .modifiers = gio_onKeyboardModifiers, 119 .repeat_info = gio_onKeyboardRepeatInfo 120 }; 121 122 void gio_wl_keyboard_add_listener(struct wl_keyboard *keyboard) { 123 wl_keyboard_add_listener(keyboard, &wl_keyboard_listener, NULL); 124 } 125 126 static const struct zwp_text_input_v3_listener zwp_text_input_v3_listener = { 127 .enter = gio_onTextInputEnter, 128 .leave = gio_onTextInputLeave, 129 // Cast away const parameter. 130 .preedit_string = (void (*)(void *, struct zwp_text_input_v3 *, const char *, int32_t, int32_t))gio_onTextInputPreeditString, 131 .commit_string = (void (*)(void *, struct zwp_text_input_v3 *, const char *))gio_onTextInputCommitString, 132 .delete_surrounding_text = gio_onTextInputDeleteSurroundingText, 133 .done = gio_onTextInputDone 134 }; 135 136 void gio_zwp_text_input_v3_add_listener(struct zwp_text_input_v3 *im) { 137 zwp_text_input_v3_add_listener(im, &zwp_text_input_v3_listener, NULL); 138 }