From 84c3e0baf10050315325da97f85199e0d02d5eb2 Mon Sep 17 00:00:00 2001 From: Ben Buhse Date: Mon, 2 Dec 2024 20:40:49 -0600 Subject: [PATCH] Remove noop() Sending a handler with incompatible pointer types is undefined behavior, so this removes noop() and implements empty handlers for all of its previous uses. This used to work until C23. --- wlopm.c | 53 +++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/wlopm.c b/wlopm.c index 8b54f30..80f1cb3 100644 --- a/wlopm.c +++ b/wlopm.c @@ -92,8 +92,6 @@ struct zwlr_output_power_manager_v1 *wlr_output_power_manager = NULL; int ret = EXIT_SUCCESS; bool loop = true; -static void noop () {} - static void wlr_output_power_handle_mode (void *data, struct zwlr_output_power_v1 *wlr_output_power, enum zwlr_output_power_v1_mode mode) { @@ -121,13 +119,43 @@ static void wl_output_handle_name (void *data, struct wl_output *wl_output, output->name = strdup(name); } +static void wl_output_handle_geometry (void *data, struct wl_output *wl_output, + int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, + int32_t subpixel, const char* make, const char* model, int32_t transform) +{ + /* This function is deliberately left empty. */ +} + +static void wl_output_handle_mode (void *data, struct wl_output *wl_output, + uint32_t flags, int32_t width, int32_t height, int32_t refresh) +{ + /* This function is deliberately left empty. */ +} + +static void wl_output_handle_scale (void *data, struct wl_output *wl_output, + int32_t scale) +{ + /* This function is deliberately left empty. */ +} + +static void wl_output_handle_description (void *data, struct wl_output *wl_output, + const char *description) +{ + /* This function is deliberately left empty. */ +} + +static void wl_output_handle_done (void *data, struct wl_output *wl_output) +{ + /* This function is deliberately left empty. */ +} + static const struct wl_output_listener wl_output_listener = { .name = wl_output_handle_name, - .geometry = noop, - .mode = noop, - .scale = noop, - .description = noop, - .done = noop, + .geometry = wl_output_handle_geometry, + .mode = wl_output_handle_mode, + .scale = wl_output_handle_scale, + .description = wl_output_handle_description, + .done = wl_output_handle_done, }; static void registry_handle_global (void *data, struct wl_registry *registry, @@ -150,7 +178,7 @@ static void registry_handle_global (void *data, struct wl_registry *registry, return; } - output->wl_output = wl_registry_bind(registry, name, + output->wl_output = wl_registry_bind(registry, name, &wl_output_interface, 4); wl_output_add_listener(output->wl_output, &wl_output_listener, output); output->wlr_output_power = NULL; @@ -164,9 +192,15 @@ static void registry_handle_global (void *data, struct wl_registry *registry, &zwlr_output_power_manager_v1_interface, version); } +static void registry_handle_global_remove (void *data, struct wl_registry *registry, + uint32_t name) +{ + /* We don't run long enough to care. */ +} + static const struct wl_registry_listener registry_listener = { .global = registry_handle_global, - .global_remove = noop, /* We don't run long enough to care. */ + .global_remove = registry_handle_global_remove, }; static void sync_handle_done (void *data, struct wl_callback *wl_callback, uint32_t other_data); @@ -569,4 +603,3 @@ int main(int argc, char *argv[]) return ret; } -