diff options
-rw-r--r-- | src/service.vala | 8 | ||||
-rw-r--r-- | src/volume-control-pulse.vala | 29 | ||||
-rw-r--r-- | src/volume-control.vala | 2 | ||||
-rw-r--r-- | tests/volume-control-mock.vala | 12 |
4 files changed, 28 insertions, 23 deletions
diff --git a/src/service.vala b/src/service.vala index 25b3520..cd016c1 100644 --- a/src/service.vala +++ b/src/service.vala @@ -48,7 +48,7 @@ public class IndicatorSound.Service: Object { this.volume_control = volume; this.volume_control.active_output_changed.connect(() => { bool headphones; - switch(volume_control.active_output) { + switch(volume_control.active_output()) { case VolumeControl.ActiveOutput.HEADPHONES: case VolumeControl.ActiveOutput.USB_HEADPHONES: case VolumeControl.ActiveOutput.HDMI_HEADPHONES: @@ -252,7 +252,7 @@ public class IndicatorSound.Service: Object { void update_root_icon () { double volume = this.volume_control.volume.volume; - string icon = get_volume_root_icon (volume, this.volume_control.mute, volume_control.active_output); + string icon = get_volume_root_icon (volume, this.volume_control.mute, volume_control.active_output()); string accessible_name; if (this.volume_control.mute) { @@ -276,7 +276,7 @@ public class IndicatorSound.Service: Object { private bool block_info_notifications = false; - private string get_volume_root_icon_by_volume (double volume, VolumeControl.ActiveOutput active_output) + private static string get_volume_root_icon_by_volume (double volume, VolumeControl.ActiveOutput active_output) { string icon = ""; switch (active_output) @@ -439,7 +439,7 @@ public class IndicatorSound.Service: Object { private void update_notification () { if (!_volume_warning.active && !block_info_notifications) { - _info_notification.show(this.volume_control.active_output, + _info_notification.show(this.volume_control.active_output(), get_volume_percent(), _volume_warning.high_volume); } diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala index d8b9520..74ef015 100644 --- a/src/volume-control-pulse.vala +++ b/src/volume-control-pulse.vala @@ -209,18 +209,16 @@ public class VolumeControlPulse : VolumeControl if (is_playing != playing) is_playing = playing; - // store the current status of the active output - VolumeControl.ActiveOutput active_output_before = active_output; + var oldval = _active_output; + var newval = calculate_active_output(i); - // calculate the output - _active_output = calculate_active_output (i); - - // check if the output has changed, if so... emit a signal - VolumeControl.ActiveOutput active_output_now = active_output; - if (active_output_now != active_output_before && - (active_output_now != VolumeControl.ActiveOutput.CALL_MODE && - active_output_before != VolumeControl.ActiveOutput.CALL_MODE)) { - this.active_output_changed (active_output_now); + _active_output = newval; + + // Emit a change signal iff CALL_MODE wasn't involved. (FIXME: yuck.) + if ((oldval != VolumeControl.ActiveOutput.CALL_MODE) && + (newval != VolumeControl.ActiveOutput.CALL_MODE) && + (oldval != newval)) { + this.active_output_changed (newval); } if (_pulse_use_stream_restore == false && @@ -555,12 +553,9 @@ public class VolumeControlPulse : VolumeControl } } - public override VolumeControl.ActiveOutput active_output - { - get - { - return _active_output; - } + public override VolumeControl.ActiveOutput active_output() + { + return _active_output; } /* Volume operations */ diff --git a/src/volume-control.vala b/src/volume-control.vala index 59b3f8e..c67bbe8 100644 --- a/src/volume-control.vala +++ b/src/volume-control.vala @@ -63,7 +63,6 @@ public abstract class VolumeControl : Object public virtual bool active_mic { get { return false; } set { } } public virtual bool mute { get { return false; } } public bool is_playing { get; protected set; default = false; } - public virtual VolumeControl.ActiveOutput active_output { get { return VolumeControl.ActiveOutput.SPEAKERS; } } private Volume _volume; public virtual Volume volume { get { return _volume; } set { } } public virtual double mic_volume { get { return 0.0; } set { } } @@ -77,5 +76,6 @@ public abstract class VolumeControl : Object this.volume = v; } + public abstract VolumeControl.ActiveOutput active_output(); public signal void active_output_changed (VolumeControl.ActiveOutput active_output); } diff --git a/tests/volume-control-mock.vala b/tests/volume-control-mock.vala index 3fbfefe..159df3b 100644 --- a/tests/volume-control-mock.vala +++ b/tests/volume-control-mock.vala @@ -31,7 +31,17 @@ public class VolumeControlMock : VolumeControl public override double mic_volume { get; set; } public override void set_mute (bool mute) { - + } + + private VolumeControl.ActiveOutput _active_output = VolumeControl.ActiveOutput.SPEAKERS; + + public override VolumeControl.ActiveOutput active_output() { + return _active_output; + } + + public void mock_set_active_output (VolumeControl.ActiveOutput val) { + _active_output = val; + this.active_output_changed(val); } public VolumeControlMock(IndicatorSound.Options options) { |