widgets: Restore GTK2 tab scrolling behavior

In GTK2 and GIMP 2.10, you can use the mouse scroller to
switch between dockable tabs if you hover over the bar.
This behavior was removed from GtkNotebook in GTK3.
This patch follows other GTK3 applications in re-implementing
the behavior with a scroll-event callback.
This commit is contained in:
Alx Sa 2023-09-21 05:30:48 +00:00 committed by Jehan
parent e26271bae6
commit 3beb2e88ec
1 changed files with 44 additions and 0 deletions

View File

@ -126,6 +126,9 @@ static void gimp_dockbook_page_reordered (GtkNotebook *notebook,
GtkWidget *child,
guint page_num);
static gboolean gimp_dockbook_tab_scroll_cb (GtkWidget *widget,
GdkEventScroll *event);
static gboolean gimp_dockbook_menu_button_press (GimpDockbook *dockbook,
GdkEventButton *bevent,
GtkWidget *button);
@ -222,6 +225,12 @@ gimp_dockbook_init (GimpDockbook *dockbook)
gtk_notebook_set_show_tabs (notebook, TRUE);
gtk_notebook_set_group_name (notebook, "gimp-dockbook");
gtk_widget_add_events (GTK_WIDGET (notebook),
GDK_SCROLL_MASK);
g_signal_connect (GTK_WIDGET (notebook), "scroll-event",
G_CALLBACK (gimp_dockbook_tab_scroll_cb),
NULL);
gtk_drag_dest_set (GTK_WIDGET (dockbook),
0,
dialog_target_table, G_N_ELEMENTS (dialog_target_table),
@ -522,6 +531,41 @@ gimp_dockbook_page_removed (GtkNotebook *notebook,
}
}
/* Restore GTK2 behavior of mouse-scrolling to switch between
* notebook tabs. References Geany's notebook_tab_bar_click_cb ()
* at https://github.com/geany/geany/blob/master/src/notebook.c
*/
static gboolean
gimp_dockbook_tab_scroll_cb (GtkWidget *widget,
GdkEventScroll *event)
{
GtkNotebook *notebook = GTK_NOTEBOOK (widget);
GtkWidget *page = NULL;
page = gtk_notebook_get_nth_page (notebook,
gtk_notebook_get_current_page (notebook));
if (! page)
return FALSE;
switch (event->direction)
{
case GDK_SCROLL_RIGHT:
case GDK_SCROLL_DOWN:
gtk_notebook_next_page (notebook);
break;
case GDK_SCROLL_LEFT:
case GDK_SCROLL_UP:
gtk_notebook_prev_page (notebook);
break;
default:
break;
}
return TRUE;
}
static void
gimp_dockbook_page_reordered (GtkNotebook *notebook,
GtkWidget *child,