types/wlr_tablet_pad: add base wlr_input_device

wlr_tablet_pad owns its wlr_input_device. It will be initialized when the
tablet pad is initialized, and finished when the tablet pad is destroyed.
This commit is contained in:
Simon Zeni 2022-02-01 10:25:28 -05:00 committed by Kirill Primak
parent 0f3b38365d
commit a662743610
5 changed files with 14 additions and 4 deletions

View file

@ -75,7 +75,10 @@ struct wlr_tablet_pad *create_libinput_tablet_pad(
wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_pad"); wlr_log(WLR_ERROR, "Unable to allocate wlr_tablet_pad");
return NULL; return NULL;
} }
wlr_tablet_pad_init(wlr_tablet_pad, NULL); const char *name = libinput_device_get_name(libinput_dev);
wlr_tablet_pad_init(wlr_tablet_pad, NULL, name);
wlr_tablet_pad->base.vendor = libinput_device_get_id_vendor(libinput_dev);
wlr_tablet_pad->base.product = libinput_device_get_id_product(libinput_dev);
wlr_tablet_pad->button_count = wlr_tablet_pad->button_count =
libinput_device_tablet_pad_get_num_buttons(libinput_dev); libinput_device_tablet_pad_get_num_buttons(libinput_dev);

View file

@ -453,7 +453,7 @@ static void handle_pad_added(void *data,
zwp_tablet_pad_v2_destroy(id); zwp_tablet_pad_v2_destroy(id);
return; return;
} }
wlr_tablet_pad_init(wlr_dev->tablet_pad, NULL); wlr_tablet_pad_init(wlr_dev->tablet_pad, NULL, wlr_dev->name);
zwp_tablet_pad_v2_add_listener(id, &tablet_pad_listener, dev); zwp_tablet_pad_v2_add_listener(id, &tablet_pad_listener, dev);
} }

View file

@ -16,7 +16,7 @@ struct wlr_tablet_pad_impl {
}; };
void wlr_tablet_pad_init(struct wlr_tablet_pad *pad, void wlr_tablet_pad_init(struct wlr_tablet_pad *pad,
struct wlr_tablet_pad_impl *impl); struct wlr_tablet_pad_impl *impl, const char *name);
void wlr_tablet_pad_destroy(struct wlr_tablet_pad *pad); void wlr_tablet_pad_destroy(struct wlr_tablet_pad *pad);
#endif #endif

View file

@ -22,6 +22,8 @@
struct wlr_tablet_pad_impl; struct wlr_tablet_pad_impl;
struct wlr_tablet_pad { struct wlr_tablet_pad {
struct wlr_input_device base;
struct wlr_tablet_pad_impl *impl; struct wlr_tablet_pad_impl *impl;
struct { struct {

View file

@ -1,11 +1,15 @@
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <wayland-server-core.h> #include <wayland-server-core.h>
#include <wlr/interfaces/wlr_input_device.h>
#include <wlr/interfaces/wlr_tablet_pad.h> #include <wlr/interfaces/wlr_tablet_pad.h>
#include <wlr/types/wlr_tablet_pad.h> #include <wlr/types/wlr_tablet_pad.h>
void wlr_tablet_pad_init(struct wlr_tablet_pad *pad, void wlr_tablet_pad_init(struct wlr_tablet_pad *pad,
struct wlr_tablet_pad_impl *impl) { struct wlr_tablet_pad_impl *impl, const char *name) {
wlr_input_device_init(&pad->base, WLR_INPUT_DEVICE_TABLET_PAD, NULL, name);
pad->base.tablet_pad = pad;
pad->impl = impl; pad->impl = impl;
wl_signal_init(&pad->events.button); wl_signal_init(&pad->events.button);
wl_signal_init(&pad->events.ring); wl_signal_init(&pad->events.ring);
@ -27,6 +31,7 @@ void wlr_tablet_pad_destroy(struct wlr_tablet_pad *pad) {
} }
wl_array_release(&pad->paths); wl_array_release(&pad->paths);
wlr_input_device_finish(&pad->base);
if (pad->impl && pad->impl->destroy) { if (pad->impl && pad->impl->destroy) {
pad->impl->destroy(pad); pad->impl->destroy(pad);
} else { } else {