From: Hans de Goede Date: Fri, 6 Jun 2014 15:01:07 +0000 (+0200) Subject: evdev-mt-touchpad-tap: Switch over to new timer subsystem X-Git-Tag: 0.4.0~43 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=04c79874433d0e5eb97ca78e1ce11ff3b59413b9;p=platform%2Fupstream%2Flibinput.git evdev-mt-touchpad-tap: Switch over to new timer subsystem Signed-off-by: Hans de Goede Reviewed-by: Peter Hutterer Signed-off-by: Peter Hutterer --- diff --git a/src/evdev-mt-touchpad-tap.c b/src/evdev-mt-touchpad-tap.c index 442201f5..be8a03d2 100644 --- a/src/evdev-mt-touchpad-tap.c +++ b/src/evdev-mt-touchpad-tap.c @@ -30,9 +30,7 @@ #include #include #include -#include #include -#include #include "evdev-mt-touchpad.h" @@ -120,22 +118,13 @@ tp_tap_notify(struct tp_dispatch *tp, static void tp_tap_set_timer(struct tp_dispatch *tp, uint64_t time) { - uint64_t timeout = time + DEFAULT_TAP_TIMEOUT_PERIOD; - struct itimerspec its; - - its.it_interval.tv_sec = 0; - its.it_interval.tv_nsec = 0; - its.it_value.tv_sec = timeout / 1000; - its.it_value.tv_nsec = (timeout % 1000) * 1000 * 1000; - timerfd_settime(tp->tap.timer_fd, TFD_TIMER_ABSTIME, &its, NULL); - - tp->tap.timeout = timeout; + libinput_timer_set(&tp->tap.timer, time + DEFAULT_TAP_TIMEOUT_PERIOD); } static void tp_tap_clear_timer(struct tp_dispatch *tp) { - tp->tap.timeout = 0; + libinput_timer_cancel(&tp->tap.timer); } static void @@ -548,60 +537,21 @@ tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time) } static void -tp_tap_timeout_handler(void *data) +tp_tap_handle_timeout(uint64_t time, void *data) { - struct tp_dispatch *touchpad = data; - uint64_t expires; - int len; - struct timespec ts; - uint64_t now; - - len = read(touchpad->tap.timer_fd, &expires, sizeof expires); - if (len != sizeof expires) - /* This will only happen if the application made the fd - * non-blocking, but this function should only be called - * upon the timeout, so lets continue anyway. */ - log_error("timerfd read error: %s\n", strerror(errno)); - - clock_gettime(CLOCK_MONOTONIC, &ts); - now = ts.tv_sec * 1000ULL + ts.tv_nsec / 1000000; - - tp_tap_handle_timeout(touchpad, now); -} - -unsigned int -tp_tap_handle_timeout(struct tp_dispatch *tp, uint64_t time) -{ - if (!tp->tap.enabled) - return 0; - - if (tp->tap.timeout && tp->tap.timeout <= time) { - tp_tap_clear_timer(tp); - tp_tap_handle_event(tp, TAP_EVENT_TIMEOUT, time); - } + struct tp_dispatch *tp = data; - return tp->tap.timeout; + tp_tap_handle_event(tp, TAP_EVENT_TIMEOUT, time); } int tp_init_tap(struct tp_dispatch *tp) { tp->tap.state = TAP_STATE_IDLE; - tp->tap.timer_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC); - if (tp->tap.timer_fd == -1) - return -1; - - tp->tap.source = - libinput_add_fd(tp->device->base.seat->libinput, - tp->tap.timer_fd, - tp_tap_timeout_handler, - tp); - - if (tp->tap.source == NULL) { - close(tp->tap.timer_fd); - return -1; - } + libinput_timer_init(&tp->tap.timer, + tp->device->base.seat->libinput, + tp_tap_handle_timeout, tp); tp->tap.enabled = 1; /* FIXME */ @@ -611,13 +561,5 @@ tp_init_tap(struct tp_dispatch *tp) void tp_destroy_tap(struct tp_dispatch *tp) { - if (tp->tap.source) { - libinput_remove_source(tp->device->base.seat->libinput, - tp->tap.source); - tp->tap.source = NULL; - } - if (tp->tap.timer_fd > -1) { - close(tp->tap.timer_fd); - tp->tap.timer_fd = -1; - } + libinput_timer_cancel(&tp->tap.timer); } diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c index c23e5657..8b502b78 100644 --- a/src/evdev-mt-touchpad.c +++ b/src/evdev-mt-touchpad.c @@ -747,7 +747,6 @@ tp_init(struct tp_dispatch *tp, tp->base.interface = &tp_interface; tp->device = device; - tp->tap.timer_fd = -1; if (tp_init_slots(tp, device) != 0) return -1; diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h index 1749a55a..0b1457db 100644 --- a/src/evdev-mt-touchpad.h +++ b/src/evdev-mt-touchpad.h @@ -200,9 +200,7 @@ struct tp_dispatch { struct { bool enabled; - int timer_fd; - struct libinput_source *source; - unsigned int timeout; + struct libinput_timer timer; enum tp_tap_state state; } tap; }; @@ -219,9 +217,6 @@ tp_set_pointer(struct tp_dispatch *tp, struct tp_touch *t); int tp_tap_handle_state(struct tp_dispatch *tp, uint64_t time); -unsigned int -tp_tap_handle_timeout(struct tp_dispatch *tp, uint64_t time); - int tp_init_tap(struct tp_dispatch *tp);