Skip to content

Commit

Permalink
Merge branch 'Open-Wine-Components:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
beh-10257 authored Oct 18, 2024
2 parents cebb6c9 + c714ae8 commit e8b98a6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 22 deletions.
2 changes: 2 additions & 0 deletions umu/umu_consts.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
".local", "share", "Steam", "compatibilitytools.d"
)

STEAM_WINDOW_ID: int = 769

PROTON_VERBS = {
"waitforexitandrun",
"run",
Expand Down
40 changes: 33 additions & 7 deletions umu/umu_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
PR_SET_CHILD_SUBREAPER,
PROTON_VERBS,
STEAM_COMPAT,
STEAM_WINDOW_ID,
UMU_LOCAL,
)
from umu.umu_log import CustomFormatter, console_handler, log
Expand Down Expand Up @@ -433,17 +434,22 @@ def rearrange_gamescope_baselayer_order(
) -> tuple[list[int], int] | None:
"""Rearrange a gamescope base layer sequence retrieved from a window."""
rearranged: list[int]
steam_layer_id: int = get_steam_layer_id(sequence)

# Gamescope identifies Steam's window by the App ID 769 or by the atom
# STEAM_BIGPICTURE. This id must be the last element in the sequence
if sequence and sequence[-1] == 769:
log.debug("Base layer sequence: %s", sequence)

if not steam_layer_id:
return None

rearranged = [sequence[0], sequence[-1], *sequence[1:-1]]
# FIXME: This is brittle. Implement a better rearrangement algorithm
# that isolates the layer id while preserving the correct layer order
# because Steam has changed GAMESCOPECTRL_BASELAYER_APPID in the past
# so the values may be more/less than 3 elements.
rearranged = [sequence[0], steam_layer_id, STEAM_WINDOW_ID]
log.debug("Rearranging base layer sequence")
log.debug("'%s' -> '%s'", sequence, rearranged)

return rearranged, rearranged[1]
return rearranged, steam_layer_id


def set_gamescope_baselayer_order(d: display.Display, rearranged: list[int]) -> None:
Expand All @@ -463,6 +469,17 @@ def set_gamescope_baselayer_order(d: display.Display, rearranged: list[int]) ->
log.exception(e)


def get_steam_layer_id(sequence: list[int]) -> int:
"""Get the Steam layer ID from a base layer seq."""
steam_layer_id: int = 0

for val in sequence:
if val != sequence[0] and val != STEAM_WINDOW_ID:
steam_layer_id = val

return steam_layer_id


def window_setup( # noqa
d_primary: display.Display,
d_secondary: display.Display,
Expand Down Expand Up @@ -528,7 +545,9 @@ def monitor_windows(
) -> None:
"""Monitor for new windows and assign them Steam's layer ID."""
window_ids: set[str] = game_window_ids.copy()
steam_assigned_layer_id: int = gamescope_baselayer_sequence[-1]
steam_assigned_layer_id: int = get_steam_layer_id(
gamescope_baselayer_sequence
)

log.debug("Monitoring windows")

Expand Down Expand Up @@ -627,13 +646,20 @@ def run_command(command: tuple[Path | str, ...]) -> int:
ret: int = 0
prctl_ret: int = 0
libc: str = get_libc()
is_gamescope_session: bool = (
os.environ.get("XDG_CURRENT_DESKTOP") == "gamescope"
or os.environ.get("XDG_SESSION_DESKTOP") == "gamescope"
)
# Note: STEAM_MULTIPLE_XWAYLANDS is steam mode specific and is
# documented to be a legacy env var.
is_steammode: bool = (
os.environ.get("XDG_CURRENT_DESKTOP") == "gamescope"
is_gamescope_session
and os.environ.get("STEAM_MULTIPLE_XWAYLANDS") == "1"
)

if is_gamescope_session and os.environ.get("XDG_CURRENT_DESKTOP") != "gamescope":
os.environ["XDG_CURRENT_DESKTOP"] = "gamescope"

if not command:
err: str = f"Command list is empty or None: {command}"
raise ValueError(err)
Expand Down
44 changes: 29 additions & 15 deletions umu/umu_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,36 +186,50 @@ def tearDown(self):
if self.test_cache_home.exists():
rmtree(self.test_cache_home.as_posix())

def test_rearrange_gamescope_baselayer_none(self):
"""Test rearrange_gamescope_baselayer_order when passed correct seq.
def test_rearrange_gamescope_baselayer_order_broken(self):
"""Test rearrange_gamescope_baselayer_order when passed broken seq.
A rearranged sequence should only be returned when the last element
is 769. Otherwise, None should be returned
When the Steam client's window ID is not the last element in
the atom GAMESCOPECTRL_BASELAYER_APPID, then a rearranged sequence
should be returned where the last element is Steam's window ID and
the 2nd to last is the assigned layer ID.
"""
baselayer = [1, 2, 3, 769]
steam_window_id = 769
steam_layer_id = 2
baselayer = [1, steam_window_id, steam_layer_id]
expected = (
[baselayer[0], steam_layer_id, steam_window_id],
steam_layer_id,
)
result = umu_run.rearrange_gamescope_baselayer_order(baselayer)

self.assertTrue(
result is None,
f"Expected None to be returned for sequence {baselayer}",
self.assertEqual(
result,
expected,
f"Expected {expected}, received {result}",
)

def test_rearrange_gamescope_baselayer_order_err(self):
"""Test rearrange_gamescope_baselayer_order for unexpected seq."""
def test_rearrange_gamescope_baselayer_order_invalid(self):
"""Test rearrange_gamescope_baselayer_order for invalid seq."""
baselayer = []

with self.assertRaises(IndexError):
umu_run.rearrange_gamescope_baselayer_order(baselayer)
self.assertTrue(
umu_run.rearrange_gamescope_baselayer_order(baselayer) is None,
"Expected None",
)

def test_rearrange_gamescope_baselayer_order(self):
"""Test rearrange_gamescope_baselayer_order when passed a sequence."""
baselayer = [1, 2, 3, 4]
steam_window_id = 769
steam_layer_id = 2
baselayer = [1, steam_layer_id, steam_window_id]
expected = (
[baselayer[0], baselayer[-1], *baselayer[1:-1]],
baselayer[-1],
[baselayer[0], steam_layer_id, steam_window_id],
steam_layer_id,
)
result = umu_run.rearrange_gamescope_baselayer_order(baselayer)

# Original sequence should be returned when Steam's window ID is last
self.assertEqual(
result,
expected,
Expand Down

0 comments on commit e8b98a6

Please sign in to comment.