Support running games under Proton.

Ther were some missing environment variables that were not taken into
account.
This commit is contained in:
hjozwiak committed 2026-10-31 07:42:11 -04:00
1 parent cff2a47243
commit 044c1063d7
4 files changed
+209 -9

No files matched your search

+92 -1
View File
@@ -56,13 +56,30 @@ class FakeProc:
self.proc.mkdir()
def add(self, pid, exe, environment, cmdline="app.exe"):
self.add_path(pid, self.bin / exe, environment, cmdline)
def add_path(self, pid, exe, environment, cmdline="app.exe"):
entry = self.proc / str(pid)
entry.mkdir()
(entry / "exe").symlink_to(self.bin / exe)
(entry / "exe").symlink_to(exe)
(entry / "environ").write_bytes(
b"\0".join(f"{k}={v}".encode() for k, v in environment.items()) + b"\0")
(entry / "cmdline").write_bytes(cmdline.encode() + b"\0")
def make_executable(self, relative, content=""):
path = self.root / relative
path.parent.mkdir(parents=True, exist_ok=True)
path.write_text(content)
path.chmod(0o755)
return path
def proton(self):
"""A Proton tree: files/bin/wine, preloaders under files/lib/wine."""
wine = self.make_executable("Proton/files/bin/wine")
preloader = self.make_executable(
"Proton/files/lib/wine/i386-unix/wine64-preloader")
return wine, preloader
def remove(self, pid):
for child in (self.proc / str(pid)).iterdir():
child.unlink()
@@ -87,6 +104,27 @@ class DiscoveryTests(unittest.TestCase):
self.assertEqual(loader_for(2, {}, self.fake.proc), str(self.fake.bin / "wine"))
self.assertIsNone(loader_for(3, {}, self.fake.proc))
def test_loader_finds_proton_wine_from_preloader(self):
# Steam Play runs games through the preloader deep in the Proton
# tree; the loader beside no same-directory wine is files/bin/wine.
wine, preloader = self.fake.proton()
self.fake.add_path(4, preloader,
{"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/42"})
environment = {"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/42"}
self.assertEqual(loader_for(4, environment, self.fake.proc), str(wine))
def test_loader_ignores_protontricks_proxy(self):
# Protontricks-exported WINELOADER is its runtime proxy script,
# which exits without the protontricks session environment.
wine, preloader = self.fake.proton()
proxy = self.fake.make_executable(
"protontricks-cache/bin/wine",
"#!/bin/bash\n# PROTONTRICKS_STEAM_RUNTIME dispatch\n")
environment = {"WINEPREFIX": "/steam/compatdata/42/pfx",
"WINELOADER": str(proxy)}
self.fake.add_path(5, preloader, environment)
self.assertEqual(loader_for(5, environment, self.fake.proc), str(wine))
def test_other_sessions_are_left_alone(self):
self.fake.add(30, "wine", {"WINEPREFIX": "/p/mine", "DISPLAY": ":0",
"DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus"})
@@ -99,6 +137,18 @@ class DiscoveryTests(unittest.TestCase):
found = sorted(manager.discover())
self.assertEqual(found, sorted([os.path.realpath("/p/mine"), os.path.realpath("/p/nobus")]))
def test_pressure_vessel_bus_counts_as_our_session(self):
# Steam Play games see the session bus through pressure-vessel's
# filtered proxy at a fixed container path, never the host socket.
ours = {"DISPLAY": ":0",
"DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus"}
theirs = {"DISPLAY": ":0",
"DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/pressure-vessel/bus"}
self.assertTrue(manager_module.same_session(theirs, ours))
# A different display is still another session.
theirs["DISPLAY"] = ":1"
self.assertFalse(manager_module.same_session(theirs, ours))
def test_equivalent_session_spellings_match(self):
ours = {"DISPLAY": ":0.0",
"DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus,guid=abc"}
@@ -191,6 +241,47 @@ class SupervisionTests(unittest.TestCase):
self.manager.poll()
self.assertEqual(len(self.spawned), 1)
def test_protontricks_game_starts_helper_with_proton_wine(self):
wine, preloader = self.fake.proton()
proxy = self.fake.make_executable(
"protontricks-cache/bin/wine",
"#!/bin/bash\n# PROTONTRICKS_STEAM_RUNTIME dispatch\n")
self.fake.remove(20)
self.fake.add_path(23, preloader, {
"WINEPREFIX": "/steam/compatdata/42/pfx", "DISPLAY": ":7",
"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/42",
"WINELOADER": str(proxy), "WINEESYNC": "1", "WINEFSYNC": "1",
}, r"Z:\games\game.exe")
self.manager.poll()
self.assertEqual(len(self.spawned), 1)
helper = self.spawned[0]
self.assertEqual(helper.env["WINEPREFIX"],
os.path.realpath("/steam/compatdata/42/pfx"))
self.assertEqual(helper.env["WINELOADER"], str(wine))
# The helper must use the running server's sync mode.
self.assertEqual(helper.env["WINEESYNC"], "1")
self.assertEqual(helper.env["WINEFSYNC"], "1")
def test_steam_game_helper_uses_host_bus_not_container_proxy(self):
wine, preloader = self.fake.proton()
self.fake.remove(20)
self.fake.add_path(24, preloader, {
"WINEPREFIX": "/steam/compatdata/42/pfx/", "DISPLAY": ":7",
"STEAM_COMPAT_DATA_PATH": "/steam/compatdata/42",
"DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/pressure-vessel/bus",
"PRESSURE_VESSEL_RUNTIME": "steamrt4",
}, r"S:\games\game.exe")
with unittest.mock.patch.dict(os.environ, {
"DBUS_SESSION_BUS_ADDRESS": "unix:path=/run/user/1000/bus"}):
self.manager.poll()
self.assertEqual(len(self.spawned), 1)
helper = self.spawned[0]
self.assertEqual(helper.env["WINEPREFIX"],
os.path.realpath("/steam/compatdata/42/pfx"))
self.assertEqual(helper.env["WINELOADER"], str(wine))
self.assertEqual(helper.env["DBUS_SESSION_BUS_ADDRESS"],
"unix:path=/run/user/1000/bus")
def test_no_helper_installed_does_nothing(self):
self.manager.helper = None
self.manager.poll()