Merge branch 'matthiasc/for-main' into 'main'

dnd: Avoid a critical

See merge request GNOME/gtk!7392
This commit is contained in:
Matthias Clasen 2024-06-28 19:19:46 +00:00
commit 653f4d4183
2 changed files with 20 additions and 3 deletions

View File

@ -675,11 +675,13 @@ gtk_drop_target_async_reject_drop (GtkDropTargetAsync *self,
{
g_return_if_fail (GTK_IS_DROP_TARGET_ASYNC (self));
g_return_if_fail (GDK_IS_DROP (drop));
g_return_if_fail (self->drop == drop);
if (self->rejected)
return;
if (self->drop != drop)
return;
self->rejected = TRUE;
gtk_widget_unset_state_flags (gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (self)),
GTK_STATE_FLAG_DROP_ACTIVE);

View File

@ -215,6 +215,8 @@ image_drag_accept (GtkDropTargetAsync *dest,
GtkWidget *image = data;
g_object_set_data_full (G_OBJECT (image), "drop", g_object_ref (drop), g_object_unref);
g_print ("accept\n");
g_timeout_add (1000, delayed_deny, dest);
return TRUE;
@ -229,10 +231,22 @@ image_drag_drop (GtkDropTarget *dest,
{
GtkWidget *image = data;
GdkDragAction action = gdk_drop_get_actions (drop);
const char *name[] = { "copy", "move", "link", "ask" };
g_object_set_data_full (G_OBJECT (image), "drop", g_object_ref (drop), g_object_unref);
g_print ("drop, actions %d\n", action);
g_print ("drop, actions: ");
for (guint i = 0; i < 4; i++)
{
if (action & (1 << i))
{
if (i > 0)
g_print (", ");
g_print ("%s", name[i]);
}
}
g_print ("\n");
if (!gdk_drag_action_is_unique (action))
ask_actions (drop, image);
else
@ -321,7 +335,8 @@ drag_cancel (GtkDragSource *source,
GdkDrag *drag,
GdkDragCancelReason reason)
{
g_print ("drag failed: %d\n", reason);
const char *msg[] = { "no target", "user cancelled", "error" };
g_print ("drag failed: %s\n", msg[reason]);
return FALSE;
}