[nautilus/wip/antoniof/gtk4-preparation-step-event-controllers: 1/21] list-view: Merge did_not_drag() into its caller




commit 51b102a7ad2cd668b03ec2e9e09a8710bee66491
Author: António Fernandes <antoniof gnome org>
Date:   Wed Dec 22 01:19:23 2021 +0000

    list-view: Merge did_not_drag() into its caller
    
    This function has only one caller and it relies on the passed GdkEvent
    for everything.
    
    However, in GTK 4, we are going to depend less on GdkEvent and more on
    the gesture itself and its signal handler parameters.
    
    So, inline the function to make sure we have everything at ready for
    when we switch to GTK 4.

 src/nautilus-list-view.c | 133 +++++++++++++++++++++--------------------------
 1 file changed, 58 insertions(+), 75 deletions(-)
---
diff --git a/src/nautilus-list-view.c b/src/nautilus-list-view.c
index 2e26247dc..bd0af8c19 100644
--- a/src/nautilus-list-view.c
+++ b/src/nautilus-list-view.c
@@ -255,69 +255,6 @@ get_click_policy (void)
                                 NAUTILUS_PREFERENCES_CLICK_POLICY);
 }
 
-static void
-nautilus_list_view_did_not_drag (NautilusListView *view,
-                                 const GdkEvent   *event)
-{
-    GtkTreeView *tree_view;
-    GtkTreeSelection *selection;
-    gdouble x;
-    gdouble y;
-    GtkTreePath *path;
-    guint button;
-    GdkModifierType state;
-
-    tree_view = view->details->tree_view;
-    selection = gtk_tree_view_get_selection (tree_view);
-
-    if (!gdk_event_get_coords (event, &x, &y))
-    {
-        return;
-    }
-
-    if (!gtk_tree_view_get_path_at_pos (tree_view, x, y, &path, NULL, NULL, NULL))
-    {
-        return;
-    }
-
-    if (!gdk_event_get_button (event, &button))
-    {
-        return;
-    }
-
-    gdk_event_get_state (event, &state);
-
-    if ((button == GDK_BUTTON_PRIMARY || button == GDK_BUTTON_MIDDLE)
-        && ((state & GDK_CONTROL_MASK) != 0 ||
-            (state & GDK_SHIFT_MASK) == 0)
-        && view->details->row_selected_on_button_down)
-    {
-        if (!button_event_modifies_selection (event))
-        {
-            gtk_tree_selection_unselect_all (selection);
-            gtk_tree_selection_select_path (selection, path);
-        }
-        else
-        {
-            gtk_tree_selection_unselect_path (selection, path);
-        }
-    }
-
-    if ((get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
-        && !button_event_modifies_selection (event))
-    {
-        if (button == GDK_BUTTON_PRIMARY)
-        {
-            activate_selected_items (view);
-        }
-        else if (button == GDK_BUTTON_MIDDLE)
-        {
-            activate_selected_items_alternate (view, NULL, TRUE);
-        }
-    }
-    gtk_tree_path_free (path);
-}
-
 static void
 on_event_controller_motion_motion (GtkEventControllerMotion *controller,
                                    double                    x,
@@ -852,6 +789,12 @@ on_tree_view_multi_press_gesture_released (GtkGestureMultiPress *gesture,
 {
     NautilusListView *view;
     guint button;
+    GdkEventSequence *sequence;
+    const GdkEvent *event;
+    GtkTreeView *tree_view;
+    GtkTreeSelection *selection;
+    GtkTreePath *path;
+    GdkModifierType state;
 
     view = NAUTILUS_LIST_VIEW (callback_data);
     button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
@@ -861,24 +804,64 @@ on_tree_view_multi_press_gesture_released (GtkGestureMultiPress *gesture,
     }
 
     view->details->drag_button = 0;
-    if (!view->details->drag_started)
+
+    if (view->details->drag_started)
     {
-        GdkEventSequence *sequence;
-        const GdkEvent *event;
+        return;
+    }
 
-        sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
-        event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
-        /* Typically will only happen with GTK+ <= 3.22.30 and <= 3.93.0,
-         * where ::released is emitted after ::cancel, but can’t hurt to guard
-         * against it anyway.
-         */
-        if (event == NULL)
+    /* Did not drag. */
+
+    sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
+    event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
+    /* Typically will only happen with GTK+ <= 3.22.30 and <= 3.93.0,
+     * where ::released is emitted after ::cancel, but can’t hurt to guard
+     * against it anyway.
+     */
+    if (event == NULL)
+    {
+        return;
+    }
+
+    tree_view = view->details->tree_view;
+    selection = gtk_tree_view_get_selection (tree_view);
+
+    if (!gtk_tree_view_get_path_at_pos (tree_view, x, y, &path, NULL, NULL, NULL))
+    {
+        return;
+    }
+
+    gdk_event_get_state (event, &state);
+
+    if ((button == GDK_BUTTON_PRIMARY || button == GDK_BUTTON_MIDDLE)
+        && ((state & GDK_CONTROL_MASK) != 0 ||
+            (state & GDK_SHIFT_MASK) == 0)
+        && view->details->row_selected_on_button_down)
+    {
+        if (!button_event_modifies_selection (event))
         {
-            return;
+            gtk_tree_selection_unselect_all (selection);
+            gtk_tree_selection_select_path (selection, path);
+        }
+        else
+        {
+            gtk_tree_selection_unselect_path (selection, path);
         }
+    }
 
-        nautilus_list_view_did_not_drag (view, event);
+    if ((get_click_policy () == NAUTILUS_CLICK_POLICY_SINGLE)
+        && !button_event_modifies_selection (event))
+    {
+        if (button == GDK_BUTTON_PRIMARY)
+        {
+            activate_selected_items (view);
+        }
+        else if (button == GDK_BUTTON_MIDDLE)
+        {
+            activate_selected_items_alternate (view, NULL, TRUE);
+        }
     }
+    gtk_tree_path_free (path);
 }
 
 static gboolean


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