app/internal/window: [Wayland] use a single callback entry for each object

The callbackMap is used to look up Go references in event callbacks. Instead
of registering one entry for each possible callback type, use a single
handle for each Go reference.

Signed-off-by: Elias Naur <mail@eliasnaur.com>
This commit is contained in:
Elias Naur
2020-05-15 15:59:58 +02:00
parent bf129ca989
commit 1a48b5c33c
3 changed files with 95 additions and 107 deletions
+22 -22
View File
@@ -8,52 +8,52 @@
#include "os_wayland.h"
#include "_cgo_export.h"
void gio_wl_registry_add_listener(struct wl_registry *reg) {
void gio_wl_registry_add_listener(struct wl_registry *reg, void *data) {
static const struct wl_registry_listener listener = {
// Cast away const parameter.
.global = (void (*)(void *, struct wl_registry *, uint32_t, const char *, uint32_t))gio_onRegistryGlobal,
.global_remove = gio_onRegistryGlobalRemove
};
wl_registry_add_listener(reg, &listener, NULL);
wl_registry_add_listener(reg, &listener, data);
}
void gio_wl_surface_add_listener(struct wl_surface *surface) {
void gio_wl_surface_add_listener(struct wl_surface *surface, void *data) {
static struct wl_surface_listener listener = {
.enter = gio_onSurfaceEnter,
.leave = gio_onSurfaceLeave,
};
wl_surface_add_listener(surface, &listener, NULL);
wl_surface_add_listener(surface, &listener, data);
}
void gio_xdg_surface_add_listener(struct xdg_surface *surface) {
void gio_xdg_surface_add_listener(struct xdg_surface *surface, void *data) {
static const struct xdg_surface_listener listener = {
.configure = gio_onXdgSurfaceConfigure,
};
xdg_surface_add_listener(surface, &listener, NULL);
xdg_surface_add_listener(surface, &listener, data);
}
void gio_xdg_toplevel_add_listener(struct xdg_toplevel *toplevel) {
void gio_xdg_toplevel_add_listener(struct xdg_toplevel *toplevel, void *data) {
static const struct xdg_toplevel_listener listener = {
.configure = gio_onToplevelConfigure,
.close = gio_onToplevelClose,
};
xdg_toplevel_add_listener(toplevel, &listener, NULL);
xdg_toplevel_add_listener(toplevel, &listener, data);
}
static void xdg_wm_base_handle_ping(void *data, struct xdg_wm_base *wm, uint32_t serial) {
xdg_wm_base_pong(wm, serial);
}
void gio_xdg_wm_base_add_listener(struct xdg_wm_base *wm) {
void gio_xdg_wm_base_add_listener(struct xdg_wm_base *wm, void *data) {
static const struct xdg_wm_base_listener listener = {
.ping = xdg_wm_base_handle_ping,
};
xdg_wm_base_add_listener(wm, &listener, NULL);
xdg_wm_base_add_listener(wm, &listener, data);
}
void gio_wl_callback_add_listener(struct wl_callback *callback, void *data) {
@@ -64,7 +64,7 @@ void gio_wl_callback_add_listener(struct wl_callback *callback, void *data) {
wl_callback_add_listener(callback, &listener, data);
}
void gio_wl_output_add_listener(struct wl_output *output) {
void gio_wl_output_add_listener(struct wl_output *output, void *data) {
static const struct wl_output_listener listener = {
// Cast away const parameter.
.geometry = (void (*)(void *, struct wl_output *, int32_t, int32_t, int32_t, int32_t, int32_t, const char *, const char *, int32_t))gio_onOutputGeometry,
@@ -73,20 +73,20 @@ void gio_wl_output_add_listener(struct wl_output *output) {
.scale = gio_onOutputScale,
};
wl_output_add_listener(output, &listener, NULL);
wl_output_add_listener(output, &listener, data);
}
void gio_wl_seat_add_listener(struct wl_seat *seat) {
void gio_wl_seat_add_listener(struct wl_seat *seat, void *data) {
static const struct wl_seat_listener listener = {
.capabilities = gio_onSeatCapabilities,
// Cast away const parameter.
.name = (void (*)(void *, struct wl_seat *, const char *))gio_onSeatName,
};
wl_seat_add_listener(seat, &listener, NULL);
wl_seat_add_listener(seat, &listener, data);
}
void gio_wl_pointer_add_listener(struct wl_pointer *pointer) {
void gio_wl_pointer_add_listener(struct wl_pointer *pointer, void *data) {
static const struct wl_pointer_listener listener = {
.enter = gio_onPointerEnter,
.leave = gio_onPointerLeave,
@@ -99,10 +99,10 @@ void gio_wl_pointer_add_listener(struct wl_pointer *pointer) {
.axis_discrete = gio_onPointerAxisDiscrete,
};
wl_pointer_add_listener(pointer, &listener, NULL);
wl_pointer_add_listener(pointer, &listener, data);
}
void gio_wl_touch_add_listener(struct wl_touch *touch) {
void gio_wl_touch_add_listener(struct wl_touch *touch, void *data) {
static const struct wl_touch_listener listener = {
.down = gio_onTouchDown,
.up = gio_onTouchUp,
@@ -111,10 +111,10 @@ void gio_wl_touch_add_listener(struct wl_touch *touch) {
.cancel = gio_onTouchCancel,
};
wl_touch_add_listener(touch, &listener, NULL);
wl_touch_add_listener(touch, &listener, data);
}
void gio_wl_keyboard_add_listener(struct wl_keyboard *keyboard) {
void gio_wl_keyboard_add_listener(struct wl_keyboard *keyboard, void *data) {
static const struct wl_keyboard_listener listener = {
.keymap = gio_onKeyboardKeymap,
.enter = gio_onKeyboardEnter,
@@ -124,10 +124,10 @@ void gio_wl_keyboard_add_listener(struct wl_keyboard *keyboard) {
.repeat_info = gio_onKeyboardRepeatInfo
};
wl_keyboard_add_listener(keyboard, &listener, NULL);
wl_keyboard_add_listener(keyboard, &listener, data);
}
void gio_zwp_text_input_v3_add_listener(struct zwp_text_input_v3 *im) {
void gio_zwp_text_input_v3_add_listener(struct zwp_text_input_v3 *im, void *data) {
static const struct zwp_text_input_v3_listener listener = {
.enter = gio_onTextInputEnter,
.leave = gio_onTextInputLeave,
@@ -138,5 +138,5 @@ void gio_zwp_text_input_v3_add_listener(struct zwp_text_input_v3 *im) {
.done = gio_onTextInputDone
};
zwp_text_input_v3_add_listener(im, &listener, NULL);
zwp_text_input_v3_add_listener(im, &listener, data);
}