diff --git a/backend/libinput/events.c b/backend/libinput/events.c index 35c58b53..f032b4a5 100644 --- a/backend/libinput/events.c +++ b/backend/libinput/events.c @@ -27,7 +27,7 @@ void destroy_libinput_input_device(struct wlr_libinput_input_device *dev) { wlr_touch_destroy(&dev->touch); } if (dev->tablet.impl) { - wlr_tablet_destroy(&dev->tablet); + finish_device_tablet(dev); } if (dev->tablet_pad.impl) { finish_device_tablet_pad(dev); diff --git a/backend/libinput/tablet_tool.c b/backend/libinput/tablet_tool.c index af212218..c778ccc2 100644 --- a/backend/libinput/tablet_tool.c +++ b/backend/libinput/tablet_tool.c @@ -14,24 +14,8 @@ struct tablet_tool { struct wl_list link; // wlr_libinput_input_device::tablet_tools }; -static void tool_destroy(struct tablet_tool *tool) { - wlr_signal_emit_safe(&tool->wlr_tool.events.destroy, &tool->wlr_tool); - libinput_tablet_tool_unref(tool->handle); - libinput_tablet_tool_set_user_data(tool->handle, NULL); - wl_list_remove(&tool->link); - free(tool); -} - -static void tablet_destroy(struct wlr_tablet *wlr_tablet) { - struct wlr_libinput_input_device *dev = device_from_tablet(wlr_tablet); - struct tablet_tool *tool, *tmp; - wl_list_for_each_safe(tool, tmp, &dev->tablet_tools, link) { - tool_destroy(tool); - } -} - const struct wlr_tablet_impl libinput_tablet_impl = { - .destroy = tablet_destroy, + .name = "libinput-tablet-tool", }; void init_device_tablet(struct wlr_libinput_input_device *dev) { @@ -48,6 +32,23 @@ void init_device_tablet(struct wlr_libinput_input_device *dev) { wl_list_init(&dev->tablet_tools); } +static void tool_destroy(struct tablet_tool *tool) { + wlr_signal_emit_safe(&tool->wlr_tool.events.destroy, &tool->wlr_tool); + libinput_tablet_tool_unref(tool->handle); + libinput_tablet_tool_set_user_data(tool->handle, NULL); + wl_list_remove(&tool->link); + free(tool); +} + +void finish_device_tablet(struct wlr_libinput_input_device *dev) { + struct tablet_tool *tool, *tmp; + wl_list_for_each_safe(tool, tmp, &dev->tablet_tools, link) { + tool_destroy(tool); + } + + wlr_tablet_finish(&dev->tablet); +} + struct wlr_libinput_input_device *device_from_tablet( struct wlr_tablet *wlr_tablet) { assert(wlr_tablet->impl == &libinput_tablet_impl); diff --git a/backend/wayland/seat.c b/backend/wayland/seat.c index 7bf7d863..cf1bba91 100644 --- a/backend/wayland/seat.c +++ b/backend/wayland/seat.c @@ -563,6 +563,10 @@ void destroy_wl_input_device(struct wlr_wl_input_device *dev) { wlr_tablet_pad_finish(wlr_dev->tablet_pad); free(wlr_dev->tablet_pad); break; + case WLR_INPUT_DEVICE_TABLET_TOOL: + wlr_tablet_finish(wlr_dev->tablet); + free(wlr_dev->tablet); + break; default: wlr_input_device_destroy(wlr_dev); break; diff --git a/backend/wayland/tablet_v2.c b/backend/wayland/tablet_v2.c index 0a8f3c8d..dfebd463 100644 --- a/backend/wayland/tablet_v2.c +++ b/backend/wayland/tablet_v2.c @@ -867,13 +867,8 @@ static void handle_tablet_removed(void *data, struct zwp_tablet_v2 *zwp_tablet_v2) { struct wlr_wl_input_device *dev = 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->link); - zwp_tablet_v2_destroy(dev->resource); - free(dev); + destroy_wl_input_device(dev); } static const struct zwp_tablet_v2_listener tablet_listener = { @@ -884,7 +879,9 @@ static const struct zwp_tablet_v2_listener tablet_listener = { .removed = handle_tablet_removed, }; -const struct wlr_tablet_impl tablet_impl = {0}; +const struct wlr_tablet_impl tablet_impl = { + .name = "wl-tablet-tool", +}; static void handle_tab_added(void *data, struct zwp_tablet_seat_v2 *zwp_tablet_seat_v2, @@ -908,7 +905,7 @@ static void handle_tab_added(void *data, return; } zwp_tablet_v2_set_user_data(id, wlr_dev->tablet); - wlr_tablet_init(wlr_dev->tablet, &tablet_impl, wlr_dev->name); + wlr_tablet_init(wlr_dev->tablet, &tablet_impl, "wlr_tablet_v2"); zwp_tablet_v2_add_listener(id, &tablet_listener, dev); } diff --git a/include/backend/libinput.h b/include/backend/libinput.h index faf48591..7c1dc30a 100644 --- a/include/backend/libinput.h +++ b/include/backend/libinput.h @@ -108,6 +108,7 @@ void handle_touch_frame(struct libinput_event *event, struct wlr_touch *touch); void init_device_tablet(struct wlr_libinput_input_device *dev); +void finish_device_tablet(struct wlr_libinput_input_device *dev); struct wlr_libinput_input_device *device_from_tablet( struct wlr_tablet *tablet); void handle_tablet_tool_axis(struct libinput_event *event, diff --git a/include/wlr/interfaces/wlr_tablet_tool.h b/include/wlr/interfaces/wlr_tablet_tool.h index de7430a2..68bf8cf7 100644 --- a/include/wlr/interfaces/wlr_tablet_tool.h +++ b/include/wlr/interfaces/wlr_tablet_tool.h @@ -12,11 +12,11 @@ #include struct wlr_tablet_impl { - void (*destroy)(struct wlr_tablet *tablet); + const char *name; }; void wlr_tablet_init(struct wlr_tablet *tablet, const struct wlr_tablet_impl *impl, const char *name); -void wlr_tablet_destroy(struct wlr_tablet *tablet); +void wlr_tablet_finish(struct wlr_tablet *tablet); #endif diff --git a/types/wlr_input_device.c b/types/wlr_input_device.c index 1da7d132..067c0b0d 100644 --- a/types/wlr_input_device.c +++ b/types/wlr_input_device.c @@ -2,7 +2,6 @@ #include #include #include -#include #include #include #include @@ -49,7 +48,7 @@ void wlr_input_device_destroy(struct wlr_input_device *dev) { wlr_touch_destroy(dev->touch); break; case WLR_INPUT_DEVICE_TABLET_TOOL: - wlr_tablet_destroy(dev->tablet); + wlr_log(WLR_ERROR, "wlr_tablet_tool will not be destroyed"); break; case WLR_INPUT_DEVICE_TABLET_PAD: wlr_log(WLR_ERROR, "wlr_tablet_pad will not be destroyed"); diff --git a/types/wlr_tablet_tool.c b/types/wlr_tablet_tool.c index e50d29d1..8718abe9 100644 --- a/types/wlr_tablet_tool.c +++ b/types/wlr_tablet_tool.c @@ -17,21 +17,12 @@ void wlr_tablet_init(struct wlr_tablet *tablet, wl_array_init(&tablet->paths); } -void wlr_tablet_destroy(struct wlr_tablet *tablet) { - if (!tablet) { - return; - } +void wlr_tablet_finish(struct wlr_tablet *tablet) { + wlr_input_device_finish(&tablet->base); char **path_ptr; wl_array_for_each(path_ptr, &tablet->paths) { free(*path_ptr); } wl_array_release(&tablet->paths); - - wlr_input_device_finish(&tablet->base); - if (tablet->impl && tablet->impl->destroy) { - tablet->impl->destroy(tablet); - } else { - free(tablet); - } }