dnd: Guard drags with a reference when finishing

Usually the "dnd-finished" signal will be used to unref the GdkDrag. In
those cases, we would lose the object, so that when we do the final
drag_drop_done() afterwards, we wouldn't have a remaining reference.

With the reference guard, this now works.
This commit is contained in:
Benjamin Otte 2021-07-26 02:16:47 +02:00
parent 620ccdabb5
commit f5dc71021f
3 changed files with 6 additions and 0 deletions

View File

@ -242,9 +242,11 @@ gdk_macos_drag_drop_performed (GdkDrag *drag,
g_assert (GDK_IS_MACOS_DRAG (self)); g_assert (GDK_IS_MACOS_DRAG (self));
g_object_ref (self);
drag_ungrab (self); drag_ungrab (self);
g_signal_emit_by_name (drag, "dnd-finished"); g_signal_emit_by_name (drag, "dnd-finished");
gdk_drag_drop_done (drag, TRUE); gdk_drag_drop_done (drag, TRUE);
g_object_unref (self);
} }
static void static void

View File

@ -290,8 +290,10 @@ data_source_dnd_finished (void *data,
{ {
GdkDrag *drag = data; GdkDrag *drag = data;
g_object_ref (drag);
g_signal_emit_by_name (drag, "dnd-finished"); g_signal_emit_by_name (drag, "dnd-finished");
gdk_drag_drop_done (drag, TRUE); gdk_drag_drop_done (drag, TRUE);
g_object_unref (drag);
} }
static void static void

View File

@ -884,8 +884,10 @@ gdk_x11_drag_handle_finished (GdkDisplay *display,
if (drag_x11->version == 5) if (drag_x11->version == 5)
drag_x11->drop_failed = xevent->xclient.data.l[1] == 0; drag_x11->drop_failed = xevent->xclient.data.l[1] == 0;
g_object_ref (drag);
g_signal_emit_by_name (drag, "dnd-finished"); g_signal_emit_by_name (drag, "dnd-finished");
gdk_drag_drop_done (drag, !drag_x11->drop_failed); gdk_drag_drop_done (drag, !drag_x11->drop_failed);
g_object_unref (drag);
} }
} }