diff --git a/src/callbacks.cpp b/src/callbacks.cpp index 138aaa26..69fe466b 100644 --- a/src/callbacks.cpp +++ b/src/callbacks.cpp @@ -506,3 +506,63 @@ cb_radio_processes(GtkAction *action, GtkRadioAction *current, gpointer data) g_settings_set_int (procdata->settings, "view-as", procdata->config.whose_process); } + +gboolean +cb_dialog_page_scroll_event(GtkWidget *widget, GdkEventScroll *event, GtkWindow *window) +{ + GtkNotebook *notebook = GTK_NOTEBOOK (widget); + GtkWidget *child, *event_widget, *action_widget; + + child = gtk_notebook_get_nth_page (notebook, gtk_notebook_get_current_page (notebook)); + if (child == NULL) + return FALSE; + + event_widget = gtk_get_event_widget ((GdkEvent *) event); + + /* Ignore scroll events from the content of the page */ + if (event_widget == NULL || + event_widget == child || + gtk_widget_is_ancestor (event_widget, child)) + return FALSE; + + /* And also from the action widgets */ + action_widget = gtk_notebook_get_action_widget (notebook, GTK_PACK_START); + if (event_widget == action_widget || + (action_widget != NULL && gtk_widget_is_ancestor (event_widget, action_widget))) + return FALSE; + action_widget = gtk_notebook_get_action_widget (notebook, GTK_PACK_END); + if (event_widget == action_widget || + (action_widget != NULL && gtk_widget_is_ancestor (event_widget, action_widget))) + 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; + case GDK_SCROLL_SMOOTH: + switch (gtk_notebook_get_tab_pos (notebook)) { + case GTK_POS_LEFT: + case GTK_POS_RIGHT: + if (event->delta_y > 0) + gtk_notebook_next_page (notebook); + else if (event->delta_y < 0) + gtk_notebook_prev_page (notebook); + break; + case GTK_POS_TOP: + case GTK_POS_BOTTOM: + if (event->delta_x > 0) + gtk_notebook_next_page (notebook); + else if (event->delta_x < 0) + gtk_notebook_prev_page (notebook); + break; + } + break; + } + + return TRUE; +} diff --git a/src/callbacks.h b/src/callbacks.h index 69f50568..b43f9a7d 100644 --- a/src/callbacks.h +++ b/src/callbacks.h @@ -80,4 +80,8 @@ void cb_kill_sigstop(GtkAction *action, void cb_kill_sigcont(GtkAction *action, gpointer data); +gboolean cb_dialog_page_scroll_event(GtkWidget *widget, + GdkEventScroll *event, + GtkWindow *window); + #endif /* _PROCMAN_CALLBACKS_H_ */ diff --git a/src/interface.cpp b/src/interface.cpp index f7dbe84f..79be8594 100644 --- a/src/interface.cpp +++ b/src/interface.cpp @@ -698,6 +698,11 @@ create_main_window (ProcData *procdata) /* create the main notebook */ procdata->notebook = notebook = gtk_notebook_new (); + + gtk_widget_add_events (procdata->notebook, GDK_SCROLL_MASK); + g_signal_connect (procdata->notebook, "scroll-event", + G_CALLBACK (cb_dialog_page_scroll_event), GTK_WINDOW (app)); + gtk_box_pack_start (GTK_BOX (main_box), notebook, TRUE, TRUE, 0); gtk_container_set_border_width (GTK_CONTAINER (notebook), 12); diff --git a/src/procdialogs.cpp b/src/procdialogs.cpp index ee695bc3..3fa53e96 100644 --- a/src/procdialogs.cpp +++ b/src/procdialogs.cpp @@ -546,6 +546,11 @@ procdialog_create_preferences_dialog (ProcData *procdata) gtk_box_set_spacing (GTK_BOX (main_vbox), 2); notebook = gtk_notebook_new (); + + gtk_widget_add_events (notebook, GDK_SCROLL_MASK); + g_signal_connect (notebook, "scroll-event", + G_CALLBACK (cb_dialog_page_scroll_event), GTK_WINDOW (dialog)); + gtk_container_set_border_width (GTK_CONTAINER (notebook), 5); gtk_box_pack_start (GTK_BOX (main_vbox), notebook, TRUE, TRUE, 0);