From 1f73b44437d91e2531551a9d90fcac601ddb5d77 Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Sat, 31 Dec 2011 11:36:05 +0300 Subject: [PATCH] Adds Mute to right click menu. This patch adds a mute/unmute menu button to the right click menu of the mixer panel plugin. For bug 7944. --- panel-plugin/xfce-mixer-plugin.c | 50 +++++++++++++++++++++++++++++++++++++- 1 files changed, 49 insertions(+), 1 deletions(-) diff --git a/panel-plugin/xfce-mixer-plugin.c b/panel-plugin/xfce-mixer-plugin.c index 2308c2e..40c1146 100644 --- a/panel-plugin/xfce-mixer-plugin.c +++ b/panel-plugin/xfce-mixer-plugin.c @@ -70,6 +70,7 @@ struct _XfceMixerPlugin /* Widgets */ GtkWidget *hvbox; GtkWidget *button; + GtkWidget *menu_item; #ifdef HAVE_GST_MIXER_NOTIFICATION /* Flag for ignoring messages from the GstBus */ @@ -93,6 +94,8 @@ static void xfce_mixer_plugin_volume_changed (XfceMixerPlugin *m gdouble volume); static void xfce_mixer_plugin_mute_toggled (XfceMixerPlugin *mixer_plugin, gboolean mute); +static void xfce_mixer_plugin_mute_pressed (GtkWidget *widget, + XfceMixerPlugin *mixer_plugin); static void xfce_mixer_plugin_configure (XfceMixerPlugin *mixer_plugin); static void xfce_mixer_plugin_clicked (XfceMixerPlugin *mixer_plugin); static void xfce_mixer_plugin_read_config (XfceMixerPlugin *mixer_plugin); @@ -160,6 +163,12 @@ xfce_mixer_plugin_new (XfcePanelPlugin *plugin) /* Let the volume button receive mouse events */ xfce_panel_plugin_add_action_widget (plugin, mixer_plugin->button); + /* Add the Mute menu item to the right-click menu */ + mixer_plugin->menu_item = gtk_menu_item_new_with_mnemonic (_("M_ute")); + g_signal_connect (G_OBJECT (mixer_plugin->menu_item), "activate", G_CALLBACK (xfce_mixer_plugin_mute_pressed), mixer_plugin); + gtk_widget_show (mixer_plugin->menu_item); + xfce_panel_plugin_menu_insert_item(plugin, (GtkMenuItem *)mixer_plugin->menu_item); + return mixer_plugin; } @@ -298,6 +307,31 @@ xfce_mixer_plugin_volume_changed (XfceMixerPlugin *mixer_plugin, static void +xfce_mixer_plugin_mute_pressed (GtkWidget *widget, + XfceMixerPlugin *mixer_plugin) +{ + gboolean muted; + XfceVolumeButton *volume; + g_return_if_fail (mixer_plugin != NULL); + g_return_if_fail (GST_IS_MIXER (mixer_plugin->card)); + g_return_if_fail (GST_IS_MIXER_TRACK (mixer_plugin->track)); + g_return_if_fail (IS_XFCE_VOLUME_BUTTON(mixer_plugin->button)); + + volume = (XfceVolumeButton *)mixer_plugin->button; + + /* Get the current mute state. */ + muted = GST_MIXER_TRACK_HAS_FLAG (mixer_plugin->track, GST_MIXER_TRACK_MUTE); + + /* Toggle mute */ + xfce_mixer_plugin_mute_toggled (mixer_plugin, !muted); + + /* Notify the volume button of the change. */ + xfce_volume_button_set_muted (volume, !muted); +} + + + +static void xfce_mixer_plugin_mute_toggled (XfceMixerPlugin *mixer_plugin, gboolean mute) { @@ -317,7 +351,21 @@ xfce_mixer_plugin_mute_toggled (XfceMixerPlugin *mixer_plugin, else { /* Toggle capture */ - gst_mixer_set_record (GST_MIXER (mixer_plugin->card), mixer_plugin->track, !mute); + mute = !mute; + gst_mixer_set_record (GST_MIXER (mixer_plugin->card), mixer_plugin->track, mute); + } + + if (mute) + { + /* Set the right-click menu item to Unmute */ + gtk_menu_item_set_label ((GtkMenuItem *)mixer_plugin->menu_item, + _("Unm_ute")); + } + else + { + /* Set the right-click menu item to Mute */ + gtk_menu_item_set_label ((GtkMenuItem *)mixer_plugin->menu_item, + _("M_ute")); } #ifdef HAVE_GST_MIXER_NOTIFICATION -- 1.7.5.4