From 39118bb719b3e9069ea5c3663625a1d9ee0b852d Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Sun, 11 Mar 2012 11:57:02 +0300 Subject: [PATCH] Adds Mute to right click menu of panel button. (Bug 7944) This patch adds a mute/unmute menu button to the right click menu of the mixer panel plugin. --- panel-plugin/xfce-mixer-plugin.c | 132 ++++++++++++++++++++++++++++++-------- 1 files changed, 106 insertions(+), 26 deletions(-) diff --git a/panel-plugin/xfce-mixer-plugin.c b/panel-plugin/xfce-mixer-plugin.c index f6cf276..61a11b4 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 */ @@ -83,32 +84,36 @@ struct _XfceMixerPlugin /* Function prototypes */ -static void xfce_mixer_plugin_construct (XfcePanelPlugin *plugin); -static XfceMixerPlugin *xfce_mixer_plugin_new (XfcePanelPlugin *plugin); -static void xfce_mixer_plugin_free (XfceMixerPlugin *mixer_plugin, - XfcePanelPlugin *plugin); -static gboolean xfce_mixer_plugin_size_changed (XfceMixerPlugin *mixer_plugin, - gint size); -static void xfce_mixer_plugin_volume_changed (XfceMixerPlugin *mixer_plugin, - gdouble volume); -static void xfce_mixer_plugin_mute_toggled (XfceMixerPlugin *mixer_plugin, - gboolean mute); -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); -static void xfce_mixer_plugin_write_config (XfceMixerPlugin *mixer_plugin); -static void xfce_mixer_plugin_update_track (XfceMixerPlugin *mixer_plugin); +static void xfce_mixer_plugin_construct (XfcePanelPlugin *plugin); +static XfceMixerPlugin *xfce_mixer_plugin_new (XfcePanelPlugin *plugin); +static void xfce_mixer_plugin_free (XfceMixerPlugin *mixer_plugin, + XfcePanelPlugin *plugin); +static gboolean xfce_mixer_plugin_size_changed (XfceMixerPlugin *mixer_plugin, + gint size); +static void xfce_mixer_plugin_volume_changed (XfceMixerPlugin *mixer_plugin, + 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_update_mute_tooltip (XfceMixerPlugin *mixer_plugin, + gboolean muted); +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); +static void xfce_mixer_plugin_write_config (XfceMixerPlugin *mixer_plugin); +static void xfce_mixer_plugin_update_track (XfceMixerPlugin *mixer_plugin); #ifdef HAVE_GST_MIXER_NOTIFICATION -static void xfce_mixer_plugin_bus_message (GstBus *bus, - GstMessage *message, - XfceMixerPlugin *mixer_plugin); +static void xfce_mixer_plugin_bus_message (GstBus *bus, + GstMessage *message, + XfceMixerPlugin *mixer_plugin); #endif -static void xfce_mixer_plugin_set_card (XfceMixerPlugin *mixer_plugin, - GstElement *card); -static void xfce_mixer_plugin_set_track (XfceMixerPlugin *mixer_plugin, - GstMixerTrack *track); -static void xfce_mixer_plugin_set_command (XfceMixerPlugin *mixer_plugin, - const gchar *command); +static void xfce_mixer_plugin_set_card (XfceMixerPlugin *mixer_plugin, + GstElement *card); +static void xfce_mixer_plugin_set_track (XfceMixerPlugin *mixer_plugin, + GstMixerTrack *track); +static void xfce_mixer_plugin_set_command (XfceMixerPlugin *mixer_plugin, + const gchar *command); @@ -160,6 +165,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; } @@ -293,6 +304,64 @@ 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; + + if (G_LIKELY (xfce_mixer_track_type_new (mixer_plugin->track) == XFCE_MIXER_TRACK_TYPE_PLAYBACK)) + { + /* Get the current mute state. */ + muted = GST_MIXER_TRACK_HAS_FLAG (mixer_plugin->track, GST_MIXER_TRACK_MUTE); + muted = !muted; + } + else + { + /* Get the current record state. */ + muted = GST_MIXER_TRACK_HAS_FLAG (mixer_plugin->track, GST_MIXER_TRACK_RECORD); + } + + /* 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_update_mute_tooltip (XfceMixerPlugin *mixer_plugin, + gboolean muted) +{ + 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)); + + if (muted) + { + /* 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")); + } +} + + + +static void xfce_mixer_plugin_mute_toggled (XfceMixerPlugin *mixer_plugin, gboolean mute) { @@ -304,6 +373,8 @@ xfce_mixer_plugin_mute_toggled (XfceMixerPlugin *mixer_plugin, mixer_plugin->ignore_bus_messages = TRUE; #endif + xfce_mixer_plugin_update_mute_tooltip (mixer_plugin, mute); + if (G_LIKELY (xfce_mixer_track_type_new (mixer_plugin->track) == XFCE_MIXER_TRACK_TYPE_PLAYBACK)) { /* Apply mute change to the sound card */ @@ -557,6 +628,9 @@ xfce_mixer_plugin_update_track (XfceMixerPlugin *mixer_plugin) xfce_volume_button_set_volume (XFCE_VOLUME_BUTTON (mixer_plugin->button), volume); xfce_volume_button_set_muted (XFCE_VOLUME_BUTTON (mixer_plugin->button), muted); + /* Update the mute button */ + xfce_mixer_plugin_update_mute_tooltip (mixer_plugin, muted); + /* Free volume array */ g_free (volumes); } @@ -601,7 +675,10 @@ xfce_mixer_plugin_bus_message (GstBus *bus, /* Update the volume button if the message belongs to the current mixer track */ if (G_UNLIKELY (g_utf8_collate (label, mixer_plugin->track_label) == 0)) - xfce_volume_button_set_muted (XFCE_VOLUME_BUTTON (mixer_plugin->button), mute); + { + xfce_volume_button_set_muted (XFCE_VOLUME_BUTTON (mixer_plugin->button), mute); + xfce_mixer_plugin_update_mute_tooltip (mixer_plugin, mute); + } g_free (label); break; @@ -612,7 +689,10 @@ xfce_mixer_plugin_bus_message (GstBus *bus, /* Update the volume button if the message belongs to the current mixer track */ if (G_UNLIKELY (g_utf8_collate (label, mixer_plugin->track_label) == 0)) - xfce_volume_button_set_muted (XFCE_VOLUME_BUTTON (mixer_plugin->button), !record); + { + xfce_volume_button_set_muted (XFCE_VOLUME_BUTTON (mixer_plugin->button), !record); + xfce_mixer_plugin_update_mute_tooltip (mixer_plugin, !record); + } g_free (label); default: -- 1.7.5.4