aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorcharles kerr <charlesk@canonical.com>2015-12-20 12:48:53 -0600
committercharles kerr <charlesk@canonical.com>2015-12-20 12:48:53 -0600
commitf2b76dc9e8cf64ccf23f366fbf44077be24ab1b1 (patch)
tree0e596adaafcda03ccece943eff321704b71031c7 /src
parent2492b33a3638378f2837b1aa54cc9ca797a05a25 (diff)
downloadayatana-indicator-sound-f2b76dc9e8cf64ccf23f366fbf44077be24ab1b1.tar.gz
ayatana-indicator-sound-f2b76dc9e8cf64ccf23f366fbf44077be24ab1b1.tar.bz2
ayatana-indicator-sound-f2b76dc9e8cf64ccf23f366fbf44077be24ab1b1.zip
replace volume-warning's 'stream' property with a more focused 'multimedia-active' property
Diffstat (limited to 'src')
-rw-r--r--src/volume-warning.vala100
1 files changed, 44 insertions, 56 deletions
diff --git a/src/volume-warning.vala b/src/volume-warning.vala
index 3bed0c7..401da00 100644
--- a/src/volume-warning.vala
+++ b/src/volume-warning.vala
@@ -30,9 +30,47 @@ public class VolumeWarning : Object
// true if the warning dialog is currently active
public bool active { get; public set; default = false; }
- // true iff we're playing unapproved loud multimedia over headphones
+ // true if we're playing unapproved loud multimedia over headphones
public bool high_volume { get; protected set; default = false; }
+ // true if the active sink input has its role property set to multimedia
+ protected bool multimedia_active { get; set; default = false; }
+
+ // true if the user has approved high volumes recently
+ protected bool high_volume_approved { get; set; default = false; }
+
+ public enum Key {
+ VOLUME_UP,
+ VOLUME_DOWN
+ }
+
+ public void user_keypress(Key key) {
+ if (key == Key.VOLUME_DOWN)
+ on_user_response(IndicatorSound.WarnNotification.Response.CANCEL);
+ }
+
+ public VolumeWarning (IndicatorSound.Options options)
+ {
+ _options = options;
+
+ _volume.volume = 0.0;
+ _volume.reason = VolumeControl.VolumeReasons.PULSE_CHANGE;
+
+ if (loop == null)
+ loop = new PulseAudio.GLibMainLoop ();
+
+ init_all_properties();
+
+ this.reconnect_to_pulse ();
+
+ _notification = new IndicatorSound.WarnNotification();
+ _notification.user_responded.connect((n, response) => on_user_response(response));
+ }
+
+ /***
+ ****
+ ***/
+
/* this is static to ensure it being freed after @context (loop does not have ref counting) */
private static PulseAudio.GLibMainLoop loop;
@@ -50,22 +88,7 @@ public class VolumeWarning : Object
private bool _pulse_use_stream_restore = false;
private int32 _active_sink_input = -1;
private string[] _valid_roles = {"multimedia", "alert", "alarm", "phone"};
- private 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;
@@ -76,24 +99,6 @@ public class VolumeWarning : Object
private VolumeControl.ActiveOutput _active_output = VolumeControl.ActiveOutput.SPEAKERS;
private IndicatorSound.Options _options;
- public VolumeWarning (IndicatorSound.Options options)
- {
- _options = options;
-
- _volume.volume = 0.0;
- _volume.reason = VolumeControl.VolumeReasons.PULSE_CHANGE;
-
- if (loop == null)
- loop = new PulseAudio.GLibMainLoop ();
-
- init_all_properties();
-
- this.reconnect_to_pulse ();
-
- _notification = new IndicatorSound.WarnNotification();
- _notification.user_responded.connect((n, response) => on_user_response(response));
- }
-
private void init_all_properties()
{
init_high_volume();
@@ -249,6 +254,9 @@ public class VolumeWarning : Object
sink_input_objp = _sink_input_hash.get (index);
_active_sink_input = index;
+ multimedia_active = (index != -1)
+ && (_sink_input_hash.get(index) == _objp_role_multimedia);
+
/* Listen for role volume changes from pulse itself (external clients) */
try {
var builder = new VariantBuilder (new VariantType ("ao"));
@@ -610,21 +618,11 @@ public class VolumeWarning : Object
private bool calculate_high_volume_from_volume(double volume) {
return _active_port_headphones
&& _options.is_loud(_volume)
- && (stream == "multimedia");
- }
-
- public void set_warning_volume() {
- var vol = new VolumeControl.Volume();
- vol.volume = volume_to_double(_options.loud_volume());
- vol.reason = _volume.reason;
- debug("Setting warning level volume from %f down to %f", _volume.volume, vol.volume);
- volume = vol;
+ && multimedia_active;
}
/** HIGH VOLUME APPROVED PROPERTY **/
- public bool high_volume_approved { get; private set; default = false; }
-
private void approve_high_volume() {
_high_volume_approved_at = GLib.get_monotonic_time();
update_high_volume_approved();
@@ -725,16 +723,6 @@ public class VolumeWarning : Object
this.active = false;
}
- public enum Key {
- VOLUME_UP,
- VOLUME_DOWN
- }
-
- public void user_keypress(Key key) {
- if (key == Key.VOLUME_DOWN)
- on_user_response(IndicatorSound.WarnNotification.Response.CANCEL);
- }
-
// VOLUME CLAMPING
private uint _clamp_to_loud_timeout = 0;