[gtk/readonly-events-1: 45/51] 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: 45/51] gesture: Keep the target widget for events
- Date: Mon, 17 Feb 2020 05:50:33 +0000 (UTC)
commit da5407829337d24d67fce03ec6fbbb1439602ed7
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 | 33 ++++++++++++++++++++++++++++++---
gtk/gtkgesture.h | 4 ++++
2 files changed, 34 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkgesture.c b/gtk/gtkgesture.c
index fb9e8b3c75..9275b8ba14 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)
@@ -505,6 +507,7 @@ _gtk_gesture_update_point (GtkGesture *gesture,
gdk_event_unref (data->event);
data->event = gdk_event_ref ((GdkEvent *)event);
+ data->target = g_object_ref (target);
data->widget_x = x;
data->widget_y = y;
_update_touchpad_deltas (data);
@@ -612,6 +615,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 +629,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 +639,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 +673,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 +698,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 +879,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 +1169,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]