diff --git a/gtk/gtkdnd.c b/gtk/gtkdnd.c index dd66413f5d..96edea65f8 100644 --- a/gtk/gtkdnd.c +++ b/gtk/gtkdnd.c @@ -1699,18 +1699,20 @@ gtk_drag_is_managed (GtkWidget *source_widget) FALSE; } -/* Like gtk_drag_begin(), but also takes a GtkIconHelper - * so that we can set the icon from the source site information +/* Like gtk_drag_begin(), but also communicates the need to + * create an icon for the drag operation back to the caller. + * If the caller passes out_needs_icon == NULL, it means that + * the caller does not care. */ GdkDragContext * -gtk_drag_begin_internal (GtkWidget *widget, - GtkImageDefinition *icon, - GtkTargetList *target_list, - GdkDragAction actions, - gint button, - const GdkEvent *event, - int x, - int y) +gtk_drag_begin_internal (GtkWidget *widget, + gboolean *out_needs_icon, + GtkTargetList *target_list, + GdkDragAction actions, + gint button, + const GdkEvent *event, + int x, + int y) { GtkDragSourceInfo *info; GList *targets = NULL; @@ -1873,20 +1875,16 @@ gtk_drag_begin_internal (GtkWidget *widget, * application may have set one in ::drag_begin, or it may * not have set one. */ - if (!info->icon_widget) + if (!info->icon_widget && out_needs_icon == NULL) { - if (icon) - { - set_icon_helper (info->context, icon, 0, 0); - } - else - { - icon = gtk_image_definition_new_icon_name ("text-x-generic"); - set_icon_helper (info->context, icon, 0, 0); - gtk_image_definition_unref (icon); - } + GtkImageDefinition *icon = gtk_image_definition_new_icon_name ("text-x-generic"); + set_icon_helper (info->context, icon, 0, 0); + gtk_image_definition_unref (icon); } + if (out_needs_icon != NULL) + *out_needs_icon = (info->icon_widget == NULL); + if (managed) { g_signal_connect (context, "drop-performed", diff --git a/gtk/gtkdndprivate.h b/gtk/gtkdndprivate.h index f14a456ffb..89f1b0f4db 100644 --- a/gtk/gtkdndprivate.h +++ b/gtk/gtkdndprivate.h @@ -43,7 +43,7 @@ struct _GtkDragDestSite G_BEGIN_DECLS GdkDragContext * gtk_drag_begin_internal (GtkWidget *widget, - GtkImageDefinition *icon, + gboolean *out_needs_icon, GtkTargetList *target_list, GdkDragAction actions, gint button, diff --git a/gtk/gtkdragsource.c b/gtk/gtkdragsource.c index 677281aa88..bbe3d2ecad 100644 --- a/gtk/gtkdragsource.c +++ b/gtk/gtkdragsource.c @@ -88,6 +88,8 @@ gtk_drag_source_event_cb (GtkWidget *widget, GdkEventSequence *sequence; GdkEvent *last_event; guint button; + gboolean needs_icon; + GdkDragContext *context; sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (site->drag_gesture)); last_event = gdk_event_copy (gtk_gesture_get_last_event (site->drag_gesture, sequence)); @@ -95,9 +97,12 @@ gtk_drag_source_event_cb (GtkWidget *widget, button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (site->drag_gesture)); gtk_event_controller_reset (GTK_EVENT_CONTROLLER (site->drag_gesture)); - gtk_drag_begin_internal (widget, site->image_def, site->target_list, - site->actions, button, last_event, - start_x, start_y); + context = gtk_drag_begin_internal (widget, &needs_icon, site->target_list, + site->actions, button, last_event, + start_x, start_y); + + if (context != NULL && needs_icon) + gtk_drag_set_icon_definition (context, site->image_def, 0, 0); gdk_event_free (last_event);