input: remove tablet/pad signal listeners on destroy

We should remove those when destroying a tablet
or a tablet pad.

Also rename 'tablet' to 'pad' in 'tablet_pad' for better
readability and consistency.
This commit is contained in:
Jens Peters 2024-04-11 23:47:10 +02:00 committed by Johan Malm
parent b6e439a5cc
commit 163f11595f
2 changed files with 17 additions and 9 deletions

View file

@ -124,6 +124,11 @@ handle_destroy(struct wl_listener *listener, void *data)
{ {
struct drawing_tablet *tablet = struct drawing_tablet *tablet =
wl_container_of(listener, tablet, handlers.destroy); wl_container_of(listener, tablet, handlers.destroy);
wl_list_remove(&tablet->handlers.tip.link);
wl_list_remove(&tablet->handlers.button.link);
wl_list_remove(&tablet->handlers.axis.link);
wl_list_remove(&tablet->handlers.destroy.link);
free(tablet); free(tablet);
} }

View file

@ -27,19 +27,22 @@ handle_button(struct wl_listener *listener, void *data)
static void static void
handle_destroy(struct wl_listener *listener, void *data) handle_destroy(struct wl_listener *listener, void *data)
{ {
struct drawing_tablet_pad *tablet = struct drawing_tablet_pad *pad =
wl_container_of(listener, tablet, handlers.destroy); wl_container_of(listener, pad, handlers.destroy);
free(tablet);
wl_list_remove(&pad->handlers.button.link);
wl_list_remove(&pad->handlers.destroy.link);
free(pad);
} }
void void
tablet_pad_init(struct seat *seat, struct wlr_input_device *wlr_device) tablet_pad_init(struct seat *seat, struct wlr_input_device *wlr_device)
{ {
wlr_log(WLR_DEBUG, "setting up tablet pad"); wlr_log(WLR_DEBUG, "setting up tablet pad");
struct drawing_tablet_pad *tablet = znew(*tablet); struct drawing_tablet_pad *pad = znew(*pad);
tablet->seat = seat; pad->seat = seat;
tablet->tablet = wlr_tablet_pad_from_input_device(wlr_device); pad->tablet = wlr_tablet_pad_from_input_device(wlr_device);
tablet->tablet->data = tablet; pad->tablet->data = pad;
CONNECT_SIGNAL(tablet->tablet, &tablet->handlers, button); CONNECT_SIGNAL(pad->tablet, &pad->handlers, button);
CONNECT_SIGNAL(wlr_device, &tablet->handlers, destroy); CONNECT_SIGNAL(wlr_device, &pad->handlers, destroy);
} }