[nautilus/wip/corey/list-view: 3/3] list-base: Show the single click cursor when in single click mode




commit 585547c3744baea740152a5225b61900019983fe
Author: Corey Berla <corey berla me>
Date:   Sun Aug 21 14:16:31 2022 -0700

    list-base: Show the single click cursor when in single click mode
    
    We used to do this in gtk3, but it appears to have been lost in the
    switch.  In gtk3 we had to check the hover state and change the
    cursor on the fly.  In gtk4 there's a convenient
    gtk_widget_set_cursor_from_name() function.
    
    Fixes: https://gitlab.gnome.org/GNOME/nautilus/-/issues/2434

 src/nautilus-list-base.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)
---
diff --git a/src/nautilus-list-base.c b/src/nautilus-list-base.c
index 83f671e79..54465284c 100644
--- a/src/nautilus-list-base.c
+++ b/src/nautilus-list-base.c
@@ -872,6 +872,8 @@ setup_cell_common (GtkListItem      *listitem,
 {
     GtkEventController *controller;
     GtkDropTarget *drop_target;
+    g_autoptr (NautilusListBase) self = nautilus_view_cell_get_view (cell);
+    NautilusListBasePrivate *priv = nautilus_list_base_get_instance_private (self);
 
     g_object_bind_property (listitem, "item",
                             cell, "item",
@@ -914,6 +916,11 @@ setup_cell_common (GtkListItem      *listitem,
     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);
+
+    if (priv->single_click_mode)
+    {
+        gtk_widget_set_cursor_from_name (GTK_WIDGET (cell), "pointer");
+    }
 }
 
 static void
@@ -1002,7 +1009,33 @@ set_click_mode_from_settings (NautilusListBase *self)
 static void
 real_click_policy_changed (NautilusFilesView *files_view)
 {
+    GtkWidget *view;
+    gchar *cursor_name;
+    int n_items;
+    NautilusListBasePrivate *priv = nautilus_list_base_get_instance_private (NAUTILUS_LIST_BASE 
(files_view));
+
     set_click_mode_from_settings (NAUTILUS_LIST_BASE (files_view));
+
+    view = NAUTILUS_LIST_BASE_CLASS (G_OBJECT_GET_CLASS (files_view))->get_view_ui (NAUTILUS_LIST_BASE 
(files_view));
+    n_items = g_list_model_get_n_items (G_LIST_MODEL (priv->model));
+    cursor_name = priv->single_click_mode ? "pointer" : NULL;
+
+    for (int i = 0; i < n_items; i++)
+    {
+        g_autoptr (NautilusViewItem) item = NULL;
+        GtkWidget *widget;
+
+        item = get_view_item (G_LIST_MODEL (priv->model), i);
+        widget = nautilus_view_item_get_item_ui (item);
+
+        if (GTK_IS_COLUMN_VIEW (view))
+        {
+            /* In List View we need to change the cursor for the whole row */
+            widget = gtk_widget_get_parent (gtk_widget_get_parent (widget));
+        }
+
+        gtk_widget_set_cursor_from_name (widget, cursor_name);
+    }
 }
 
 static void


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