widget: Don't duplicate events to translate coordinates

This commit is contained in:
Timm Bäder 2019-08-13 12:29:00 +02:00
parent 1c9fbe3773
commit 960e766206
3 changed files with 40 additions and 30 deletions

View File

@ -652,8 +652,8 @@ static void gtk_widget_propagate_state (GtkWidget
const GtkStateData *data); const GtkStateData *data);
static void gtk_widget_update_alpha (GtkWidget *widget); static void gtk_widget_update_alpha (GtkWidget *widget);
static gint gtk_widget_event_internal (GtkWidget *widget, static gboolean gtk_widget_event_internal (GtkWidget *widget,
const GdkEvent *event); GdkEvent *event);
static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget, static gboolean gtk_widget_real_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling); gboolean group_cycling);
static void gtk_widget_real_measure (GtkWidget *widget, static void gtk_widget_real_measure (GtkWidget *widget,
@ -5167,8 +5167,8 @@ gtk_widget_real_mnemonic_activate (GtkWidget *widget,
* the event was handled) * the event was handled)
**/ **/
gboolean gboolean
gtk_widget_event (GtkWidget *widget, gtk_widget_event (GtkWidget *widget,
const GdkEvent *event) GdkEvent *event)
{ {
g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE); g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE); g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
@ -5229,13 +5229,16 @@ gtk_widget_run_controllers (GtkWidget *widget,
static gboolean static gboolean
translate_event_coordinates (GdkEvent *event, translate_event_coordinates (GdkEvent *event,
double event_x,
double event_y,
GtkWidget *widget); GtkWidget *widget);
gboolean gboolean
_gtk_widget_captured_event (GtkWidget *widget, _gtk_widget_captured_event (GtkWidget *widget,
const GdkEvent *event) GdkEvent *event)
{ {
gboolean return_val = FALSE; gboolean return_val = FALSE;
GdkEvent *event_copy; double old_x, old_y;
gboolean reset_event = FALSE;
g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE); g_return_val_if_fail (GTK_IS_WIDGET (widget), TRUE);
g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE); g_return_val_if_fail (WIDGET_REALIZED_FOR_EVENT (widget, event), TRUE);
@ -5243,13 +5246,17 @@ _gtk_widget_captured_event (GtkWidget *widget,
if (!event_surface_is_still_viewable (event)) if (!event_surface_is_still_viewable (event))
return TRUE; return TRUE;
event_copy = gdk_event_copy (event); if (gdk_event_get_coords (event, &old_x, &old_y))
translate_event_coordinates (event_copy, widget); {
reset_event = TRUE;
translate_event_coordinates (event, old_x, old_y, widget);
}
return_val = gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_CAPTURE); return_val = gtk_widget_run_controllers (widget, event, GTK_PHASE_CAPTURE);
return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event_copy); return_val |= !WIDGET_REALIZED_FOR_EVENT (widget, event);
g_object_unref (event_copy); if (reset_event)
gdk_event_set_coords (event, old_x, old_y);
return return_val; return return_val;
} }
@ -5293,20 +5300,18 @@ event_surface_is_still_viewable (const GdkEvent *event)
static gboolean static gboolean
translate_event_coordinates (GdkEvent *event, translate_event_coordinates (GdkEvent *event,
double event_x,
double event_y,
GtkWidget *widget) GtkWidget *widget)
{ {
GtkWidget *event_widget; GtkWidget *event_widget;
double x, y;
graphene_point_t p; graphene_point_t p;
if (!gdk_event_get_coords (event, &x, &y))
return TRUE;
event_widget = gtk_get_event_widget (event); event_widget = gtk_get_event_widget (event);
if (!gtk_widget_compute_point (event_widget, if (!gtk_widget_compute_point (event_widget,
widget, widget,
&GRAPHENE_POINT_INIT (x, y), &GRAPHENE_POINT_INIT (event_x, event_y),
&p)) &p))
return FALSE; return FALSE;
@ -5316,11 +5321,12 @@ translate_event_coordinates (GdkEvent *event,
} }
static gboolean static gboolean
gtk_widget_event_internal (GtkWidget *widget, gtk_widget_event_internal (GtkWidget *widget,
const GdkEvent *event) GdkEvent *event)
{ {
gboolean return_val = FALSE; gboolean return_val = FALSE;
GdkEvent *event_copy; gboolean reset_event = FALSE;
double old_x, old_y;
/* We check only once for is-still-visible; if someone /* We check only once for is-still-visible; if someone
* hides the window in on of the signals on the widget, * hides the window in on of the signals on the widget,
@ -5333,22 +5339,26 @@ gtk_widget_event_internal (GtkWidget *widget,
if (!_gtk_widget_get_mapped (widget)) if (!_gtk_widget_get_mapped (widget))
return FALSE; return FALSE;
event_copy = gdk_event_copy (event); if (gdk_event_get_coords (event, &old_x, &old_y))
{
reset_event = TRUE;
translate_event_coordinates (event, old_x, old_y, widget);
}
translate_event_coordinates (event_copy, widget); if (widget == gtk_get_event_target (event))
return_val |= gtk_widget_run_controllers (widget, event, GTK_PHASE_TARGET);
if (widget == gtk_get_event_target (event_copy))
return_val |= gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_TARGET);
if (return_val == FALSE) if (return_val == FALSE)
return_val |= gtk_widget_run_controllers (widget, event_copy, GTK_PHASE_BUBBLE); return_val |= gtk_widget_run_controllers (widget, event, GTK_PHASE_BUBBLE);
g_object_unref (event_copy);
if (return_val == FALSE && if (return_val == FALSE &&
(event->any.type == GDK_KEY_PRESS || (event->any.type == GDK_KEY_PRESS ||
event->any.type == GDK_KEY_RELEASE)) event->any.type == GDK_KEY_RELEASE))
return_val |= gtk_bindings_activate_event (G_OBJECT (widget), (GdkEventKey *) event); return_val |= gtk_bindings_activate_event (G_OBJECT (widget), (GdkEventKey *) event);
if (reset_event)
gdk_event_set_coords (event, old_x, old_y);
return return_val; return return_val;
} }

View File

@ -443,7 +443,7 @@ gboolean gtk_widget_mnemonic_activate (GtkWidget *widget,
gboolean group_cycling); gboolean group_cycling);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gboolean gtk_widget_event (GtkWidget *widget, gboolean gtk_widget_event (GtkWidget *widget,
const GdkEvent *event); GdkEvent *event);
GDK_AVAILABLE_IN_ALL GDK_AVAILABLE_IN_ALL
gboolean gtk_widget_activate (GtkWidget *widget); gboolean gtk_widget_activate (GtkWidget *widget);

View File

@ -281,8 +281,8 @@ void _gtk_widget_buildable_finish_accelerator (GtkWidget *widget,
gpointer user_data); gpointer user_data);
GtkStyleContext * _gtk_widget_peek_style_context (GtkWidget *widget); GtkStyleContext * _gtk_widget_peek_style_context (GtkWidget *widget);
gboolean _gtk_widget_captured_event (GtkWidget *widget, gboolean _gtk_widget_captured_event (GtkWidget *widget,
const GdkEvent *event); GdkEvent *event);
GtkWidgetPath * _gtk_widget_create_path (GtkWidget *widget); GtkWidgetPath * _gtk_widget_create_path (GtkWidget *widget);
void gtk_widget_clear_path (GtkWidget *widget); void gtk_widget_clear_path (GtkWidget *widget);