Support running games under Proton.
Ther were some missing environment variables that were not taken into account.
This commit is contained in:
1 parent
cff2a47243
commit
044c1063d7
4 files changed
+209
-9
No files matched your search
@@ -306,6 +306,59 @@ focus and the window manager's active window must identify that same virtual
|
||||
desktop. Existing application focus, Linux windows, minimized/disabled windows,
|
||||
and ambiguous choices between multiple applications are left alone.
|
||||
|
||||
## Steam, Proton and Protontricks
|
||||
|
||||
Games and applications launched through Steam Play (Proton) work the same
|
||||
way as plain Wine applications, with no per-game setup: the reader's
|
||||
supervisor discovers the Proton prefix from `STEAM_COMPAT_DATA_PATH`
|
||||
(`<compatdata>/<appid>/pfx`) and starts the helper with that game's own
|
||||
Proton Wine. The same applies to programs started through Protontricks,
|
||||
including `protontricks-launch --appid <id> <program>` and windows opened
|
||||
by Winetricks verbs (`protontricks <appid> <verb>`).
|
||||
|
||||
What a supervisor must get right for Proton prefixes:
|
||||
|
||||
- **Use Proton's own loader.** The helper has to join the prefix's running
|
||||
wineserver, so it must be started through the same Wine build as the
|
||||
game. Steam Play processes run under Proton's preloader
|
||||
(`.../files/lib/wine/<arch>-unix/wine64-preloader`); the matching loader
|
||||
is `files/bin/wine` in that Proton tree. Starting the helper with the
|
||||
system Wine against a Proton server (or the reverse) fails.
|
||||
- **Do not use Protontricks' `WINELOADER`.** Protontricks points
|
||||
`WINELOADER` at its own proxy script (under
|
||||
`~/.cache/protontricks/proton/<version>/bin/wine`). That script needs
|
||||
the Protontricks session environment, exits without it
|
||||
(`Unknown PROTONTRICKS_STEAM_RUNTIME value` in the helper log), and
|
||||
would run the helper inside the Steam Runtime container, where the
|
||||
host's `/usr/libexec/wine-access` files and libraries are not visible.
|
||||
Resolve the real Proton loader from the process executable instead.
|
||||
- **Run the helper on the host, not in the container.** It links host
|
||||
GLib/GIO and XCB and must reach the reader on the session bus at
|
||||
`$DBUS_SESSION_BUS_ADDRESS` (usually `/run/user/<uid>/bus`). Inside
|
||||
pressure-vessel, games instead see that bus through a filtered proxy
|
||||
at `/run/pressure-vessel/bus`; that address identifies the same session
|
||||
but is not reachable on the host, so the helper must be given the
|
||||
reader's own bus address, not the game's. The game's `DISPLAY` and the
|
||||
server's sync mode (`WINEESYNC`/`WINEFSYNC`) must match the game's;
|
||||
copy them from a game process in the same prefix.
|
||||
|
||||
The Orca extension in this repository implements all of this. Cthulhu's
|
||||
supervisor needs the equivalent loader resolution in Cthulhu itself; until
|
||||
then, Protontricks-launched applications do not get a Cthulhu helper. To
|
||||
start the helper manually for a running game, use its Proton build and
|
||||
prefix, for example:
|
||||
|
||||
```sh
|
||||
WINEPREFIX="$HOME/.local/share/Steam/steamapps/compatdata/<appid>/pfx" \
|
||||
WINELOADER="$HOME/.local/share/Steam/steamapps/common/Proton 11.0/files/bin/wine" \
|
||||
WINEESYNC=1 WINEFSYNC=1 \
|
||||
/usr/libexec/wine-access/wine-access.exe
|
||||
```
|
||||
|
||||
(add the reader options from above for Orca). Flatpak builds of Steam or
|
||||
Protontricks are not supported: their sandboxes hide both the host helper
|
||||
installation and the game processes from the reader.
|
||||
|
||||
## Protocol and behavior
|
||||
|
||||
`nvdaController.idl` contains the compatible local RPC interfaces. The helper
|
||||
|
||||
+6
-2
@@ -75,8 +75,12 @@ wine-access.exe --reader orca --reader-path /org/gnome/Orca1/Service/WineAccess
|
||||
--reader-interface org.gnome.Orca1.WineAccess
|
||||
```
|
||||
|
||||
with the program's own `WINELOADER`, display and bus, and
|
||||
`ORCA_WINE_ACCESS_MANAGED=1`. A helper stops 10 seconds after its prefix
|
||||
with the program's own loader, display and bus, and
|
||||
`ORCA_WINE_ACCESS_MANAGED=1`. For Steam Play and Protontricks launches the
|
||||
loader is resolved to the game's real Proton `files/bin/wine` (Protontricks'
|
||||
proxy `WINELOADER` is bypassed) and the game's `WINEESYNC`/`WINEFSYNC` are
|
||||
forwarded so the helper joins the running server; see the main README's
|
||||
Steam section. A helper stops 10 seconds after its prefix
|
||||
goes idle and restarts with exponential backoff after quick failures. Helpers
|
||||
run in their own session and survive an Orca restart, so a newly loaded
|
||||
extension retires a marked helper it did not start before starting its own.
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -33,7 +33,10 @@ WINE_SERVICES = {"services.exe", "explorer.exe", "winedevice.exe", "plugplay.exe
|
||||
"svchost.exe", "rpcss.exe", "conhost.exe", "tabtip.exe",
|
||||
"wineboot.exe", "winemenubuilder.exe", "start.exe", "wineserver"}
|
||||
FORWARDED_ENVIRONMENT = ("DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY",
|
||||
"XDG_RUNTIME_DIR", "DBUS_SESSION_BUS_ADDRESS")
|
||||
"XDG_RUNTIME_DIR", "DBUS_SESSION_BUS_ADDRESS",
|
||||
# A client joining a running server (Proton enables
|
||||
# both) must agree on the sync mode.
|
||||
"WINEESYNC", "WINEFSYNC")
|
||||
|
||||
|
||||
def helper_candidates() -> list[str]:
|
||||
@@ -98,6 +101,23 @@ def prefix_for(environment: dict[str, str]) -> str:
|
||||
return os.path.realpath(os.path.expanduser(prefix))
|
||||
|
||||
|
||||
def _is_protontricks_proxy(path: str) -> bool:
|
||||
"""Whether a loader path is Protontricks' Wine proxy script.
|
||||
|
||||
The proxy dispatches through the Steam Runtime using Protontricks'
|
||||
own session environment (PROTONTRICKS_STEAM_RUNTIME and friends),
|
||||
which the helper does not inherit, and would run the helper inside
|
||||
the container where its host files are not visible. The real Proton
|
||||
loader beside the running preloader is the usable one.
|
||||
"""
|
||||
|
||||
try:
|
||||
with open(path, "rb") as proxy:
|
||||
return b"PROTONTRICKS_STEAM_RUNTIME" in proxy.read(8192)
|
||||
except OSError:
|
||||
return False
|
||||
|
||||
|
||||
def loader_for(pid: int, environment: dict[str, str], proc: Path = Path("/proc")) -> str | None:
|
||||
"""The Wine loader that runs this process, or None if it isn't Wine."""
|
||||
|
||||
@@ -112,13 +132,27 @@ def loader_for(pid: int, environment: dict[str, str], proc: Path = Path("/proc")
|
||||
if name not in LOADER_NAMES | PRELOADER_NAMES:
|
||||
return None
|
||||
configured = environment.get("WINELOADER")
|
||||
if configured and os.access(configured, os.X_OK):
|
||||
if (configured and os.access(configured, os.X_OK)
|
||||
and not _is_protontricks_proxy(configured)):
|
||||
return configured
|
||||
directory = os.path.dirname(executable)
|
||||
for candidate in (name.removesuffix("-preloader"), "wine"):
|
||||
loader = os.path.join(directory, candidate)
|
||||
if os.access(loader, os.X_OK):
|
||||
return loader
|
||||
# Proton keeps preloaders deep under files/lib/wine/<arch>-unix with
|
||||
# the loader in files/bin; a system layout resolves the same way
|
||||
# (.../lib/wine/<arch>-unix up to the prefix's bin).
|
||||
ancestor = directory
|
||||
for _ in range(5):
|
||||
parent = os.path.dirname(ancestor)
|
||||
if parent == ancestor:
|
||||
break
|
||||
ancestor = parent
|
||||
for candidate in ("wine", "wine64"):
|
||||
loader = os.path.join(ancestor, "bin", candidate)
|
||||
if os.access(loader, os.X_OK):
|
||||
return loader
|
||||
return None
|
||||
|
||||
|
||||
@@ -141,6 +175,12 @@ def _bus(value: str) -> str:
|
||||
return value
|
||||
|
||||
|
||||
# Steam Play's pressure-vessel puts a filtered proxy of the host session
|
||||
# bus at this fixed path inside the container. It is our bus, proxied —
|
||||
# but the socket path itself exists only inside the container.
|
||||
PRESSURE_VESSEL_BUS = "/run/pressure-vessel/bus"
|
||||
|
||||
|
||||
def same_session(environment: dict[str, str], ours: dict[str, str]) -> bool:
|
||||
"""Whether a process shares our D-Bus session and display.
|
||||
|
||||
@@ -150,8 +190,14 @@ def same_session(environment: dict[str, str], ours: dict[str, str]) -> bool:
|
||||
|
||||
for key, normal in (("DBUS_SESSION_BUS_ADDRESS", _bus), ("DISPLAY", _display)):
|
||||
theirs, mine = environment.get(key), ours.get(key)
|
||||
if theirs and mine and normal(theirs) != normal(mine):
|
||||
return False
|
||||
if not theirs or not mine or normal(theirs) == normal(mine):
|
||||
continue
|
||||
# A pressure-vessel proxy address cannot be compared with the
|
||||
# host socket it forwards to; the display check still separates
|
||||
# graphical sessions.
|
||||
if key == "DBUS_SESSION_BUS_ADDRESS" and normal(theirs) == PRESSURE_VESSEL_BUS:
|
||||
continue
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
@@ -262,8 +308,14 @@ class HelperManager:
|
||||
return
|
||||
environment = os.environ.copy()
|
||||
for key in FORWARDED_ENVIRONMENT:
|
||||
if source.get(key):
|
||||
environment[key] = source[key]
|
||||
if not source.get(key):
|
||||
continue
|
||||
# The container's bus proxy path is not reachable on the host;
|
||||
# the helper uses our own address for the same bus.
|
||||
if (key == "DBUS_SESSION_BUS_ADDRESS"
|
||||
and _bus(source[key]) == PRESSURE_VESSEL_BUS):
|
||||
continue
|
||||
environment[key] = source[key]
|
||||
environment.update(WINEPREFIX=prefix, WINELOADER=loader, WINEDEBUG="-all")
|
||||
environment[MANAGED_KEY] = "1"
|
||||
log = self._log_file(prefix)
|
||||
|
||||
Reference in new issue
Block a user