From ba20d5b3cae29a90b1d66c9d53f295a7c41c932e Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Mon, 14 Aug 2017 16:07:00 +0200 Subject: [PATCH] Refactor out wlr_touch_state --- backend/libinput/touch.c | 8 +++++++- include/wlr/interfaces/wlr_touch.h | 6 +++--- include/wlr/types/wlr_touch.h | 2 -- types/wlr_touch.c | 14 ++++++-------- 4 files changed, 16 insertions(+), 14 deletions(-) diff --git a/backend/libinput/touch.c b/backend/libinput/touch.c index 5d990d3c..9e08d028 100644 --- a/backend/libinput/touch.c +++ b/backend/libinput/touch.c @@ -10,7 +10,13 @@ struct wlr_touch *wlr_libinput_touch_create( struct libinput_device *libinput_dev) { assert(libinput_dev); - return wlr_touch_create(NULL, NULL); + struct wlr_touch *wlr_touch = calloc(1, sizeof(struct wlr_touch)); + if (!wlr_touch) { + wlr_log(L_ERROR, "Unable to allocate wlr_touch"); + return NULL; + } + wlr_touch_init(wlr_touch, NULL); + return wlr_touch; } void handle_touch_down(struct libinput_event *event, diff --git a/include/wlr/interfaces/wlr_touch.h b/include/wlr/interfaces/wlr_touch.h index d83ad558..b5fcef18 100644 --- a/include/wlr/interfaces/wlr_touch.h +++ b/include/wlr/interfaces/wlr_touch.h @@ -3,11 +3,11 @@ #include struct wlr_touch_impl { - void (*destroy)(struct wlr_touch_state *state); + void (*destroy)(struct wlr_touch *touch); }; -struct wlr_touch *wlr_touch_create(struct wlr_touch_impl *impl, - struct wlr_touch_state *state); +void wlr_touch_init(struct wlr_touch *touch, + struct wlr_touch_impl *impl); void wlr_touch_destroy(struct wlr_touch *touch); #endif diff --git a/include/wlr/types/wlr_touch.h b/include/wlr/types/wlr_touch.h index 740d70f6..93069fcb 100644 --- a/include/wlr/types/wlr_touch.h +++ b/include/wlr/types/wlr_touch.h @@ -3,11 +3,9 @@ #include #include -struct wlr_touch_state; struct wlr_touch_impl; struct wlr_touch { - struct wlr_touch_state *state; struct wlr_touch_impl *impl; struct { diff --git a/types/wlr_touch.c b/types/wlr_touch.c index e698decd..46ae7ce9 100644 --- a/types/wlr_touch.c +++ b/types/wlr_touch.c @@ -4,22 +4,20 @@ #include #include -struct wlr_touch *wlr_touch_create(struct wlr_touch_impl *impl, - struct wlr_touch_state *state) { - struct wlr_touch *touch = calloc(1, sizeof(struct wlr_touch)); +void wlr_touch_init(struct wlr_touch *touch, + struct wlr_touch_impl *impl) { touch->impl = impl; - touch->state = state; wl_signal_init(&touch->events.down); wl_signal_init(&touch->events.up); wl_signal_init(&touch->events.motion); wl_signal_init(&touch->events.cancel); - return touch; } void wlr_touch_destroy(struct wlr_touch *touch) { if (!touch) return; - if (touch->impl) { - touch->impl->destroy(touch->state); + if (touch->impl && touch->impl->destroy) { + touch->impl->destroy(touch); + } else { + free(touch); } - free(touch); }