diff options
author | António Fernandes <antoniof@gnome.org> | 2021-12-19 14:40:07 +0000 |
---|---|---|
committer | António Fernandes <antoniof@gnome.org> | 2022-01-05 11:41:13 +0000 |
commit | 6cf723537c6efdee8bb5f0fbd8b8bd2b3968806d (patch) | |
tree | 86cbe7f07b7cc61d1206b90072cd75f6c8d8b56e | |
parent | e84ce5acb38377ab773ee08d71936cac9942ab5a (diff) | |
download | nautilus-6cf723537c6efdee8bb5f0fbd8b8bd2b3968806d.tar.gz |
window: Handle tab clicks here
We have 2 gestures for handling clicks on the notebook: one in the
notebook.c file, the other in window.c file.
The notebook one needs to emit a signal which the window listens to
anyway. So, it's simpler to handle everything in a single gesture
in the window class.
-rw-r--r-- | src/nautilus-notebook.c | 82 | ||||
-rw-r--r-- | src/nautilus-notebook.h | 7 | ||||
-rw-r--r-- | src/nautilus-window.c | 36 |
3 files changed, 50 insertions, 75 deletions
diff --git a/src/nautilus-notebook.c b/src/nautilus-notebook.c index ffde9a899..95be6721d 100644 --- a/src/nautilus-notebook.c +++ b/src/nautilus-notebook.c @@ -54,8 +54,6 @@ static guint signals[LAST_SIGNAL]; struct _NautilusNotebook { GtkNotebook parent_instance; - - GtkGesture *multi_press_gesture; }; G_DEFINE_TYPE (NautilusNotebook, nautilus_notebook, GTK_TYPE_NOTEBOOK); @@ -63,12 +61,6 @@ 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 (¬ebook->multi_press_gesture); - G_OBJECT_CLASS (nautilus_notebook_parent_class)->dispose (object); } @@ -134,55 +126,6 @@ find_tab_num_at_pos (NautilusNotebook *notebook, } 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, guint page_num, @@ -200,14 +143,6 @@ 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 @@ -236,11 +171,20 @@ nautilus_notebook_contains_slot (NautilusNotebook *notebook, } gboolean -nautilus_notebook_content_area_hit (NautilusNotebook *notebook, - gint x, - gint y) +nautilus_notebook_get_tab_clicked (NautilusNotebook *notebook, + gint x, + gint y, + gint *position) { - return find_tab_num_at_pos (notebook, x, y) == -1; + gint tab_num; + + tab_num = find_tab_num_at_pos (notebook, x, y); + + if (position != NULL) + { + *position = tab_num; + } + return tab_num != -1; } void diff --git a/src/nautilus-notebook.h b/src/nautilus-notebook.h index 1590e111b..ad227d183 100644 --- a/src/nautilus-notebook.h +++ b/src/nautilus-notebook.h @@ -54,8 +54,9 @@ void nautilus_notebook_next_page (NautilusNotebook *notebook); gboolean nautilus_notebook_contains_slot (NautilusNotebook *notebook, NautilusWindowSlot *slot); -gboolean nautilus_notebook_content_area_hit (NautilusNotebook *notebook, - gint x, - gint y); +gboolean nautilus_notebook_get_tab_clicked (NautilusNotebook *notebook, + gint x, + gint y, + gint *position); G_END_DECLS diff --git a/src/nautilus-window.c b/src/nautilus-window.c index fb46a232c..6d784115a 100644 --- a/src/nautilus-window.c +++ b/src/nautilus-window.c @@ -1791,15 +1791,45 @@ 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_content_area_hit (NAUTILUS_NOTEBOOK (window->notebook), x, y)) + if (!nautilus_notebook_get_tab_clicked (NAUTILUS_NOTEBOOK (notebook), x, y, &tab_clicked)) { return; } - notebook_popup_menu_show (window, x, y); + 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)); + } } static gboolean @@ -2664,7 +2694,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), - GDK_BUTTON_SECONDARY); + 0); window->key_capture_controller = gtk_event_controller_key_new (GTK_WIDGET (window)); gtk_event_controller_set_propagation_phase (window->key_capture_controller, |