Refactor out wlr_touch_state

This commit is contained in:
Dominique Martinet 2017-08-14 16:07:00 +02:00
parent bd67849c03
commit ba20d5b3ca
4 changed files with 16 additions and 14 deletions

View file

@ -10,7 +10,13 @@
struct wlr_touch *wlr_libinput_touch_create( struct wlr_touch *wlr_libinput_touch_create(
struct libinput_device *libinput_dev) { struct libinput_device *libinput_dev) {
assert(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, void handle_touch_down(struct libinput_event *event,

View file

@ -3,11 +3,11 @@
#include <wlr/types/wlr_touch.h> #include <wlr/types/wlr_touch.h>
struct wlr_touch_impl { 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, void wlr_touch_init(struct wlr_touch *touch,
struct wlr_touch_state *state); struct wlr_touch_impl *impl);
void wlr_touch_destroy(struct wlr_touch *touch); void wlr_touch_destroy(struct wlr_touch *touch);
#endif #endif

View file

@ -3,11 +3,9 @@
#include <wayland-server.h> #include <wayland-server.h>
#include <stdint.h> #include <stdint.h>
struct wlr_touch_state;
struct wlr_touch_impl; struct wlr_touch_impl;
struct wlr_touch { struct wlr_touch {
struct wlr_touch_state *state;
struct wlr_touch_impl *impl; struct wlr_touch_impl *impl;
struct { struct {

View file

@ -4,22 +4,20 @@
#include <wlr/types/wlr_touch.h> #include <wlr/types/wlr_touch.h>
#include <wlr/interfaces/wlr_touch.h> #include <wlr/interfaces/wlr_touch.h>
struct wlr_touch *wlr_touch_create(struct wlr_touch_impl *impl, void wlr_touch_init(struct wlr_touch *touch,
struct wlr_touch_state *state) { struct wlr_touch_impl *impl) {
struct wlr_touch *touch = calloc(1, sizeof(struct wlr_touch));
touch->impl = impl; touch->impl = impl;
touch->state = state;
wl_signal_init(&touch->events.down); wl_signal_init(&touch->events.down);
wl_signal_init(&touch->events.up); wl_signal_init(&touch->events.up);
wl_signal_init(&touch->events.motion); wl_signal_init(&touch->events.motion);
wl_signal_init(&touch->events.cancel); wl_signal_init(&touch->events.cancel);
return touch;
} }
void wlr_touch_destroy(struct wlr_touch *touch) { void wlr_touch_destroy(struct wlr_touch *touch) {
if (!touch) return; if (!touch) return;
if (touch->impl) { if (touch->impl && touch->impl->destroy) {
touch->impl->destroy(touch->state); touch->impl->destroy(touch);
} } else {
free(touch); free(touch);
}
} }