[gtk/readonly-events-1: 19/35] gesture: Keep the target widget for events
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/readonly-events-1: 19/35] gesture: Keep the target widget for events
- Date: Tue, 18 Feb 2020 05:24:09 +0000 (UTC)
commit bf7c71d0aee2178b82bef6ab2c6836403fe95391
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Feb 16 02:46:40 2020 -0500
gesture: Keep the target widget for events
We already store the events; keep the target widget
in addition. This is a step towards getting rid of
gdk_event_get_target.
gtk/gtkgesture.c | 32 +++++++++++++++++++++++++++++---
gtk/gtkgesture.h | 4 ++++
2 files changed, 33 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkgesture.c b/gtk/gtkgesture.c
index 0d728ad67d..f902ac2c93 100644
--- a/gtk/gtkgesture.c
+++ b/gtk/gtkgesture.c
@@ -145,6 +145,7 @@ enum {
struct _PointData
{
GdkEvent *event;
+ GtkWidget *target;
gdouble widget_x;
gdouble widget_y;
@@ -440,6 +441,7 @@ gtk_gesture_get_group_state (GtkGesture *gesture,
static gboolean
_gtk_gesture_update_point (GtkGesture *gesture,
const GdkEvent *event,
+ GtkWidget *target,
double x,
double y,
gboolean add)
@@ -612,6 +614,7 @@ gtk_gesture_handle_event (GtkEventController *controller,
GdkEventType event_type;
GdkTouchpadGesturePhase phase;
GdkModifierType state;
+ GtkWidget *target;
source_device = gdk_event_get_source_device (event);
@@ -625,6 +628,8 @@ gtk_gesture_handle_event (GtkEventController *controller,
gdk_event_get_state (event, &state);
gdk_event_get_touchpad_gesture_phase (event, &phase);
+ target = gtk_event_controller_get_target (controller);
+
if (gtk_gesture_get_sequence_state (gesture, sequence) != GTK_EVENT_SEQUENCE_DENIED)
priv->last_sequence = sequence;
@@ -633,7 +638,7 @@ gtk_gesture_handle_event (GtkEventController *controller,
(event_type == GDK_TOUCHPAD_SWIPE && phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN) ||
(event_type == GDK_TOUCHPAD_PINCH && phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN))
{
- if (_gtk_gesture_update_point (gesture, event, x, y, TRUE))
+ if (_gtk_gesture_update_point (gesture, event, target, x, y, TRUE))
{
gboolean triggered_recognition;
@@ -667,7 +672,7 @@ gtk_gesture_handle_event (GtkEventController *controller,
{
gboolean was_claimed;
- if (_gtk_gesture_update_point (gesture, event, x, y, FALSE))
+ if (_gtk_gesture_update_point (gesture, event, target, x, y, FALSE))
{
if (was_recognized &&
_gtk_gesture_check_recognized (gesture, sequence))
@@ -692,7 +697,7 @@ gtk_gesture_handle_event (GtkEventController *controller,
return FALSE;
}
- if (_gtk_gesture_update_point (gesture, event, x, y, FALSE) &&
+ if (_gtk_gesture_update_point (gesture, event, target, x, y, FALSE) &&
_gtk_gesture_check_recognized (gesture, sequence))
g_signal_emit (gesture, signals[UPDATE], 0, sequence);
}
@@ -873,6 +878,9 @@ free_point_data (gpointer data)
if (point->event)
gdk_event_unref (point->event);
+ if (point->target)
+ g_object_unref (point->target);
+
g_free (point);
}
@@ -1160,6 +1168,24 @@ gtk_gesture_get_last_event (GtkGesture *gesture,
return data->event;
}
+GtkWidget *
+gtk_gesture_get_last_target (GtkGesture *gesture,
+ GdkEventSequence *sequence)
+{
+ GtkGesturePrivate *priv;
+ PointData *data;
+
+ g_return_val_if_fail (GTK_IS_GESTURE (gesture), NULL);
+
+ priv = gtk_gesture_get_instance_private (gesture);
+ data = g_hash_table_lookup (priv->points, sequence);
+
+ if (!data)
+ return NULL;
+
+ return data->target;
+}
+
/**
* gtk_gesture_get_point:
* @gesture: a #GtkGesture
diff --git a/gtk/gtkgesture.h b/gtk/gtkgesture.h
index 7513853157..8a11a155a8 100644
--- a/gtk/gtkgesture.h
+++ b/gtk/gtkgesture.h
@@ -69,6 +69,10 @@ GDK_AVAILABLE_IN_ALL
const GdkEvent *
gtk_gesture_get_last_event (GtkGesture *gesture,
GdkEventSequence *sequence);
+
+GDK_AVAILABLE_IN_ALL
+GtkWidget *gtk_gesture_get_last_target (GtkGesture *gesture,
+ GdkEventSequence *sequence);
GDK_AVAILABLE_IN_ALL
gboolean gtk_gesture_get_point (GtkGesture *gesture,
GdkEventSequence *sequence,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]