[nautilus/wip/antoniof/gnome-42: 22/72] Revert "window: Handle tab clicks here"




commit 930415ddd7472477bfe226cf2678a5e706096b68
Author: António Fernandes <antoniof gnome org>
Date:   Fri Feb 11 19:01:38 2022 +0000

    Revert "window: Handle tab clicks here"
    
    This reverts commit 6cf723537c6efdee8bb5f0fbd8b8bd2b3968806d.

 src/nautilus-notebook.c | 82 +++++++++++++++++++++++++++++++++++++++++--------
 src/nautilus-notebook.h |  7 ++---
 src/nautilus-window.c   | 36 ++--------------------
 3 files changed, 75 insertions(+), 50 deletions(-)
---
diff --git a/src/nautilus-notebook.c b/src/nautilus-notebook.c
index 95be6721d..ffde9a899 100644
--- a/src/nautilus-notebook.c
+++ b/src/nautilus-notebook.c
@@ -54,6 +54,8 @@ static guint signals[LAST_SIGNAL];
 struct _NautilusNotebook
 {
     GtkNotebook parent_instance;
+
+    GtkGesture *multi_press_gesture;
 };
 
 G_DEFINE_TYPE (NautilusNotebook, nautilus_notebook, GTK_TYPE_NOTEBOOK);
@@ -61,6 +63,12 @@ G_DEFINE_TYPE (NautilusNotebook, nautilus_notebook, GTK_TYPE_NOTEBOOK);
 static void
 nautilus_notebook_dispose (GObject *object)
 {
+    NautilusNotebook *notebook;
+
+    notebook = NAUTILUS_NOTEBOOK (object);
+
+    g_clear_object (&notebook->multi_press_gesture);
+
     G_OBJECT_CLASS (nautilus_notebook_parent_class)->dispose (object);
 }
 
@@ -125,6 +133,55 @@ find_tab_num_at_pos (NautilusNotebook *notebook,
     return AFTER_ALL_TABS;
 }
 
+static void
+button_press_cb (GtkGestureMultiPress *gesture,
+                 gint                  n_press,
+                 gdouble               x,
+                 gdouble               y,
+                 gpointer              user_data)
+{
+    guint button;
+    GdkEventSequence *sequence;
+    const GdkEvent *event;
+    GtkWidget *widget;
+    NautilusNotebook *notebook;
+    int tab_clicked;
+    GdkModifierType state;
+
+    button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
+    sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
+    event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
+    widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
+    notebook = NAUTILUS_NOTEBOOK (widget);
+    tab_clicked = find_tab_num_at_pos (notebook, x, y);
+
+    gdk_event_get_state (event, &state);
+
+    if (n_press != 1)
+    {
+        return;
+    }
+
+    if (tab_clicked == -1)
+    {
+        return;
+    }
+
+    if (button == GDK_BUTTON_SECONDARY &&
+        (state & gtk_accelerator_get_default_mod_mask ()) == 0)
+    {
+        /* switch to the page the mouse is over, but don't consume the event */
+        gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), tab_clicked);
+    }
+    else if (button == GDK_BUTTON_MIDDLE)
+    {
+        GtkWidget *slot;
+
+        slot = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), tab_clicked);
+        g_signal_emit (notebook, signals[TAB_CLOSE_REQUEST], 0, slot);
+    }
+}
+
 static void
 on_page_removed (GtkNotebook *notebook,
                  GtkWidget   *child,
@@ -143,6 +200,14 @@ nautilus_notebook_init (NautilusNotebook *notebook)
     gtk_notebook_set_show_tabs (GTK_NOTEBOOK (notebook), FALSE);
 
     g_signal_connect (notebook, "page-removed", G_CALLBACK (on_page_removed), NULL);
+
+    notebook->multi_press_gesture = gtk_gesture_multi_press_new (GTK_WIDGET (notebook));
+
+    gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (notebook->multi_press_gesture),
+                                                GTK_PHASE_CAPTURE);
+    gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (notebook->multi_press_gesture), 0);
+
+    g_signal_connect (notebook->multi_press_gesture, "pressed", G_CALLBACK (button_press_cb), NULL);
 }
 
 gboolean
