From 19d447425a8eaee64291ce1667d82506de065756 Mon Sep 17 00:00:00 2001 From: Xavi Garcia Mena Date: Thu, 3 Mar 2016 13:40:53 +0100 Subject: Changes to show up the microphone volume control when an external mic is detected --- src/volume-control-pulse.vala | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/volume-control-pulse.vala b/src/volume-control-pulse.vala index c8a6071..92f12a3 100644 --- a/src/volume-control-pulse.vala +++ b/src/volume-control-pulse.vala @@ -54,6 +54,8 @@ public class VolumeControlPulse : VolumeControl private double _account_service_volume = 0.0; private VolumeControl.ActiveOutput _active_output = VolumeControl.ActiveOutput.SPEAKERS; private AccountsServiceAccess _accounts_service_access; + private bool _external_mic_detected = false; + private bool _source_sink_mic_activated = false; /** true when a microphone is active **/ public override bool active_mic { get; private set; default = false; } @@ -180,7 +182,8 @@ public class VolumeControlPulse : VolumeControl break; case Context.SubscriptionEventType.REMOVE: - this.active_mic = false; + this._source_sink_mic_activated = false; + this.active_mic = _external_mic_detected; break; } break; @@ -229,6 +232,19 @@ public class VolumeControlPulse : VolumeControl if (i == null) return; + if (i.active_port != null && + ( (i.active_port.name.contains ("headphone") || + i.active_port.name.contains ("headset") || + i.active_port.name.contains ("mic") ) && + (!i.active_port.name.contains ("internal") && + !i.active_port.name.contains ("builtin")) )) { + this.active_mic = true; + _external_mic_detected = true; + } else { + this.active_mic = _source_sink_mic_activated; + _external_mic_detected = false; + } + if (_mic_volume != volume_to_double (i.volume.values[0])) { _mic_volume = volume_to_double (i.volume.values[0]); @@ -434,8 +450,10 @@ public class VolumeControlPulse : VolumeControl return; unowned string role = i.proplist.gets (PulseAudio.Proplist.PROP_MEDIA_ROLE); - if (role == "phone" || role == "production") + if (role == "phone" || role == "production") { this.active_mic = true; + this._source_sink_mic_activated = true; + } } private void context_state_callback (Context c) -- cgit v1.2.3