From e98cb7c5ab8916d4c401da8d1b121a9a90419304 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 17 Sep 2018 22:10:34 +0200 Subject: backend/wayland: add assertions --- backend/wayland/backend.c | 14 ++++++++++---- backend/wayland/output.c | 41 +++++++++++++++++++++++------------------ backend/wayland/wl_seat.c | 30 +++++++++++++++++++----------- include/backend/wayland.h | 2 ++ 4 files changed, 54 insertions(+), 33 deletions(-) diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 506bcd5e..28f61863 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -15,6 +15,12 @@ #include "util/signal.h" #include "xdg-shell-unstable-v6-client-protocol.h" +struct wlr_wl_backend *get_wl_backend_from_backend( + struct wlr_backend *wlr_backend) { + assert(wlr_backend_is_wl(wlr_backend)); + return (struct wlr_wl_backend *)wlr_backend; +} + static int dispatch_events(int fd, uint32_t mask, void *data) { struct wlr_wl_backend *backend = data; int count = 0; @@ -39,8 +45,8 @@ static int dispatch_events(int fd, uint32_t mask, void *data) { * compositor and creates surfaces for each output, then registers globals on * the specified display. */ -static bool backend_start(struct wlr_backend *_backend) { - struct wlr_wl_backend *backend = (struct wlr_wl_backend *)_backend; +static bool backend_start(struct wlr_backend *wlr_backend) { + struct wlr_wl_backend *backend = get_wl_backend_from_backend(wlr_backend); wlr_log(WLR_INFO, "Initializating wayland backend"); poll_wl_registry(backend); @@ -66,7 +72,7 @@ static bool backend_start(struct wlr_backend *_backend) { } static void backend_destroy(struct wlr_backend *wlr_backend) { - struct wlr_wl_backend *backend = (struct wlr_wl_backend *)wlr_backend; + struct wlr_wl_backend *backend = get_wl_backend_from_backend(wlr_backend); if (backend == NULL) { return; } @@ -118,7 +124,7 @@ static void backend_destroy(struct wlr_backend *wlr_backend) { static struct wlr_renderer *backend_get_renderer( struct wlr_backend *wlr_backend) { - struct wlr_wl_backend *backend = (struct wlr_wl_backend *)wlr_backend; + struct wlr_wl_backend *backend = get_wl_backend_from_backend(wlr_backend); return backend->renderer; } diff --git a/backend/wayland/output.c b/backend/wayland/output.c index 2fd35a3a..4eb99a3b 100644 --- a/backend/wayland/output.c +++ b/backend/wayland/output.c @@ -15,7 +15,11 @@ #include "util/signal.h" #include "xdg-shell-unstable-v6-client-protocol.h" -int os_create_anonymous_file(off_t size); +static struct wlr_wl_output *get_wl_output_from_output( + struct wlr_output *wlr_output) { + assert(wlr_output_is_wl(wlr_output)); + return (struct wlr_wl_output *)wlr_output; +} static struct wl_callback_listener frame_listener; @@ -33,9 +37,9 @@ static struct wl_callback_listener frame_listener = { .done = surface_frame_callback }; -static bool output_set_custom_mode(struct wlr_output *_output, +static bool output_set_custom_mode(struct wlr_output *wlr_output, int32_t width, int32_t height, int32_t refresh) { - struct wlr_wl_output *output = (struct wlr_wl_output *)_output; + struct wlr_wl_output *output = get_wl_output_from_output(wlr_output); wl_egl_window_resize(output->egl_window, width, height, 0, 0); wlr_output_update_custom_mode(&output->wlr_output, width, height, 0); return true; @@ -44,7 +48,7 @@ static bool output_set_custom_mode(struct wlr_output *_output, static bool output_make_current(struct wlr_output *wlr_output, int *buffer_age) { struct wlr_wl_output *output = - (struct wlr_wl_output *)wlr_output; + get_wl_output_from_output(wlr_output); return wlr_egl_make_current(&output->backend->egl, output->egl_surface, buffer_age); } @@ -52,7 +56,7 @@ static bool output_make_current(struct wlr_output *wlr_output, static bool output_swap_buffers(struct wlr_output *wlr_output, pixman_region32_t *damage) { struct wlr_wl_output *output = - (struct wlr_wl_output *)wlr_output; + get_wl_output_from_output(wlr_output); if (output->frame_callback != NULL) { wlr_log(WLR_ERROR, "Skipping buffer swap"); @@ -66,21 +70,22 @@ static bool output_swap_buffers(struct wlr_output *wlr_output, damage); } -static void output_transform(struct wlr_output *_output, +static void output_transform(struct wlr_output *wlr_output, enum wl_output_transform transform) { - struct wlr_wl_output *output = (struct wlr_wl_output *)_output; + struct wlr_wl_output *output = get_wl_output_from_output(wlr_output); output->wlr_output.transform = transform; } static bool output_set_cursor(struct wlr_output *wlr_output, struct wlr_texture *texture, int32_t scale, - enum wl_output_transform transform, int32_t hotspot_x, int32_t hotspot_y, - bool update_texture) { - struct wlr_wl_output *output = (struct wlr_wl_output *)wlr_output; + enum wl_output_transform transform, + int32_t hotspot_x, int32_t hotspot_y, bool update_texture) { + struct wlr_wl_output *output = get_wl_output_from_output(wlr_output); struct wlr_wl_backend *backend = output->backend; struct wlr_box hotspot = { .x = hotspot_x, .y = hotspot_y }; - wlr_box_transform(&hotspot, wlr_output_transform_invert(wlr_output->transform), + wlr_box_transform(&hotspot, + wlr_output_transform_invert(wlr_output->transform), output->cursor.width, output->cursor.height, &hotspot); // TODO: use output->wlr_output.transform to transform pixels and hotpot @@ -147,8 +152,7 @@ static bool output_set_cursor(struct wlr_output *wlr_output, } static void output_destroy(struct wlr_output *wlr_output) { - struct wlr_wl_output *output = - (struct wlr_wl_output *)wlr_output; + struct wlr_wl_output *output = get_wl_output_from_output(wlr_output); if (output == NULL) { return; } @@ -215,7 +219,8 @@ static struct zxdg_surface_v6_listener xdg_surface_listener = { .configure = xdg_surface_handle_configure, }; -static void xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *xdg_toplevel, +static void xdg_toplevel_handle_configure(void *data, + struct zxdg_toplevel_v6 *xdg_toplevel, int32_t width, int32_t height, struct wl_array *states) { struct wlr_wl_output *output = data; assert(output && output->xdg_toplevel == xdg_toplevel); @@ -228,7 +233,8 @@ static void xdg_toplevel_handle_configure(void *data, struct zxdg_toplevel_v6 *x wlr_output_update_custom_mode(&output->wlr_output, width, height, 0); } -static void xdg_toplevel_handle_close(void *data, struct zxdg_toplevel_v6 *xdg_toplevel) { +static void xdg_toplevel_handle_close(void *data, + struct zxdg_toplevel_v6 *xdg_toplevel) { struct wlr_wl_output *output = data; assert(output && output->xdg_toplevel == xdg_toplevel); @@ -240,9 +246,8 @@ static struct zxdg_toplevel_v6_listener xdg_toplevel_listener = { .close = xdg_toplevel_handle_close, }; -struct wlr_output *wlr_wl_output_create(struct wlr_backend *_backend) { - assert(wlr_backend_is_wl(_backend)); - struct wlr_wl_backend *backend = (struct wlr_wl_backend *)_backend; +struct wlr_output *wlr_wl_output_create(struct wlr_backend *wlr_backend) { + struct wlr_wl_backend *backend = get_wl_backend_from_backend(wlr_backend); if (!backend->started) { ++backend->requested_outputs; return NULL; diff --git a/backend/wayland/wl_seat.c b/backend/wayland/wl_seat.c index 8fb4aa5f..562d9431 100644 --- a/backend/wayland/wl_seat.c +++ b/backend/wayland/wl_seat.c @@ -122,11 +122,11 @@ static void pointer_handle_axis(void *data, struct wl_pointer *wl_pointer, } static void pointer_handle_frame(void *data, struct wl_pointer *wl_pointer) { - + // This space is intentionally left blank } -static void pointer_handle_axis_source(void *data, struct wl_pointer *wl_pointer, - uint32_t axis_source) { +static void pointer_handle_axis_source(void *data, + struct wl_pointer *wl_pointer, uint32_t axis_source) { struct wlr_wl_backend *backend = data; struct wlr_wl_pointer *pointer = backend->current_pointer; if (pointer == NULL) { @@ -138,11 +138,11 @@ static void pointer_handle_axis_source(void *data, struct wl_pointer *wl_pointer static void pointer_handle_axis_stop(void *data, struct wl_pointer *wl_pointer, uint32_t time, uint32_t axis) { - + // This space is intentionally left blank } -static void pointer_handle_axis_discrete(void *data, struct wl_pointer *wl_pointer, - uint32_t axis, int32_t discrete) { +static void pointer_handle_axis_discrete(void *data, + struct wl_pointer *wl_pointer, uint32_t axis, int32_t discrete) { struct wlr_wl_backend *backend = data; struct wlr_wl_pointer *pointer = backend->current_pointer; if (pointer == NULL) { @@ -239,9 +239,9 @@ static void keyboard_handle_modifiers(void *data, struct wl_keyboard *wl_keyboar mods_locked, group); } -static void keyboard_handle_repeat_info(void *data, struct wl_keyboard *wl_keyboard, - int32_t rate, int32_t delay) { - +static void keyboard_handle_repeat_info(void *data, + struct wl_keyboard *wl_keyboard, int32_t rate, int32_t delay) { + // This space is intentionally left blank } static struct wl_keyboard_listener keyboard_listener = { @@ -253,8 +253,15 @@ static struct wl_keyboard_listener keyboard_listener = { .repeat_info = keyboard_handle_repeat_info }; +static struct wlr_wl_input_device *get_wl_input_device_from_input_device( + struct wlr_input_device *wlr_dev) { + assert(wlr_input_device_is_wl(wlr_dev)); + return (struct wlr_wl_input_device *)wlr_dev; +} + static void input_device_destroy(struct wlr_input_device *wlr_dev) { - struct wlr_wl_input_device *dev = (struct wlr_wl_input_device *)wlr_dev; + struct wlr_wl_input_device *dev = + get_wl_input_device_from_input_device(wlr_dev); if (dev->resource) { wl_proxy_destroy(dev->resource); } @@ -399,7 +406,8 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, } } -static void seat_handle_name(void *data, struct wl_seat *wl_seat, const char *name) { +static void seat_handle_name(void *data, struct wl_seat *wl_seat, + const char *name) { struct wlr_wl_backend *backend = data; assert(backend->seat == wl_seat); // Do we need to check if seatName was previously set for name change? diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 46f18c84..47585d9e 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -78,6 +78,8 @@ struct wlr_wl_pointer { struct wl_listener output_destroy; }; +struct wlr_wl_backend *get_wl_backend_from_backend( + struct wlr_backend *wlr_backend); void poll_wl_registry(struct wlr_wl_backend *backend); void update_wl_output_cursor(struct wlr_wl_output *output); struct wlr_wl_pointer *pointer_get_wl(struct wlr_pointer *wlr_pointer); -- cgit v1.2.3