mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2025-12-25 08:10:05 +01:00
touchpad: Allow querying whether a gesture ended normally or was cancelled
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
This commit is contained in:
parent
ad26785f6a
commit
9fae0f8c3e
8 changed files with 79 additions and 19 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -373,6 +373,12 @@ gesture_notify_swipe(struct libinput_device *device,
|
|||
const struct normalized_coords *delta,
|
||||
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,
|
||||
|
|
@ -382,6 +388,11 @@ gesture_notify_pinch(struct libinput_device *device,
|
|||
double scale,
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -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,10 +1470,22 @@ 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,
|
||||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -987,6 +987,23 @@ libinput_event_gesture_get_base_event(struct libinput_event_gesture *event);
|
|||
int
|
||||
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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue