diff options
author | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-06-18 18:07:58 -0400 |
---|---|---|
committer | Lars Uebernickel <lars.uebernickel@canonical.com> | 2013-06-18 18:07:58 -0400 |
commit | d3ee0f57c526d7825eac40f416a72502793d6c05 (patch) | |
tree | 78b726bf83c1fd4afa657b60b332bba229eaf2cf | |
parent | e2d1ed2cb0b066a7b34db15e42af0a4b49626ec8 (diff) | |
download | ayatana-indicator-sound-d3ee0f57c526d7825eac40f416a72502793d6c05.tar.gz ayatana-indicator-sound-d3ee0f57c526d7825eac40f416a72502793d6c05.tar.bz2 ayatana-indicator-sound-d3ee0f57c526d7825eac40f416a72502793d6c05.zip |
Update indicator icon when volume changes
-rw-r--r-- | src/service.vala | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/src/service.vala b/src/service.vala index 83d0d17..2196135 100644 --- a/src/service.vala +++ b/src/service.vala @@ -134,6 +134,24 @@ public class IndicatorSound.Service { } } + void update_root_icon () { + double volume = this.volume_control.get_volume (); + string icon; + if (this.volume_control.mute) + icon = "audio-volume-muted-panel"; + else if (volume <= 0.0) + icon = "audio-volume-low-zero-panel"; + else if (volume <= 0.3) + icon = "audio-volume-low-panel"; + else if (volume <= 0.7) + icon = "audio-volume-medium-panel"; + else + icon = "audio-volume-high-panel"; + + var root_action = this.actions.lookup ("root") as SimpleAction; + root_action.set_state (new Variant.parsed ("{ 'icon': <%s> }", icon)); + } + Action create_mute_action () { var mute_action = new SimpleAction.stateful ("mute", null, this.volume_control.mute); @@ -147,11 +165,19 @@ public class IndicatorSound.Service { this.volume_control.notify["mute"].connect ( () => { mute_action.set_state (this.volume_control.mute); + this.update_root_icon (); }); return mute_action; } + void volume_changed (double volume) { + var volume_action = this.actions.lookup ("volume") as SimpleAction; + volume_action.set_state (volume); + + this.update_root_icon (); + } + Action create_volume_action () { var volume_action = new SimpleAction.stateful ("volume", null, this.volume_control.get_volume ()); @@ -159,9 +185,7 @@ public class IndicatorSound.Service { volume_control.set_volume (val.get_double ()); }); - this.volume_control.volume_changed.connect ( (volume) => { - volume_action.set_state (volume); - }); + this.volume_control.volume_changed.connect (volume_changed); this.volume_control.bind_property ("ready", volume_action, "enabled", BindingFlags.SYNC_CREATE); |