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.
This commit is contained in:
Matthias Clasen 2020-02-16 02:46:40 -05:00
parent cd601ffb9e
commit 2bac066a63
5 changed files with 46 additions and 3 deletions

View File

@ -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

View File

@ -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,

View File

@ -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__ */

View File

@ -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"

View File

@ -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"