fix: miss detect valid poiter in talbe device create

This commit is contained in:
DreamMaoMao 2026-06-03 23:15:06 +08:00
parent bea689ca0c
commit 133ebc76d9

View file

@ -22,6 +22,7 @@ static struct wlr_tablet_manager_v2 *tablet_mgr;
struct Tablet { struct Tablet {
struct wlr_tablet_v2_tablet *tablet_v2; struct wlr_tablet_v2_tablet *tablet_v2;
struct wl_listener destroy; struct wl_listener destroy;
struct wlr_input_device *device;
struct wl_list link; struct wl_list link;
}; };
static struct wl_list tablets; static struct wl_list tablets;
@ -72,11 +73,18 @@ void createtablet(struct wlr_input_device *device) {
return; return;
} }
tablet->device = device;
tablet->tablet_v2 = wlr_tablet_create(tablet_mgr, seat, device); tablet->tablet_v2 = wlr_tablet_create(tablet_mgr, seat, device);
if (!tablet->tablet_v2) {
free(tablet);
return;
}
tablet->tablet_v2->wlr_tablet->data = tablet; tablet->tablet_v2->wlr_tablet->data = tablet;
tablet->destroy.notify = destroytablet; tablet->destroy.notify = destroytablet;
wl_signal_add(&tablet->tablet_v2->wlr_device->events.destroy, wl_signal_add(&tablet->device->events.destroy, &tablet->destroy);
&tablet->destroy);
if (libinput_device_config_send_events_get_modes(device_handle)) { if (libinput_device_config_send_events_get_modes(device_handle)) {
libinput_device_config_send_events_set_mode(device_handle, libinput_device_config_send_events_set_mode(device_handle,
config.send_events_mode); config.send_events_mode);
@ -129,8 +137,7 @@ void attach_tablet_pad(struct TabletPad *tablet_pad, struct Tablet *tablet) {
wl_list_remove(&tablet_pad->tablet_destroy.link); wl_list_remove(&tablet_pad->tablet_destroy.link);
tablet_pad->tablet_destroy.notify = tabletpadtabletdestroy; tablet_pad->tablet_destroy.notify = tabletpadtabletdestroy;
wl_signal_add(&tablet->tablet_v2->wlr_device->events.destroy, wl_signal_add(&tablet->device->events.destroy, &tablet_pad->tablet_destroy);
&tablet_pad->tablet_destroy);
} }
void tabletpadattach(struct wl_listener *listener, void *data) { void tabletpadattach(struct wl_listener *listener, void *data) {
@ -153,11 +160,19 @@ void createtabletpad(struct wlr_input_device *device) {
return; return;
} }
tablet_pad->pad_v2 = wlr_tablet_pad_create(tablet_mgr, seat, device); tablet_pad->pad_v2 = wlr_tablet_pad_create(tablet_mgr, seat, device);
if (!tablet_pad->pad_v2) {
wlr_log(WLR_ERROR, "could not create tablet_pad_v2 wrapper");
free(tablet_pad);
return;
}
tablet_pad->destroy.notify = destroytabletpad; tablet_pad->destroy.notify = destroytabletpad;
tablet_pad->attach.notify = tabletpadattach; tablet_pad->attach.notify = tabletpadattach;
wl_list_init(&tablet_pad->tablet_destroy.link); wl_list_init(&tablet_pad->tablet_destroy.link);
wl_signal_add(&tablet_pad->pad_v2->wlr_device->events.destroy,
&tablet_pad->destroy); wl_signal_add(&device->events.destroy, &tablet_pad->destroy);
wl_signal_add(&tablet_pad->pad_v2->wlr_pad->events.attach_tablet, wl_signal_add(&tablet_pad->pad_v2->wlr_pad->events.attach_tablet,
&tablet_pad->attach); &tablet_pad->attach);
wl_list_insert(&tablet_pads, &tablet_pad->link); wl_list_insert(&tablet_pads, &tablet_pad->link);