merge: with main branch

This commit is contained in:
0x1Nawaf committed 2026-10-25 10:38:42 +00:00
commit aa1a8da39a
285 files changed
+18085 -1245

No files matched your search

@@ -259,24 +259,91 @@ def focus_snapshot():
STEAM_APP_CLASS = re.compile(r"steam_app_(\d+)$")
def tag_game_windows(snap):
if os.environ.get("BL_STEAM_CLIENT_ARCH") != "x86_64":
return False
def process_env(pid, proc=Path("/proc")):
try:
return dict(entry.split(b"=", 1) for entry in (proc / str(pid) / "environ").read_bytes().split(b"\0") if b"=" in entry)
except OSError:
return {}
def steam_app_id(env):
try:
app = int(env.get(b"SteamAppId", b"0"))
except ValueError:
return None
return app if 0 < app < 2**32 else None
def under_reaper(pid, proc=Path("/proc")):
for _ in range(64):
try:
if (proc / str(pid) / "comm").read_text().strip() == "reaper":
return True
stat = (proc / str(pid) / "stat").read_text()
pid = int(stat[stat.rindex(")") + 2:].split()[1])
except (OSError, ValueError, IndexError):
return False
if pid <= 1:
return False
return False
def sandboxed_apps(proc=Path("/proc")):
apps = {}
try:
pids = [entry for entry in os.listdir(proc) if entry.isdigit()]
except OSError:
return apps
for pid in pids:
env = process_env(pid, proc)
flatpak, app = env.get(b"FLATPAK_ID"), steam_app_id(env)
if flatpak and app:
name = flatpak.decode(errors="replace").lower()
for key in {name, name.rsplit(".", 1)[-1]}:
apps[key] = app if apps.get(key, app) == app else None
return apps
def window_steam_app(win, flatpaks, proc=Path("/proc")):
match = STEAM_APP_CLASS.match(win.get("class") or "")
if match:
return match.group(1) if os.environ.get("BL_STEAM_CLIENT_ARCH") == "x86_64" else None
pid = win.get("pid")
if pid:
if under_reaper(pid, proc):
return None
app = steam_app_id(process_env(pid, proc))
if app:
return str(app)
app = flatpaks().get((win.get("class") or "").lower())
return str(app) if app else None
def tag_game_windows(snap, proc=Path("/proc")):
tagged = False
found = []
def flatpaks():
if not found:
found.append(sandboxed_apps(proc))
return found[0]
for display, wins in snap.get("displays", {}).items():
if display == os.environ.get("DISPLAY"):
continue
for win in wins:
match = STEAM_APP_CLASS.match(win.get("class") or "")
if not match or win.get("appId") or win.get("map") != "viewable" or win.get("overrideRedirect"):
if win.get("appId") or win.get("map") != "viewable" or win.get("overrideRedirect") or win.get("inputOnly"):
continue
app = window_steam_app(win, flatpaks, proc)
if not app:
continue
try:
done = subprocess.run(["xprop", "-display", display, "-id", str(win["window"]), "-f", "STEAM_GAME", "32c",
"-set", "STEAM_GAME", match.group(1)],
"-set", "STEAM_GAME", app],
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, timeout=5).returncode == 0
except (OSError, subprocess.TimeoutExpired):
done = False
log("game window %s on %s tagged STEAM_GAME=%s: %s" % (win["window"], display, match.group(1), "ok" if done else "failed"))
log("game window %s on %s tagged STEAM_GAME=%s: %s" % (win["window"], display, app, "ok" if done else "failed"))
tagged = tagged or done
return tagged
@@ -8,7 +8,7 @@ X64 = os.environ.get("BL_STEAM_CLIENT_ARCH") == "x86_64"
CLIENT_HOME = (os.environ.get("BL_X64_HOME") or os.path.join(HOME, ".droiddeck-x64")) if X64 else HOME
STEAM_ROOT = sys.argv[1] if len(sys.argv) > 1 else os.path.join(CLIENT_HOME, ".local/share/Steam")
LIBRARIES = ((STEAM_ROOT, "Steam Games"), ("/mnt/droiddeck-sd/x86-64" if X64 else "/mnt/droiddeck-sd", "SD Games"))
NOT_GAMES = {228980, 1070560, 1391110, 1493710, 1628350, 3127680, 4183110, 4185400, 4427310, 4628740}
NOT_GAMES = {228980, 1070560, 1161040, 1391110, 1493710, 1628350, 1826330, 3127680, 4183110, 4185400, 4427310, 4628740}
APPS_DIR = os.path.join(HOME, ".local/share/applications")
PREFIX = "droiddeck-game-"
NAME = re.compile(r'^\s*"name"\s*"([^"]*)"', re.M)
@@ -589,7 +589,8 @@ def guest_environment(fex, env):
result["FEX_THUNKHOSTLIBS"] = fex["host_thunks"]
result["FEX_THUNKGUESTLIBS"] = fex["guest_thunks"]
result["FEX_THUNKCONFIG"] = os.path.join(CONFIG_DIR, "ThunksConfig.json")
preload = [part for part in split_paths(result.get("LD_PRELOAD")) if os.path.exists(part) and not is_arm(part)]
preload = [part for part in split_paths(result.get("LD_PRELOAD"))
if "/" not in part or (os.path.exists(part) and not is_arm(part))]
library_path = [part for part in (result.get("LD_LIBRARY_PATH") or "").split(":")
if part and "arm64" not in part and "aarch64" not in part]
for name, parts in (("LD_PRELOAD", preload), ("LD_LIBRARY_PATH", library_path)):
@@ -671,15 +672,26 @@ def launch(command, env, mode, decide=None):
return os.execve(fex["bin"], [fex["bin"], program] + command[1:], guest)
def game_environment(env):
def game_environment(env, command):
try:
game_env = runpy.run_path(os.path.join(BIN_DIR, "droiddeck-game-env"))
env = game_env["game_gpu"](env)
app = game_env["game_id"](env) or env.get("SteamAppId") or env.get("SteamGameId")
if not app:
return env
with open(GAME_ENVIRONMENT, encoding="utf-8") as source:
return game_env["apply_config"](env, json.load(source), str(app))
fixes = {}
game = game_env["Game"](resolve(command[0], env), command[1:])
for check in game_env["FIXES"]:
found = check(game)
if found and found[0]:
fixes.update(found[0])
say(found[2])
try:
with open(GAME_ENVIRONMENT, encoding="utf-8") as source:
config = json.load(source)
except FileNotFoundError:
config = {"version": 1}
return game_env["apply_config"](env, config, str(app), fixes)
except FileNotFoundError:
return env
except Exception as error:
@@ -810,7 +822,7 @@ def main(argv):
return 0
if not command:
return 2
return launch(command, game_environment(dict(os.environ)), os.environ.get("DROIDDECK_FEX", "auto"))
return launch(command, game_environment(dict(os.environ), command), os.environ.get("DROIDDECK_FEX", "auto"))
if action == "run":
try:
mode, decide, command = parse_run(args)
@@ -6,6 +6,7 @@ import re
import runpy
import subprocess
import sys
import tempfile
from pathlib import Path
GAME_TU_DEBUG = "DROIDDECK_GAME_TU_DEBUG"
@@ -87,6 +88,12 @@ def dotnet_memory_ordering(game):
return DOTNET_FEX, [], ".NET runtime: FEX with full TSO and without multiblock"
@fix
def unity_memory_ordering(game):
if {"unityplayer.so", "gameassembly.so", "unityplayer.dll"} & game.files:
return {"FEX_TSOENABLED": "1"}, [], "Unity: FEX with TSO"
@fix
def godot_vulkan(game):
if is_godot(game) and not game.has_arg("--rendering-driver"):
@@ -114,6 +121,21 @@ def arkham_city_x87(game):
return {"FEX_X87REDUCEDPRECISION": "0"}, [], "Batman: Arkham City: FEX with full x87 precision"
@fix
def caravan_sandwitch_feature_level(game):
if "caravansandwitch.exe" in game.files or game.stem == "caravansandwitch-win64-shipping":
return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "Caravan SandWitch: D3D12 feature level 12_1 (12_2 hands it mesh shader pipelines vkd3d-proton cannot build)"
@fix
def cyberpunk_feature_level(game):
if game.stem == "cyberpunk2077" or (
game.stem == "redprelauncher"
and os.path.isfile(os.path.join(os.path.dirname(game.exe), "bin", "x64", "Cyberpunk2077.exe"))
):
return {"VKD3D_FEATURE_LEVEL": "12_1"}, [], "Cyberpunk 2077: D3D12 feature level 12_1"
def skip_red_launcher(command):
"""Cyberpunk 2077's prelauncher opens REDlauncher, a Qt WebEngine window that hands over to the
game half a minute later and then stays up beside it, well over a core busy for as long as the
@@ -127,6 +149,61 @@ def skip_red_launcher(command):
return command
UBISOFT_LAUNCHER = "drive_c/Program Files (x86)/Ubisoft/Ubisoft Game Launcher"
UBISOFT_SETTINGS = "drive_c/users/steamuser/AppData/Local/Ubisoft Game Launcher/settings.yaml"
def overlay_off(text):
lines = text.splitlines()
try:
start = next(i for i, line in enumerate(lines) if re.fullmatch(r"overlay:\s*(#.*)?", line))
except StopIteration:
if lines and not lines[-1].strip():
lines.pop()
return "\n".join(lines + ["overlay:", " enabled: false", " warning_enabled: false"]) + "\n"
end = start + 1
for index in range(start + 1, len(lines)):
if lines[index].strip() and not lines[index].startswith(" "):
break
if lines[index].strip():
end = index + 1
block = lines[start + 1:end]
for key in ("enabled", "warning_enabled"):
entry = " %s: false" % key
found = [i for i, line in enumerate(block) if line.split(":", 1)[0] == " " + key]
if found:
block[found[0]] = entry
else:
block.append(entry)
return "\n".join(lines[:start + 1] + block + lines[end:]) + "\n"
def ubisoft_overlay_off(env):
prefix = Path(env.get("STEAM_COMPAT_DATA_PATH", "/nonexistent")) / "pfx"
if not (prefix / UBISOFT_LAUNCHER).is_dir():
return
settings = prefix / UBISOFT_SETTINGS
try:
text = settings.read_text(encoding="utf-8") if settings.exists() else ""
updated = overlay_off(text)
if updated == text:
return
settings.parent.mkdir(parents=True, exist_ok=True)
handle, staged = tempfile.mkstemp(prefix=".settings-", dir=settings.parent)
try:
with os.fdopen(handle, "w", encoding="utf-8") as target:
target.write(updated)
if settings.exists():
os.chmod(staged, settings.stat().st_mode & 0o7777)
os.replace(staged, settings)
except BaseException:
os.unlink(staged)
raise
print("droiddeck-game-env: Ubisoft Connect overlay turned off", file=sys.stderr)
except (OSError, UnicodeDecodeError) as error:
print("droiddeck-game-env: Ubisoft Connect overlay left as is (%s)" % error, file=sys.stderr)
def offline_without_anticheat(command, env):
"""Start the configured game executable when the player opts into launching without EAC."""
if (env.get("DROIDDECK_ANTICHEAT_OFFLINE") != "1" or len(command) <= 2
@@ -443,6 +520,7 @@ def main():
fixes = {}
if waiting:
command = skip_red_launcher(command)
ubisoft_overlay_off(env)
fixes, extra, notes = engine_fixes(command[2], command[3:]) if len(command) > 2 else ({}, [], [])
for note in notes:
print("droiddeck-game-env: " + note, file=sys.stderr)
@@ -24,7 +24,7 @@ read_scripts() { xargs -0 -r awk -v want="${1:-redists}" '
proc[depth] = 1
program = tolower(part[4])
sub(/.*[\\\/]/, "", program)
if (program ~ /vulkan/) vulkan[depth] = 1
if (program ~ /vulkan|uplay|ubisoft/) vulkan[depth] = 1
next
}
if (n == 3) pending = part[2]
@@ -243,7 +243,7 @@ for system in "${regs[@]}"; do
had=()
for line in "${kept[@]}"; do had[$line]=1; done
printf '%s\n' "${other[@]}" "${kept[@]}" >"$seeded"
echo "== took Vulkan runtime markers out of $reg"
echo "== took Vulkan runtime and Ubisoft Connect markers out of $reg"
fi
if [ ${#had[@]} -gt 0 ] && { [ -z "$id" ] || [ "$id" != "$prev" ]; }; then
declare -A held=()
@@ -86,12 +86,6 @@ run_gamescope() (
collect_steam_logs() {
[ -n "${BL_DEBUG_DIR:-}" ] || return 0
local steam_root=${XDG_DATA_HOME:-$HOME/.local/share}/Steam
[ "${steam_x64:-0}" = 1 ] && steam_root=${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam
mkdir -p "$BL_DEBUG_DIR/steam" 2>/dev/null || return 0
[ -d "$steam_root/logs" ] && find "$steam_root/logs" -maxdepth 1 -type f -size -8192k \
-exec cp {} "$BL_DEBUG_DIR/steam/" \; 2>/dev/null
[ "${steam_x64:-0}" = 0 ] && [ -f "$HOME/.steam/steam/logs/steamwebhelper.log" ] && cp "$HOME/.steam/steam/logs/steamwebhelper.log" "$BL_DEBUG_DIR/steam/" 2>/dev/null
local sync_store=$HOME/.local/share/droiddeck-esync sync_file
if [ -d "$sync_store" ] && mkdir -p "$BL_DEBUG_DIR/droiddeck-esync" 2>/dev/null; then
for sync_file in launches.log tools.tsv wanted.tsv prefixes.json; do
@@ -102,7 +96,6 @@ collect_steam_logs() {
if [ -d "$fex_state" ] && mkdir -p "$BL_DEBUG_DIR/droiddeck-fex" 2>/dev/null; then
cp "$fex_state/status.json" "$fex_state/config/Config.json" "$BL_DEBUG_DIR/droiddeck-fex/" 2>/dev/null
fi
echo "== steam logs copied to $BL_DEBUG_DIR/steam"
}
trap 'collect_steam_logs 2>/dev/null || true' TERM INT HUP
if [ -n "${BL_VK_DRIVER:-}" ]; then
@@ -227,7 +220,9 @@ if [ -z "${BL_INSIDE:-}" ]; then
echo "== gamescope: games at ${nested}x${height} stretched to the ${width}x${height} output"
fi
fi
if [ "$mode" = steam ]; then
# Off unless Performance asks for it. Compositing the cursor here adds a second
# plane on the phone's compositor; a controller-driven cursor is the reason to turn it on.
if [ "$mode" = steam ] && [ "${BL_CURSOR_COMPOSITE:-0}" = 1 ]; then
export gamescope_cursor_composite=2
fi
args=(--backend wayland --expose-wayland -f -W "$width" -H "$height" -w "$nested" -h "$height")
@@ -401,8 +396,14 @@ case $mode in
steam_root=$XDG_DATA_HOME/Steam
if [ -f "${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam/local.vdf" ]; then
droiddeck-steam-x64 --sync-login || true
droiddeck-steam-x64 --share || true
fi
steam_client=("$steam_root/steamrtarm64/steam")
_bl_srt_shim=$HOME/.droiddeck-steamrt-shim
if droiddeck-steamrt-shim "$steam_root/steamrtarm64" "$_bl_srt_shim"; then
echo "== steam: Valve containerized the arm64 Steam client (it carries a Steam Runtime container); starting it through $_bl_srt_shim"
steam_client=(env STEAM_RUNTIME_STEAMRT="$_bl_srt_shim" PATH="$_bl_srt_shim/bin:$PATH" "${steam_client[@]}")
fi
fi
_bl_proton_root=$steam_root
if [ "$steam_x64" = 1 ]; then
@@ -561,6 +562,11 @@ case $mode in
fi
droiddeck-seed-redists "$steam_root" || true
fi
if [ -n "${BL_SHADER_PRECACHE:-}" ]; then
droiddeck-steam-shaders "$BL_SHADER_PRECACHE" "$XDG_DATA_HOME/Steam" \
"${BL_X64_HOME:-$HOME/.droiddeck-x64}/.local/share/Steam" &&
echo "$BL_SHADER_PRECACHE" > "$HOME/.bl-shader-precache-applied" || true
fi
if [ "$steam_x64" = 0 ] && [ ! -f "$steam_root/steamapps/appmanifest_4427310.acf" ]; then
step "asking the client to fetch the ARM64 Proton"
set -- "$@" steam://install/4427310
@@ -781,10 +787,13 @@ BUSCONF
fi
# The UI bridge launches SteamVR, which needs the guest agent's library environment.
_bl_compat_env=(env -u LD_LIBRARY_PATH -u STEAM_RUNTIME)
_bl_compat_env=(env -u LD_LIBRARY_PATH -u STEAM_RUNTIME -u STEAM_STEAMRT_RECURSION_GUARD)
[ "${LD_LIBRARY_PATH+x}" ] && _bl_compat_env+=("LD_LIBRARY_PATH=$LD_LIBRARY_PATH")
[ "${STEAM_RUNTIME+x}" ] && _bl_compat_env+=("STEAM_RUNTIME=$STEAM_RUNTIME")
[ "${STEAM_STEAMRT_RECURSION_GUARD+x}" ] && _bl_compat_env+=("STEAM_STEAMRT_RECURSION_GUARD=$STEAM_STEAMRT_RECURSION_GUARD")
export STEAM_RUNTIME=1
# A containerized client re-executes itself through pressure-vessel-wrap (bwrap) unless told it is already inside.
export STEAM_STEAMRT_RECURSION_GUARD=1
export LD_LIBRARY_PATH=$steam_root/steamrtarm64:$steam_root/steamrtarm64/panorama${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
export SDL_VIDEO_X11_DGAMOUSE=0
decky_loader=$HOME/homebrew/services/PluginLoader
@@ -834,7 +843,7 @@ BUSCONF
echo "== steam: devtools port $BL_CDP_PORT, guest processes only"
fi
[ -n "${BL_LAUNCH_DIR:-}" ] && mkdir -p "$BL_LAUNCH_DIR/agent" && echo "$BL_CDP_PORT" > "$BL_LAUNCH_DIR/agent/cdp-port"
[ "$steam_x64" = 1 ] || "${_bl_compat_env[@]}" droiddeck-steam-compat "$steam_root" 2>&1 &
[ "$steam_x64" = 1 ] || { "${_bl_compat_env[@]}" droiddeck-steam-compat "$steam_root" 2>&1 & }
_bl_ui=(-gamepadui)
[ "${BL_STEAM_UI:-}" = desktop ] && _bl_ui=()
_bl_cef=(-cef-force-gpu -cef-use-gl=angle -cef-use-angle=vulkan)
@@ -864,6 +873,9 @@ BUSCONF
unset _stale _f
fi
steam_channel=steamdeck_publicbeta
if [ "$steam_x64" = 0 ]; then
steam_channel=$(droiddeck-steam-install --channel 2>/dev/null || echo steamdeck_publicbeta)
fi
_bl_lang=()
[ -n "${BL_STEAM_LANGUAGE:-}" ] && _bl_lang=(-language "$BL_STEAM_LANGUAGE")
steam_beta=$steam_root/package/beta
@@ -196,6 +196,51 @@ TOUR_JS = r"""
return "off";
})()
"""
FILE_BINDING = "droiddeckOpenFileDialog"
FILE_JS = r"""
(() => {
const cancelled = () => ({ result: 2, message: "" });
if (window.__droiddeckFiles) {
window.__droiddeckFiles.cancelAll();
return "present";
}
const self = { next: 0, pending: new Map() };
const open = function (options) {
return new Promise((resolve, reject) => {
if (typeof window.__BINDING__ !== "function") { reject(cancelled()); return; }
const id = ++self.next;
self.pending.set(id, { resolve, reject });
try { window.__BINDING__(JSON.stringify({ id, options: options || {} })); }
catch (e) { self.pending.delete(id); reject(cancelled()); }
});
};
self.done = (id, path) => {
const item = self.pending.get(id);
if (!item) return false;
self.pending.delete(id);
if (typeof path === "string" && path) item.resolve(path); else item.reject(cancelled());
return true;
};
self.cancelAll = () => {
const items = Array.from(self.pending.values());
self.pending.clear();
for (const item of items) item.reject(cancelled());
};
const patch = (w) => {
const system = w?.SteamClient?.System;
if (system && system.OpenFileDialog !== open) system.OpenFileDialog = open;
};
patch(window);
if (SteamClient.System.OpenFileDialog !== open) throw new Error("Steam OpenFileDialog could not be redirected");
const popups = window.g_PopupManager;
if (popups) {
for (const popup of popups.GetPopups?.() || []) patch(popup.window);
popups.AddPopupCreatedCallback?.((popup) => patch(popup.window));
}
window.__droiddeckFiles = self;
return "installed";
})()
""".replace("__BINDING__", FILE_BINDING)
VR_BINDING = "droiddeckLaunchSteamVr"
VR_HELPER = "/usr/local/bin/droiddeck-steamvr"
VR_JS = r"""
@@ -274,6 +319,62 @@ def launch_steamvr():
say("SteamVR library launch failed: %s" % e)
def choose_file(options):
import gi
gi.require_version("Gdk", "3.0")
gi.require_version("Gtk", "3.0")
from gi.repository import Gdk, Gtk
directory = bool(options.get("bChooseDirectory"))
save = bool(options.get("bSaveMode")) and not directory
action = (Gtk.FileChooserAction.SELECT_FOLDER if directory else
Gtk.FileChooserAction.SAVE if save else Gtk.FileChooserAction.OPEN)
dialog = Gtk.FileChooserDialog(title=str(options.get("strTitle") or ""), action=action)
dialog.add_buttons("gtk-cancel", Gtk.ResponseType.CANCEL,
"gtk-save" if save else "gtk-open", Gtk.ResponseType.ACCEPT)
dialog.set_default_response(Gtk.ResponseType.ACCEPT)
dialog.set_local_only(True)
dialog.set_do_overwrite_confirmation(True)
for folder in ("/root/Storage", "/mnt/droiddeck-sd"):
if os.path.isdir(folder):
try:
dialog.add_shortcut_folder(folder)
except Exception:
pass
if not directory:
for entry in options.get("rgFilters") or []:
patterns = [str(p) for p in entry.get("rFilePatterns") or [] if p]
if not patterns:
continue
chosen = Gtk.FileFilter()
chosen.set_name(str(entry.get("strFileTypeName") or ", ".join(patterns)))
for pattern in patterns:
pattern = "*" if pattern == "*.*" else pattern
chosen.add_pattern(pattern)
if pattern.lower() != pattern.upper():
chosen.add_pattern(pattern.upper())
dialog.add_filter(chosen)
if entry.get("bUseAsDefault"):
dialog.set_filter(chosen)
initial = str(options.get("strInitialFile") or "").strip('"')
if initial:
if os.path.isdir(initial):
dialog.set_current_folder(initial)
elif save:
if os.path.isdir(os.path.dirname(initial)):
dialog.set_current_folder(os.path.dirname(initial))
dialog.set_current_name(os.path.basename(initial))
elif os.path.exists(initial):
dialog.set_filename(initial)
elif os.path.isdir(os.path.dirname(initial)):
dialog.set_current_folder(os.path.dirname(initial))
screen = Gdk.Screen.get_default()
if screen is not None:
dialog.set_default_size(screen.get_width(), screen.get_height())
chosen_path = dialog.get_filename() if dialog.run() == Gtk.ResponseType.ACCEPT else None
dialog.destroy()
return chosen_path
class Closed(Exception):
pass
@@ -530,6 +631,65 @@ class Helper:
self.tools_asked = {}
self.tools_checked = None
self.vr_launch = None
self.chooser = None
def open_chooser(self, payload):
try:
request = json.loads(payload)
ident = int(request["id"])
options = request.get("options", {})
if not isinstance(options, dict):
raise ValueError("options are not an object")
except (ValueError, KeyError, TypeError) as e:
say("ignored a file dialog request (%s)" % e)
return
if self.chooser is not None:
self.finish_chooser(ident, None)
return
command = [sys.executable, os.path.realpath(__file__), "--choose-file"]
reaper = os.path.join(self.steam_root, "steamrtarm64", "reaper")
if os.access(reaper, os.X_OK):
command = [reaper, "SteamLaunch", "AppId=769", "--"] + command
try:
proc = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL, start_new_session=True)
proc.stdin.write(json.dumps(options).encode("utf-8"))
proc.stdin.close()
except OSError as e:
say("could not open a file dialog (%s)" % e)
self.finish_chooser(ident, None)
return
say("file dialog open: %s" % (options.get("strTitle") or "untitled"))
self.chooser = (ident, proc)
def chooser_done(self):
ident, proc = self.chooser
self.chooser = None
out = proc.stdout.read().decode("utf-8", "replace")
proc.stdout.close()
proc.wait()
if proc.returncode == 2:
say("file dialog needs GTK 3 and PyGObject, which come with the desktop")
try:
path = json.loads(out) if proc.returncode == 0 else None
except ValueError:
path = None
self.finish_chooser(ident, path if isinstance(path, str) and path else None)
def finish_chooser(self, ident, path):
say("file dialog %s" % ("chose " + path if path else "cancelled"))
self.page.evaluate("window.__droiddeckFiles?.done(%d, %s)" % (ident, json.dumps(path)))
def close_chooser(self):
if self.chooser is not None:
_, proc = self.chooser
self.chooser = None
try:
os.killpg(proc.pid, signal.SIGTERM)
except OSError:
pass
proc.stdout.close()
proc.wait()
def attach(self):
path = shared_context(self.port)
@@ -542,6 +702,8 @@ class Helper:
page.call("Runtime.addBinding", {"name": BINDING})
page.call("Runtime.addBinding", {"name": VR_BINDING})
page.evaluate(VR_JS)
page.call("Runtime.addBinding", {"name": FILE_BINDING})
page.evaluate(FILE_JS)
try:
page.evaluate(TOUR_JS)
except RuntimeError:
@@ -583,9 +745,8 @@ class Helper:
picked = COMPAT["picked_apps"](state)
runnable = {t["name"].lower() for t in live}
apps = sorted(set(installed) | set(picks) | set(prior_auto) | native_choices, key=COMPAT["app_order"])
overrides = COMPAT["requested_games"](
COMPAT["game_requests"](), catalog, [t["name"] for t in live])
apps = sorted(set(apps) | set(overrides), key=COMPAT["app_order"])
asked = [app for app, request in COMPAT["game_requests"]().items() if COMPAT["valid_game_request"](app, request)]
apps = sorted(set(apps) | set(asked), key=COMPAT["app_order"])
current = dict(page.compat("many(%s)" % json.dumps(apps)) or {})
refused = set(apps) - set(current)
refused_native = native_choices & refused
@@ -597,7 +758,6 @@ class Helper:
if isinstance(state.get("auto"), dict):
state["auto"] = prior_auto
native_choices -= refused
overrides = {app: tool for app, tool in overrides.items() if app not in refused}
current["0"] = top["selected"]
native = COMPAT["native_targets"](self.steam_root, apps)
raw_mapping = COMPAT["read_config_mapping"](
@@ -619,6 +779,9 @@ class Helper:
current[app] = ""
elif not current.get(app):
current.pop(app, None)
requests = COMPAT["settled_game_requests"](state, current, catalog)
overrides = COMPAT["requested_games"](requests or {}, catalog, [t["name"] for t in live])
overrides = {app: tool for app, tool in overrides.items() if app not in refused}
changes, auto = COMPAT["plan_mapping"](
current, installed, [t["name"] for t in live], default,
COMPAT["followers"](state, current), native, picks, overrides,
@@ -630,7 +793,8 @@ class Helper:
state.update(
auto={app: tool for app, tool in auto.items() if tool is not COMPAT["NATIVE_CHOICE"]},
native_choices=sorted(refused_native | {app for app, tool in auto.items() if tool is COMPAT["NATIVE_CHOICE"]}),
picked=COMPAT["picked_after"](current, changes), tools=catalog, live=True)
picked=COMPAT["picked_after"](current, changes), tools=catalog, live=True,
games_applied=COMPAT["applied_game_requests"](requests, overrides, state))
state.pop("native", None)
if waiting:
state["pending"] = wanted
@@ -678,6 +842,9 @@ class Helper:
if vr_games and (self.vr_launch is None or self.vr_launch.poll() is not None):
say("preparing SteamVR for library app(s): " + ", ".join(sorted(vr_games)))
self.vr_launch = launch_steamvr()
for e in events:
if called(e, FILE_BINDING) and isinstance(e.get("params", {}).get("payload"), str):
self.open_chooser(e["params"]["payload"])
return events
def serve(self, watcher):
@@ -688,7 +855,11 @@ class Helper:
self.ensure_tools()
while True:
sources = [self.page.ws] + ([watcher] if watcher.fileno() >= 0 else [])
if self.chooser is not None:
sources.append(self.chooser[1].stdout)
ready = [self.page.ws] if self.page.ws.pending() else select.select(sources, [], [], 30 if watcher.fileno() >= 0 else 2)[0]
if self.chooser is not None and self.chooser[1].stdout in ready:
self.chooser_done()
due = False
if self.page.ws in ready:
due = any(called(e, BINDING) for e in self.drain())
@@ -716,6 +887,21 @@ def detach():
COMPAT["write_json"](state_file, state)
def chooser_main():
try:
options = json.load(sys.stdin)
except ValueError:
return 1
try:
path = choose_file(options if isinstance(options, dict) else {})
except (ImportError, ValueError):
return 2
if not path:
return 1
print(json.dumps(path))
return 0
def main():
steam_root = sys.argv[1]
try:
@@ -737,6 +923,7 @@ def main():
last = None
helper.serve(watcher)
except Exception as e:
helper.close_chooser()
if helper.page is not None:
say("lost the client (%s); reattaching" % e)
helper.page.ws.close()
@@ -750,6 +937,8 @@ def main():
if __name__ == "__main__":
if sys.argv[1:2] == ["--choose-file"]:
sys.exit(chooser_main())
signal.signal(signal.SIGTERM, lambda *_: sys.exit(0))
try:
sys.exit(main())
@@ -1,25 +1,57 @@
#!/bin/bash
set -eu
cdn_list="https://client-update.steamstatic.com https://client-update.akamai.steamstatic.com https://client-update.fastly.steamstatic.com"
steam_channel=steamdeck_publicbeta
manifest=steam_client_${steam_channel}_linuxarm64
beta_channel=steamdeck_publicbeta
stable_channel=steamdeck_stable
steam_root=${XDG_DATA_HOME:-$HOME/.local/share}/Steam
channel_state=$steam_root/package/droiddeck-channel
pinned=1
wanted=${BL_STEAM_CHANNEL:-$(cat "$HOME/.config/droiddeck/steam-channel" 2>/dev/null || true)}
case $wanted in
stable|"$stable_channel") steam_channel=$stable_channel ;;
beta|"$beta_channel") steam_channel=$beta_channel ;;
*)
pinned=
steam_channel=$beta_channel
[ "$(cat "$channel_state" 2>/dev/null)" = "$stable_channel" ] && steam_channel=$stable_channel
;;
esac
if [ "${1:-}" = --channel ]; then
echo "$steam_channel"
exit 0
fi
manifest=steam_client_${steam_channel}_linuxarm64
stamp=$steam_root/package/droiddeck-installed
legacy_stamp=$steam_root/package/bannerlator-installed
unconfirmed=$steam_root/package/droiddeck-unconfirmed
repair_request=$HOME/.bl-steam-repair
parts=$steam_root/package/droiddeck-download
if [ -f "$legacy_stamp" ] && [ ! -f "$stamp" ]; then
mv -f "$legacy_stamp" "$stamp" || true
fi
repair=""
fallback=""
starts=0
[ -f "$unconfirmed" ] && starts=$(grep -cx start "$unconfirmed" || true)
if [ -e "$repair_request" ]; then
repair="requested"
elif [ -f "$unconfirmed" ] && ! grep -qx repaired "$unconfirmed" \
&& [ "$(grep -cx start "$unconfirmed")" -ge 2 ]; then
repair="the client was started $(grep -cx start "$unconfirmed") times without showing anything"
elif [ "$starts" -ge 2 ] && ! grep -qx repaired "$unconfirmed"; then
repair="the client was started $starts times without showing anything"
elif [ "$starts" -ge 2 ] && [ -z "$pinned" ] && [ "$steam_channel" = "$beta_channel" ] && [ "${1:-}" != --sync ]; then
repair="the repaired $beta_channel client was started $starts more times without showing anything"
fallback=1
fi
if [ -n "$fallback" ]; then
echo "== STEP $(date -u +%H:%M:%S) falling back to Valve's $stable_channel Steam client: $repair"
steam_channel=$stable_channel
manifest=steam_client_${steam_channel}_linuxarm64
fi
if [ -n "$repair" ]; then
echo "== STEP $(date -u +%H:%M:%S) repairing the Steam client ($repair)"
if [ ! -f "$parts/.repair" ]; then
rm -rf "$parts"
mkdir -p "$parts" && : > "$parts/.repair"
fi
rm -f "$stamp" "$legacy_stamp" "$steam_root/.crash" "$steam_root/steam.pid" \
"$steam_root"/package/steam_client_*.manifest "$steam_root"/package/steam_client_*.installed
for part in "$steam_root"/package/*.zip.*; do
@@ -42,20 +74,99 @@ fi
work=$(mktemp -d)
trap 'rm -rf "$work"' EXIT
cdn=""
for candidate in $cdn_list; do
if curl -fsSL --connect-timeout 10 --max-time 30 --retry 2 --retry-connrefused --retry-delay 3 \
"$candidate/$manifest" -o "$work/manifest"; then
cdn=$candidate
break
nap() {
[ -n "${nap_fd:-}" ] || exec {nap_fd}<> <(:)
read -r -t "$1" -u "$nap_fd" _ 2>/dev/null || :
}
size_of() {
local n=0
[ -f "$1" ] && n=$(wc -c < "$1")
echo $((n))
}
limits=(--connect-timeout 30 --speed-limit 4096 --speed-time 60)
read -r -a delays <<< "${BL_STEAM_RETRY_DELAYS:-5 10 20 30 30}"
step() { echo "== STEP $(date -u +%H:%M:%S) $*"; }
progress() {
local mb=$(( (done_bytes + $(size_of "$1")) / 1000000 ))
[ -z "${3:-}" ] && [ "$mb" = "${shown_mb:-}" ] && [ "$2" = "${shown_part:-}" ] && return 0
shown_mb=$mb shown_part=$2
step "downloading Steam: $2 ($i/$total), $mb of $((total_bytes / 1000000)) MB${3:+ - $3}"
}
fetch() {
local url=$1 dest=$2 size=$3 sum=$4 part=$5 failures=0 bad=0 finished=0 before rc fd wait
while :; do
if [ -f "$dest" ] && { [ "$finished" = 1 ] || { [ "$size" -gt 0 ] && [ "$(size_of "$dest")" -ge "$size" ]; }; }; then
echo "$sum $dest" | sha256sum -c --quiet 2>/dev/null && return 0
rm -f "$dest"
finished=0 bad=$((bad + 1))
[ "$bad" -lt 3 ] || { echo "droiddeck-steam-install: $part does not match its checksum" >&2; return 1; }
fi
before=$(size_of "$dest")
exec {fd}< <(code=$(curl -fsSL "${limits[@]}" -w '%{http_code}' -C - -o "$dest" "$url") && echo "0 $code" || echo "$? $code")
until read -r -t 5 -u "$fd" rc http; do
if [ $? -le 128 ]; then rc=1; break; fi
progress "$dest" "$part"
done
exec {fd}<&-
if [ "$rc" = 0 ]; then finished=1; continue; fi
case "$rc:${http:-}" in
22:416 | 33:*) rm -f "$dest" ;;
22:4??)
echo "droiddeck-steam-install: $part: HTTP $http from ${url%/*}" >&2
return 1
;;
esac
if [ "$(size_of "$dest")" -gt "$before" ]; then failures=0; else failures=$((failures + 1)); fi
if [ "$failures" -gt "${#delays[@]}" ]; then
echo "droiddeck-steam-install: could not download $part (curl exit $rc); what arrived is kept for the next try" >&2
return 1
fi
wait=${delays[$((failures > 0 ? failures - 1 : 0))]}
progress "$dest" "$part" "interrupted (curl exit $rc), trying again in ${wait} s"
nap "$wait"
done
}
fetch_manifest() {
cdn=""
for candidate in $cdn_list; do
if curl -fsSL --connect-timeout 10 --max-time 30 --retry 2 --retry-connrefused --retry-delay 3 \
"$candidate/$manifest" -o "$work/manifest"; then
cdn=$candidate
break
fi
done
[ -n "$cdn" ] || { echo "droiddeck-steam-install: no Steam client CDN answered for $manifest" >&2; exit 1; }
cdn_order=("$cdn")
for candidate in $cdn_list; do
[ "$candidate" = "$cdn" ] || cdn_order+=("$candidate")
done
version=$(awk -F'"' '$2 == "version" { print $4; exit }' "$work/manifest")
awk -F'"' '
/^\t"/ && NF >= 3 && $4 == "" { block = $2 }
$2 == "file" { file[block] = $4 }
$2 == "sha2" { sha[block] = $4 }
$2 == "size" { size[block] = $4 }
END { for (b in file) if (b ~ /_all$/ || b ~ /_linuxarm64_linuxarm64$/) print b, file[b], sha[b], size[b] + 0 }
' "$work/manifest" | sort > "$work/parts"
[ -s "$work/parts" ] && return 0
echo "droiddeck-steam-install: no client components in $manifest; its blocks are:" \
"$(awk -F'"' '/^\t"/ && NF >= 3 && $4 == "" { printf "%s ", $2 }' "$work/manifest")" >&2
return 1
}
if ! fetch_manifest; then
if [ -n "$sync" ] || [ -n "$pinned" ] || [ "$steam_channel" = "$stable_channel" ]; then
exit 1
fi
done
[ -n "$cdn" ] || { echo "droiddeck-steam-install: no Steam client CDN answered for $manifest" >&2; exit 1; }
cdn_order=("$cdn")
for candidate in $cdn_list; do
[ "$candidate" = "$cdn" ] || cdn_order+=("$candidate")
done
version=$(awk -F'"' '$2 == "version" { print $4; exit }' "$work/manifest")
echo "== STEP $(date -u +%H:%M:%S) falling back to Valve's $stable_channel Steam client: $manifest has no arm64 client"
steam_channel=$stable_channel
manifest=steam_client_${steam_channel}_linuxarm64
fallback=1
fetch_manifest || exit 1
fi
if [ -n "$sync" ]; then
installed=$(awk -F'"' '$2 == "version" { print $4; exit }' "$steam_root/package/$manifest.manifest" 2>/dev/null || true)
if [ -x "$steam_root/steamrtarm64/steam" ] && [ "$installed" = "$version" ]; then
@@ -64,31 +175,36 @@ if [ -n "$sync" ]; then
fi
echo "== STEP $(date -u +%H:%M:%S) updating the arm64 Steam client to $version (was ${installed:-none}) for the x86-64 client"
fi
awk -F'"' '
/^\t"/ && NF >= 3 && $4 == "" { block = $2 }
$2 == "file" { file[block] = $4 }
$2 == "sha2" { sha[block] = $4 }
END { for (b in file) if (b ~ /_all$/ || b ~ /_linuxarm64_linuxarm64$/) print b, file[b], sha[b] }
' "$work/manifest" | sort > "$work/parts"
[ -s "$work/parts" ] || { echo "droiddeck-steam-install: no client components in $manifest" >&2; exit 1; }
total=$(grep -c . "$work/parts" 2>/dev/null || echo 0)
total_bytes=$(awk '{ n += $4 } END { print n + 0 }' "$work/parts")
mkdir -p "$steam_root/package"
while read -r block file sum; do
mkdir -p "$parts"
for left in "$parts"/*; do
[ -e "$left" ] || continue
name=${left##*/}
name=${name%.unpacked}
grep -qF " $name " "$work/parts" || rm -rf "$left"
done
done_bytes=0
while read -r block file sum size; do
i=$((${i:-0} + 1))
echo "== STEP $(date -u +%H:%M:%S) downloading Steam: $block ($i/$total)"
if [ -f "$parts/$file.unpacked" ]; then
done_bytes=$((done_bytes + size))
continue
fi
progress "$parts/$file" "$block"
fetched=""
for host in "${cdn_order[@]}"; do
if curl -fsSL --connect-timeout 10 --speed-limit 1024 --speed-time 60 --max-time 1800 \
"$host/$file" -o "$work/$file" && echo "$sum $work/$file" | sha256sum -c --quiet; then
if fetch "$host/$file" "$parts/$file" "$size" "$sum" "$block"; then
fetched=$host
break
fi
rm -f "$work/$file"
done
[ -n "$fetched" ] || { echo "droiddeck-steam-install: $file failed on every CDN" >&2; exit 1; }
unzip -qo "$work/$file" -d "$steam_root"
rm -f "$work/$file"
unzip -qo "$parts/$file" -d "$steam_root"
: > "$parts/$file.unpacked"
rm -f "$parts/$file"
done_bytes=$((done_bytes + size))
done < "$work/parts"
find "$steam_root" -depth -name '*\\*' | while read -r odd; do
fixed=${odd//\\//}
@@ -117,6 +233,11 @@ ln -sfn "$steam_root/linuxarm64" "$HOME/.steam/sdkarm64"
ln -sfn "$steam_root/steamrtarm64" "$HOME/.steam/binarm64"
ln -sfn "$steam_root/linux32" "$HOME/.steam/sdk32"
echo "$version" > "$stamp"
rm -rf "$parts"
if [ -n "$fallback" ]; then
echo "$stable_channel" > "$channel_state"
echo "== STEP $(date -u +%H:%M:%S) the Steam client now follows $stable_channel (beta in ~/.config/droiddeck/steam-channel returns to $beta_channel)"
fi
if [ -n "$repair" ]; then
echo repaired > "$unconfirmed"
rm -f "$repair_request"
@@ -12,6 +12,10 @@ case $target in
esac
if [ "$ui" = desktop ] && [ "${BL_DESKTOP:-}" = 1 ]; then
case ",${MESA_VK_WSI_DEBUG:-}," in
*,sw,*) ;;
*) export MESA_VK_WSI_DEBUG=${MESA_VK_WSI_DEBUG:+$MESA_VK_WSI_DEBUG,}sw ;;
esac
if [ "${BL_STEAM_CLIENT_ARCH:-}" = x86_64 ]; then
client_home=${BL_X64_HOME:-${HOME:-/root}/.droiddeck-x64}
client=(/usr/local/bin/droiddeck-steam-x64 --exec)
@@ -0,0 +1,61 @@
#!/usr/bin/python3
"""Sets the Steam client's shader pre-caching (Settings > Downloads), before the client starts.
droiddeck-steam-shaders <0|1> <steam root>...
The client stores the toggle as InstallConfigStore/Software/Valve/Steam/ShaderCacheManager/
DisableShaderCache in config/config.vdf: "1" when off, "0" when on. It keeps the setting in memory
and writes config.vdf back on exit, so this runs only while the client is stopped. The launcher
passes a value only after its own toggle changes; otherwise the client's toggle stays the user's."""
from pathlib import Path
import runpy
import sys
VDF = runpy.run_path(str(Path(__file__).with_name("droiddeck-steam-ui-scale")))
PATH = ("Software", "Valve", "Steam", "ShaderCacheManager", "DisableShaderCache")
def set_text(text, enabled):
value = "0" if enabled else "1"
updated, changed = VDF["seed_value"](text, PATH, value)
if changed:
return updated, True
block = VDF["parse"](text).get("InstallConfigStore")
for section in PATH[:-1]:
block = block.get(section)
current = block.get(PATH[-1])
if isinstance(current, VDF["Block"]):
raise ValueError("invalid DisableShaderCache setting")
if current == value:
return text, False
at = block.offset(PATH[-1])
end = VDF["TOKEN"].match(text, at).end()
return text[:at] + f'"{value}"' + text[end:], True
def apply(steam_root, enabled):
config = Path(steam_root) / "config/config.vdf"
text = config.read_text() if config.exists() else '"InstallConfigStore"\n{\n}\n'
updated, changed = set_text(text, enabled)
if changed:
VDF["atomic_write"](config, updated)
return changed
if __name__ == "__main__":
if len(sys.argv) < 3 or sys.argv[1] not in ("0", "1"):
print("usage: droiddeck-steam-shaders <0|1> <steam root>...", file=sys.stderr)
sys.exit(2)
enabled = sys.argv[1] == "1"
status = 0
for root in sys.argv[2:]:
if not Path(root).is_dir():
continue
try:
if apply(root, enabled):
print(f"== steam: shader pre-caching {'on' if enabled else 'off'} in {root}")
except (OSError, ValueError, RecursionError) as error:
print(f"== steam: left shader pre-caching unchanged in {root}: {error}", file=sys.stderr)
status = 1
sys.exit(status)
+273
View File
@@ -0,0 +1,273 @@
#!/usr/bin/python3
import json
import os
import re
import runpy
import sys
NOT_GAMES = frozenset((
"228980", "1070560", "1391110", "1628350", "1493710", "3127680",
"4183110", "4185400", "4427310", "4628740",
))
TOOL_DIR = re.compile(r"(steam ?linux ?runtime.*|proton.*|steamworks shared|fex|steamvr)", re.I)
AUTOMATIC = ("", "droiddeck-direct", "droiddeck-fex", "droiddeck-proton-arm64", "droiddeck-proton-11-arm64")
LINUX_TOOLS = ("droiddeck-direct", "droiddeck-fex")
STATE = ".droiddeck-shared.json"
LABELS = {"arm64": "ARM64 client games", "x86-64": "x86-64 client games"}
def say(message):
print("droiddeck-steam-share: " + message)
def read(path):
try:
with open(path, encoding="utf-8", errors="surrogateescape") as f:
return f.read()
except OSError:
return None
def write(path, text):
staged = path + ".droiddeck-new"
with open(staged, "w", encoding="utf-8", errors="surrogateescape") as f:
f.write(text)
os.replace(staged, path)
def field(text, key):
m = re.search(r'"%s"\s+"([^"]*)"' % re.escape(key), text or "", re.I)
return m.group(1) if m else None
def number(text, key):
value = field(text, key)
return int(value) if value and value.isdigit() else 0
def same(a, b):
return os.path.realpath(a) == os.path.realpath(b)
def libraries(root, skip):
found = [root] + [p.replace("\\\\", "\\") for p in
re.findall(r'"path"\s+"((?:[^"\\]|\\.)*)"', read(os.path.join(root, "steamapps", "libraryfolders.vdf")) or "")]
return [p for p in dict.fromkeys(found) if not any(same(p, s) for s in skip)]
def installs(libs):
games = {}
for library in libs:
steamapps = os.path.join(library, "steamapps")
try:
names = sorted(os.listdir(steamapps))
except OSError:
continue
for name in names:
m = re.fullmatch(r"appmanifest_(\d+)\.acf", name)
if not m or m.group(1) in NOT_GAMES or m.group(1) in games:
continue
text = read(os.path.join(steamapps, name))
folder = field(text, "installdir")
if (not folder or folder in (".", "..") or "/" in folder or TOOL_DIR.fullmatch(folder)
or not number(text, "StateFlags") & 4
or not os.path.isdir(os.path.join(steamapps, "common", folder))):
continue
games[m.group(1)] = (steamapps, text, folder)
return games
def link(path, target):
if os.path.islink(path):
if os.readlink(path) == target:
return True
os.unlink(path)
elif os.path.lexists(path):
return False
os.symlink(target, path)
return True
def unlink(path):
if os.path.islink(path):
os.unlink(path)
def emptied(src, folder):
path = os.path.join(src, "common", folder)
return not os.path.isdir(path) or not os.listdir(path)
def sync(view, source, own):
steamapps = os.path.join(view, "steamapps")
for sub in ("common", "compatdata"):
os.makedirs(os.path.join(steamapps, sub), exist_ok=True)
state = {}
try:
state = json.loads(read(os.path.join(view, STATE)) or "{}")
except ValueError:
pass
managed = {app: tuple(v) for app, v in state.get("shared", {}).items() if isinstance(v, list) and len(v) == 2}
hidden = state.get("hidden", {})
shared, back = {}, []
for app, (src, folder) in managed.items():
if app in source and app not in own:
continue
manifest = os.path.join(steamapps, "appmanifest_%s.acf" % app)
if app not in own and not os.path.isfile(manifest) and emptied(src, folder) and os.path.isfile(os.path.join(src, "appmanifest_%s.acf" % app)):
os.unlink(os.path.join(src, "appmanifest_%s.acf" % app))
unlink(os.path.join(steamapps, "common", folder))
unlink(os.path.join(steamapps, "compatdata", app))
if os.path.isfile(manifest):
os.unlink(manifest)
for app, (src, text, folder) in sorted(source.items(), key=lambda item: int(item[0])):
if app in own:
continue
stamp = number(text, "LastUpdated")
if hidden.get(app) == stamp:
continue
hidden.pop(app, None)
manifest = os.path.join(steamapps, "appmanifest_%s.acf" % app)
mine = read(manifest)
if app in managed and mine is None:
unlink(os.path.join(steamapps, "common", folder))
unlink(os.path.join(steamapps, "compatdata", app))
if emptied(src, folder):
os.unlink(os.path.join(src, "appmanifest_%s.acf" % app))
else:
hidden[app] = stamp
continue
if not link(os.path.join(steamapps, "common", folder), os.path.join(src, "common", folder)):
continue
if os.path.isdir(os.path.join(src, "compatdata", app)):
link(os.path.join(steamapps, "compatdata", app), os.path.join(src, "compatdata", app))
if mine is not None and number(mine, "LastUpdated") > stamp:
write(os.path.join(src, "appmanifest_%s.acf" % app), mine)
back.append(app)
elif mine != text:
write(manifest, text)
shared[app] = [src, folder]
state = {"shared": shared, "hidden": hidden}
write(os.path.join(view, STATE), json.dumps(state, indent=1, sort_keys=True) + "\n")
return shared, back
def tools(root):
names = set()
folder = os.path.join(root, "compatibilitytools.d")
try:
entries = os.listdir(folder)
except OSError:
return names
for entry in entries:
text = read(os.path.join(folder, entry, "compatibilitytool.vdf")) or ""
m = re.search(r'"compat_tools"\s*\{\s*"([^"]+)"', text)
if m:
names.add(m.group(1))
return names
def mapping_block(text):
m = re.search(r'"CompatToolMapping"\s*\{', text)
if not m:
return None
depth, k = 1, m.end()
while depth and k < len(text):
depth += {"{": 1, "}": -1}.get(text[k], 0)
k += 1
return m.end(), k - 1
def entries(text):
span = mapping_block(text)
found = {}
if not span:
return found
inner = text[span[0]:span[1]]
for m in re.finditer(r'"(\d+)"\s*\{([^{}]*)\}', inner):
name = re.search(r'"name"\s*"([^"]*)"', m.group(2))
found.setdefault(m.group(1), name.group(1) if name else "")
return found
def set_tools(config, wanted):
text = read(config)
if text is None or not wanted:
return []
span = mapping_block(text)
if not span:
return []
inner = text[span[0]:span[1]]
changed = []
for app, tool in sorted(wanted.items(), key=lambda item: int(item[0])):
m = re.search(r'"%s"\s*\{([^{}]*)\}' % app, inner)
if m:
name = re.search(r'"name"\s*"([^"]*)"', m.group(1))
name = name.group(1) if name else ""
if name == tool or not (canonical(name) in map(canonical, AUTOMATIC) or name.startswith("proton_")):
continue
if name and (name in LINUX_TOOLS) == (tool in LINUX_TOOLS):
continue
inner = inner[:m.start()] + inner[m.end():]
inner = ('\n\t\t\t\t\t"%s"\n\t\t\t\t\t{\n\t\t\t\t\t\t"name"\t\t"%s"\n\t\t\t\t\t\t"config"\t\t""\n'
'\t\t\t\t\t\t"priority"\t\t"250"\n\t\t\t\t\t}' % (app, tool)) + inner
changed.append(app)
if changed:
write(config, text[:span[0]] + inner + text[span[1]:])
return changed
def canonical(name):
return re.sub(r"arm64|aarch64", "a64", name)
def translate(name, here, available):
if name == "droiddeck-fex" and here == "x86-64":
return "droiddeck-direct"
if name == "droiddeck-direct" and here == "arm64":
return "droiddeck-fex"
return {canonical(a): a for a in available}.get(canonical(name))
def library_helper():
sibling = os.path.join(os.path.dirname(os.path.realpath(__file__)), "droiddeck-steam-library")
return runpy.run_path(sibling if os.path.isfile(sibling) else "/usr/local/bin/droiddeck-steam-library")
def main(argv):
if len(argv) != 5 or argv[0] not in LABELS:
say("usage: droiddeck-steam-share arm64|x86-64 ARM_STEAM X64_STEAM X64_CARD SHARED_DIR")
return 2
here, arm, x64, x64_card, shared_dir = argv
views = {name: os.path.join(shared_dir, name) for name in LABELS}
roots = {"arm64": arm, "x86-64": x64}
other = "x86-64" if here == "arm64" else "arm64"
skip = list(views.values()) + [x64, x64_card]
arm_libs = libraries(arm, skip)
x64_libs = [x64] + [p for p in libraries(x64, list(views.values()) + [arm]) if not same(p, x64)]
games = {"arm64": installs(arm_libs), "x86-64": installs(x64_libs)}
view = views[other]
shared, back = sync(view, games[other], games[here])
helper = library_helper()
if not any(re.fullmatch(r"appmanifest_\d+\.acf", n) for n in os.listdir(os.path.join(view, "steamapps"))):
helper["forget"](roots[here], view)
return 0
helper["register"](roots[here], view, LABELS[other])
helper["relabel"](roots[here], view, LABELS[other])
picks = entries(read(os.path.join(roots[other], "config", "config.vdf")) or "")
available = tools(roots[here]) | {"droiddeck-direct" if here == "x86-64" else "droiddeck-fex"}
wanted = {}
for app in shared:
tool = translate(picks.get(app) or picks.get("0", ""), here, available)
if tool:
wanted[app] = tool
changed = set_tools(os.path.join(roots[here], "config", "config.vdf"), wanted)
say("%d game(s) from the %s client%s%s" % (
len(shared), other,
"; tools set for %s" % " ".join(changed) if changed else "",
"; manifests sent back for %s" % " ".join(back) if back else ""))
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv[1:]))
@@ -18,13 +18,17 @@ TAG = "droiddeck-app"
def account_dir(steam_root):
"""The most recent account's userdata folder, else the only one that is not 0."""
users = os.path.join(steam_root, "config", "loginusers.vdf")
recent = None
recent, best = None, None
try:
with open(users, encoding="utf-8", errors="replace") as f:
text = f.read()
for block in re.finditer(r'"(\d{5,})"\s*\{([^}]*)\}', text):
if re.search(r'"MostRecent"\s*"1"', block.group(2)):
recent = int(block.group(1))
stamp = re.search(r'"timestamp"\s*"(\d+)"', block.group(2))
rank = (bool(re.search(r'"MostRecent"\s*"1"', block.group(2))),
bool(re.search(r'"AutoLogin"\s*"1"', block.group(2))),
int(stamp.group(1)) if stamp else 0)
if any(rank) and (best is None or rank >= best):
recent, best = int(block.group(1)), rank
except OSError:
pass
userdata = os.path.join(steam_root, "userdata")
@@ -26,9 +26,10 @@ TOKEN = re.compile(r'\s+|//[^\n]*|"(?:\\.|[^"\\])*"|[{}]')
class Block:
def __init__(self, pairs, end):
def __init__(self, pairs, end, offsets=()):
self.pairs = pairs
self.end = end
self.offsets = offsets
def get(self, name):
matches = [value for key, value in self.pairs if key.lower() == name.lower()]
@@ -36,6 +37,9 @@ class Block:
raise ValueError("duplicate UI setting")
return matches[0] if matches else None
def offset(self, name):
return next(at for (key, _), at in zip(self.pairs, self.offsets) if key.lower() == name.lower())
def parse(text):
tokens = []
@@ -51,17 +55,17 @@ def parse(text):
raise ValueError("invalid config.vdf")
def block(index, nested=False):
pairs = []
pairs, offsets = [], []
while index < len(tokens):
token, offset = tokens[index]
if token == '}':
if not nested:
raise ValueError("unexpected closing brace")
return Block(pairs, offset), index + 1
return Block(pairs, offset, offsets), index + 1
if not token.startswith('"') or index + 1 == len(tokens):
raise ValueError("missing config value")
key = token[1:-1]
value = tokens[index + 1][0]
value, at = tokens[index + 1]
index += 2
if value == '{':
value, index = block(index, True)
@@ -70,9 +74,10 @@ def parse(text):
else:
raise ValueError("invalid config value")
pairs.append((key, value))
offsets.append(at)
if nested:
raise ValueError("unclosed config block")
return Block(pairs, len(text)), index
return Block(pairs, len(text), offsets), index
return block(0)[0]
@@ -87,7 +87,7 @@ x64_map_direct() {
[ -f "$STEAM_X64/config/config.vdf" ] || return 0
if [ "$mode" = write ] && pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1; then return 0; fi
python3 - "$mode" "$STEAM_X64/config/config.vdf" "$STEAM_X64/appcache/appinfo.vdf" "$X64_HOME/direct-auto.json" \
"$X64_HOME/direct-sniper" "$STEAM_X64/steamapps:/mnt/droiddeck-sd/x86-64/steamapps" "$(x64_default_tool)" \
"$X64_HOME/direct-sniper" "$STEAM_X64/steamapps:/mnt/droiddeck-sd/x86-64/steamapps:$X64_HOME/shared/arm64/steamapps" "$(x64_default_tool)" \
"$REAL_HOME/.bl-compat-pending" ${BL_X64_DIRECT_APPS:-550} \
<<'PY' || { [ "$mode" = live ] || step "could not map titles to DroidDeck direct"; }
# Steam does not swap an installed build when the tool changes: a title installed for Windows stays on Proton.
@@ -520,39 +520,8 @@ ln -sfn "$STEAM_X64/ubuntu12_32" "$X64_HOME/.steam/bin32"
ln -sfn "$STEAM_X64/ubuntu12_64" "$X64_HOME/.steam/bin64"
ln -sfn "$STEAM_X64/linux32" "$X64_HOME/.steam/sdk32"
ln -sfn "$STEAM_X64/linux64" "$X64_HOME/.steam/sdk64"
# The client's bwrap probe (steam-runtime-check-requirements) needs user namespaces, which no Android app has.
srt_real=$STEAM_X64/steamrt64/pv-runtime/steam-runtime-steamrt
srt_shim=$X64_HOME/steamrt-shim
if [ -d "$srt_real" ]; then
rm -rf "$srt_shim"
mkdir -p "$srt_shim/bin"
for e in "$srt_real"/* "$srt_real"/.[!.]*; do
[ -e "$e" ] || continue
[ "$(basename "$e")" = bin ] || ln -s "$e" "$srt_shim/$(basename "$e")"
done
for e in "$srt_real"/bin/*; do ln -s "$e" "$srt_shim/bin/$(basename "$e")"; done
rm -f "$srt_shim/bin/steam-runtime-check-requirements"
printf '#!/bin/sh
exit 0
' > "$srt_shim/bin/steam-runtime-check-requirements"
chmod 755 "$srt_shim/bin/steam-runtime-check-requirements"
rm -f "$srt_shim/bin/steam-runtime-launch-client"
cat > "$srt_shim/bin/steam-runtime-launch-client" <<'LAUNCH'
#!/bin/sh
while [ $# -gt 0 ]; do
case $1 in
--) shift; break ;;
--directory=*) cd "${1#--directory=}" || exit 127 ;;
--env=*) export "${1#--env=}" ;;
--unset-env=*) unset "${1#--unset-env=}" ;;
esac
shift
done
[ $# -gt 0 ] || exit 0
exec "$@"
LAUNCH
chmod 755 "$srt_shim/bin/steam-runtime-launch-client"
fi
# Valve's Steam Runtime container needs user namespaces and a session-bus launcher; steamrt-shim stands in for both.
droiddeck-steamrt-shim "$STEAM_X64/steamrt64" "$X64_HOME/steamrt-shim" || rm -rf "$X64_HOME/steamrt-shim"
# Valve's platform libraries ship without soname links (pressure-vessel makes them); ldconfig adds them here.
srt_libs=$X64_HOME/steamrt-libs
rm -rf "$srt_libs"
@@ -641,6 +610,7 @@ RUN
printf '"InstallConfigStore"\n{\n\t"Software"\n\t{\n\t\t"Valve"\n\t\t{\n\t\t\t"Steam"\n\t\t\t{\n\t\t\t\t"CompatToolMapping"\n\t\t\t\t{\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n}\n' \
> "$STEAM_X64/config/config.vdf"
fi
x64_share x86-64
x64_map_direct
# Each wrapper execs droiddeck-x64-arm-proton through an arm64 binary, which FEX hands straight to the CPU.
arm_tools=$ARM_STEAM/compatibilitytools.d
@@ -690,9 +660,9 @@ VDF
# Each client keeps its own libraries; written only while no x86 client runs, as it rewrites these on exit.
if ! pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1; then
listing_ok=0
if python3 - "$STEAM_X64" "${BL_X64_STEAM_LIBRARIES:-}" "$STEAM_X64/config/libraryfolders.vdf" "$STEAM_X64/steamapps/libraryfolders.vdf" <<'PY'; then
if BL_X64_SHARED=$X64_HOME/shared/arm64 python3 - "$STEAM_X64" "${BL_X64_STEAM_LIBRARIES:-}" "$STEAM_X64/config/libraryfolders.vdf" "$STEAM_X64/steamapps/libraryfolders.vdf" <<'PY'; then
import json, os, re, sys
keep = {os.path.realpath(sys.argv[1])}
keep = {os.path.realpath(sys.argv[1]), os.path.realpath(os.environ["BL_X64_SHARED"])}
# Without the session's list nothing is known about the card: leave the folders as they are.
if not sys.argv[2]:
sys.exit(3)
@@ -942,6 +912,14 @@ x64_exec() {
exec "${BL_FEX:-/usr/local/bin/FEX}" "$STEAM_X64/steamrt64/steam" "$@"
}
x64_share() {
pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1 && return 0
pgrep -f 'steamrtarm64/steam( |$)' >/dev/null 2>&1 && return 0
[ -d "$STEAM_X64/steamapps" ] && [ -d "$ARM_STEAM/steamapps" ] || return 0
droiddeck-steam-share "$1" "$ARM_STEAM" "$STEAM_X64" /mnt/droiddeck-sd/x86-64 "$X64_HOME/shared" ||
step "could not share the games between the clients"
}
# Steam renews its token every few days and refuses old copies: copy the newest every start, never while a client runs.
x64_sync_login() {
pgrep -f 'steamrt64/steam( |$)' >/dev/null 2>&1 && return 0
@@ -1058,6 +1036,7 @@ PY
case "${1:-}" in
--sync-login) x64_sync_login; exit 0 ;;
--share) x64_share arm64; exit 0 ;;
--prepare) x64_prepare; exit 0 ;;
--exec) shift; x64_exec "$@" ;;
--gpu) x64_gpu; exit $? ;;
+58
View File
@@ -0,0 +1,58 @@
#!/bin/bash
# droiddeck-steamrt-shim <client runtime dir> <shim dir>
# Builds <shim dir> from the Steam Runtime container the client carries and exits 0, or removes it and exits 1
# when the client carries none.
set -eu
client=$1
shim=$2
srt_real=$client/pv-runtime/steam-runtime-steamrt
if [ ! -d "$srt_real" ]; then
probe=$(find "$client" -maxdepth 4 -name steam-runtime-check-requirements -path '*/bin/*' -print -quit 2>/dev/null || true)
srt_real=${probe:+${probe%/bin/*}}
fi
if [ -z "$srt_real" ] || [ ! -d "$srt_real" ]; then
rm -rf "$shim"
exit 1
fi
rm -rf "$shim"
trap 'rm -rf "$shim"' ERR
mkdir -p "$shim/bin"
for e in "$srt_real"/* "$srt_real"/.[!.]*; do
[ -e "$e" ] || continue
[ "$(basename "$e")" = bin ] || ln -s "$e" "$shim/$(basename "$e")"
done
for e in "$srt_real"/bin/*; do
[ -e "$e" ] || continue
ln -s "$e" "$shim/bin/$(basename "$e")"
done
# The client's bwrap probe (steam-runtime-check-requirements) needs user namespaces, which no Android app has.
rm -f "$shim/bin/steam-runtime-check-requirements"
printf '#!/bin/sh
exit 0
' > "$shim/bin/steam-runtime-check-requirements"
chmod 755 "$shim/bin/steam-runtime-check-requirements"
# Valve's launcher asks a service on the session bus; proot is already the container, so the command runs here.
rm -f "$shim/bin/steam-runtime-launch-client"
cat > "$shim/bin/steam-runtime-launch-client" <<'LAUNCH'
#!/bin/sh
while [ $# -gt 0 ]; do
case $1 in
--) shift; break ;;
--directory=*) cd "${1#--directory=}" || exit 127 ;;
--env=*) export "${1#--env=}" ;;
--unset-env=*) unset "${1#--unset-env=}" ;;
--directory|--env|--unset-env)
[ $# -ge 2 ] || exit 127
case $1 in
--directory) cd "$2" || exit 127 ;;
--env) export "$2" ;;
--unset-env) unset "$2" ;;
esac
shift ;;
esac
shift
done
[ $# -gt 0 ] || exit 0
exec "$@"
LAUNCH
chmod 755 "$shim/bin/steam-runtime-launch-client"
@@ -15,7 +15,18 @@ import threading
BIN = Path(__file__).resolve().parent
RUNTIME = Path('/usr/local/lib/droiddeck-xbox')
DLLS = ('xgameruntime.dll', 'winhttp.dll', 'windows.web.dll', 'twinapi.appcore.dll', 'libnghttp2.dll')
DLLS = ('xgameruntime.dll', 'winhttp.dll', 'windows.web.dll', 'twinapi.appcore.dll', 'wintypes.dll', 'libnghttp2.dll')
CLASSES = {
'twinapi.appcore.dll': ('Windows.ApplicationModel.DataTransfer.DataTransferManager',
'Windows.Security.ExchangeActiveSyncProvisioning.EasClientDeviceInformation',
'Windows.System.Profile.AnalyticsInfo', 'Windows.System.UserProfile.AdvertisingManager',
'Windows.UI.ViewManagement.ApplicationView'),
'windows.web.dll': ('Windows.Data.Json.JsonArray', 'Windows.Data.Json.JsonObject', 'Windows.Data.Json.JsonValue'),
'wintypes.dll': ('Windows.Foundation.PropertyValue', 'Windows.Foundation.Collections.PropertySet',
'Windows.Foundation.Metadata.ApiInformation', 'Windows.Storage.Streams.Buffer',
'Windows.Storage.Streams.DataWriter'),
}
CLASS_KEY = 'Software\\Microsoft\\WindowsRuntime\\ActivatableClassId\\'
def bridge(upstream):
@@ -102,6 +113,30 @@ def bridge(upstream):
return server.getsockname()[1], key.decode('ascii'), close
def register_classes(proton, prefix, env):
try:
registry = (prefix / 'system.reg').read_text(encoding='utf-8', errors='replace')
except OSError:
return
missing = [(name, dll) for dll, names in CLASSES.items() for name in names
if '[%s]' % (CLASS_KEY + name).replace('\\', '\\\\') not in registry]
if not missing:
return
text = 'Windows Registry Editor Version 5.00\r\n\r\n' + ''.join(
'[HKEY_LOCAL_MACHINE\\%s%s]\r\n"DllPath"="C:\\\\windows\\\\system32\\\\%s"\r\n\r\n' % (CLASS_KEY, name, dll)
for name, dll in missing)
with tempfile.TemporaryDirectory(prefix='droiddeck-xbox-') as temporary:
source = Path(temporary) / 'classes.reg'
source.write_bytes(b'\xff\xfe' + text.encode('utf-16-le'))
try:
failed = subprocess.run([proton, 'run', 'reg.exe', 'import', 'Z:' + str(source).replace('/', '\\')],
stdout=sys.stderr, env=env, timeout=90).returncode != 0
except subprocess.TimeoutExpired:
failed = True
if failed:
print('droiddeck-xbox: Windows Runtime class registration failed; launching without it', file=sys.stderr)
def wine(argv, source_env=None):
source_env = os.environ if source_env is None else source_env
with open(source_env['DROIDDECK_XBOX_COMMAND_FILE'], encoding='utf-8') as file:
@@ -109,7 +144,8 @@ def wine(argv, source_env=None):
if len(command) < 3 or command[1] != 'waitforexitandrun' or len(argv) != 1:
raise ValueError('Invalid Xbox Proton invocation')
env = dict(source_env)
env.pop('DROIDDECK_XBOX_CREDENTIAL_SOCKET', None)
for name in ('DROIDDECK_XBOX_CREDENTIAL_SOCKET', 'DROIDDECK_XBOX_CREDENTIAL_PORT', 'DROIDDECK_XBOX_CREDENTIAL_KEY'):
env.pop(name, None)
env.pop('DROIDDECK_XBOX_COMMAND_FILE', None)
prefix = Path(source_env['STEAM_COMPAT_DATA_PATH']) / 'pfx'
prefix.parent.mkdir(parents=True, exist_ok=True)
@@ -124,6 +160,7 @@ def wine(argv, source_env=None):
if target.is_symlink():
target.unlink()
shutil.copyfile(RUNTIME / 'windows' / name, target)
register_classes(command[0], prefix, env)
overrides = ';'.join(name[:-4] + '=n' for name in DLLS if name != 'libnghttp2.dll')
env['WINEDLLOVERRIDES'] = overrides + ';' + env.get('WINEDLLOVERRIDES', '')
return subprocess.call([*command[:2], argv[0], *command[3:]], env=env)
@@ -171,7 +208,8 @@ def launch(command, env):
owned_env = dict(env, DROIDDECK_XBOX_ACTIVE='1', DROIDDECK_XBOX_COMMAND_FILE=str(context),
XODUS_SOCKET=reply['socket'], XODUS_BRIDGE_PORT=str(port), XODUS_BRIDGE_KEY=key,
XODUS_LOG='off', RUST_LOG='off', XODUS_SAVE_SYNC='auto' if sidecar.get('cloud', True) else 'off')
owned_env.pop('DROIDDECK_XBOX_CREDENTIAL_SOCKET', None)
for name in ('DROIDDECK_XBOX_CREDENTIAL_SOCKET', 'DROIDDECK_XBOX_CREDENTIAL_PORT', 'DROIDDECK_XBOX_CREDENTIAL_KEY'):
owned_env.pop(name, None)
if reply.get('playfab'):
owned_env['XODUS_XSTS_PLAYFAB'] = reply['playfab']
content = folder / '.xbox-content'
@@ -1113,10 +1113,89 @@ def requested_tool(request, catalog):
def game_requests(directory=None):
value = read_json(state_path("games.json", directory))
if value.get("version") != 1 or not isinstance(value.get("games"), dict):
return {}
return value["games"]
return read_game_requests(directory)[0]
def read_game_requests(directory=None):
try:
with open(state_path("games.json", directory), encoding="utf-8") as f:
text = f.read()
value = json.loads(text)
except (OSError, ValueError):
return {}, None
if not isinstance(value, dict) or value.get("version") != 1 or not isinstance(value.get("games"), dict):
return {}, text
return value["games"], text
def write_game_requests(requests, original, directory=None):
path = state_path("games.json", directory)
try:
with open(path, encoding="utf-8") as f:
if f.read() != original:
return False
except OSError:
if original is not None:
return False
return write_json(path, {"version": 1, "games": requests})
def valid_game_request(app, request):
return (isinstance(app, str) and re.fullmatch(r"[1-9][0-9]*", app) is not None and int(app) <= 0xFFFFFFFF and
(request is None or isinstance(request, dict) and isinstance(request.get("dir"), str) and
request["dir"] != "" and isinstance(request.get("valve"), bool)))
def settle_game_requests(requests, state, current, catalog, missing_is_cleared=False):
recorded = state.get("games_applied")
if isinstance(recorded, dict):
applied = dict(recorded)
else:
applied = dict(requests) if "tools" in state else {}
by_name = {t["name"]: t for t in catalog}
out = dict(requests)
for app, request in requests.items():
if not valid_game_request(app, request) or app not in applied or applied[app] != request:
continue
if request is None:
del out[app]
continue
wanted = requested_tool(request, catalog)
if wanted is None:
continue
if app in current:
picked = current[app]
elif missing_is_cleared:
picked = ""
else:
continue
if picked == wanted:
continue
tool = by_name.get(picked)
if tool and tool["dir"]:
out[app] = {"valve": tool["valve"], "dir": tool["dir"]}
else:
del out[app]
return out, out != requests
def settled_game_requests(state, current, catalog, missing_is_cleared=False, directory=None):
for _ in range(2):
requests, text = read_game_requests(directory)
settled, moved = settle_game_requests(requests, state, current, catalog, missing_is_cleared)
if not moved or write_game_requests(settled, text, directory):
return settled
return None
def applied_game_requests(requests, overrides, state):
recorded = state.get("games_applied")
before = recorded if isinstance(recorded, dict) else {}
if requests is None:
return dict(before)
return {app: request if app in overrides and overrides[app] is not DEFERRED_GAME_TOOL else before[app]
for app, request in requests.items()
if app in overrides and overrides[app] is not DEFERRED_GAME_TOOL or app in before}
def requested_games(requests, catalog, runnable=None):
@@ -1306,7 +1385,8 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
else:
default = state.get("default") if state.get("default") in names else TOOL
steam_root = os.path.dirname(os.path.dirname(os.path.abspath(config_path)))
overrides = requested_games(game_requests(directory), catalog)
requests = settled_game_requests(state, current, catalog, not steam_running(), directory)
overrides = requested_games(requests or {}, catalog)
managed = state.get("auto", {}).keys() if isinstance(state.get("auto"), dict) else ()
native_choices = state.get("native_choices", ())
native = native_targets(steam_root, set(apps) | set(picks) | set(managed) | set(native_choices))
@@ -1325,6 +1405,7 @@ def register_default(config_path, apps=(), protect=(), default=None, catalog=Non
state["auto"] = {app: tool for app, tool in auto.items() if tool is not NATIVE_CHOICE}
state["native_choices"] = sorted(app for app, tool in auto.items() if tool is NATIVE_CHOICE)
state["picked"] = picked_after(current, changes)
state["games_applied"] = applied_game_requests(requests, overrides, state)
state.pop("native", None)
state["tools"] = catalog
state.setdefault("default", default)
+279 -74
View File
@@ -17,6 +17,7 @@
#include <sys/syscall.h>
#include <sys/timerfd.h>
#include <time.h>
#include <ucontext.h>
#include <unistd.h>
struct ns_sem_args {
@@ -68,12 +69,13 @@ struct ns_wait_args {
#define NS_PROCS 256u
#define NS_FDS 65536
#define NS_DEVS 8
#define NS_VERSION 1u
#define NS_VERSION 2u
#define NS_HEAD_MAGIC 0x31434e5953544e44ull
#define NS_DEV_MAGIC 0x4e54445600000000ull
#define NS_OBJ_MAGIC 0x27ull
#define NS_WAITERS 0x80000000u
#define NS_SWEEP_NS 2000000000ull
#define NS_SPIN_NS 4000ull
#define NS_DEAD 0xffffffffu
#ifndef CLOSE_RANGE_CLOEXEC
@@ -144,6 +146,7 @@ struct ns_q {
uint32_t waiting;
uint32_t inuse;
uint32_t next_free;
uint32_t sleeping;
struct ns_ent ent[NS_ENTS];
};
@@ -168,6 +171,7 @@ struct ns_tls {
struct ns_dev *d;
uint32_t q;
int waiting;
int sleep;
};
static struct ns_dev ns_devs[NS_DEVS];
@@ -255,19 +259,148 @@ static void ns_unlock(uint32_t *w) {
}
}
static void ns_block(sigset_t *old) {
sigset_t s;
sigfillset(&s);
sigdelset(&s, SIGSEGV);
sigdelset(&s, SIGBUS);
sigdelset(&s, SIGILL);
sigdelset(&s, SIGFPE);
sigdelset(&s, SIGTRAP);
pthread_sigmask(SIG_BLOCK, &s, old);
#define NS_DEFER 4
#define NS_LEVELS 8
struct ns_cs {
int depth;
int count;
int level;
unsigned held_levels;
int sigs[NS_DEFER];
siginfo_t info[NS_DEFER];
sigset_t held[NS_LEVELS];
};
static __thread struct ns_cs ns_cs;
static uintptr_t ns_handlers[_NSIG];
static uint8_t ns_siginfo[_NSIG];
int bl_from_ntdll(const void *caller) __attribute__((visibility("hidden")));
static int ns_deferrable(int sig) {
return sig > 0 && sig < _NSIG && sig != SIGKILL && sig != SIGSTOP && sig != SIGSEGV && sig != SIGBUS && sig != SIGILL
&& sig != SIGFPE && sig != SIGTRAP && sig != SIGSYS;
}
static void ns_restore(const sigset_t *old) {
pthread_sigmask(SIG_SETMASK, old, NULL);
static int ns_defer(int sig, const siginfo_t *si) {
struct ns_cs *cs = &ns_cs;
if (sig < SIGRTMIN)
for (int i = 0; i < NS_DEFER; i++)
if (__atomic_load_n(&cs->sigs[i], __ATOMIC_RELAXED) == sig) return 1;
int i = __atomic_fetch_add(&cs->count, 1, __ATOMIC_RELAXED);
if (i >= NS_DEFER) {
__atomic_fetch_sub(&cs->count, 1, __ATOMIC_RELAXED);
return 0;
}
if (si) memcpy(&cs->info[i], si, sizeof(*si));
else memset(&cs->info[i], 0, sizeof(*si));
__atomic_signal_fence(__ATOMIC_SEQ_CST);
__atomic_store_n(&cs->sigs[i], sig, __ATOMIC_RELAXED);
return 1;
}
static int ns_park(int sig, const siginfo_t *si, ucontext_t *uc) {
int level = ns_cs.level;
if (level < 0 || level >= NS_LEVELS) return 0;
sigset_t one;
sigemptyset(&one);
sigaddset(&one, sig);
int saved = errno;
pthread_sigmask(SIG_BLOCK, &one, NULL);
pid_t pid = getpid(), tid = (pid_t)ns_self();
int ok = (si && syscall(SYS_rt_tgsigqueueinfo, pid, tid, sig, si) == 0) || syscall(SYS_tgkill, pid, tid, sig) == 0;
if (!ok) pthread_sigmask(SIG_UNBLOCK, &one, NULL);
errno = saved;
if (!ok) return 0;
sigaddset(&uc->uc_sigmask, sig);
unsigned long *words = (unsigned long *)&ns_cs.held[level];
unsigned bits = 8 * sizeof(unsigned long);
__atomic_fetch_or(&words[(unsigned)(sig - 1) / bits], 1ul << ((unsigned)(sig - 1) % bits), __ATOMIC_RELAXED);
__atomic_fetch_or(&ns_cs.held_levels, 1u << level, __ATOMIC_RELAXED);
return 1;
}
static void ns_trampoline(int sig, siginfo_t *si, void *uc) {
if (__atomic_load_n(&ns_cs.depth, __ATOMIC_RELAXED) > 0 && (ns_defer(sig, si) || (uc && ns_park(sig, si, uc)))) return;
uintptr_t h = __atomic_load_n(&ns_handlers[sig], __ATOMIC_ACQUIRE);
if (!h) return;
ns_cs.level++;
__atomic_signal_fence(__ATOMIC_SEQ_CST);
if (__atomic_load_n(&ns_siginfo[sig], __ATOMIC_RELAXED)) ((void (*)(int, siginfo_t *, void *))h)(sig, si, uc);
else ((void (*)(int))h)(sig);
__atomic_signal_fence(__ATOMIC_SEQ_CST);
ns_cs.level--;
}
static void ns_flush(void) {
struct ns_cs *cs = &ns_cs;
sigset_t all, mask;
sigfillset(&all);
int saved = errno;
pthread_sigmask(SIG_BLOCK, &all, &mask);
int n = cs->count < NS_DEFER ? cs->count : NS_DEFER;
pid_t pid = getpid(), tid = (pid_t)ns_self();
for (int i = 0; i < n; i++)
if (cs->sigs[i] > 0 && syscall(SYS_rt_tgsigqueueinfo, pid, tid, cs->sigs[i], &cs->info[i]) != 0) syscall(SYS_tgkill, pid, tid, cs->sigs[i]);
memset(cs->sigs, 0, sizeof(cs->sigs));
cs->count = 0;
int level = cs->level;
if (level >= 0 && level < NS_LEVELS && (cs->held_levels & (1u << level))) {
for (int sig = 1; sig < _NSIG; sig++)
if (sigismember(&cs->held[level], sig) == 1) sigdelset(&mask, sig);
sigemptyset(&cs->held[level]);
cs->held_levels &= ~(1u << level);
}
pthread_sigmask(SIG_SETMASK, &mask, NULL);
errno = saved;
}
static void ns_block(void) {
ns_cs.depth++;
__atomic_signal_fence(__ATOMIC_SEQ_CST);
}
static void ns_restore(void) {
__atomic_signal_fence(__ATOMIC_SEQ_CST);
if (--ns_cs.depth == 0) {
__atomic_signal_fence(__ATOMIC_SEQ_CST);
if (ns_cs.count || (ns_cs.held_levels && ns_cs.level >= 0 && ns_cs.level < NS_LEVELS && (ns_cs.held_levels & (1u << ns_cs.level))))
ns_flush();
}
}
int sigaction(int sig, const struct sigaction *act, struct sigaction *old) {
static int (*real)(int, const struct sigaction *, struct sigaction *);
if (!real) real = (int (*)(int, const struct sigaction *, struct sigaction *))dlsym(RTLD_NEXT, "sigaction");
if (!real) {
errno = ENOSYS;
return -1;
}
if (!ns_deferrable(sig) || !ns_on()) return real(sig, act, old);
uintptr_t prev = __atomic_load_n(&ns_handlers[sig], __ATOMIC_ACQUIRE);
uint8_t prev_info = __atomic_load_n(&ns_siginfo[sig], __ATOMIC_RELAXED);
struct sigaction mine;
const struct sigaction *use = act;
if (act && act->sa_handler != SIG_DFL && act->sa_handler != SIG_IGN && !(act->sa_flags & SA_RESETHAND) &&
bl_from_ntdll(__builtin_return_address(0))) {
mine = *act;
mine.sa_sigaction = ns_trampoline;
mine.sa_flags |= SA_SIGINFO;
__atomic_store_n(&ns_siginfo[sig], (act->sa_flags & SA_SIGINFO) ? 1 : 0, __ATOMIC_RELAXED);
__atomic_store_n(&ns_handlers[sig], (uintptr_t)act->sa_sigaction, __ATOMIC_RELEASE);
use = &mine;
}
int r = real(sig, use, old);
if (r != 0 && use == &mine) {
__atomic_store_n(&ns_siginfo[sig], prev_info, __ATOMIC_RELAXED);
__atomic_store_n(&ns_handlers[sig], prev, __ATOMIC_RELEASE);
}
if (r == 0 && old && old->sa_sigaction == ns_trampoline) {
old->sa_sigaction = (void (*)(int, siginfo_t *, void *))prev;
if (!prev_info) old->sa_flags &= ~SA_SIGINFO;
}
return r;
}
static inline struct ns_obj *ns_obj(struct ns_head *h, uint32_t s) {
@@ -378,10 +511,11 @@ static int ns_claim(struct ns_q *q, int32_t index) {
if (dead) return 0;
}
int32_t want = -1;
return __atomic_compare_exchange_n(&q->signaled, &want, index, 0, __ATOMIC_ACQ_REL, __ATOMIC_RELAXED);
return __atomic_compare_exchange_n(&q->signaled, &want, index, 0, __ATOMIC_SEQ_CST, __ATOMIC_RELAXED);
}
static void ns_wake(struct ns_q *q) {
if (!__atomic_load_n(&q->sleeping, __ATOMIC_SEQ_CST)) return;
int saved = errno;
ns_futex(&q->signaled, FUTEX_WAKE, 1, NULL, 0);
errno = saved;
@@ -618,14 +752,13 @@ static void ns_dev_put_locked(struct ns_dev *d) {
static void ns_dev_put(struct ns_dev *d) {
if (__atomic_sub_fetch(&d->refs, 1, __ATOMIC_ACQ_REL)) return;
sigset_t old;
int saved = errno;
ns_block(&old);
ns_block();
pthread_mutex_lock(&ns_mx);
uint32_t zero = 0;
if (d->h && __atomic_compare_exchange_n(&d->refs, &zero, NS_DEAD, 0, __ATOMIC_ACQ_REL, __ATOMIC_ACQUIRE)) ns_release(d);
pthread_mutex_unlock(&ns_mx);
ns_restore(&old);
ns_restore();
errno = saved;
}
@@ -682,20 +815,18 @@ static void ns_forget_locked(int fd) {
}
static void ns_forget(int fd) {
sigset_t old;
int saved = errno;
ns_block(&old);
ns_block();
pthread_mutex_lock(&ns_mx);
ns_forget_locked(fd);
pthread_mutex_unlock(&ns_mx);
ns_restore(&old);
ns_restore();
errno = saved;
}
static uint64_t ns_adopt(struct ns_dev *d, uint32_t tag, int fd, uint32_t gen, uint32_t s) {
uint64_t e = 0;
sigset_t old;
ns_block(&old);
ns_block();
pthread_mutex_lock(&ns_mx);
if (!d->h || d->tag != tag || !ns_table() || ns_attach(d) < 0 || s >= NS_SLOTS) goto out;
if ((e = __atomic_load_n(&ns_fdt[fd], __ATOMIC_ACQUIRE))) goto out;
@@ -710,7 +841,7 @@ static uint64_t ns_adopt(struct ns_dev *d, uint32_t tag, int fd, uint32_t gen, u
ns_unlock(&o->lock);
out:
pthread_mutex_unlock(&ns_mx);
ns_restore(&old);
ns_restore();
return e;
}
@@ -719,8 +850,7 @@ static uint64_t ns_note_device(int fd) {
uint64_t e = 0;
if (syscall(SYS_fstat, fd, &st) != 0 || !S_ISREG(st.st_mode)) return 0;
if (((uint64_t)st.st_size & ~0xffffull) != NS_DEV_MAGIC) return 0;
sigset_t old;
ns_block(&old);
ns_block();
pthread_mutex_lock(&ns_mx);
struct ns_dev *d = ns_table() ? ns_map(fd, (uint32_t)st.st_size & 0xffff, (uint64_t)st.st_ino) : NULL;
if (d) {
@@ -732,7 +862,7 @@ static uint64_t ns_note_device(int fd) {
}
}
pthread_mutex_unlock(&ns_mx);
ns_restore(&old);
ns_restore();
return e;
}
@@ -773,15 +903,14 @@ static int ns_ready(struct ns_dev *d) {
static void ns_thread_gone(void *p) {
struct ns_tls *t = p;
if (!t || !t->d || !t->q) return;
sigset_t old;
if (!t || !t->d) return;
struct ns_dev *d = t->d;
ns_block(&old);
ns_free_q(d->h, t->q - 1);
ns_block();
if (t->q) ns_free_q(d->h, t->q - 1);
t->q = 0;
t->waiting = 0;
t->d = NULL;
ns_restore(&old);
ns_restore();
ns_dev_put(d);
}
@@ -789,24 +918,28 @@ static void ns_key_init(void) {
pthread_key_create(&ns_key, ns_thread_gone);
}
static struct ns_q *ns_thread_q(struct ns_dev *d, uint32_t *qi) {
struct ns_head *h = d->h;
if (ns_tq.d && ns_tq.q && ns_tq.waiting) {
ns_drop_q(ns_tq.d->h, ns_tq.q - 1);
ns_tq.waiting = 0;
}
if (ns_tq.d == d && ns_tq.q) {
*qi = ns_tq.q - 1;
return ns_q(h, *qi);
}
if (ns_tq.d && ns_tq.q) {
struct ns_dev *old = ns_tq.d;
ns_free_q(old->h, ns_tq.q - 1);
static int ns_hold(struct ns_dev *d) {
if (ns_tq.d == d) return 1;
if (!ns_dev_get(d)) return 0;
if (ns_tq.sleep) return 2;
struct ns_dev *old = ns_tq.d;
if (old) {
ns_block();
if (ns_tq.q) ns_free_q(old->h, ns_tq.q - 1);
ns_tq.q = 0;
ns_tq.waiting = 0;
ns_tq.d = NULL;
ns_restore();
ns_dev_put(old);
}
pthread_once(&ns_once, ns_key_init);
ns_tq.d = d;
pthread_setspecific(ns_key, &ns_tq);
return 1;
}
static struct ns_q *ns_new_q(struct ns_dev *d, uint32_t *qi) {
struct ns_head *h = d->h;
uint32_t i;
if (!ns_pop(h, &h->q_free, 0, &i) && !ns_grow(&h->q_hwm, NS_QS, &i)) {
ns_sweep_dead(h);
@@ -815,22 +948,35 @@ static struct ns_q *ns_thread_q(struct ns_dev *d, uint32_t *qi) {
struct ns_q *q = ns_q(h, i);
q->proc = (uint32_t)d->proc;
q->waiting = 0;
q->sleeping = 0;
q->inuse = 1;
__atomic_add_fetch(&d->refs, 1, __ATOMIC_ACQ_REL);
ns_tq.d = d;
ns_tq.q = i + 1;
ns_tq.waiting = 0;
pthread_setspecific(ns_key, &ns_tq);
*qi = i;
return q;
}
static struct ns_q *ns_thread_q(struct ns_dev *d, uint32_t *qi) {
struct ns_head *h = d->h;
if (ns_tq.d != d) return NULL;
if (ns_tq.q && ns_tq.waiting) {
ns_drop_q(h, ns_tq.q - 1);
ns_tq.waiting = 0;
}
if (ns_tq.q) {
*qi = ns_tq.q - 1;
return ns_q(h, *qi);
}
struct ns_q *q = ns_new_q(d, qi);
if (!q) return NULL;
ns_tq.q = *qi + 1;
ns_tq.waiting = 0;
return q;
}
static int ns_create(struct ns_dev *d, int type, uint32_t a, uint32_t b) {
struct ns_head *h = d->h;
sigset_t old;
int fd = -1, err = 0;
uint32_t s = 0;
ns_block(&old);
ns_block();
pthread_mutex_lock(&ns_mx);
if (!ns_table() || ns_attach(d) < 0) {
err = ENOMEM;
@@ -879,7 +1025,7 @@ static int ns_create(struct ns_dev *d, int type, uint32_t a, uint32_t b) {
ns_unlock(&o->lock);
out:
pthread_mutex_unlock(&ns_mx);
ns_restore(&old);
ns_restore();
if (fd < 0) errno = err;
return fd;
}
@@ -890,6 +1036,20 @@ static int ns_expired(const struct ns_wait_args *args) {
return (uint64_t)now.tv_sec * 1000000000ull + (uint64_t)now.tv_nsec >= args->timeout;
}
static uint64_t ns_now(void) {
struct timespec now;
clock_gettime(CLOCK_MONOTONIC, &now);
return (uint64_t)now.tv_sec * 1000000000ull + (uint64_t)now.tv_nsec;
}
static void ns_spin(struct ns_q *q) {
uint64_t end = ns_now() + NS_SPIN_NS;
for (unsigned i = 1; __atomic_load_n(&q->signaled, __ATOMIC_ACQUIRE) == -1; i++) {
ns_relax();
if (!(i & 63) && ns_now() >= end) return;
}
}
static int ns_sleep(struct ns_q *q, const struct ns_wait_args *args) {
struct timespec ts, *tsp = NULL;
int op = FUTEX_WAIT_BITSET | ((args->flags & NS_WAIT_REALTIME) ? FUTEX_CLOCK_REALTIME : 0);
@@ -898,14 +1058,45 @@ static int ns_sleep(struct ns_q *q, const struct ns_wait_args *args) {
ts.tv_nsec = (long)(args->timeout % 1000000000ull);
tsp = &ts;
}
while (__atomic_load_n(&q->signaled, __ATOMIC_ACQUIRE) == -1) {
if (tsp && ns_expired(args)) return ETIMEDOUT;
if (ns_futex(&q->signaled, op, (uint32_t)-1, tsp, FUTEX_BITSET_MATCH_ANY) == -1) {
if (errno == ETIMEDOUT) return ETIMEDOUT;
if (errno == EINTR) return EINTR;
}
ns_spin(q);
int ret = 0;
__atomic_store_n(&q->sleeping, 1, __ATOMIC_SEQ_CST);
while (!ret && __atomic_load_n(&q->signaled, __ATOMIC_SEQ_CST) == -1) {
if (tsp && ns_expired(args)) ret = ETIMEDOUT;
else if (ns_futex(&q->signaled, op, (uint32_t)-1, tsp, FUTEX_BITSET_MATCH_ANY) == -1 && (errno == ETIMEDOUT || errno == EINTR))
ret = errno;
}
return 0;
__atomic_store_n(&q->sleeping, 0, __ATOMIC_RELAXED);
return ret;
}
static int ns_try_any(struct ns_head *h, const uint32_t *slots, const uint32_t *gens, uint32_t total, uint32_t owner, int *dead) {
for (uint32_t i = 0; i < total; i++) {
struct ns_obj *o = ns_obj(h, slots[i]);
ns_lock(&o->lock);
int busy = o->type == NS_FREE || o->gen != gens[i] || o->any_head || o->all_hint;
if (!busy && ns_signaled(o, owner)) {
switch (o->type) {
case NS_SEM:
o->a--;
break;
case NS_MUTEX:
*dead = (int)o->ownerdead;
o->ownerdead = 0;
o->a++;
o->b = owner;
break;
case NS_EVENT:
if (!o->a) o->b = 0;
break;
}
ns_unlock(&o->lock);
return (int)i;
}
ns_unlock(&o->lock);
if (busy) return -1;
}
return -2;
}
static int ns_wait(struct ns_dev *d, struct ns_wait_args *ua, int all) {
@@ -927,12 +1118,24 @@ static int ns_wait(struct ns_dev *d, struct ns_wait_args *ua, int all) {
for (uint32_t j = 0; j < i; j++)
if (slots[j] == slots[i]) return EINVAL;
}
sigset_t old;
ns_block(&old);
int nested = ns_tq.sleep > 0;
ns_block();
if (!all && (nested || !ns_tq.waiting)) {
int dead = 0, got = ns_try_any(h, slots, gens, total, args.owner, &dead);
if (got >= 0) {
ns_restore();
ua->index = (uint32_t)got;
return dead ? EOWNERDEAD : 0;
}
if (got == -2 && args.timeout != UINT64_MAX && ns_expired(&args)) {
ns_restore();
return ETIMEDOUT;
}
}
uint32_t qi;
struct ns_q *q = ns_ready(d) ? ns_thread_q(d, &qi) : NULL;
struct ns_q *q = !ns_ready(d) ? NULL : nested ? ns_new_q(d, &qi) : ns_thread_q(d, &qi);
if (!q) {
ns_restore(&old);
ns_restore();
return ENOMEM;
}
ns_maybe_sweep(h);
@@ -952,7 +1155,7 @@ static int ns_wait(struct ns_dev *d, struct ns_wait_args *ua, int all) {
}
q->total = total;
q->waiting = 1;
ns_tq.waiting = 1;
if (!nested) ns_tq.waiting = 1;
int bad = 0;
if (!all) {
for (uint32_t i = 0; i < total && !bad; i++) {
@@ -1004,16 +1207,18 @@ static int ns_wait(struct ns_dev *d, struct ns_wait_args *ua, int all) {
}
int ret = 0;
if (!bad && __atomic_load_n(&q->signaled, __ATOMIC_ACQUIRE) == -1) {
sigset_t held;
ns_restore(&old);
ns_tq.sleep++;
ns_restore();
ret = ns_sleep(q, &args);
ns_block(&held);
ns_block();
ns_tq.sleep--;
}
ns_drop_q(h, qi);
ns_tq.waiting = 0;
if (!nested) ns_tq.waiting = 0;
int32_t got = __atomic_load_n(&q->signaled, __ATOMIC_ACQUIRE);
int dead = (int)q->ownerdead;
ns_restore(&old);
if (nested) ns_free_q(h, qi);
ns_restore();
if (bad) return EINVAL;
if (got != -1) {
ua->index = (uint32_t)got;
@@ -1061,12 +1266,11 @@ static int ns_obj_ioctl(struct ns_dev *d, uint64_t e, unsigned long req, void *a
return ENOTTY;
}
if (type != (uint32_t)want) return EINVAL;
sigset_t old;
ns_block(&old);
ns_block();
int all = ns_lock_obj(h, o);
if (o->type != (uint32_t)want || o->gen != gen) {
ns_unlock_obj(h, o, all);
ns_restore(&old);
ns_restore();
return EINVAL;
}
switch (req) {
@@ -1133,7 +1337,7 @@ static int ns_obj_ioctl(struct ns_dev *d, uint64_t e, unsigned long req, void *a
}
}
ns_unlock_obj(h, o, all);
ns_restore(&old);
ns_restore();
if (ret) return ret;
if (req == NS_SEM_RELEASE || req == NS_EVENT_SET || req == NS_EVENT_RESET || req == NS_EVENT_PULSE)
memcpy(arg, &prev, sizeof(prev));
@@ -1176,9 +1380,10 @@ int bl_ntsync_ioctl(int fd, unsigned long req, void *arg, int *rc) {
uint64_t e = ns_lookup(fd);
if (!e) return 0;
struct ns_dev *d = &ns_devs[(e >> 56) & 7];
if (!ns_dev_get(d)) return 0;
int held = ns_hold(d);
if (!held) return 0;
int out = 0, err = (e & NS_E_DEVICE) ? ns_dev_ioctl(d, req, arg, &out) : ns_obj_ioctl(d, e, req, arg);
ns_dev_put(d);
if (held == 2) ns_dev_put(d);
if (err) {
errno = err;
*rc = -1;
+9 -2
View File
@@ -51,9 +51,16 @@ static void rt_send(void *dpy, uint32_t action) {
}
}
static void *rt_xtst(const char *name) {
void *fn = dlsym(RTLD_NEXT, name);
if (fn) return fn;
void *lib = dlopen("libXtst.so.6", RTLD_LAZY | RTLD_NOLOAD);
return lib ? dlsym(lib, name) : NULL;
}
int XTestFakeMotionEvent(void *dpy, int screen, int x, int y, unsigned long delay) {
static int (*real)(void *, int, int, int, unsigned long);
if (!real) real = (int (*)(void *, int, int, int, unsigned long))dlsym(RTLD_NEXT, "XTestFakeMotionEvent");
if (!real) real = (int (*)(void *, int, int, int, unsigned long))rt_xtst("XTestFakeMotionEvent");
if (rt_enabled()) {
pthread_mutex_lock(&rt_lock);
rt_x = x;
@@ -69,7 +76,7 @@ int XTestFakeMotionEvent(void *dpy, int screen, int x, int y, unsigned long dela
int XTestFakeButtonEvent(void *dpy, unsigned int button, int press, unsigned long delay) {
static int (*real)(void *, unsigned int, int, unsigned long);
if (!real) real = (int (*)(void *, unsigned int, int, unsigned long))dlsym(RTLD_NEXT, "XTestFakeButtonEvent");
if (!real) real = (int (*)(void *, unsigned int, int, unsigned long))rt_xtst("XTestFakeButtonEvent");
if (button == 1) {
pthread_mutex_lock(&rt_lock);
int handled = 0;