From a35bb303d06824b7b7287fa533d779ce50d568ed 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 | 118 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 118 insertions(+) diff --git a/xfce4-mixer/xfce-mixer-track.c b/xfce4-mixer/xfce-mixer-track.c index a7442ed..454dfbd 100644 --- a/xfce4-mixer/xfce-mixer-track.c +++ b/xfce4-mixer/xfce-mixer-track.c @@ -57,6 +57,17 @@ static void xfce_mixer_track_lock_toggled (GtkToggleButton 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); @@ -205,6 +216,91 @@ xfce_mixer_track_lock_button_line_expose_event (GtkWidget *widget, return TRUE; } +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 @@ -270,6 +366,12 @@ xfce_mixer_track_create_contents (XfceMixerTrack *track) 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); + /* Equal volume across all channels means the track is locked */ if (volume_locked && channel > 0 && volumes[channel] != volumes[channel - 1]) volume_locked = FALSE; @@ -324,6 +426,7 @@ xfce_mixer_track_create_contents (XfceMixerTrack *track) gtk_widget_set_size_request (lock_button_hbox, lock_button_hbox_requisition.width, lock_button_hbox_requisition.height); gtk_box_pack_start (GTK_BOX (faders_vbox), lock_button_hbox, FALSE, FALSE, 0); gtk_widget_show (lock_button_hbox); + xfce_mixer_update_locked_tooltip (track->lock_button, TRUE); } buttons_alignment = gtk_alignment_new (0.5, 1.0, 0, 0); @@ -350,6 +453,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 (buttons_hbox), track->mute_button, FALSE, FALSE, 0); gtk_widget_show (track->mute_button); + xfce_mixer_update_mute_tooltip (track->mute_button, FALSE); g_free (tooltip_text); } @@ -370,6 +474,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 (buttons_hbox), track->record_button, FALSE, FALSE, 0); gtk_widget_show (track->record_button); + xfce_mixer_update_record_tooltip (track->record_button, FALSE); g_free (tooltip_text); } @@ -428,6 +533,12 @@ xfce_mixer_track_fader_changed (GtkRange *range, gtk_range_set_value (GTK_RANGE (iter->data), gtk_range_get_value (range)); new_volumes[channel] = (gint) gtk_range_get_value (GTK_RANGE (iter->data)); + + xfce_mixer_update_fader_tooltip (iter->data, + channel, + track->gst_track->num_channels, + new_volumes[channel], + track->gst_track->max_volume); } /* Deliver the volume update to GStreamer */ @@ -485,11 +596,13 @@ xfce_mixer_track_mute_toggled (GtkToggleButton *button, { stock = "audio-volume-muted"; gst_mixer_set_mute (GST_MIXER (track->card), track->gst_track, TRUE); + xfce_mixer_update_mute_tooltip ((GtkWidget *)button, TRUE); } else { stock = "audio-volume-high"; 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); @@ -513,11 +626,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); @@ -557,11 +672,13 @@ xfce_mixer_track_record_toggled (GtkToggleButton *button, { stock = "audio-input-microphone"; gst_mixer_set_record (GST_MIXER (track->card), track->gst_track, TRUE); + xfce_mixer_update_record_tooltip ((GtkWidget *)button, TRUE); } else { stock = "audio-input-microphone-muted"; 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); @@ -597,6 +714,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.8.3.2