gdk: Prepare touchpad events for sequences

It makes sense to connect the begin/update/end events
for touchpad swipes and pinches in a sequence. This
commit adds the plumbing for it, but not backends
are setting sequences yet.
This commit is contained in:
Matthias Clasen 2021-12-15 20:11:51 -05:00
parent 69b160cfe8
commit 2772ff624f
6 changed files with 77 additions and 41 deletions

View File

@ -2476,6 +2476,14 @@ gdk_touchpad_event_get_state (GdkEvent *event)
return self->state;
}
static GdkEventSequence *
gdk_touchpad_event_get_sequence (GdkEvent *event)
{
GdkTouchpadEvent *self = (GdkTouchpadEvent *) event;
return self->sequence;
}
static gboolean
gdk_touchpad_event_get_position (GdkEvent *event,
double *x,
@ -2495,7 +2503,7 @@ static const GdkEventTypeInfo gdk_touchpad_event_info = {
NULL,
gdk_touchpad_event_get_state,
gdk_touchpad_event_get_position,
NULL,
gdk_touchpad_event_get_sequence,
NULL,
NULL,
};
@ -2506,19 +2514,28 @@ GDK_DEFINE_EVENT_TYPE (GdkTouchpadEvent, gdk_touchpad_event,
GDK_EVENT_TYPE_SLOT (GDK_TOUCHPAD_PINCH))
GdkEvent *
gdk_touchpad_event_new_swipe (GdkSurface *surface,
GdkDevice *device,
guint32 time,
GdkModifierType state,
GdkTouchpadGesturePhase phase,
double x,
double y,
int n_fingers,
double dx,
double dy)
gdk_touchpad_event_new_swipe (GdkSurface *surface,
GdkEventSequence *sequence,
GdkDevice *device,
guint32 time,
GdkModifierType state,
GdkTouchpadGesturePhase phase,
double x,
double y,
int n_fingers,
double dx,
double dy)
{
GdkTouchpadEvent *self = gdk_event_alloc (GDK_TOUCHPAD_SWIPE, surface, device, time);
GdkTouchpadEvent *self;
g_return_val_if_fail (phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN ||
phase == GDK_TOUCHPAD_GESTURE_PHASE_END ||
phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE ||
phase == GDK_TOUCHPAD_GESTURE_PHASE_CANCEL, NULL);
self = gdk_event_alloc (GDK_TOUCHPAD_SWIPE, surface, device, time);
self->sequence = sequence;
self->state = state;
self->phase = phase;
self->x = x;
@ -2531,21 +2548,30 @@ gdk_touchpad_event_new_swipe (GdkSurface *surface,
}
GdkEvent *
gdk_touchpad_event_new_pinch (GdkSurface *surface,
GdkDevice *device,
guint32 time,
GdkModifierType state,
GdkTouchpadGesturePhase phase,
double x,
double y,
int n_fingers,
double dx,
double dy,
double scale,
double angle_delta)
gdk_touchpad_event_new_pinch (GdkSurface *surface,
GdkEventSequence *sequence,
GdkDevice *device,
guint32 time,
GdkModifierType state,
GdkTouchpadGesturePhase phase,
double x,
double y,
int n_fingers,
double dx,
double dy,
double scale,
double angle_delta)
{
GdkTouchpadEvent *self = gdk_event_alloc (GDK_TOUCHPAD_PINCH, surface, device, time);
GdkTouchpadEvent *self;
g_return_val_if_fail (phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN ||
phase == GDK_TOUCHPAD_GESTURE_PHASE_END ||
phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE ||
phase == GDK_TOUCHPAD_GESTURE_PHASE_CANCEL, NULL);
self = gdk_event_alloc (GDK_TOUCHPAD_PINCH, surface, device, time);
self->sequence = sequence;
self->state = state;
self->phase = phase;
self->x = x;

View File

@ -402,6 +402,7 @@ struct _GdkTouchpadEvent
{
GdkEvent parent_instance;
GdkEventSequence *sequence;
GdkModifierType state;
gint8 phase;
gint8 n_fingers;
@ -506,18 +507,20 @@ GdkEvent * gdk_touch_event_new (GdkEventType type,
double *axes,
gboolean emulating);
GdkEvent * gdk_touchpad_event_new_swipe (GdkSurface *surface,
GdkDevice *device,
guint32 time,
GdkModifierType state,
GdkEvent * gdk_touchpad_event_new_swipe (GdkSurface *surface,
GdkEventSequence *sequence,
GdkDevice *device,
guint32 time,
GdkModifierType state,
GdkTouchpadGesturePhase phase,
double x,
double y,
int n_fingers,
double dx,
double dy);
double x,
double y,
int n_fingers,
double dx,
double dy);
GdkEvent * gdk_touchpad_event_new_pinch (GdkSurface *surface,
GdkEventSequence *sequence,
GdkDevice *device,
guint32 time,
GdkModifierType state,

View File

@ -537,6 +537,7 @@ fill_pinch_event (GdkMacosDisplay *display,
seat = gdk_display_get_default_seat (GDK_DISPLAY (display));
return gdk_touchpad_event_new_pinch (GDK_SURFACE (surface),
NULL, /* FIXME make up sequences */
gdk_seat_get_pointer (seat),
get_time_from_ns_event (nsevent),
get_keyboard_modifiers_from_ns_event (nsevent),

View File

@ -1127,7 +1127,7 @@ data_offer_source_actions (void *data,
seat->pending_source_actions = gdk_wayland_actions_to_gdk_actions (source_actions);
return;
}
if (seat->drop == NULL)
return;
@ -1152,7 +1152,7 @@ data_offer_action (void *data,
seat->pending_action = gdk_wayland_actions_to_gdk_actions (action);
return;
}
if (seat->drop == NULL)
return;
@ -2164,7 +2164,7 @@ deliver_key_event (GdkWaylandSeat *seat,
key,
device_get_modifiers (seat->logical_pointer),
_gdk_wayland_keymap_key_is_modifier (keymap, key),
&translated,
&translated,
&no_lock);
_gdk_wayland_display_deliver_event (seat->display, event);
@ -2668,6 +2668,7 @@ emit_gesture_swipe_event (GdkWaylandSeat *seat,
seat->pointer_info.time = _time;
event = gdk_touchpad_event_new_swipe (seat->pointer_info.focus,
NULL,
seat->logical_pointer,
_time,
device_get_modifiers (seat->logical_pointer),
@ -2764,6 +2765,7 @@ emit_gesture_pinch_event (GdkWaylandSeat *seat,
seat->pointer_info.time = _time;
event = gdk_touchpad_event_new_pinch (seat->pointer_info.focus,
NULL,
seat->logical_pointer,
_time,
device_get_modifiers (seat->logical_pointer),
@ -4088,7 +4090,7 @@ tablet_pad_strip_handle_frame (void *data,
event = gdk_pad_event_new_strip (seat->keyboard_focus,
pad->device,
time,
g_list_index (pad->mode_groups, group),
g_list_index (pad->mode_groups, group),
g_list_index (pad->strips, wp_tablet_pad_strip),
group->current_mode,
group->axis_tmp_info.value);

View File

@ -1665,7 +1665,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
_gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group),
direction,
FALSE);
}
else
{
@ -1799,7 +1799,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
_gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, &xev->group),
x, y,
axes);
}
break;
@ -1838,7 +1838,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
x = (double) xev->event_x / scale;
y = (double) xev->event_y / scale;
event = gdk_touch_event_new (ev->evtype == XI_TouchBegin
? GDK_TOUCH_BEGIN
: GDK_TOUCH_END,
@ -1946,6 +1946,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
y = (double) xev->event_y / scale;
event = gdk_touchpad_event_new_pinch (surface,
NULL, /* FIXME make up sequences */
device,
xev->time,
state,
@ -2006,6 +2007,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
y = (double) xev->event_y / scale;
event = gdk_touchpad_event_new_swipe (surface,
NULL, /* FIXME make up sequences */
device,
xev->time,
state,

View File

@ -951,6 +951,7 @@ rewrite_event_for_surface (GdkEvent *event,
case GDK_TOUCHPAD_SWIPE:
gdk_touchpad_event_get_deltas (event, &dx, &dy);
return gdk_touchpad_event_new_swipe (new_surface,
gdk_event_get_event_sequence (event),
gdk_event_get_device (event),
gdk_event_get_time (event),
gdk_event_get_modifier_state (event),
@ -961,6 +962,7 @@ rewrite_event_for_surface (GdkEvent *event,
case GDK_TOUCHPAD_PINCH:
gdk_touchpad_event_get_deltas (event, &dx, &dy);
return gdk_touchpad_event_new_pinch (new_surface,
gdk_event_get_event_sequence (event),
gdk_event_get_device (event),
gdk_event_get_time (event),
gdk_event_get_modifier_state (event),