From f0bfdc3d63e680812a37bbcbb4476617560576f4 Mon Sep 17 00:00:00 2001
From: Simon McVittie <smcv@collabora.com>
Date: Tue, 11 Feb 2025 20:31:00 +0000
Subject: [PATCH] launch-options: Allow control over SDL dynamic API overrides

By default, we will use a bundled copy of SDL 2 or SDL 3 if a game happens
to provide one: for example, Hitman (2016) has a bundled copy of SDL
2.0.5, and Dota 2 has a bundled copy of some intermediate version between
3.1.6 and 3.1.8 at the time of writing. When using pressure-vessel,
we can override that with the Steam Runtime's newer, presumably-better
version (steamrt/tasks#578).

For SDL 2, in runtime versions that contain sdl2-compat as a non-default
version, we can do the same to replace classic SDL 2 with sdl2-compat
(steamrt/tasks#579).

Expose this in steam-runtime-launch-options to make it more discoverable
and easier to test.

Signed-off-by: Simon McVittie <smcv@collabora.com>
---
 bin/launch-options.py | 39 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/bin/launch-options.py b/bin/launch-options.py
index 2ed19fa17..81fe529ba 100755
--- a/bin/launch-options.py
+++ b/bin/launch-options.py
@@ -626,6 +626,29 @@ class Gui:
 
         row += 1
 
+        label = Gtk.Label.new('SDL 2')
+        self.grid.attach(label, 0, row, 1, 1)
+
+        self.sdl2_dynapi_combo = Gtk.ComboBoxText.new()
+        self.sdl2_dynapi_combo.append(None, "Don't override")
+        self.sdl2_dynapi_combo.append('1', 'Use runtime copy')
+        self.sdl2_dynapi_combo.append('sdl2-compat', 'Use sdl2-compat')
+        self.sdl2_dynapi_combo.set_active(0)
+        self.grid.attach(self.sdl2_dynapi_combo, 1, row, 2, 1)
+
+        row += 1
+
+        label = Gtk.Label.new('SDL 3')
+        self.grid.attach(label, 0, row, 1, 1)
+
+        self.sdl3_dynapi_combo = Gtk.ComboBoxText.new()
+        self.sdl3_dynapi_combo.append(None, "Don't override")
+        self.sdl3_dynapi_combo.append('1', 'Use runtime copy')
+        self.sdl3_dynapi_combo.set_active(0)
+        self.grid.attach(self.sdl3_dynapi_combo, 1, row, 2, 1)
+
+        row += 1
+
         label = Gtk.Label.new('Graphics stack')
         self.grid.attach(label, 0, row, 1, 1)
 
@@ -1260,10 +1283,14 @@ class Gui:
 
         if self._changing_container_runtime:
             self._changing_container_runtime = False
+            # These widgets are features of pressure-vessel, and are
+            # applicable if and only if we are going to use it.
             widgets = [
                 self.graphics_provider_combo,
                 self.layered_runtime_combo,
                 self.remove_game_overlay_combo,
+                self.sdl2_dynapi_combo,
+                self.sdl3_dynapi_combo,
                 self.share_home_combo,
                 self.share_pid_combo,
                 self.vulkan_layers_combo,
@@ -1830,6 +1857,18 @@ class Gui:
             environ['SDL_VIDEODRIVER'] = value
             environ['SDL_VIDEO_DRIVER'] = value
 
+        value = self.sdl2_dynapi_combo.get_active_id()
+
+        if value is not None:
+            environ.pop('SDL_DYNAMIC_API', None)
+            environ['STEAM_COMPAT_RUNTIME_SDL2'] = value
+
+        value = self.sdl3_dynapi_combo.get_active_id()
+
+        if value is not None:
+            environ.pop('SDL3_DYNAMIC_API', None)
+            environ['STEAM_COMPAT_RUNTIME_SDL3'] = value
+
         if self.debug_check.get_active():
             environ['STEAM_LINUX_RUNTIME_VERBOSE'] = '1'
             environ['G_MESSAGES_DEBUG'] = 'all'
-- 
GitLab