aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/volume-control-pulse.vala32
-rw-r--r--src/volume-control.vala9
-rw-r--r--tests/notifications-test.cc6
-rw-r--r--tests/volume-control-mock.vala5
4 files changed, 29 insertions, 23 deletions
diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala
index fae113d..a5d3baf 100644
--- a/src/volume-control-pulse.vala
+++ b/src/volume-control-pulse.vala
@@ -53,22 +53,6 @@ public class VolumeControlPulse : VolumeControl
private bool _pulse_use_stream_restore = false;
private int32 _active_sink_input = -1;
private string[] _valid_roles = {"multimedia", "alert", "alarm", "phone"};
- public override string stream {
- get {
- if (_active_sink_input == -1)
- return "alert";
- var path = _sink_input_hash[_active_sink_input];
- if (path == _objp_role_multimedia)
- return "multimedia";
- if (path == _objp_role_alert)
- return "alert";
- if (path == _objp_role_alarm)
- return "alarm";
- if (path == _objp_role_phone)
- return "phone";
- return "alert";
- }
- }
private string? _objp_role_multimedia = null;
private string? _objp_role_alert = null;
private string? _objp_role_alarm = null;
@@ -329,6 +313,21 @@ public class VolumeControlPulse : VolumeControl
return message;
}
+ private VolumeControl.Stream calculate_active_stream()
+ {
+ if (_active_sink_input != -1) {
+ var path = _sink_input_hash[_active_sink_input];
+ if (path == _objp_role_multimedia)
+ return Stream.MULTIMEDIA;
+ if (path == _objp_role_alarm)
+ return Stream.ALARM;
+ if (path == _objp_role_phone)
+ return Stream.PHONE;
+ }
+
+ return VolumeControl.Stream.ALERT;
+ }
+
private async void update_active_sink_input (int32 index)
{
if ((index == -1) || (index != _active_sink_input && index in _sink_input_list)) {
@@ -336,6 +335,7 @@ public class VolumeControlPulse : VolumeControl
if (index != -1)
sink_input_objp = _sink_input_hash.get (index);
_active_sink_input = index;
+ active_stream = calculate_active_stream();
/* Listen for role volume changes from pulse itself (external clients) */
try {
diff --git a/src/volume-control.vala b/src/volume-control.vala
index 53e4336..d13bf31 100644
--- a/src/volume-control.vala
+++ b/src/volume-control.vala
@@ -40,6 +40,13 @@ public abstract class VolumeControl : Object
CALL_MODE
}
+ public enum Stream {
+ ALERT,
+ MULTIMEDIA,
+ ALARM,
+ PHONE
+ }
+
public class Volume : Object {
public double volume;
public VolumeReasons reason;
@@ -51,7 +58,7 @@ public abstract class VolumeControl : Object
_options = options;
}
- public virtual string stream { get { return ""; } }
+ public Stream active_stream { get; protected set; default = Stream.ALERT; }
public bool ready { get; protected set; default = false; }
public virtual bool active_mic { get { return false; } set { } }
public virtual bool mute { get { return false; } }
diff --git a/tests/notifications-test.cc b/tests/notifications-test.cc
index 19aeac1..855b2c1 100644
--- a/tests/notifications-test.cc
+++ b/tests/notifications-test.cc
@@ -257,7 +257,7 @@ TEST_F(NotificationsTest, StreamChanges) {
/* Change Streams, no volume change */
notifications->clearNotifications();
- volume_control_mock_set_mock_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), "alarm");
+ volume_control_mock_mock_set_active_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), VOLUME_CONTROL_STREAM_ALARM);
setMockVolume(volumeControl, 0.5, VOLUME_CONTROL_VOLUME_REASONS_VOLUME_STREAM_CHANGE);
loop(50);
notev = notifications->getNotifications();
@@ -265,7 +265,7 @@ TEST_F(NotificationsTest, StreamChanges) {
/* Change Streams, volume change */
notifications->clearNotifications();
- volume_control_mock_set_mock_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), "alert");
+ volume_control_mock_mock_set_active_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), VOLUME_CONTROL_STREAM_ALERT);
setMockVolume(volumeControl, 0.6, VOLUME_CONTROL_VOLUME_REASONS_VOLUME_STREAM_CHANGE);
loop(50);
notev = notifications->getNotifications();
@@ -273,7 +273,7 @@ TEST_F(NotificationsTest, StreamChanges) {
/* Change Streams, no volume change, volume up */
notifications->clearNotifications();
- volume_control_mock_set_mock_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), "multimedia");
+ volume_control_mock_mock_set_active_stream(VOLUME_CONTROL_MOCK(volumeControl.get()), VOLUME_CONTROL_STREAM_MULTIMEDIA);
setMockVolume(volumeControl, 0.6, VOLUME_CONTROL_VOLUME_REASONS_VOLUME_STREAM_CHANGE);
loop(50);
setMockVolume(volumeControl, 0.65);
diff --git a/tests/volume-control-mock.vala b/tests/volume-control-mock.vala
index 95d6a6a..3fbfefe 100644
--- a/tests/volume-control-mock.vala
+++ b/tests/volume-control-mock.vala
@@ -20,13 +20,12 @@
public class VolumeControlMock : VolumeControl
{
- public string mock_stream { get; set; default = "multimedia"; }
- public override string stream { get { return mock_stream; } }
public void mock_set_is_ready(bool b) { ready = b; }
+ public void mock_set_active_stream(VolumeControl.Stream s) { active_stream = s; }
+ public void mock_set_is_playing(bool b) { is_playing = b; }
public override bool active_mic { get; set; }
public bool mock_mute { get; set; }
public override bool mute { get { return mock_mute; } }
- public void mock_set_is_playing(bool b) { is_playing = b; }
private VolumeControl.Volume _vol = new VolumeControl.Volume();
public override VolumeControl.Volume volume { get { return _vol; } set { _vol = value; }}
public override double mic_volume { get; set; }