From a289940bff8bcda5cc6aeb1d88f4f1e5c2c38317 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Mon, 14 Aug 2017 15:59:59 +0200 Subject: [PATCH] Refactor out wlr_tablet_pad_state --- backend/libinput/tablet_pad.c | 8 +++++++- include/wlr/interfaces/wlr_tablet_pad.h | 6 +++--- include/wlr/types/wlr_tablet_pad.h | 2 -- types/wlr_tablet_pad.c | 14 ++++++-------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/backend/libinput/tablet_pad.c b/backend/libinput/tablet_pad.c index 9713bb1d7..efad1068f 100644 --- a/backend/libinput/tablet_pad.c +++ b/backend/libinput/tablet_pad.c @@ -10,7 +10,13 @@ struct wlr_tablet_pad *wlr_libinput_tablet_pad_create( struct libinput_device *libinput_dev) { assert(libinput_dev); - return wlr_tablet_pad_create(NULL, NULL); + struct wlr_tablet_pad *wlr_tablet_pad = calloc(1, sizeof(struct wlr_tablet_pad)); + if (!wlr_tablet_pad) { + wlr_log(L_ERROR, "Unable to allocate wlr_tablet_pad"); + return NULL; + } + wlr_tablet_pad_init(wlr_tablet_pad, NULL); + return wlr_tablet_pad; } void handle_tablet_pad_button(struct libinput_event *event, diff --git a/include/wlr/interfaces/wlr_tablet_pad.h b/include/wlr/interfaces/wlr_tablet_pad.h index 09274c6cb..81af3c3fa 100644 --- a/include/wlr/interfaces/wlr_tablet_pad.h +++ b/include/wlr/interfaces/wlr_tablet_pad.h @@ -3,11 +3,11 @@ #include struct wlr_tablet_pad_impl { - void (*destroy)(struct wlr_tablet_pad_state *pad); + void (*destroy)(struct wlr_tablet_pad *pad); }; -struct wlr_tablet_pad *wlr_tablet_pad_create(struct wlr_tablet_pad_impl *impl, - struct wlr_tablet_pad_state *state); +void wlr_tablet_pad_init(struct wlr_tablet_pad *pad, + struct wlr_tablet_pad_impl *impl); void wlr_tablet_pad_destroy(struct wlr_tablet_pad *pad); #endif diff --git a/include/wlr/types/wlr_tablet_pad.h b/include/wlr/types/wlr_tablet_pad.h index d23650863..6c14c669c 100644 --- a/include/wlr/types/wlr_tablet_pad.h +++ b/include/wlr/types/wlr_tablet_pad.h @@ -11,11 +11,9 @@ */ struct wlr_tablet_pad_impl; -struct wlr_tablet_pad_state; struct wlr_tablet_pad { struct wlr_tablet_pad_impl *impl; - struct wlr_tablet_pad_state *state; struct { struct wl_signal button; diff --git a/types/wlr_tablet_pad.c b/types/wlr_tablet_pad.c index 80c6187d8..b7f03493c 100644 --- a/types/wlr_tablet_pad.c +++ b/types/wlr_tablet_pad.c @@ -4,21 +4,19 @@ #include #include -struct wlr_tablet_pad *wlr_tablet_pad_create(struct wlr_tablet_pad_impl *impl, - struct wlr_tablet_pad_state *state) { - struct wlr_tablet_pad *pad = calloc(1, sizeof(struct wlr_tablet_pad)); +void wlr_tablet_pad_init(struct wlr_tablet_pad *pad, + struct wlr_tablet_pad_impl *impl) { pad->impl = impl; - pad->state = state; wl_signal_init(&pad->events.button); wl_signal_init(&pad->events.ring); wl_signal_init(&pad->events.strip); - return pad; } void wlr_tablet_pad_destroy(struct wlr_tablet_pad *pad) { if (!pad) return; - if (pad->impl) { - pad->impl->destroy(pad->state); + if (pad->impl && pad->impl->destroy) { + pad->impl->destroy(pad); + } else { + free(pad); } - free(pad); }