Do not modify a const GdkEvent in place

When deciding whether or not to emulate a press event, we're translating
the last event coordinates and mutating the given event structure
unconditionally.

We should modify the newly created GdkEvent copy, since it's what we're
going to use when emitting the press event.

This avoids mutating a constant GdkEvent and global state, and also
avoids a compiler warning.
This commit is contained in:
Emmanuele Bassi 2018-06-26 17:57:29 +01:00
parent 88b4076fe5
commit 73d736d800

View File

@ -2515,7 +2515,6 @@ _gtk_widget_emulate_press (GtkWidget *widget,
gtk_widget_get_toplevel (event_widget),
x, y,
&x, &y);
gdk_event_set_coords (event, x, y);
if (event->any.type == GDK_TOUCH_BEGIN ||
event->any.type == GDK_TOUCH_UPDATE ||
@ -2535,8 +2534,6 @@ _gtk_widget_emulate_press (GtkWidget *widget,
press = gdk_event_new (GDK_BUTTON_PRESS);
press->any.surface = g_object_ref (event->any.surface);
press->button.time = event->motion.time;
press->button.x = event->motion.x;
press->button.y = event->motion.y;
press->button.x_root = event->motion.x_root;
press->button.y_root = event->motion.y_root;
press->button.state = event->motion.state;
@ -2563,6 +2560,8 @@ _gtk_widget_emulate_press (GtkWidget *widget,
else
return;
gdk_event_set_coords (press, x, y);
press->any.send_event = TRUE;
next_child = event_widget;
parent = _gtk_widget_get_parent (next_child);