[nautilus/wip/coreyberla/dnd-threshold: 12/13] dnd: Make "change location on hover" a little bit less aggressive




commit 29ce168d609c3cf666e1e762bc2621f3fc49555f
Author: Corey Berla <corey berla me>
Date:   Mon Aug 8 12:14:24 2022 -0700

    dnd: Make "change location on hover" a little bit less aggressive
    
    Reset the hover timeout if the x,y passes the GTK drag threshold
    before the HOVER_TIMEOUT.  This makes it less likely that a location
    will occur if the drag is merely happening over an item.  In GTK4
    the cells cover a bigger space so this is even more likely to occur.
    
    Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/1526

 src/gtk/nautilusgtkplacessidebar.c |  7 ++++++-
 src/nautilus-list-base.c           | 22 ++++++++++++++++++++++
 src/nautilus-window-slot-dnd.c     | 10 +++++++++-
 3 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/src/gtk/nautilusgtkplacessidebar.c b/src/gtk/nautilusgtkplacessidebar.c
index 876a587f6..6367e28a9 100644
--- a/src/gtk/nautilusgtkplacessidebar.c
+++ b/src/gtk/nautilusgtkplacessidebar.c
@@ -129,6 +129,8 @@ struct _NautilusGtkPlacesSidebar {
   int drag_row_y;
   GtkWidget *row_placeholder;
   DropState drop_state;
+  int drag_x; /* track the mouse state for hover timeout */
+  int drag_y;
   guint hover_timer_id;
   GtkListBoxRow *hover_row;
 
@@ -1657,11 +1659,14 @@ drag_motion_callback (GtkDropTarget    *target,
   action = 0;
   row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (sidebar->list_box), y);
 
-  if (row != sidebar->hover_row)
+  if (row != sidebar->hover_row ||
+      gtk_drag_check_threshold (GTK_WIDGET (sidebar), sidebar->drag_x, sidebar->drag_y, x, y))
     {
       g_clear_handle_id (&sidebar->hover_timer_id, g_source_remove);
       sidebar->hover_row = row;
       sidebar->hover_timer_id = g_timeout_add (HOVER_TIMEOUT, hover_timer, sidebar);
+      sidebar->drag_x = x;
+      sidebar->drag_y = y;
     }
 
   /* Workaround https://gitlab.gnome.org/GNOME/gtk/-/issues/5023 */
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c
index 4bd754b8e..c48712682 100644
--- a/src/nautilus-list-base.c
+++ b/src/nautilus-list-base.c
@@ -49,6 +49,8 @@ struct _NautilusListBasePrivate
 
     GdkDragAction drag_item_action;
     GdkDragAction drag_view_action;
+    int drag_x;
+    int drag_y;
     guint hover_timer_id;
     GtkDropTarget *view_drop_target;
 };
@@ -586,6 +588,25 @@ on_item_drag_hover_leave (GtkDropControllerMotion *controller,
     g_clear_handle_id (&priv->hover_timer_id, g_source_remove);
 }
 
+static void
+on_item_drag_hover_motion (GtkDropControllerMotion *controller,
+                           gdouble                  x,
+                           gdouble                  y,
+                           gpointer                 user_data)
+{
+    NautilusViewCell *cell = user_data;
+    g_autoptr (NautilusListBase) self = nautilus_view_cell_get_view (cell);
+    NautilusListBasePrivate *priv = nautilus_list_base_get_instance_private (self);
+
+    if (gtk_drag_check_threshold (GTK_WIDGET (cell), priv->drag_x, priv->drag_y, x, y))
+    {
+        g_clear_handle_id (&priv->hover_timer_id, g_source_remove);
+        priv->hover_timer_id = g_timeout_add (HOVER_TIMEOUT, hover_timer, cell);
+        priv->drag_x = x;
+        priv->drag_y = y;
+    }
+}
+
 static GdkDragAction
 get_preferred_action (NautilusFile *target_file,
                       const GValue *value)
@@ -886,6 +907,7 @@ setup_cell_common (GtkListItem      *listitem,
     gtk_widget_add_controller (GTK_WIDGET (cell), controller);
     g_signal_connect (controller, "enter", G_CALLBACK (on_item_drag_hover_enter), cell);
     g_signal_connect (controller, "leave", G_CALLBACK (on_item_drag_hover_leave), cell);
+    g_signal_connect (controller, "motion", G_CALLBACK (on_item_drag_hover_motion), cell);
 }
 
 static void
diff --git a/src/nautilus-window-slot-dnd.c b/src/nautilus-window-slot-dnd.c
index 1c1839737..3ea685110 100644
--- a/src/nautilus-window-slot-dnd.c
+++ b/src/nautilus-window-slot-dnd.c
@@ -35,6 +35,8 @@ typedef struct
     NautilusWindowSlot *target_slot;
     GtkWidget *widget;
 
+    int drag_x;
+    int drag_y;
     guint switch_location_timer;
 } NautilusDragSlotProxyInfo;
 
@@ -170,7 +172,13 @@ slot_proxy_drag_motion (GtkDropTarget *target,
     g_free (target_uri);
 
 out:
-    slot_proxy_check_switch_location_timer (drag_info);
+    if (gtk_drag_check_threshold (drag_info->widget, drag_info->drag_x, drag_info->drag_y, x, y))
+    {
+        slot_proxy_remove_switch_location_timer (drag_info);
+        slot_proxy_check_switch_location_timer (drag_info);
+        drag_info->drag_x = x;
+        drag_info->drag_y = y;
+    }
 
     return action;
 }


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