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
@@ -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