diff --git a/tools/linuxfs/desktop/droiddeck-gpu b/tools/linuxfs/desktop/droiddeck-gpu index 012cd30625..da4bf7e41c 100644 --- a/tools/linuxfs/desktop/droiddeck-gpu +++ b/tools/linuxfs/desktop/droiddeck-gpu @@ -42,6 +42,14 @@ export BL_DESKTOP_GPU_CHILD=1 export MESA_LOADER_DRIVER_OVERRIDE=zink GALLIUM_DRIVER=zink LIBGL_KOPPER_DRI2=true [ -n "${DROIDDECK_GLTHREAD:-}" ] && export mesa_glthread=$DROIDDECK_GLTHREAD export APPIMAGE_EXTRACT_AND_RUN=1 +if ! command -v gamescopereaper >/dev/null 2>&1; then + for dir in /usr/games /usr/local/games /usr/bin; do + if [ -x "$dir/gamescopereaper" ]; then + export PATH=${PATH:+$PATH:}$dir + break + fi + done +fi if [ "$window" = 1 ]; then export BL_GPU_CHILD_WSI=${MESA_VK_WSI_DEBUG:-} SDL_VIDEODRIVER=wayland MESA_VK_WSI_DEBUG=sw gamescope "${args[@]}" -- /usr/local/bin/droiddeck-gpu-window "$@" diff --git a/tools/tests/test_gamescope_backend.py b/tools/tests/test_gamescope_backend.py index d9f91bf828..166ea94129 100644 --- a/tools/tests/test_gamescope_backend.py +++ b/tools/tests/test_gamescope_backend.py @@ -1,6 +1,7 @@ import json import os from pathlib import Path +import shutil import subprocess import sys import tempfile @@ -100,3 +101,50 @@ class DesktopGamescopeBackendTest(unittest.TestCase): self.assertEqual(64, result.returncode) self.assertIn("unsupported gamescope backend: drm", result.stderr) self.assertIsNone(capture) + + +class DesktopGamescopeReaperTest(unittest.TestCase): + def launch(self, reaper_on_path): + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + bin_dir = root / "bin" + games = root / "games" + bin_dir.mkdir() + games.mkdir() + capture = root / "path.txt" + gamescope = bin_dir / "gamescope" + gamescope.write_text( + "#!/bin/sh\n" + "printf '%s\\n' \"$PATH\" > \"$GAMESCOPE_CAPTURE\"\n" + "command -v gamescopereaper >> \"$GAMESCOPE_CAPTURE\" || exit 3\n" + ) + gamescope.chmod(0o755) + reaper = (bin_dir if reaper_on_path else games) / "gamescopereaper" + reaper.write_text("#!/bin/sh\n") + reaper.chmod(0o755) + date = bin_dir / "date" + date.write_text(f"#!/bin/sh\nexec {shutil.which('date')} \"$@\"\n") + date.chmod(0o755) + script = root / "droiddeck-gpu" + source = DESKTOP_GPU.read_text() + self.assertIn("for dir in /usr/games ", source) + script.write_text(source.replace("for dir in /usr/games ", f"for dir in {games} ", 1)) + start_path = str(bin_dir) + env = {"PATH": start_path, "HOME": directory, "GAMESCOPE_CAPTURE": str(capture), + "WAYLAND_DISPLAY": "desktop-0", "BL_DESKTOP_GPU_WINDOW": "0"} + result = subprocess.run(["/bin/bash", str(script), "demo"], env=env, text=True, + capture_output=True, timeout=5) + lines = capture.read_text().splitlines() if capture.exists() else [] + return result, start_path, lines, str(reaper) + + def test_reaper_outside_path_is_added_for_gamescope(self): + result, start_path, lines, reaper = self.launch(reaper_on_path=False) + self.assertEqual(0, result.returncode, result.stdout + result.stderr) + self.assertEqual(start_path + os.pathsep + str(Path(reaper).parent), lines[0]) + self.assertEqual(reaper, lines[1]) + + def test_path_with_reaper_is_left_as_it_is(self): + result, start_path, lines, reaper = self.launch(reaper_on_path=True) + self.assertEqual(0, result.returncode, result.stdout + result.stderr) + self.assertEqual(start_path, lines[0]) + self.assertEqual(reaper, lines[1])