From 3e1c568f950f0e0ba872fb4d3d5d0551f98bcfe1 Mon Sep 17 00:00:00 2001 From: Tanu Kaskinen Date: Sun, 5 Mar 2017 19:23:09 +0200 Subject: [PATCH] switch-on-port-available: avoid switching away from preferred ports In bug 100064 it was reported that the selected HDMI output wasn't getting remembered across login sessions. The user had a multi-monitor setup, and it turned out that module-switch-on-port-available was switching the card profile away from HDMI 3 (the preferred output) when HDMI 2 became available. HDMI 3 was available all the time, but HDMI 2 was initially unavailable for some reason, and became available soon after pulseaudio had started. PulseAudio has the knowledge that HDMI 3 is the preferred port in this situation, but that knowledge was not used when considering what to do when HDMI 2 becomes available too. This patch adds a check that avoids switching away from the preferred port, if that port is still available. BugLink: https://bugs.freedesktop.org/show_bug.cgi?id=100064 --- src/modules/module-switch-on-port-available.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/modules/module-switch-on-port-available.c b/src/modules/module-switch-on-port-available.c index b9a0f3b3a..dfd8374fe 100644 --- a/src/modules/module-switch-on-port-available.c +++ b/src/modules/module-switch-on-port-available.c @@ -272,6 +272,22 @@ static bool switch_from_port(pa_device_port *port) { return false; } +static bool is_preferred_port_active_and_available(pa_card *card, pa_direction_t direction) { + pa_device_port *port; + struct port_pointers pp; + + if (direction == PA_DIRECTION_OUTPUT) + port = card->preferred_output_port; + else + port = card->preferred_input_port; + + if (!port) + return false; + + pp = find_port_pointers(port); + + return pp.is_port_active && port->available != PA_AVAILABLE_NO; +} static pa_hook_result_t port_available_hook_callback(pa_core *c, pa_device_port *port, void* userdata) { pa_assert(port); @@ -288,7 +304,11 @@ static pa_hook_result_t port_available_hook_callback(pa_core *c, pa_device_port switch (port->available) { case PA_AVAILABLE_YES: - switch_to_port(port); + /* If the user's preferred port is active and still available, we don't + * want to switch away from it just because another port became + * available. */ + if (!is_preferred_port_active_and_available(port->card, port->direction)) + switch_to_port(port); break; case PA_AVAILABLE_NO: switch_from_port(port); -- 2.11.0