summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCorey Berla <corey@berla.me>2022-08-08 12:14:24 -0700
committerAntónio Fernandes <antoniof@gnome.org>2022-08-12 15:02:57 +0000
commitadce60cf9a5902b0aaaddf6e1edde9820b1f52e7 (patch)
tree1ba6541d51689859afcdc894fd3aa214b6507048
parent65da6b94701702b4918c43817377d689cf9294fd (diff)
downloadnautilus-adce60cf9a5902b0aaaddf6e1edde9820b1f52e7.tar.gz
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
-rw-r--r--src/gtk/nautilusgtkplacessidebar.c8
-rw-r--r--src/nautilus-list-base.c22
-rw-r--r--src/nautilus-window-slot-dnd.c11
3 files changed, 39 insertions, 2 deletions
diff --git a/src/gtk/nautilusgtkplacessidebar.c b/src/gtk/nautilusgtkplacessidebar.c
index 876a587f6..9ba3e0c99 100644
--- a/src/gtk/nautilusgtkplacessidebar.c
+++ b/src/gtk/nautilusgtkplacessidebar.c
@@ -130,6 +130,7 @@ struct _NautilusGtkPlacesSidebar {
GtkWidget *row_placeholder;
DropState drop_state;
guint hover_timer_id;
+ graphene_point_t hover_start_point;
GtkListBoxRow *hover_row;
/* volume mounting - delayed open process */
@@ -1652,16 +1653,21 @@ drag_motion_callback (GtkDropTarget *target,
int row_index;
int row_placeholder_index;
const GValue *value;
+ graphene_point_t start;
sidebar->dragging_over = TRUE;
action = 0;
row = gtk_list_box_get_row_at_y (GTK_LIST_BOX (sidebar->list_box), y);
- if (row != sidebar->hover_row)
+ start = sidebar->hover_start_point;
+ if (row != sidebar->hover_row ||
+ gtk_drag_check_threshold (GTK_WIDGET (sidebar), start.x, start.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->hover_start_point.x = x;
+ sidebar->hover_start_point.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..9b283473d 100644
--- a/src/nautilus-list-base.c
+++ b/src/nautilus-list-base.c
@@ -49,6 +49,7 @@ struct _NautilusListBasePrivate
GdkDragAction drag_item_action;
GdkDragAction drag_view_action;
+ graphene_point_t hover_start_point;
guint hover_timer_id;
GtkDropTarget *view_drop_target;
};
@@ -586,6 +587,26 @@ 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);
+ graphene_point_t start = priv->hover_start_point;
+
+ if (gtk_drag_check_threshold (GTK_WIDGET (cell), start.x, start.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->hover_start_point.x = x;
+ priv->hover_start_point.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..8645d472d 100644
--- a/src/nautilus-window-slot-dnd.c
+++ b/src/nautilus-window-slot-dnd.c
@@ -35,6 +35,7 @@ typedef struct
NautilusWindowSlot *target_slot;
GtkWidget *widget;
+ graphene_point_t hover_start_point;
guint switch_location_timer;
} NautilusDragSlotProxyInfo;
@@ -107,6 +108,7 @@ slot_proxy_drag_motion (GtkDropTarget *target,
char *target_uri;
GFile *location;
const GValue *value;
+ graphene_point_t start;
drag_info = user_data;
@@ -170,7 +172,14 @@ slot_proxy_drag_motion (GtkDropTarget *target,
g_free (target_uri);
out:
- slot_proxy_check_switch_location_timer (drag_info);
+ start = drag_info->hover_start_point;
+ if (gtk_drag_check_threshold (drag_info->widget, start.x, start.y, x, y))
+ {
+ slot_proxy_remove_switch_location_timer (drag_info);
+ slot_proxy_check_switch_location_timer (drag_info);
+ drag_info->hover_start_point.x = x;
+ drag_info->hover_start_point.y = y;
+ }
return action;
}