@@ -171,20 +236,11 @@ nautilus_notebook_contains_slot (NautilusNotebook   *notebook,
 }
 
 gboolean
-nautilus_notebook_get_tab_clicked (NautilusNotebook *notebook,
-                                   gint              x,
-                                   gint              y,
-                                   gint             *position)
+nautilus_notebook_content_area_hit (NautilusNotebook *notebook,
+                                    gint              x,
+                                    gint              y)
 {
-    gint tab_num;
-
-    tab_num = find_tab_num_at_pos (notebook, x, y);
-
-    if (position != NULL)
-    {
-        *position = tab_num;
-    }
-    return tab_num != -1;
+    return find_tab_num_at_pos (notebook, x, y) == -1;
 }
 
 void
diff --git a/src/nautilus-notebook.h b/src/nautilus-notebook.h
index ad227d183..1590e111b 100644
--- a/src/nautilus-notebook.h
+++ b/src/nautilus-notebook.h
@@ -54,9 +54,8 @@ void            nautilus_notebook_next_page (NautilusNotebook *notebook);
 gboolean        nautilus_notebook_contains_slot (NautilusNotebook   *notebook,
                                                  NautilusWindowSlot *slot);
 
-gboolean        nautilus_notebook_get_tab_clicked (NautilusNotebook *notebook,
-                                                   gint              x,
-                                                   gint              y,
-                                                   gint             *position);
+gboolean        nautilus_notebook_content_area_hit (NautilusNotebook *notebook,
+                                                    gint              x,
+                                                    gint              y);
 
 G_END_DECLS
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index d0162a56c..fe8a2cbde 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -1792,45 +1792,15 @@ notebook_button_press_cb (GtkGestureMultiPress *gesture,
                           gpointer              user_data)
 {
     NautilusWindow *window;
-    GtkNotebook *notebook;
-    gint tab_clicked;
-    guint button;
-    GdkEventSequence *sequence;
-    const GdkEvent *event;
-    GdkModifierType state;
-
-    if (n_press != 1)
-    {
-        return;
-    }
 
     window = NAUTILUS_WINDOW (user_data);
-    notebook = GTK_NOTEBOOK (window->notebook);
 
-    if (!nautilus_notebook_get_tab_clicked (NAUTILUS_NOTEBOOK (notebook), x, y, &tab_clicked))
+    if (nautilus_notebook_content_area_hit (NAUTILUS_NOTEBOOK (window->notebook), x, y))
     {
         return;
     }
 
-    button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
-    sequence = gtk_gesture_single_get_current_sequence (GTK_GESTURE_SINGLE (gesture));
-    event = gtk_gesture_get_last_event (GTK_GESTURE (gesture), sequence);
-    gdk_event_get_state (event, &state);
-
-    if (button == GDK_BUTTON_SECONDARY &&
-        (state & gtk_accelerator_get_default_mod_mask ()) == 0)
-    {
-        /* switch to the page before opening the menu */
-        gtk_notebook_set_current_page (notebook, tab_clicked);
-        notebook_popup_menu_show (window, x, y);
-    }
-    else if (button == GDK_BUTTON_MIDDLE)
-    {
-        GtkWidget *slot;
-
-        slot = gtk_notebook_get_nth_page (notebook, tab_clicked);
-        nautilus_window_slot_close (window, NAUTILUS_WINDOW_SLOT (slot));
-    }
+    notebook_popup_menu_show (window, x, y);
 }
 
 static gboolean
@@ -2695,7 +2665,7 @@ nautilus_window_init (NautilusWindow *window)
     gtk_event_controller_set_propagation_phase (GTK_EVENT_CONTROLLER (window->notebook_multi_press_gesture),
                                                 GTK_PHASE_CAPTURE);
     gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (window->notebook_multi_press_gesture),
-                                   0);
+                                   GDK_BUTTON_SECONDARY);
 
     window->key_capture_controller = gtk_event_controller_key_new (GTK_WIDGET (window));
     gtk_event_controller_set_propagation_phase (window->key_capture_controller,


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