[nautilus/1535-nautilus-crashes-when-dragging-from-archive-manager: 401/401] window-slot-dnd: Ignore data not received on hover




commit a38593f03af2f0073ef93b02e53b610b269fd37e
Author: António Fernandes <antoniof gnome org>
Date:   Fri Jul 16 23:25:22 2021 +0100

    window-slot-dnd: Ignore data not received on hover
    
    Sometimes, after having called gtk_drag_get_data() on ::drag-motion, we
    only get the data after ::drag-leave.
    
    This is fine if the ::drag-leave is followed by ::drag-drop. Otherwise,
    as ::drag-leave is responsible for cleanup, data arriving afterwards is
    leaking into the next time content is dragged hover the widget, even if
    the dragged content is no longer the same.
    
    Instead, keep track of the hover status and don't save data that's no
    longer relevant.

 src/nautilus-window-slot-dnd.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
---
diff --git a/src/nautilus-window-slot-dnd.c b/src/nautilus-window-slot-dnd.c
index e31740988..5e5bf060e 100644
--- a/src/nautilus-window-slot-dnd.c
+++ b/src/nautilus-window-slot-dnd.c
@@ -36,6 +36,7 @@ typedef struct
     gboolean have_data;
     gboolean have_valid_data;
 
+    gboolean is_hover;
     gboolean drop_occurred;
 
     unsigned int info;
@@ -163,6 +164,8 @@ slot_proxy_drag_motion (GtkWidget      *widget,
 
     drag_info = user_data;
 
+    drag_info->is_hover = TRUE;
+
     action = 0;
     valid_text_drag = FALSE;
     valid_xds_drag = FALSE;
@@ -328,6 +331,7 @@ slot_proxy_drag_leave (GtkWidget      *widget,
 
     drag_info = user_data;
 
+    drag_info->is_hover = FALSE;
     gtk_drag_unhighlight (widget);
     drag_info_clear (drag_info);
 }
@@ -467,6 +471,13 @@ slot_proxy_drag_data_received (GtkWidget        *widget,
     g_assert (!drag_info->have_data);
     drag_info->waiting_for_data = FALSE;
 
+    if (!drag_info->is_hover && !drag_info->drop_occurred)
+    {
+        /* Ignore data arriving after ::drag-leave, except if followed by
+         * ::drag-drop. */
+        return;
+    }
+
     if (gtk_selection_data_get_length (data) < 0)
     {
         /* Data retrieval failed. */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]