[gtk/readonly-events-1: 117/149] 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: 117/149] gesture: Keep the target widget for events
- Date: Fri, 21 Feb 2020 05:59:04 +0000 (UTC)
commit 2bac066a636c121c93b85f18c17f549b0407b30b
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 | 42 +++++++++++++++++++++++++++++++++++++++---
gtk/gtkgesture.h | 1 +
gtk/gtkgestureprivate.h | 4 ++++
gtk/gtkscrolledwindow.c | 1 +
gtk/gtkwidget.c | 1 +
5 files changed, 46 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkgesture.c b/gtk/gtkgesture.c
index 0d728ad67d..7ade52986f 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,34 @@ gtk_gesture_get_last_event (GtkGesture *gesture,
return data->event;
}
+/*
+ * gtk_gesture_get_last_target:
+ * @gesture: a #GtkGesture
+ * @sequence: event sequence
+ *
+ * Returns the widget that the last event was targeted at.
+ * See gtk_gesture_get_last_event().
+ *
+ * Returns: (transfer none) (nullable): The target of the last 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..23c5eb73bb 100644
--- a/gtk/gtkgesture.h
+++ b/gtk/gtkgesture.h
@@ -69,6 +69,7 @@ GDK_AVAILABLE_IN_ALL
const GdkEvent *
gtk_gesture_get_last_event (GtkGesture *gesture,
GdkEventSequence *sequence);
+
GDK_AVAILABLE_IN_ALL
gboolean gtk_gesture_get_point (GtkGesture *gesture,
GdkEventSequence *sequence,
diff --git a/gtk/gtkgestureprivate.h b/gtk/gtkgestureprivate.h
index fd2199418a..1e7e498a13 100644
--- a/gtk/gtkgestureprivate.h
+++ b/gtk/gtkgestureprivate.h
@@ -70,6 +70,10 @@ gboolean _gtk_gesture_get_last_update_time (GtkGesture *gesture,
GdkEventSequence *sequence,
guint32 *evtime);
+GtkWidget *gtk_gesture_get_last_target (GtkGesture *gesture,
+ GdkEventSequence *sequence);
+
+
G_END_DECLS
#endif /* __GTK_GESTURE_PRIVATE_H__ */
diff --git a/gtk/gtkscrolledwindow.c b/gtk/gtkscrolledwindow.c
index 47dc168dff..c11abc1f0b 100644
--- a/gtk/gtkscrolledwindow.c
+++ b/gtk/gtkscrolledwindow.c
@@ -36,6 +36,7 @@
#include "gtkgesturepan.h"
#include "gtkgesturesingle.h"
#include "gtkgestureswipe.h"
+#include "gtkgestureprivate.h"
#include "gtkintl.h"
#include "gtkkineticscrollingprivate.h"
#include "gtkmain.h"
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index d915402a4f..6f436a2751 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -46,6 +46,7 @@
#include "gtkgestureprivate.h"
#include "gtkgesturesingle.h"
#include "gtkgestureswipe.h"
+#include "gtkgestureprivate.h"
#include "gtkintl.h"
#include "gtklayoutmanagerprivate.h"
#include "gtkmain.h"
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]