summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2015-04-29 13:19:51 +0200
committerPeter Hutterer <peter.hutterer@who-t.net>2015-07-06 14:09:33 +1000
commit9fae0f8c3e9e9be40d290efc9d4092d6da18881c (patch)
tree152138667f2bf3aea5df4db41d7e01644b9bfc0b
parentad26785f6a112b469757ecfff284d9937da2b6ac (diff)
touchpad: Allow querying whether a gesture ended normally or was cancelled
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r--src/evdev-mt-touchpad-gestures.c20
-rw-r--r--src/evdev-mt-touchpad.c6
-rw-r--r--src/evdev-mt-touchpad.h2
-rw-r--r--src/libinput-private.h11
-rw-r--r--src/libinput.c37
-rw-r--r--src/libinput.h17
-rw-r--r--src/libinput.sym1
-rw-r--r--tools/event-debug.c4
8 files changed, 79 insertions, 19 deletions
diff --git a/src/evdev-mt-touchpad-gestures.c b/src/evdev-mt-touchpad-gestures.c
index ce52df2..840d9ad 100644
--- a/src/evdev-mt-touchpad-gestures.c
+++ b/src/evdev-mt-touchpad-gestures.c
@@ -422,7 +422,7 @@ tp_gesture_post_events(struct tp_dispatch *tp, uint64_t time)
/* When tap-and-dragging, or a clickpad is clicked force 1fg mode */
if (tp_tap_dragging(tp) || (tp->buttons.is_clickpad && tp->buttons.state)) {
- tp_gesture_stop(tp, time);
+ tp_gesture_stop(tp, time, 1);
tp->gesture.finger_count = 1;
tp->gesture.finger_count_pending = 0;
}
@@ -457,11 +457,10 @@ tp_gesture_stop_twofinger_scroll(struct tp_dispatch *tp, uint64_t time)
}
void
-tp_gesture_stop(struct tp_dispatch *tp, uint64_t time)
+tp_gesture_stop(struct tp_dispatch *tp, uint64_t time, int cancelled)
{
struct libinput *libinput = tp->device->base.seat->libinput;
enum tp_gesture_2fg_state twofinger_state = tp->gesture.twofinger_state;
- const struct normalized_coords zero = { 0.0, 0.0 };
tp->gesture.twofinger_state = GESTURE_2FG_STATE_NONE;
@@ -481,18 +480,15 @@ tp_gesture_stop(struct tp_dispatch *tp, uint64_t time)
tp_gesture_stop_twofinger_scroll(tp, time);
break;
case GESTURE_2FG_STATE_PINCH:
- gesture_notify_pinch(&tp->device->base, time,
- LIBINPUT_EVENT_GESTURE_PINCH_END,
- &zero, &zero, 0.0, 0.0);
+ gesture_notify_pinch_end(&tp->device->base, time,
+ cancelled);
break;
}
break;
case 3:
case 4:
- gesture_notify_swipe(&tp->device->base, time,
- LIBINPUT_EVENT_GESTURE_SWIPE_END,
- tp->gesture.finger_count,
- &zero, &zero);
+ gesture_notify_swipe_end(&tp->device->base, time,
+ tp->gesture.finger_count, cancelled);
break;
}
tp->gesture.started = false;
@@ -506,7 +502,7 @@ tp_gesture_finger_count_switch_timeout(uint64_t now, void *data)
if (!tp->gesture.finger_count_pending)
return;
- tp_gesture_stop(tp, now); /* End current gesture */
+ tp_gesture_stop(tp, now, 1); /* End current gesture */
tp->gesture.finger_count = tp->gesture.finger_count_pending;
tp->gesture.finger_count_pending = 0;
}
@@ -524,7 +520,7 @@ tp_gesture_handle_state(struct tp_dispatch *tp, uint64_t time)
if (active_touches != tp->gesture.finger_count) {
/* If all fingers are lifted immediately end the gesture */
if (active_touches == 0) {
- tp_gesture_stop(tp, time);
+ tp_gesture_stop(tp, time, 0);
tp->gesture.finger_count = 0;
tp->gesture.finger_count_pending = 0;
/* Immediately switch to new mode to avoid initial latency */
diff --git a/src/evdev-mt-touchpad.c b/src/evdev-mt-touchpad.c
index 2474340..fac2e4d 100644
--- a/src/evdev-mt-touchpad.c
+++ b/src/evdev-mt-touchpad.c
@@ -797,7 +797,7 @@ tp_post_events(struct tp_dispatch *tp, uint64_t time)
tp->palm.trackpoint_active ||
tp->dwt.keyboard_active) {
tp_edge_scroll_stop_events(tp, time);
- tp_gesture_stop(tp, time);
+ tp_gesture_stop(tp, time, 1);
return;
}
@@ -976,7 +976,7 @@ tp_trackpoint_event(uint64_t time, struct libinput_event *event, void *data)
if (!tp->palm.trackpoint_active) {
tp_edge_scroll_stop_events(tp, time);
- tp_gesture_stop(tp, time);
+ tp_gesture_stop(tp, time, 1);
tp_tap_suspend(tp, time);
tp->palm.trackpoint_active = true;
}
@@ -1053,7 +1053,7 @@ tp_keyboard_event(uint64_t time, struct libinput_event *event, void *data)
if (!tp->dwt.keyboard_active) {
tp_edge_scroll_stop_events(tp, time);
- tp_gesture_stop(tp, time);
+ tp_gesture_stop(tp, time, 1);
tp_tap_suspend(tp, time);
tp->dwt.keyboard_active = true;
timeout = DEFAULT_KEYBOARD_ACTIVITY_TIMEOUT_1;
diff --git a/src/evdev-mt-touchpad.h b/src/evdev-mt-touchpad.h
index a9b7574..b8a8712 100644
--- a/src/evdev-mt-touchpad.h
+++ b/src/evdev-mt-touchpad.h
@@ -447,7 +447,7 @@ void
tp_remove_gesture(struct tp_dispatch *tp);
void
-tp_gesture_stop(struct tp_dispatch *tp, uint64_t time);
+tp_gesture_stop(struct tp_dispatch *tp, uint64_t time, int cancelled);
void
tp_gesture_handle_state(struct tp_dispatch *tp, uint64_t time);
diff --git a/src/libinput-private.h b/src/libinput-private.h
index 67324aa..3fa6d26 100644
--- a/src/libinput-private.h
+++ b/src/libinput-private.h
@@ -374,6 +374,12 @@ gesture_notify_swipe(struct libinput_device *device,
const struct normalized_coords *unaccel);
void
+gesture_notify_swipe_end(struct libinput_device *device,
+ uint64_t time,
+ int finger_count,
+ int cancelled);
+
+void
gesture_notify_pinch(struct libinput_device *device,
uint64_t time,
enum libinput_event_type type,
@@ -383,6 +389,11 @@ gesture_notify_pinch(struct libinput_device *device,
double angle);
void
+gesture_notify_pinch_end(struct libinput_device *device,
+ uint64_t time,
+ int cancelled);
+
+void
touch_notify_frame(struct libinput_device *device,
uint64_t time);
diff --git a/src/libinput.c b/src/libinput.c
index 84e623f..16c3c4f 100644
--- a/src/libinput.c
+++ b/src/libinput.c
@@ -118,6 +118,7 @@ struct libinput_event_gesture {
struct libinput_event base;
uint32_t time;
int finger_count;
+ int cancelled;
struct normalized_coords delta;
struct normalized_coords delta_unaccel;
double scale;
@@ -675,6 +676,12 @@ libinput_event_gesture_get_finger_count(struct libinput_event_gesture *event)
return event->finger_count;
}
+LIBINPUT_EXPORT int
+libinput_event_gesture_get_cancelled(struct libinput_event_gesture *event)
+{
+ return event->cancelled;
+}
+
LIBINPUT_EXPORT double
libinput_event_gesture_get_dx(struct libinput_event_gesture *event)
{
@@ -1426,6 +1433,7 @@ gesture_notify(struct libinput_device *device,
uint64_t time,
enum libinput_event_type type,
int finger_count,
+ int cancelled,
const struct normalized_coords *delta,
const struct normalized_coords *unaccel,
double scale,
@@ -1443,6 +1451,7 @@ gesture_notify(struct libinput_device *device,
*gesture_event = (struct libinput_event_gesture) {
.time = time,
.finger_count = finger_count,
+ .cancelled = cancelled,
.delta = *delta,
.delta_unaccel = *unaccel,
.scale = scale,
@@ -1461,11 +1470,23 @@ gesture_notify_swipe(struct libinput_device *device,
const struct normalized_coords *delta,
const struct normalized_coords *unaccel)
{
- gesture_notify(device, time, type, finger_count, delta, unaccel,
+ gesture_notify(device, time, type, finger_count, 0, delta, unaccel,
0.0, 0.0);
}
void
+gesture_notify_swipe_end(struct libinput_device *device,
+ uint64_t time,
+ int finger_count,
+ int cancelled)
+{
+ const struct normalized_coords zero = { 0.0, 0.0 };
+
+ gesture_notify(device, time, LIBINPUT_EVENT_GESTURE_SWIPE_END,
+ finger_count, cancelled, &zero, &zero, 0.0, 0.0);
+}
+
+void
gesture_notify_pinch(struct libinput_device *device,
uint64_t time,
enum libinput_event_type type,
@@ -1474,7 +1495,19 @@ gesture_notify_pinch(struct libinput_device *device,
double scale,
double angle)
{
- gesture_notify(device, time, type, 2, delta, unaccel, scale, angle);
+ gesture_notify(device, time, type, 2, 0, delta, unaccel,
+ scale, angle);
+}
+
+void
+gesture_notify_pinch_end(struct libinput_device *device,
+ uint64_t time,
+ int cancelled)
+{
+ const struct normalized_coords zero = { 0.0, 0.0 };
+
+ gesture_notify(device, time, LIBINPUT_EVENT_GESTURE_PINCH_END,
+ 2, cancelled, &zero, &zero, 0.0, 0.0);
}
static void
diff --git a/src/libinput.h b/src/libinput.h
index e1a2dd7..a7164d3 100644
--- a/src/libinput.h
+++ b/src/libinput.h
@@ -990,6 +990,23 @@ libinput_event_gesture_get_finger_count(struct libinput_event_gesture *event);
/**
* @ingroup event_gesture
*
+ * Return if the gesture ended normally, or if it was cancelled.
+ * For gesture events that are not of type
+ * @ref LIBINPUT_EVENT_GESTURE_SWIPE_END or
+ * @ref LIBINPUT_EVENT_GESTURE_PINCH_END, this function returns 0.
+ *
+ * @note It is an application bug to call this function for events other than
+ * @ref LIBINPUT_EVENT_GESTURE_SWIPE_END or
+ * @ref LIBINPUT_EVENT_GESTURE_PINCH_END.
+ *
+ * @return 0 or 1, with 1 indicating that the gesture was cancelled.
+ */
+int
+libinput_event_gesture_get_cancelled(struct libinput_event_gesture *event);
+
+/**
+ * @ingroup event_gesture
+ *
* Return the delta between the last event and the current event. For gesture
* events that are not of type @ref LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE or
* @ref LIBINPUT_EVENT_GESTURE_PINCH_UPDATE, this function returns 0.
diff --git a/src/libinput.sym b/src/libinput.sym
index 0060ba8..1f8b9d4 100644
--- a/src/libinput.sym
+++ b/src/libinput.sym
@@ -150,6 +150,7 @@ LIBINPUT_0.19.0 {
TOUCHPAD_GESTURES {
libinput_event_gesture_get_angle_delta;
libinput_event_gesture_get_base_event;
+ libinput_event_gesture_get_cancelled;
libinput_event_gesture_get_dx;
libinput_event_gesture_get_dx_unaccelerated;
libinput_event_gesture_get_dy;
diff --git a/tools/event-debug.c b/tools/event-debug.c
index 1902dd3..38ded5e 100644
--- a/tools/event-debug.c
+++ b/tools/event-debug.c
@@ -306,9 +306,11 @@ static void
print_gesture_event_without_coords(struct libinput_event *ev)
{
struct libinput_event_gesture *t = libinput_event_get_gesture_event(ev);
+ int finger_count = libinput_event_gesture_get_finger_count(t);
+ int cancelled = libinput_event_gesture_get_cancelled(t);
print_event_time(libinput_event_gesture_get_time(t));
- printf("%d\n", libinput_event_gesture_get_finger_count(t));
+ printf("%d%s\n", finger_count, cancelled ? " cancelled" : "");
}
static void