Skip to content

Commit

Permalink
Add feature to use gamescope for clients
Browse files Browse the repository at this point in the history
- The launcher is responsible for subreaping in behalf of clients, however, we're not able to fullfill that responsibility if gamescope is used which will require clients to handle killing the zombie wine processes if the game had exited improperly (e.g., closing the game window). Currently, all GUI launchers that do not implement a sophisticated subreaping system will need to do this. However, by executing gamescope via ULWGL, we can ensure all zombies are killed via systemd when the user exits improperly

- This will be an optional feature for GUI clients by requiring to set ULWGL_GAMESCOPE=1. To pass gamescope options to the launcher, clients must write a JSON file in ~/.local/share/ULWGL/state/<ulwgl-id>.json with the gamescope options. For example:

[
 {
   'name': 'gamescope',
   'options': ['-F', 'fsr']
 }
]
  • Loading branch information
R1kaB3rN committed Mar 18, 2024
1 parent 03496bb commit e275b4f
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
57 changes: 57 additions & 0 deletions ULWGL/ulwgl_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from shutil import which
from ulwgl_log import log
from ulwgl_consts import TOMLDocument, ULWGL_LOCAL
from json import load


def set_env_toml(
Expand Down Expand Up @@ -110,6 +111,24 @@ def _check_env_toml(env: Dict[str, str], toml: TOMLDocument) -> Dict[str, Any]:
f"Please specify a value or remove the entry:\n{key} = {val}"
)
raise ValueError(err)
if key == "gamescope" and not isinstance(val, bool):
err: str = (
f"Value is not a boolean for '{key}' in TOML.\n"
f"Please specify a value or remove the entry:\n{key} = {val}"
)
raise ValueError(err)

if (
toml.get("plugins")
and toml.get("plugins").get("gamescope")
and toml.get("plugins").get("gamescope").get("options")
and not isinstance(toml.get("plugins").get("gamescope").get("options"), list)
):
err: str = (
f"Value is not an array for '{key}' in TOML.\n"
f"Please specify a value or remove the entry:\n{key} = {val}"
)
raise ValueError(err)

return toml

Expand Down Expand Up @@ -235,3 +254,41 @@ def enable_systemd(env: Dict[str, str], command: List[str]) -> List[str]:
)

return command


def enable_gamescope(
env: Dict[str, str], command: List[str], opts: List[str] = None
) -> List[str]:
"""Enable the gamescope microcompositor."""
bin: str = which("gamescope")
id: str = env["ULWGL_ID"]
json: Dict[str, Any] = None

if not id.startswith("ulwgl-"):
id = f"ulwgl-{id}" # We use an underscore for the file

if not bin or not ULWGL_LOCAL.joinpath("state", f"{id}.json"):
return command

# Config
if opts:
command.extend([bin, *opts, "--"])
return command

# CLI
with ULWGL_LOCAL.joinpath("state", f"{id}.json").open(mode="r") as file:
json = load(file)

# Pass user options
# NOTE: We do not validate them. We trust the client
for item in json:
if item.get("name") == "gamescope":
opts = item.get("options")

if opts:
command.extend([bin, *opts, "--"])
return command

command.extend([bin, "--"])

return command
19 changes: 19 additions & 0 deletions ULWGL/ulwgl_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
set_env_toml,
enable_reaper,
enable_systemd,
enable_gamescope,
)
from ulwgl_consts import (
PROTON_VERBS,
DEBUG_FORMAT,
Expand Down Expand Up @@ -270,6 +272,22 @@ def build_command(
log.debug("Using reaper as subreaper")
enable_reaper(env, command, local)

# Gamescope
if env.get("ULWGL_GAMESCOPE") == "1":
log.debug("Using gamescope")
enable_gamescope(env, command)
elif (
config
and config.get("ulwgl").get("gamescope")
and config.get("plugins")
and config.get("plugins").get("gamescope")
and config.get("plugins").get("gamescope").get("options")
):
log.debug("Using gamescope")
enable_gamescope(
env, command, config.get("plugins").get("gamescope").get("options")
)

command.extend([local.joinpath("ULWGL").as_posix(), "--verb", verb, "--"])
command.extend(
[
Expand Down Expand Up @@ -307,6 +325,7 @@ def main() -> int: # noqa: D103
"STORE": "",
"PROTON_VERB": "",
"ULWGL_ID": "",
"ULWGL_GAMESCOPE": "",
"ULWGL_SYSTEMD": "",
}
command: List[str] = []
Expand Down

0 comments on commit e275b4f

Please sign in to comment.