[nautilus/wip/antoniof/new-list-view: 4/9] view-icon-controller: Clear selection on release




commit 39c7bc4c62d8750505a40893cfeb383f61010efb
Author: António Fernandes <antoniof gnome org>
Date:   Sat May 21 22:25:32 2022 +0100

    view-icon-controller: Clear selection on release
    
    When the view background is clicked, the current selection is cleared.
    
    Currently this is done on ::press, which causes it to happen even if
    an item is clicked. Luckily, thanks to a different selection path, in
    the end the clicked item is selected anyway. But this is going to
    become a problem in the future when reinstating drag-and-drop.
    
    So, clear selection on ::release instead, but ensure that clicks on
    items get claimed beforehand. This way, we can be sure that, if it
    was not claimed, then the click happened in the background and not
    on an item.

 src/nautilus-view-icon-controller.c | 25 +++++++++++++++----------
 1 file changed, 15 insertions(+), 10 deletions(-)
---
diff --git a/src/nautilus-view-icon-controller.c b/src/nautilus-view-icon-controller.c
index 517be020a..29f31c611 100644
--- a/src/nautilus-view-icon-controller.c
+++ b/src/nautilus-view-icon-controller.c
@@ -828,6 +828,8 @@ on_item_click_pressed (GtkGestureClick *gesture,
         }
     }
 
+    /* Claim event sequence on press in some special cases which don't interfere
+     * with touch scrolling. */
     if (button == GDK_BUTTON_PRIMARY && n_press == 2)
     {
         activate_selection_on_click (self, modifiers & GDK_SHIFT_MASK);
@@ -856,10 +858,13 @@ on_item_click_released (GtkGestureClick *gesture,
 {
     NautilusViewIconController *self = NAUTILUS_VIEW_ICON_CONTROLLER (user_data);
 
+    /* Claim the event sequence on release to prevent the view-wide handler
+     * from clearing the selection. */
+    gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
+
     if (self->activate_on_release)
     {
         activate_selection_on_click (self, FALSE);
-        gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_CLAIMED);
     }
 }
 
@@ -872,18 +877,12 @@ on_view_click_pressed (GtkGestureClick *gesture,
 {
     NautilusViewIconController *self = NAUTILUS_VIEW_ICON_CONTROLLER (user_data);
     guint button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
-    GdkModifierType modifiers = gtk_event_controller_get_current_event_state (GTK_EVENT_CONTROLLER 
(gesture));
-    gboolean selection_mode = (modifiers & (GDK_CONTROL_MASK | GDK_SHIFT_MASK));
-
-    /* Don't interfere with GtkGridView default selection handling when
-     * holding Ctrl and Shift. */
-    if (!selection_mode && !self->activate_on_release)
-    {
-        nautilus_view_set_selection (NAUTILUS_VIEW (self), NULL);
-    }
 
     if (button == GDK_BUTTON_SECONDARY)
     {
+        /* A secondary click on an item would have already claimed the event
+         * sequence, so at this point we can assume the background was clicked.
+         */
         GtkWidget *event_widget;
         gdouble view_x;
         gdouble view_y;
@@ -892,6 +891,7 @@ on_view_click_pressed (GtkGestureClick *gesture,
         gtk_widget_translate_coordinates (event_widget, GTK_WIDGET (self),
                                           x, y,
                                           &view_x, &view_y);
+        nautilus_view_set_selection (NAUTILUS_VIEW (self), NULL);
         nautilus_files_view_pop_up_background_context_menu (NAUTILUS_FILES_VIEW (self),
                                                             view_x, view_y);
     }
@@ -904,6 +904,11 @@ on_view_click_released (GtkGestureClick *gesture,
                         gdouble          y,
                         gpointer         user_data)
 {
+    NautilusViewIconController *self = NAUTILUS_VIEW_ICON_CONTROLLER (user_data);
+
+    /* At this point, we can assume we have clicked on the background because
+     * otherwise item gestures would have claimed the event sequence already. */
+    nautilus_view_set_selection (NAUTILUS_VIEW (self), NULL);
 }
 
 static void


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