Commit 7545b908 authored by Carlos Garnacho's avatar Carlos Garnacho
Browse files

gesture: Update to using GdkEvent API

To some extent, pad and touchpad gesture events need extra API.
parent 67239f11
......@@ -233,6 +233,7 @@ _gtk_gesture_get_n_touchpad_points (GtkGesture *gesture,
{
GtkGesturePrivate *priv;
PointData *data;
GdkEventType event_type;
priv = gtk_gesture_get_instance_private (gesture);
......@@ -244,15 +245,17 @@ _gtk_gesture_get_n_touchpad_points (GtkGesture *gesture,
if (!data)
return 0;
event_type = gdk_event_get_event_type (data->event);
if (only_active &&
(data->state == GTK_EVENT_SEQUENCE_DENIED ||
(data->event->type == GDK_TOUCHPAD_SWIPE &&
(event_type == GDK_TOUCHPAD_SWIPE &&
data->event->touchpad_swipe.phase == GDK_TOUCHPAD_GESTURE_PHASE_END) ||
(data->event->type == GDK_TOUCHPAD_PINCH &&
(event_type == GDK_TOUCHPAD_PINCH &&
data->event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_END)))
return 0;
switch (data->event->type)
switch (event_type)
{
case GDK_TOUCHPAD_SWIPE:
return data->event->touchpad_swipe.n_fingers;
......@@ -271,16 +274,19 @@ _gtk_gesture_get_n_touch_points (GtkGesture *gesture,
GHashTableIter iter;
guint n_points = 0;
PointData *data;
GdkEventType event_type;
priv = gtk_gesture_get_instance_private (gesture);
g_hash_table_iter_init (&iter, priv->points);
while (g_hash_table_iter_next (&iter, NULL, (gpointer *) &data))
{
event_type = gdk_event_get_event_type (data->event);
if (only_active &&
(data->state == GTK_EVENT_SEQUENCE_DENIED ||
data->event->type == GDK_TOUCH_END ||
data->event->type == GDK_BUTTON_RELEASE))
event_type == GDK_TOUCH_END ||
event_type == GDK_BUTTON_RELEASE))
continue;
n_points++;
......@@ -385,11 +391,14 @@ static void
_update_touchpad_deltas (PointData *data)
{
GdkEvent *event = data->event;
GdkEventType event_type;
if (!event)
return;
if (event->type == GDK_TOUCHPAD_SWIPE)
event_type = gdk_event_get_event_type (event);
if (event_type == GDK_TOUCHPAD_SWIPE)
{
if (event->touchpad_swipe.phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN)
data->accum_dx = data->accum_dy = 0;
......@@ -399,7 +408,7 @@ _update_touchpad_deltas (PointData *data)
data->accum_dy += event->touchpad_swipe.dy;
}
}
else if (event->type == GDK_TOUCHPAD_PINCH)
else if (event_type == GDK_TOUCHPAD_PINCH)
{
if (event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN)
data->accum_dx = data->accum_dy = 0;
......@@ -639,6 +648,7 @@ gtk_gesture_handle_event (GtkEventController *controller,
GtkGesturePrivate *priv;
GdkDevice *source_device;
gboolean was_recognized;
GdkEventType event_type;
source_device = gdk_event_get_source_device (event);
......@@ -648,15 +658,16 @@ gtk_gesture_handle_event (GtkEventController *controller,
priv = gtk_gesture_get_instance_private (gesture);
sequence = gdk_event_get_event_sequence (event);
was_recognized = gtk_gesture_is_recognized (gesture);
event_type = gdk_event_get_event_type (event);
if (gtk_gesture_get_sequence_state (gesture, sequence) != GTK_EVENT_SEQUENCE_DENIED)
priv->last_sequence = sequence;
if (event->type == GDK_BUTTON_PRESS ||
event->type == GDK_TOUCH_BEGIN ||
(event->type == GDK_TOUCHPAD_SWIPE &&
if (event_type == GDK_BUTTON_PRESS ||
event_type == GDK_TOUCH_BEGIN ||
(event_type == GDK_TOUCHPAD_SWIPE &&
event->touchpad_swipe.phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN) ||
(event->type == GDK_TOUCHPAD_PINCH &&
(event_type == GDK_TOUCHPAD_PINCH &&
event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN))
{
if (_gtk_gesture_update_point (gesture, event, TRUE))
......@@ -686,11 +697,11 @@ gtk_gesture_handle_event (GtkEventController *controller,
}
}
}
else if (event->type == GDK_BUTTON_RELEASE ||
event->type == GDK_TOUCH_END ||
(event->type == GDK_TOUCHPAD_SWIPE &&
else if (event_type == GDK_BUTTON_RELEASE ||
event_type == GDK_TOUCH_END ||
(event_type == GDK_TOUCHPAD_SWIPE &&
event->touchpad_swipe.phase == GDK_TOUCHPAD_GESTURE_PHASE_END) ||
(event->type == GDK_TOUCHPAD_PINCH &&
(event_type == GDK_TOUCHPAD_PINCH &&
event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_END))
{
gboolean was_claimed;
......@@ -709,14 +720,14 @@ gtk_gesture_handle_event (GtkEventController *controller,
return was_claimed && was_recognized;
}
else if (event->type == GDK_MOTION_NOTIFY ||
event->type == GDK_TOUCH_UPDATE ||
(event->type == GDK_TOUCHPAD_SWIPE &&
else if (event_type == GDK_MOTION_NOTIFY ||
event_type == GDK_TOUCH_UPDATE ||
(event_type == GDK_TOUCHPAD_SWIPE &&
event->touchpad_swipe.phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE) ||
(event->type == GDK_TOUCHPAD_PINCH &&
(event_type == GDK_TOUCHPAD_PINCH &&
event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE))
{
if (event->type == GDK_MOTION_NOTIFY)
if (event_type == GDK_MOTION_NOTIFY)
{
if ((event->motion.state & BUTTONS_MASK) == 0)
return FALSE;
......@@ -729,20 +740,20 @@ gtk_gesture_handle_event (GtkEventController *controller,
_gtk_gesture_check_recognized (gesture, sequence))
g_signal_emit (gesture, signals[UPDATE], 0, sequence);
}
else if (event->type == GDK_TOUCH_CANCEL)
else if (event_type == GDK_TOUCH_CANCEL)
{
if (!priv->touchpad)
_gtk_gesture_cancel_sequence (gesture, sequence);
}
else if ((event->type == GDK_TOUCHPAD_SWIPE &&
else if ((event_type == GDK_TOUCHPAD_SWIPE &&
event->touchpad_swipe.phase == GDK_TOUCHPAD_GESTURE_PHASE_CANCEL) ||
(event->type == GDK_TOUCHPAD_PINCH &&
(event_type == GDK_TOUCHPAD_PINCH &&
event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_CANCEL))
{
if (priv->touchpad)
_gtk_gesture_cancel_sequence (gesture, sequence);
}
else if (event->type == GDK_GRAB_BROKEN)
else if (event_type == GDK_GRAB_BROKEN)
{
if (!event->grab_broken.grab_window ||
!gesture_within_window (gesture, event->grab_broken.grab_window))
......@@ -1139,6 +1150,7 @@ gtk_gesture_get_sequences (GtkGesture *gesture)
GList *sequences = NULL;
GHashTableIter iter;
PointData *data;
GdkEventType event_type;
g_return_val_if_fail (GTK_IS_GESTURE (gesture), NULL);
......@@ -1149,8 +1161,11 @@ gtk_gesture_get_sequences (GtkGesture *gesture)
{
if (data->state == GTK_EVENT_SEQUENCE_DENIED)
continue;
if (data->event->type == GDK_TOUCH_END ||
data->event->type == GDK_BUTTON_RELEASE)
event_type = gdk_event_get_event_type (data->event);
if (event_type == GDK_TOUCH_END ||
event_type == GDK_BUTTON_RELEASE)
continue;
sequences = g_list_prepend (sequences, sequence);
......@@ -1304,6 +1319,7 @@ gtk_gesture_get_bounding_box (GtkGesture *gesture,
GHashTableIter iter;
guint n_points = 0;
PointData *data;
GdkEventType event_type;
g_return_val_if_fail (GTK_IS_GESTURE (gesture), FALSE);
g_return_val_if_fail (rect != NULL, FALSE);
......@@ -1320,8 +1336,11 @@ gtk_gesture_get_bounding_box (GtkGesture *gesture,
if (data->state == GTK_EVENT_SEQUENCE_DENIED)
continue;
if (data->event->type == GDK_TOUCH_END ||
data->event->type == GDK_BUTTON_RELEASE)
event_type = gdk_event_get_event_type (data->event);
if (event_type == GDK_TOUCH_END ||
event_type == GDK_BUTTON_RELEASE)
continue;
gdk_event_get_coords (data->event, &x, &y);
......@@ -1660,7 +1679,7 @@ _gtk_gesture_get_pointer_emulating_sequence (GtkGesture *gesture,
while (g_hash_table_iter_next (&iter, (gpointer*) &seq, (gpointer*) &data))
{
switch (data->event->type)
switch (gdk_event_get_event_type (data->event))
{
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_UPDATE:
......
......@@ -62,7 +62,7 @@ gtk_gesture_drag_filter_event (GtkEventController *controller,
const GdkEvent *event)
{
/* Let touchpad swipe events go through, only if they match n-points */
if (event->type == GDK_TOUCHPAD_SWIPE)
if (gdk_event_get_event_type (event) == GDK_TOUCHPAD_SWIPE)
{
guint n_points;
......
......@@ -116,6 +116,7 @@ gtk_gesture_long_press_begin (GtkGesture *gesture,
{
GtkGestureLongPressPrivate *priv;
const GdkEvent *event;
GdkEventType event_type;
GtkWidget *widget;
gint delay;
......@@ -123,9 +124,13 @@ gtk_gesture_long_press_begin (GtkGesture *gesture,
sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
event = gtk_gesture_get_last_event (gesture, sequence);
if (!event ||
(event->type != GDK_BUTTON_PRESS &&
event->type != GDK_TOUCH_BEGIN))
if (!event)
return;
event_type = gdk_event_get_event_type (event);
if (event_type != GDK_BUTTON_PRESS &&
event_type != GDK_TOUCH_BEGIN)
return;
widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
......
......@@ -198,6 +198,7 @@ gtk_gesture_multi_press_begin (GtkGesture *gesture,
guint n_presses, button = 1;
GdkEventSequence *current;
const GdkEvent *event;
GdkEventType event_type;
GdkDevice *device;
gdouble x, y;
......@@ -209,10 +210,11 @@ gtk_gesture_multi_press_begin (GtkGesture *gesture,
event = gtk_gesture_get_last_event (gesture, sequence);
current = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
device = gdk_event_get_source_device (event);
event_type = gdk_event_get_event_type (event);
if (event->type == GDK_BUTTON_PRESS)
button = event->button.button;
else if (event->type == GDK_TOUCH_BEGIN)
if (event_type == GDK_BUTTON_PRESS)
gdk_event_get_button (event, &button);
else if (event_type == GDK_TOUCH_BEGIN)
button = 1;
else
return;
......
......@@ -96,7 +96,7 @@ _gtk_gesture_rotate_get_angle (GtkGestureRotate *rotate,
last_event = gtk_gesture_get_last_event (gesture, sequences->data);
if (last_event->type == GDK_TOUCHPAD_PINCH &&
if (gdk_event_get_event_type (last_event) == GDK_TOUCHPAD_PINCH &&
(last_event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN ||
last_event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE ||
last_event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_END))
......@@ -169,7 +169,7 @@ gtk_gesture_rotate_filter_event (GtkEventController *controller,
const GdkEvent *event)
{
/* Let 2-finger touchpad pinch events go through */
if (event->type == GDK_TOUCHPAD_PINCH)
if (gdk_event_get_event_type (event) == GDK_TOUCHPAD_PINCH)
{
if (event->touchpad_pinch.n_fingers == 2)
return FALSE;
......@@ -189,7 +189,7 @@ gtk_gesture_rotate_handle_event (GtkEventController *controller,
priv = gtk_gesture_rotate_get_instance_private (rotate);
if (event->type == GDK_TOUCHPAD_PINCH)
if (gdk_event_get_event_type (event) == GDK_TOUCHPAD_PINCH)
{
if (event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN ||
event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_END)
......
......@@ -137,8 +137,9 @@ gtk_gesture_single_handle_event (GtkEventController *controller,
GtkGestureSinglePrivate *priv;
GdkDevice *source_device;
GdkInputSource source;
guint button = 0, i;
guint button = 0, state, i;
gboolean retval, test_touchscreen = FALSE;
GdkEventType event_type;
source_device = gdk_event_get_source_device (event);
......@@ -151,7 +152,9 @@ gtk_gesture_single_handle_event (GtkEventController *controller,
if (source != GDK_SOURCE_TOUCHSCREEN)
test_touchscreen = gtk_simulate_touchscreen ();
switch (event->type)
event_type = gdk_event_get_event_type (event);
switch (event_type)
{
case GDK_TOUCH_BEGIN:
case GDK_TOUCH_END:
......@@ -159,7 +162,7 @@ gtk_gesture_single_handle_event (GtkEventController *controller,
if (priv->exclusive && !event->touch.emulating_pointer)
return FALSE;
sequence = event->touch.sequence;
sequence = gdk_event_get_event_sequence (event);
button = 1;
break;
case GDK_BUTTON_PRESS:
......@@ -167,23 +170,25 @@ gtk_gesture_single_handle_event (GtkEventController *controller,
if (priv->touch_only && !test_touchscreen && source != GDK_SOURCE_TOUCHSCREEN)
return FALSE;
button = event->button.button;
gdk_event_get_button (event, &button);
break;
case GDK_MOTION_NOTIFY:
if (!gtk_gesture_handles_sequence (GTK_GESTURE (controller), sequence))
return FALSE;
if (priv->touch_only && !test_touchscreen && source != GDK_SOURCE_TOUCHSCREEN)
return FALSE;
if (!gdk_event_get_state (event, &state))
return FALSE;
if (priv->current_button > 0 && priv->current_button <= 5 &&
(event->motion.state & (GDK_BUTTON1_MASK << (priv->current_button - 1))))
(state & (GDK_BUTTON1_MASK << (priv->current_button - 1))))
button = priv->current_button;
else if (priv->current_button == 0)
{
/* No current button, find out from the mask */
for (i = 0; i < 3; i++)
{
if ((event->motion.state & (GDK_BUTTON1_MASK << i)) == 0)
if ((state & (GDK_BUTTON1_MASK << i)) == 0)
continue;
button = i + 1;
break;
......@@ -210,8 +215,8 @@ gtk_gesture_single_handle_event (GtkEventController *controller,
return FALSE;
}
if (event->type == GDK_BUTTON_PRESS || event->type == GDK_TOUCH_BEGIN ||
event->type == GDK_MOTION_NOTIFY || event->type == GDK_TOUCH_UPDATE)
if (event_type == GDK_BUTTON_PRESS || event_type == GDK_TOUCH_BEGIN ||
event_type == GDK_MOTION_NOTIFY || event_type == GDK_TOUCH_UPDATE)
{
if (!gtk_gesture_is_active (GTK_GESTURE (controller)))
priv->current_sequence = sequence;
......@@ -222,14 +227,14 @@ gtk_gesture_single_handle_event (GtkEventController *controller,
retval = GTK_EVENT_CONTROLLER_CLASS (gtk_gesture_single_parent_class)->handle_event (controller, event);
if (sequence == priv->current_sequence &&
(event->type == GDK_BUTTON_RELEASE || event->type == GDK_TOUCH_END))
(event_type == GDK_BUTTON_RELEASE || event_type == GDK_TOUCH_END))
priv->current_button = 0;
else if (priv->current_sequence == sequence &&
!gtk_gesture_handles_sequence (GTK_GESTURE (controller), sequence))
{
if (button == priv->current_button && event->type == GDK_BUTTON_PRESS)
if (button == priv->current_button && event_type == GDK_BUTTON_PRESS)
priv->current_button = 0;
else if (sequence == priv->current_sequence && event->type == GDK_TOUCH_BEGIN)
else if (sequence == priv->current_sequence && event_type == GDK_TOUCH_BEGIN)
priv->current_sequence = NULL;
}
......
......@@ -83,7 +83,7 @@ gtk_gesture_swipe_filter_event (GtkEventController *controller,
const GdkEvent *event)
{
/* Let touchpad swipe events go through, only if they match n-points */
if (event->type == GDK_TOUCHPAD_SWIPE)
if (gdk_event_get_event_type (event) == GDK_TOUCHPAD_SWIPE)
{
guint n_points;
......
......@@ -93,7 +93,7 @@ _gtk_gesture_zoom_get_distance (GtkGestureZoom *zoom,
last_event = gtk_gesture_get_last_event (gesture, sequences->data);
if (last_event->type == GDK_TOUCHPAD_PINCH &&
if (gdk_event_get_event_type (last_event) == GDK_TOUCHPAD_PINCH &&
(last_event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN ||
last_event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE ||
last_event->touchpad_pinch.phase == GDK_TOUCHPAD_GESTURE_PHASE_END))
......@@ -143,7 +143,7 @@ gtk_gesture_zoom_filter_event (GtkEventController *controller,
const GdkEvent *event)
{
/* Let 2-finger touchpad pinch events go through */
if (event->type == GDK_TOUCHPAD_PINCH)
if (gdk_event_get_event_type (event) == GDK_TOUCHPAD_PINCH)
{
if (event->touchpad_pinch.n_fingers == 2)
return FALSE;
......
......@@ -211,12 +211,13 @@ gtk_pad_controller_filter_event (GtkEventController *controller,
const GdkEvent *event)
{
GtkPadController *pad_controller = GTK_PAD_CONTROLLER (controller);
GdkEventType event_type = gdk_event_get_event_type (event);
if (event->type != GDK_PAD_BUTTON_PRESS &&
event->type != GDK_PAD_BUTTON_RELEASE &&
event->type != GDK_PAD_RING &&
event->type != GDK_PAD_STRIP &&
event->type != GDK_PAD_GROUP_MODE)
if (event_type != GDK_PAD_BUTTON_PRESS &&
event_type != GDK_PAD_BUTTON_RELEASE &&
event_type != GDK_PAD_RING &&
event_type != GDK_PAD_STRIP &&
event_type != GDK_PAD_GROUP_MODE)
return TRUE;
if (pad_controller->pad &&
......@@ -231,11 +232,12 @@ gtk_pad_controller_handle_event (GtkEventController *controller,
const GdkEvent *event)
{
GtkPadController *pad_controller = GTK_PAD_CONTROLLER (controller);
GdkEventType event_type = gdk_event_get_event_type (event);
const GtkPadActionEntry *entry;
GtkPadActionType type;
gint index, mode;
if (event->type == GDK_PAD_GROUP_MODE)
if (event_type == GDK_PAD_GROUP_MODE)
{
gtk_pad_controller_handle_mode_switch (pad_controller,
gdk_event_get_source_device (event),
......@@ -244,7 +246,7 @@ gtk_pad_controller_handle_event (GtkEventController *controller,
return GDK_EVENT_PROPAGATE;
}
switch (event->type)
switch (event_type)
{
case GDK_PAD_BUTTON_PRESS:
type = GTK_PAD_ACTION_BUTTON;
......@@ -253,7 +255,7 @@ gtk_pad_controller_handle_event (GtkEventController *controller,
break;
case GDK_PAD_RING:
case GDK_PAD_STRIP:
type = event->type == GDK_PAD_RING ?
type = event_type == GDK_PAD_RING ?
GTK_PAD_ACTION_RING : GTK_PAD_ACTION_STRIP;
index = event->pad_axis.index;
mode = event->pad_axis.mode;
......@@ -267,8 +269,8 @@ gtk_pad_controller_handle_event (GtkEventController *controller,
if (!entry)
return GDK_EVENT_PROPAGATE;
if (event->type == GDK_PAD_RING ||
event->type == GDK_PAD_STRIP)
if (event_type == GDK_PAD_RING ||
event_type == GDK_PAD_STRIP)
{
gtk_pad_controller_activate_action_with_axis (pad_controller, entry,
event->pad_axis.value);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment