clutter: Add API for retrieving gesture unaccelerated deltas

This will be useful for better aligning behavior between scrolling and
swiping for gnome-shell swipe tracker.

https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/1353
This commit is contained in:
Alexander Mikhaylenko 2020-07-05 20:22:59 +05:00 committed by Alexander Mikhaylenko
parent dbff32ec5c
commit 620386f3ac
3 changed files with 75 additions and 9 deletions

View File

@ -2126,6 +2126,42 @@ clutter_event_get_gesture_motion_delta (const ClutterEvent *event,
}
}
/**
* clutter_event_get_gesture_motion_delta_unaccelerated:
* @event: A clutter touchpad gesture event
* @dx: (out) (allow-none): the displacement relative to the pointer
* position in the X axis, or %NULL
* @dy: (out) (allow-none): the displacement relative to the pointer
* position in the Y axis, or %NULL
*
* Returns the unaccelerated gesture motion deltas relative to the current
* pointer position. Unlike clutter_event_get_gesture_motion_delta(),
* pointer acceleration is ignored.
**/
void
clutter_event_get_gesture_motion_delta_unaccelerated (const ClutterEvent *event,
gdouble *dx,
gdouble *dy)
{
g_return_if_fail (event != NULL);
g_return_if_fail (event->type == CLUTTER_TOUCHPAD_PINCH ||
event->type == CLUTTER_TOUCHPAD_SWIPE);
if (event->type == CLUTTER_TOUCHPAD_PINCH)
{
if (dx)
*dx = event->touchpad_pinch.dx_unaccel;
if (dy)
*dy = event->touchpad_pinch.dy_unaccel;
}
else if (event->type == CLUTTER_TOUCHPAD_SWIPE)
{
if (dx)
*dx = event->touchpad_swipe.dx_unaccel;
if (dy)
*dy = event->touchpad_swipe.dy_unaccel;
}
}
/**
* clutter_event_get_scroll_source:
* @event: an scroll event

View File

@ -431,6 +431,10 @@ struct _ClutterTouchEvent
* @y: the Y coordinate of the pointer, relative to the stage
* @dx: movement delta of the pinch focal point in the X axis
* @dy: movement delta of the pinch focal point in the Y axis
* @dx_unaccel: unaccelerated movement delta of the pinch focal
* point in the X axis
* @dy_unaccel: unaccelerated movement delta of the pinch focal
* point in the Y axis
* @angle_delta: angle delta in degrees, clockwise rotations are
* represented by positive deltas
* @scale: the current scale
@ -458,6 +462,8 @@ struct _ClutterTouchpadPinchEvent
gfloat y;
gfloat dx;
gfloat dy;
gfloat dx_unaccel;
gfloat dy_unaccel;
gfloat angle_delta;
gfloat scale;
guint n_fingers;
@ -474,8 +480,12 @@ struct _ClutterTouchpadPinchEvent
* @n_fingers: the number of fingers triggering the swipe
* @x: the X coordinate of the pointer, relative to the stage
* @y: the Y coordinate of the pointer, relative to the stage
* @dx: movement delta of the pinch focal point in the X axis
* @dy: movement delta of the pinch focal point in the Y axis
* @dx: movement delta of the swipe center point in the X axis
* @dy: movement delta of the swipe center point in the Y axis
* @dx_unaccel: unaccelerated movement delta of the swipe center
* point in the X axis
* @dy_unaccel: unaccelerated movement delta of the swipe center
* point in the Y axis
*
* Used for touchpad swipe gesture events. The current state of the
* gesture will be determined by the @phase field.
@ -496,6 +506,8 @@ struct _ClutterTouchpadSwipeEvent
gfloat y;
gfloat dx;
gfloat dy;
gfloat dx_unaccel;
gfloat dy_unaccel;
};
struct _ClutterPadButtonEvent
@ -773,6 +785,11 @@ void clutter_event_get_gesture_motion_delta (const Clut
gdouble *dx,
gdouble *dy);
CLUTTER_EXPORT
void clutter_event_get_gesture_motion_delta_unaccelerated (const ClutterEvent *event,
gdouble *dx,
gdouble *dy);
CLUTTER_EXPORT
ClutterScrollSource clutter_event_get_scroll_source (const ClutterEvent *event);

View File

@ -998,6 +998,8 @@ notify_pinch_gesture_event (ClutterInputDevice *input_device,
uint64_t time_us,
double dx,
double dy,
double dx_unaccel,
double dy_unaccel,
double angle_delta,
double scale,
uint32_t n_fingers)
@ -1029,6 +1031,8 @@ notify_pinch_gesture_event (ClutterInputDevice *input_device,
event->touchpad_pinch.y = pos.y;
event->touchpad_pinch.dx = dx;
event->touchpad_pinch.dy = dy;
event->touchpad_pinch.dx_unaccel = dx_unaccel;
event->touchpad_pinch.dy_unaccel = dy_unaccel;
event->touchpad_pinch.angle_delta = angle_delta;
event->touchpad_pinch.scale = scale;
event->touchpad_pinch.n_fingers = n_fingers;
@ -1047,7 +1051,9 @@ notify_swipe_gesture_event (ClutterInputDevice *input_device,
uint64_t time_us,
uint32_t n_fingers,
double dx,
double dy)
double dy,
double dx_unaccel,
double dy_unaccel)
{
MetaInputDeviceNative *device_evdev;
MetaSeatNative *seat;
@ -1076,6 +1082,8 @@ notify_swipe_gesture_event (ClutterInputDevice *input_device,
event->touchpad_swipe.y = pos.y;
event->touchpad_swipe.dx = dx;
event->touchpad_swipe.dy = dy;
event->touchpad_swipe.dx_unaccel = dx_unaccel;
event->touchpad_swipe.dy_unaccel = dy_unaccel;
event->touchpad_swipe.n_fingers = n_fingers;
meta_xkb_translate_state (event, seat->xkb, seat->button_state);
@ -2104,14 +2112,14 @@ process_device_event (MetaSeatNative *seat,
n_fingers = libinput_event_gesture_get_finger_count (gesture_event);
device = libinput_device_get_user_data (libinput_device);
time_us = libinput_event_gesture_get_time_usec (gesture_event);
notify_pinch_gesture_event (device, phase, time_us, 0, 0, 0, 0, n_fingers);
notify_pinch_gesture_event (device, phase, time_us, 0, 0, 0, 0, 0, 0, n_fingers);
break;
}
case LIBINPUT_EVENT_GESTURE_PINCH_UPDATE:
{
struct libinput_event_gesture *gesture_event =
libinput_event_get_gesture_event (event);
gdouble angle_delta, scale, dx, dy;
gdouble angle_delta, scale, dx, dy, dx_unaccel, dy_unaccel;
uint32_t n_fingers;
uint64_t time_us;
@ -2122,10 +2130,13 @@ process_device_event (MetaSeatNative *seat,
scale = libinput_event_gesture_get_scale (gesture_event);
dx = libinput_event_gesture_get_dx (gesture_event);
dy = libinput_event_gesture_get_dy (gesture_event);
dx_unaccel = libinput_event_gesture_get_dx_unaccelerated (gesture_event);
dy_unaccel = libinput_event_gesture_get_dy_unaccelerated (gesture_event);
notify_pinch_gesture_event (device,
CLUTTER_TOUCHPAD_GESTURE_PHASE_UPDATE,
time_us, dx, dy, angle_delta, scale, n_fingers);
time_us, dx, dy, dx_unaccel, dy_unaccel,
angle_delta, scale, n_fingers);
break;
}
case LIBINPUT_EVENT_GESTURE_SWIPE_BEGIN:
@ -2147,7 +2158,7 @@ process_device_event (MetaSeatNative *seat,
phase = libinput_event_gesture_get_cancelled (gesture_event) ?
CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL : CLUTTER_TOUCHPAD_GESTURE_PHASE_END;
notify_swipe_gesture_event (device, phase, time_us, n_fingers, 0, 0);
notify_swipe_gesture_event (device, phase, time_us, n_fingers, 0, 0, 0, 0);
break;
}
case LIBINPUT_EVENT_GESTURE_SWIPE_UPDATE:
@ -2156,17 +2167,19 @@ process_device_event (MetaSeatNative *seat,
libinput_event_get_gesture_event (event);
uint32_t n_fingers;
uint64_t time_us;
double dx, dy;
double dx, dy, dx_unaccel, dy_unaccel;
device = libinput_device_get_user_data (libinput_device);
time_us = libinput_event_gesture_get_time_usec (gesture_event);
n_fingers = libinput_event_gesture_get_finger_count (gesture_event);
dx = libinput_event_gesture_get_dx (gesture_event);
dy = libinput_event_gesture_get_dy (gesture_event);
dx_unaccel = libinput_event_gesture_get_dx_unaccelerated (gesture_event);
dy_unaccel = libinput_event_gesture_get_dy_unaccelerated (gesture_event);
notify_swipe_gesture_event (device,
CLUTTER_TOUCHPAD_GESTURE_PHASE_UPDATE,
time_us, n_fingers, dx, dy);
time_us, n_fingers, dx, dy, dx_unaccel, dy_unaccel);
break;
}
case LIBINPUT_EVENT_TABLET_TOOL_AXIS: