diff options
author | charles kerr <charlesk@canonical.com> | 2015-12-29 15:58:45 -0600 |
---|---|---|
committer | charles kerr <charlesk@canonical.com> | 2015-12-29 15:58:45 -0600 |
commit | 66f5198878b8a244f8bd967074480821be43c69e (patch) | |
tree | 8e21be1e65da6bc3a431e9f43735995decb20a61 /src | |
parent | ac20336e0f1990e7cf1ee8074d9c1a6143c042e4 (diff) | |
download | ayatana-indicator-sound-66f5198878b8a244f8bd967074480821be43c69e.tar.gz ayatana-indicator-sound-66f5198878b8a244f8bd967074480821be43c69e.tar.bz2 ayatana-indicator-sound-66f5198878b8a244f8bd967074480821be43c69e.zip |
generate less pulse traffic on a sink-input-removed event
Diffstat (limited to 'src')
-rw-r--r-- | src/volume-warning-pulse.vala | 39 |
1 files changed, 26 insertions, 13 deletions
diff --git a/src/volume-warning-pulse.vala b/src/volume-warning-pulse.vala index 6451cc5..09b96d1 100644 --- a/src/volume-warning-pulse.vala +++ b/src/volume-warning-pulse.vala @@ -116,6 +116,12 @@ public class VolumeWarningPulse : VolumeWarning return true; } + private void clear_multimedia () { + _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; + set_multimedia_sink_index (PulseAudio.INVALID_INDEX); + multimedia_active = false; + } + private void on_sink_input_info (Context c, SinkInputInfo? i, int eol) { if (i == null) @@ -128,9 +134,7 @@ public class VolumeWarningPulse : VolumeWarning multimedia_active = true; } else if (i.index == _multimedia_sink_input_index) { - _multimedia_sink_input_index = PulseAudio.INVALID_INDEX; - set_multimedia_sink_index (PulseAudio.INVALID_INDEX); - multimedia_active = false; + clear_multimedia(); } } @@ -163,6 +167,8 @@ public class VolumeWarningPulse : VolumeWarning switch (t & Context.SubscriptionEventType.FACILITY_MASK) { case Context.SubscriptionEventType.SINK: + // if something happens to the sink connected to our mm sink input, + // get its updated info to keep our multimedia volume up-to-date if ((index == _multimedia_sink_index) && (index != PulseAudio.INVALID_INDEX)) update_multimedia_volume_soon(); break; @@ -170,15 +176,23 @@ public class VolumeWarningPulse : VolumeWarning case Context.SubscriptionEventType.SINK_INPUT: switch (t & Context.SubscriptionEventType.TYPE_MASK) { + // if a SinkInput changed, get its updated info + // to keep our multimedia indices up-to-date case Context.SubscriptionEventType.NEW: case Context.SubscriptionEventType.CHANGE: GLib.message ("-> Context.SubscriptionEventType.CHANGE or NEW"); update_sink_input_soon(index); break; + + // if the multimedia sink input was removed, + // reset our mm fields and look for a new mm sink input case Context.SubscriptionEventType.REMOVE: - GLib.message ("-> Context.SubscriptionEventType.REMOVE"); - update_all_sink_inputs (); + if (index == _multimedia_sink_input_index) { + clear_multimedia(); + update_all_sink_inputs (); + } break; + default: GLib.debug ("Sink input event not known."); break; @@ -217,14 +231,13 @@ public class VolumeWarningPulse : VolumeWarning } private void pulse_reconnect_soon () { - if (_pulse_reconnect_timer == 0) - _pulse_reconnect_timer = Timeout.add_seconds (2, pulse_reconnect_timeout); - } - - private bool pulse_reconnect_timeout () { - _pulse_reconnect_timer = 0; - pulse_reconnect (); - return Source.REMOVE; + if (_pulse_reconnect_timer == 0) { + _pulse_reconnect_timer = Timeout.add_seconds (2, () => { + _pulse_reconnect_timer = 0; + pulse_reconnect(); + return Source.REMOVE; + }); + } } void pulse_reconnect () { |