Reworked the gamescope to work better with scaling and maximize window.

This commit is contained in:
2026-09-06 10:57:42 +02:00
parent f0d631be66
commit 3a01c6ba2a
10 changed files with 920 additions and 12 deletions

View File

@@ -18,7 +18,12 @@ from typing import Mapping, Sequence
from .command import CommandOutcome, CommandRunner, OutputLineFilter
from .container_host import container_host_error, inspect_container_host
from .depot import DEFAULT_DEPOT_START_OPTION, DepotStartOption
from .gamebox import build_gamebox_command
from .gamebox import (
GameboxConfigurationError,
build_gamebox_command,
find_gamescope,
read_game_canvas_size,
)
from .paths import AppPaths
from .settings import Settings
from .umu import find_umu_launcher
@@ -376,6 +381,18 @@ def game_runtime_ready(paths: AppPaths, selection: RuntimeSelection) -> bool:
return False
def _read_game_canvas_size_or_warn(game_config: Path) -> tuple[int, int] | None:
try:
return read_game_canvas_size(game_config)
except GameboxConfigurationError as exc:
print(
f"Warning: {exc}; using a fixed game window.",
file=sys.stderr,
flush=True,
)
return None
def run_game(
paths: AppPaths,
settings: Settings,
@@ -441,10 +458,39 @@ def run_game(
environment["PROTON_VERB"] = (
"runinprefix" if concurrent_prefix_launch else "waitforexitandrun"
)
if use_gamebox:
game_command = build_gamebox_command(game_command, settings)
if extra_environment:
environment.update(extra_environment)
if use_gamebox:
gamescope_path = None
game_size = None
if settings.allow_window_resizing:
gamescope_environment = os.environ.copy()
gamescope_environment.update(environment)
gamescope_path = find_gamescope(gamescope_environment)
if gamescope_path is None:
print(
"Warning: a resizable Gamescope window was requested, but "
"Gamescope was not found; using a fixed game window.",
file=sys.stderr,
flush=True,
)
else:
game_size = _read_game_canvas_size_or_warn(paths.game_config)
if game_size is not None:
width, height = game_size
print(
"Optimized stable resize enabled through Gamescope: the game "
f"starts at {width}x{height} and keeps its aspect ratio while "
"the outer window scales.",
file=sys.stderr,
flush=True,
)
game_command = build_gamebox_command(
game_command,
settings,
game_size=game_size,
gamescope_path=gamescope_path,
)
environment["PYTHONPATH"] = _runtime_python_path(
os.environ.get("PYTHONPATH"),
)