[gnome-control-center/sound-better-mute-icons] sound: Set audio icon based on volume
- From: Felipe Borges <felipeborges src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/sound-better-mute-icons] sound: Set audio icon based on volume
- Date: Wed, 18 Dec 2019 11:02:44 +0000 (UTC)
commit 4180e75aad7edc95d2e9162e2d4acf8670ebb94d
Author: Felipe Borges <felipeborges gnome org>
Date: Wed Dec 18 11:32:00 2019 +0100
sound: Set audio icon based on volume
The same way that GNOME Shell does it, we set:
* audio-volume-muted-symbolic when mute button is toggled*
* audio-volume-low-symbolic when 0 < volume < 30%
* audio-volume-medium-symbolic when 30% < volume < 70%
* audio-volume-high-symbolic when 70% < volume <= 100%
When "muted" we can't actually rely on volume (it can be close
to zero but not absolute zero). Instead of requiring volume == 0,
we track the state based on whether the mute button is active.
Fixes #521
panels/sound/cc-volume-slider.c | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
---
diff --git a/panels/sound/cc-volume-slider.c b/panels/sound/cc-volume-slider.c
index 98541e98a..49b5b8290 100644
--- a/panels/sound/cc-volume-slider.c
+++ b/panels/sound/cc-volume-slider.c
@@ -42,6 +42,27 @@ struct _CcVolumeSlider
G_DEFINE_TYPE (CcVolumeSlider, cc_volume_slider, GTK_TYPE_BOX)
+static void
+update_volume_icon (CcVolumeSlider *self)
+{
+ const gchar *icon_name = NULL;
+ gdouble volume, fraction;
+
+ volume = gtk_adjustment_get_value (self->volume_adjustment);
+ fraction = (100.0 * volume) / gtk_adjustment_get_upper (self->volume_adjustment);
+
+ if (gtk_toggle_button_get_active (self->mute_button))
+ icon_name = "audio-volume-muted-symbolic";
+ else if (fraction > 0.0 && fraction < 30.0)
+ icon_name = "audio-volume-low-symbolic";
+ else if (fraction > 30.0 && fraction < 70.0)
+ icon_name = "audio-volume-medium-symbolic";
+ else
+ icon_name = "audio-volume-high-symbolic";
+
+ gtk_image_set_from_icon_name (self->stream_type_icon, icon_name, GTK_ICON_SIZE_BUTTON);
+}
+
static void
volume_changed_cb (CcVolumeSlider *self)
{
@@ -57,6 +78,8 @@ volume_changed_cb (CcVolumeSlider *self)
if (gvc_mixer_stream_set_volume (self->stream, (pa_volume_t) rounded))
gvc_mixer_stream_push_volume (self->stream);
+
+ update_volume_icon (self);
}
static void
@@ -108,6 +131,8 @@ mute_button_toggled_cb (CcVolumeSlider *self)
return;
gvc_mixer_stream_change_is_muted (self->stream, gtk_toggle_button_get_active (self->mute_button));
+
+ update_volume_icon (self);
}
static void
@@ -217,6 +242,7 @@ cc_volume_slider_set_stream (CcVolumeSlider *self,
self, G_CONNECT_SWAPPED);
notify_volume_cb (self);
notify_is_muted_cb (self);
+ update_volume_icon (self);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]