From 3fd91afd9643919a3b45ce8967032bc7a5586e8c Mon Sep 17 00:00:00 2001 From: Eric Koegel Date: Sun, 11 Mar 2012 09:52:59 +0300 Subject: [PATCH] Add tooltips for the fader, mute, lock, & record buttons. (Bug 6637) Added functions to show tooltip descriptions of the current volume, which channel the user is hovered over, as well as wether it's muted or recording. This way it's easier to tell at a glance what the current values are. --- xfce4-mixer/xfce-mixer-track.c | 120 ++++++++++++++++++++++++++++++++++++++++ 1 files changed, 120 insertions(+), 0 deletions(-) diff --git a/xfce4-mixer/xfce-mixer-track.c b/xfce4-mixer/xfce-mixer-track.c index 82b412b..46214e7 100644 --- a/xfce4-mixer/xfce-mixer-track.c +++ b/xfce4-mixer/xfce-mixer-track.c @@ -51,6 +51,17 @@ static void xfce_mixer_track_lock_toggled (GtkToggleButton *button, XfceMixerTrack *track); static void xfce_mixer_track_record_toggled (GtkToggleButton *button, XfceMixerTrack *track); +static void xfce_mixer_update_fader_tooltip (GtkWidget *fader, + gint channel, + gint num_channels, + gdouble volume, + gdouble max_volume); +static void xfce_mixer_update_mute_tooltip (GtkWidget *mute, + gboolean muted); +static void xfce_mixer_update_locked_tooltip (GtkWidget *lock, + gboolean locked); +static void xfce_mixer_update_record_tooltip (GtkWidget *record, + gboolean recording); @@ -176,6 +187,93 @@ xfce_mixer_track_new (GstElement *card, static void +xfce_mixer_update_fader_tooltip (GtkWidget *fader, + gint channel, + gint num_channels, + gdouble volume, + gdouble max_volume) +{ + gchar *tooltip; + + g_return_if_fail (fader != NULL); + + if (num_channels > 1) + { + /* This is for the tooltip popup when hovering over the volume slider + * for a stereo channel (left and right channel). */ + tooltip = g_strdup_printf (_("%s channel, volume: %1.0f%%"), + channel == 0 ? _("Left") : _("Right"), + (volume / max_volume) * 100.0f); + } + else + { + /* This is for the tooltip popup when hovering over the volume slider + * for a mono channel. It displays the current volume, i.e.: volume 50% */ + tooltip = g_strdup_printf (_("volume: %1.0f%%"), + (volume / max_volume) * 100.0f); + } + gtk_widget_set_tooltip_text (fader, tooltip); + g_free (tooltip); +} + + + +static void +xfce_mixer_update_mute_tooltip (GtkWidget *mute, + gboolean muted) +{ + gchar *tooltip; + + g_return_if_fail (mute != NULL); + + /* This is for the tooltip popup when hovering over the mute button below + * a track. It's intended to show whether the track is muted or not. */ + tooltip = g_strdup_printf ("%s", muted ? _("Muted") : _("Not muted")); + gtk_widget_set_tooltip_text (mute, tooltip); + g_free (tooltip); +} + + + +static void +xfce_mixer_update_locked_tooltip (GtkWidget *lock, + gboolean locked) +{ + gchar *tooltip; + + g_return_if_fail (lock != NULL); + + /* This is for the tooltip popup when hovering over the chained/lock button + * below a track. It's intended to show whether the user can set the channel + * volume independently or not. */ + tooltip = g_strdup_printf ("%s", + locked ? _("All channels have the same volume") : + _("Each channel has an independent volume")); + gtk_widget_set_tooltip_text (lock, tooltip); + g_free (tooltip); +} + + + +static void +xfce_mixer_update_record_tooltip (GtkWidget *record, + gboolean recording) +{ + gchar *tooltip; + + g_return_if_fail (record != NULL); + + /* This is for the tooltip popup when hovering over the recording button. + * It's intended to show whether the track is currently recording or not. */ + tooltip = g_strdup_printf ("%s", recording ? _("Recording") : + _("Not recording")); + gtk_widget_set_tooltip_text (record, tooltip); + g_free (tooltip); +} + + + +static void xfce_mixer_track_create_contents (XfceMixerTrack *track) { GtkWidget *label; @@ -221,6 +319,12 @@ xfce_mixer_track_create_contents (XfceMixerTrack *track) gtk_widget_show (fader); track->channel_faders = g_list_append (track->channel_faders, fader); + + xfce_mixer_update_fader_tooltip (fader, + channel, + track->gst_track->num_channels, + (gdouble)volumes[channel], + (gdouble)track->gst_track->max_volume); } /* Create a horizontal for the control buttons */ @@ -237,6 +341,7 @@ xfce_mixer_track_create_contents (XfceMixerTrack *track) g_signal_connect (track->mute_button, "toggled", G_CALLBACK (xfce_mixer_track_mute_toggled), track); gtk_box_pack_start (GTK_BOX (button_box), track->mute_button, FALSE, FALSE, 0); gtk_widget_show (track->mute_button); + xfce_mixer_update_mute_tooltip (track->mute_button, FALSE); } if (G_LIKELY (track->gst_track->num_channels >= 2)) @@ -248,6 +353,7 @@ xfce_mixer_track_create_contents (XfceMixerTrack *track) g_signal_connect (track->lock_button, "toggled", G_CALLBACK (xfce_mixer_track_lock_toggled), track); gtk_box_pack_start (GTK_BOX (button_box), track->lock_button, FALSE, FALSE, 0); gtk_widget_show (track->lock_button); + xfce_mixer_update_locked_tooltip (track->lock_button, TRUE); } /* Create record button for capture tracks */ @@ -259,6 +365,7 @@ xfce_mixer_track_create_contents (XfceMixerTrack *track) g_signal_connect (track->record_button, "toggled", G_CALLBACK (xfce_mixer_track_record_toggled), track); gtk_box_pack_start (GTK_BOX (button_box), track->record_button, FALSE, FALSE, 0); gtk_widget_show (track->record_button); + xfce_mixer_update_record_tooltip (track->record_button, FALSE); } /* Some of the mixer controls need to be updated before they can be used */ @@ -305,6 +412,12 @@ xfce_mixer_track_fader_changed (GtkRange *range, gtk_range_set_value (GTK_RANGE (iter->data), gtk_range_get_value (range)); volumes[channel] = (gint) gtk_range_get_value (GTK_RANGE (iter->data)); + + xfce_mixer_update_fader_tooltip (iter->data, + channel, + track->gst_track->num_channels, + volumes[channel], + track->gst_track->max_volume); } /* Deliver the volume update to GStreamer */ @@ -330,11 +443,13 @@ xfce_mixer_track_mute_toggled (GtkToggleButton *button, { stock = "xfce4-mixer-muted"; gst_mixer_set_mute (GST_MIXER (track->card), track->gst_track, TRUE); + xfce_mixer_update_mute_tooltip ((GtkWidget *)button, TRUE); } else { stock = "xfce4-mixer-no-muted"; gst_mixer_set_mute (GST_MIXER (track->card), track->gst_track, FALSE); + xfce_mixer_update_mute_tooltip ((GtkWidget *)button, FALSE); } image = gtk_image_new_from_icon_name (stock, XFCE_MIXER_ICON_SIZE); @@ -358,11 +473,13 @@ xfce_mixer_track_lock_toggled (GtkToggleButton *button, { image = gtk_image_new_from_file (DATADIR "/pixmaps/xfce4-mixer/chain-broken.png"); gtk_button_set_image (GTK_BUTTON (track->lock_button), image); + xfce_mixer_update_locked_tooltip ((GtkWidget *)button, FALSE); return; } image = gtk_image_new_from_file (DATADIR "/pixmaps/xfce4-mixer/chain.png"); gtk_button_set_image (GTK_BUTTON (track->lock_button), image); + xfce_mixer_update_locked_tooltip ((GtkWidget *)button, TRUE); /* Allocate array for volumes of all channels */ volumes = g_new (gint, track->gst_track->num_channels); @@ -402,11 +519,13 @@ xfce_mixer_track_record_toggled (GtkToggleButton *button, { stock = "xfce4-mixer-record"; gst_mixer_set_record (GST_MIXER (track->card), track->gst_track, TRUE); + xfce_mixer_update_record_tooltip ((GtkWidget *)button, TRUE); } else { stock = "xfce4-mixer-no-record"; gst_mixer_set_record (GST_MIXER (track->card), track->gst_track, FALSE); + xfce_mixer_update_record_tooltip ((GtkWidget *)button, FALSE); } image = gtk_image_new_from_icon_name (stock, XFCE_MIXER_ICON_SIZE); @@ -442,6 +561,7 @@ xfce_mixer_track_update_record (XfceMixerTrack *track) { record = GST_MIXER_TRACK_HAS_FLAG (track->gst_track, GST_MIXER_TRACK_RECORD); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (track->record_button), record); + xfce_mixer_update_record_tooltip (track->record_button, record); } } -- 1.7.5.4