From 1b720eb78dc09ff22538f7005965bd5065278cab Mon Sep 17 00:00:00 2001
From: Ludovico de Nittis <ludovico.denittis@collabora.com>
Date: Tue, 16 Mar 2021 17:07:29 +0100
Subject: [PATCH] wrap: Set PulseAudio as the default ALSA driver if available

To avoid audio issues, if we have successfully bound a PulseAudio
socket, we should also set it as the default driver in ALSA.

Addresses: #65
Partially addresses:
https://github.com/ValveSoftware/steam-runtime/issues/371

Signed-off-by: Ludovico de Nittis <ludovico.denittis@collabora.com>
---
 pressure-vessel/wrap.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/pressure-vessel/wrap.c b/pressure-vessel/wrap.c
index 0edada1ff..83c5c8adf 100644
--- a/pressure-vessel/wrap.c
+++ b/pressure-vessel/wrap.c
@@ -2417,6 +2417,21 @@ main (int argc,
                            (runtime != NULL),
                            is_flatpak_env);
 
+  if (pv_environ_is_locked(container_env, "PULSE_SERVER")
+      || is_flatpak_env)
+    {
+      /* Make the PulseAudio driver the default.
+       * We do this unconditionally when we are under Flatpak for parity
+       * with the freedesktop.org Platform. */
+      const gchar *alsa_config = "pcm.!default pulse\n"
+                                 "ctl.!default pulse\n";
+
+      flatpak_bwrap_add_args_data (bwrap, "99-pulseaudio-default.conf",
+                                   alsa_config, -1,
+                                   "/etc/alsa/conf.d/99-pulseaudio-default.conf",
+                                   NULL);
+    }
+
   if (is_flatpak_env)
     {
       g_autoptr(GList) vars = NULL;
-- 
GitLab