From 1d9c1bcea6a223379af63b4d779d53663eaffcf8 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Mon, 22 Nov 2021 22:30:40 +0100 Subject: [PATCH] input-device: remove wlr_input_device.link This field's ownership is unclear: it's in wlr_input_device, but it's not managed by the common code, it's up to each individual backend to use it and clean it up. Since this is a backend implementation detail, move it to the backend-specific structs. --- backend/headless/backend.c | 5 ++-- backend/headless/input_device.c | 8 +++--- backend/libinput/backend.c | 6 ++--- backend/libinput/events.c | 16 ++++++------ backend/wayland/backend.c | 4 +-- backend/wayland/seat.c | 38 ++++++++++++++-------------- backend/wayland/tablet_v2.c | 4 +-- include/backend/headless.h | 2 +- include/backend/libinput.h | 2 +- include/backend/wayland.h | 1 + include/wlr/types/wlr_input_device.h | 2 -- 11 files changed, 44 insertions(+), 44 deletions(-) diff --git a/backend/headless/backend.c b/backend/headless/backend.c index 886be276..ad0c4ebf 100644 --- a/backend/headless/backend.c +++ b/backend/headless/backend.c @@ -33,8 +33,7 @@ static bool backend_start(struct wlr_backend *wlr_backend) { } struct wlr_headless_input_device *input_device; - wl_list_for_each(input_device, &backend->input_devices, - wlr_input_device.link) { + wl_list_for_each(input_device, &backend->input_devices, link) { wlr_signal_emit_safe(&backend->backend.events.new_input, &input_device->wlr_input_device); } @@ -59,7 +58,7 @@ static void backend_destroy(struct wlr_backend *wlr_backend) { struct wlr_headless_input_device *input_device, *input_device_tmp; wl_list_for_each_safe(input_device, input_device_tmp, - &backend->input_devices, wlr_input_device.link) { + &backend->input_devices, link) { wlr_input_device_destroy(&input_device->wlr_input_device); } diff --git a/backend/headless/input_device.c b/backend/headless/input_device.c index 1d91f8d1..4df01aff 100644 --- a/backend/headless/input_device.c +++ b/backend/headless/input_device.c @@ -12,8 +12,10 @@ #include "util/signal.h" static void input_device_destroy(struct wlr_input_device *wlr_dev) { - wl_list_remove(&wlr_dev->link); - free(wlr_dev); + struct wlr_headless_input_device *dev = + wl_container_of(wlr_dev, dev, wlr_input_device); + wl_list_remove(&dev->link); + free(dev); } static const struct wlr_input_device_impl input_device_impl = { @@ -93,7 +95,7 @@ struct wlr_input_device *wlr_headless_add_input_device( wlr_switch_init(wlr_device->switch_device, NULL); } - wl_list_insert(&backend->input_devices, &wlr_device->link); + wl_list_insert(&backend->input_devices, &device->link); if (backend->started) { wlr_signal_emit_safe(&backend->backend.events.new_input, wlr_device); diff --git a/backend/libinput/backend.c b/backend/libinput/backend.c index 00145e41..4191f350 100644 --- a/backend/libinput/backend.c +++ b/backend/libinput/backend.c @@ -143,9 +143,9 @@ static void backend_destroy(struct wlr_backend *wlr_backend) { struct wl_list **wlr_devices_ptr; wl_array_for_each(wlr_devices_ptr, &backend->wlr_device_lists) { - struct wlr_input_device *wlr_dev, *next; - wl_list_for_each_safe(wlr_dev, next, *wlr_devices_ptr, link) { - wlr_input_device_destroy(wlr_dev); + struct wlr_libinput_input_device *dev, *tmp; + wl_list_for_each_safe(dev, tmp, *wlr_devices_ptr, link) { + wlr_input_device_destroy(&dev->wlr_input_device); } free(*wlr_devices_ptr); } diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 82883779..67598998 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -23,10 +23,10 @@ struct wlr_input_device *get_appropriate_device( if (!wlr_devices) { return NULL; } - struct wlr_input_device *dev; + struct wlr_libinput_input_device *dev; wl_list_for_each(dev, wlr_devices, link) { - if (dev->type == desired_type) { - return dev; + if (dev->wlr_input_device.type == desired_type) { + return &dev->wlr_input_device; } } return NULL; @@ -36,7 +36,7 @@ static void input_device_destroy(struct wlr_input_device *wlr_dev) { struct wlr_libinput_input_device *dev = get_libinput_device_from_device(wlr_dev); libinput_device_unref(dev->handle); - wl_list_remove(&dev->wlr_input_device.link); + wl_list_remove(&dev->link); free(dev); } @@ -63,7 +63,7 @@ static struct wlr_input_device *allocate_device( if (output_name != NULL) { wlr_dev->output_name = strdup(output_name); } - wl_list_insert(wlr_devices, &wlr_dev->link); + wl_list_insert(wlr_devices, &dev->link); dev->handle = libinput_dev; libinput_device_ref(libinput_dev); wlr_input_device_init(wlr_dev, type, &input_device_impl, @@ -198,7 +198,7 @@ static void handle_device_added(struct wlr_libinput_backend *backend, fail: wlr_log(WLR_ERROR, "Could not allocate new device"); - struct wlr_input_device *dev, *tmp_dev; + struct wlr_libinput_input_device *dev, *tmp_dev; wl_list_for_each_safe(dev, tmp_dev, wlr_devices, link) { free(dev); } @@ -215,9 +215,9 @@ static void handle_device_removed(struct wlr_libinput_backend *backend, if (!wlr_devices) { return; } - struct wlr_input_device *dev, *tmp_dev; + struct wlr_libinput_input_device *dev, *tmp_dev; wl_list_for_each_safe(dev, tmp_dev, wlr_devices, link) { - wlr_input_device_destroy(dev); + wlr_input_device_destroy(&dev->wlr_input_device); } size_t i = 0; struct wl_list **ptr; diff --git a/backend/wayland/backend.c b/backend/wayland/backend.c index 3d962d4f..63d6a7df 100644 --- a/backend/wayland/backend.c +++ b/backend/wayland/backend.c @@ -314,9 +314,9 @@ static void backend_destroy(struct wlr_backend *backend) { wlr_output_destroy(&output->wlr_output); } - struct wlr_input_device *input_device, *tmp_input_device; + struct wlr_wl_input_device *input_device, *tmp_input_device; wl_list_for_each_safe(input_device, tmp_input_device, &wl->devices, link) { - wlr_input_device_destroy(input_device); + wlr_input_device_destroy(&input_device->wlr_input_device); } struct wlr_wl_buffer *buffer, *tmp_buffer; diff --git a/backend/wayland/seat.c b/backend/wayland/seat.c index 508551a0..7792d136 100644 --- a/backend/wayland/seat.c +++ b/backend/wayland/seat.c @@ -25,12 +25,13 @@ static struct wlr_wl_pointer *output_get_pointer( struct wlr_wl_output *output, const struct wl_pointer *wl_pointer) { - struct wlr_input_device *wlr_dev; - wl_list_for_each(wlr_dev, &output->backend->devices, link) { - if (wlr_dev->type != WLR_INPUT_DEVICE_POINTER) { + struct wlr_wl_input_device *dev; + wl_list_for_each(dev, &output->backend->devices, link) { + if (dev->wlr_input_device.type != WLR_INPUT_DEVICE_POINTER) { continue; } - struct wlr_wl_pointer *pointer = pointer_get_wl(wlr_dev->pointer); + struct wlr_wl_pointer *pointer = + pointer_get_wl(dev->wlr_input_device.pointer); if (pointer->output == output && pointer->wl_pointer == wl_pointer) { return pointer; } @@ -440,7 +441,7 @@ static void input_device_destroy(struct wlr_input_device *wlr_dev) { } // We can't destroy pointer here because we might have multiple devices // exposing it to compositor. - wl_list_remove(&dev->wlr_input_device.link); + wl_list_remove(&dev->link); free(dev); } @@ -473,7 +474,7 @@ struct wlr_wl_input_device *create_wl_input_device( wlr_input_device_init(wlr_dev, type, &input_device_impl, name, vendor, product); - wl_list_insert(&seat->backend->devices, &wlr_dev->link); + wl_list_insert(&seat->backend->devices, &dev->link); return dev; } @@ -822,19 +823,20 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, struct wl_pointer *wl_pointer = seat->pointer; - struct wlr_input_device *device, *tmp; + struct wlr_wl_input_device *device, *tmp; wl_list_for_each_safe(device, tmp, &backend->devices, link) { - if (device->type != WLR_INPUT_DEVICE_POINTER) { + if (device->wlr_input_device.type != WLR_INPUT_DEVICE_POINTER) { continue; } - struct wlr_wl_pointer *pointer = pointer_get_wl(device->pointer); + struct wlr_wl_pointer *pointer = + pointer_get_wl(device->wlr_input_device.pointer); if (pointer->wl_pointer != wl_pointer) { continue; } wlr_log(WLR_DEBUG, "dropping pointer %s", pointer->input_device->wlr_input_device.name); struct wlr_wl_output *output = pointer->output; - wlr_input_device_destroy(device); + wlr_input_device_destroy(&device->wlr_input_device); assert(seat->active_pointer != pointer); assert(output->cursor.pointer != pointer); } @@ -856,18 +858,16 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, if (!(caps & WL_SEAT_CAPABILITY_KEYBOARD) && seat->keyboard != NULL) { wlr_log(WLR_DEBUG, "seat %p dropped keyboard", (void *)wl_seat); - struct wlr_input_device *device, *tmp; + struct wlr_wl_input_device *device, *tmp; wl_list_for_each_safe(device, tmp, &backend->devices, link) { - if (device->type != WLR_INPUT_DEVICE_KEYBOARD) { + if (device->wlr_input_device.type != WLR_INPUT_DEVICE_KEYBOARD) { continue; } - struct wlr_wl_input_device *input_device = - get_wl_input_device_from_input_device(device); - if (input_device->seat != seat) { + if (device->seat != seat) { continue; } - wlr_input_device_destroy(device); + wlr_input_device_destroy(&device->wlr_input_device); } assert(seat->keyboard == NULL); // free'ed by input_device_destroy } @@ -883,10 +883,10 @@ static void seat_handle_capabilities(void *data, struct wl_seat *wl_seat, if (!(caps & WL_SEAT_CAPABILITY_TOUCH) && seat->touch != NULL) { wlr_log(WLR_DEBUG, "seat %p dropped touch", (void *)wl_seat); - struct wlr_input_device *device, *tmp; + struct wlr_wl_input_device *device, *tmp; wl_list_for_each_safe(device, tmp, &backend->devices, link) { - if (device->type == WLR_INPUT_DEVICE_TOUCH) { - wlr_input_device_destroy(device); + if (device->wlr_input_device.type == WLR_INPUT_DEVICE_TOUCH) { + wlr_input_device_destroy(&device->wlr_input_device); } } diff --git a/backend/wayland/tablet_v2.c b/backend/wayland/tablet_v2.c index 9f90a369..cda65101 100644 --- a/backend/wayland/tablet_v2.c +++ b/backend/wayland/tablet_v2.c @@ -402,7 +402,7 @@ static void handle_tablet_pad_removed(void *data, /* This doesn't free anything, but emits the destroy signal */ wlr_input_device_destroy(&dev->wlr_input_device); /* This is a bit ugly, but we need to remove it from our list */ - wl_list_remove(&dev->wlr_input_device.link); + wl_list_remove(&dev->link); struct wlr_wl_tablet_pad_group *group, *it; wl_list_for_each_safe(group, it, &tablet_pad->groups, group.link) { @@ -873,7 +873,7 @@ static void handle_tablet_removed(void *data, /* This doesn't free anything, but emits the destroy signal */ wlr_input_device_destroy(&dev->wlr_input_device); /* This is a bit ugly, but we need to remove it from our list */ - wl_list_remove(&dev->wlr_input_device.link); + wl_list_remove(&dev->link); zwp_tablet_v2_destroy(dev->resource); free(dev); diff --git a/include/backend/headless.h b/include/backend/headless.h index 09d5856b..f60d07e6 100644 --- a/include/backend/headless.h +++ b/include/backend/headless.h @@ -29,7 +29,7 @@ struct wlr_headless_output { struct wlr_headless_input_device { struct wlr_input_device wlr_input_device; - + struct wl_list link; struct wlr_headless_backend *backend; }; diff --git a/include/backend/libinput.h b/include/backend/libinput.h index e85ad291..a6841d7e 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -26,7 +26,7 @@ struct wlr_libinput_backend { struct wlr_libinput_input_device { struct wlr_input_device wlr_input_device; - + struct wl_list link; struct libinput_device *handle; }; diff --git a/include/backend/wayland.h b/include/backend/wayland.h index 32783597..4e5d3636 100644 --- a/include/backend/wayland.h +++ b/include/backend/wayland.h @@ -87,6 +87,7 @@ struct wlr_wl_output { struct wlr_wl_input_device { struct wlr_input_device wlr_input_device; + struct wl_list link; uint32_t fingers; struct wlr_wl_backend *backend; diff --git a/include/wlr/types/wlr_input_device.h b/include/wlr/types/wlr_input_device.h index 8ed9b465..cbc877df 100644 --- a/include/wlr/types/wlr_input_device.h +++ b/include/wlr/types/wlr_input_device.h @@ -53,8 +53,6 @@ struct wlr_input_device { } events; void *data; - - struct wl_list link; }; #endif