diff options
author | rbuj <[email protected]> | 2020-06-29 20:05:02 +0200 |
---|---|---|
committer | raveit65 <[email protected]> | 2020-07-08 18:35:31 +0200 |
commit | 5ba75b44b5f846e2e9b9af5e242fec81bd3299ea (patch) | |
tree | 00aaa56f793d72690af167351323a5fb2d5e6405 /mate-volume-control | |
parent | 7f8975cc6d8d2379fe4bc8cf3544c3eee21d2b45 (diff) | |
download | mate-media-5ba75b44b5f846e2e9b9af5e242fec81bd3299ea.tar.bz2 mate-media-5ba75b44b5f846e2e9b9af5e242fec81bd3299ea.tar.xz |
gvc-mixer-dialogi: Refactor on_notebook_scroll_event
Diffstat (limited to 'mate-volume-control')
-rw-r--r-- | mate-volume-control/gvc-mixer-dialog.c | 130 |
1 files changed, 60 insertions, 70 deletions
diff --git a/mate-volume-control/gvc-mixer-dialog.c b/mate-volume-control/gvc-mixer-dialog.c index c3f3996..2138f2c 100644 --- a/mate-volume-control/gvc-mixer-dialog.c +++ b/mate-volume-control/gvc-mixer-dialog.c @@ -127,10 +127,6 @@ static void bar_set_stream_control (GvcMixerDialog *dialog, GtkWidget *bar, MateMixerStreamControl *control); -static gboolean dialog_page_scroll_event_cb (GtkWidget *widget, - GdkEventScroll *event, - GtkWindow *window); - G_DEFINE_TYPE_WITH_PRIVATE (GvcMixerDialog, gvc_mixer_dialog, GTK_TYPE_DIALOG) static MateMixerSwitch * @@ -1873,6 +1869,64 @@ create_page_effects (GvcMixerDialog *self) TRUE, TRUE, 6); } +static gboolean +on_notebook_scroll_event (GtkWidget *widget, + GdkEventScroll *event) +{ + 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; +} + static GObject * gvc_mixer_dialog_constructor (GType type, guint n_construct_properties, @@ -1928,8 +1982,8 @@ gvc_mixer_dialog_constructor (GType type, gtk_widget_add_events (self->priv->notebook, GDK_SCROLL_MASK); g_signal_connect (self->priv->notebook, "scroll-event", - G_CALLBACK (dialog_page_scroll_event_cb), - self); + G_CALLBACK (on_notebook_scroll_event), + NULL); gtk_box_pack_start (GTK_BOX (main_vbox), self->priv->notebook, @@ -2371,67 +2425,3 @@ gvc_mixer_dialog_set_page (GvcMixerDialog *self, const gchar *page) return TRUE; } - -static gboolean -dialog_page_scroll_event_cb (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; -} |