diff --git a/umu/umu_run.py b/umu/umu_run.py index 54b4d8852..4017126e7 100755 --- a/umu/umu_run.py +++ b/umu/umu_run.py @@ -457,9 +457,16 @@ def get_gamescope_baselayer_order( def rearrange_gamescope_baselayer_order( sequence: list[int], -) -> tuple[list[int], int]: +) -> tuple[list[int], int] | None: """Rearrange a gamescope base layer sequence retrieved from a window.""" - rearranged: list[int] = [sequence[0], sequence[-1], *sequence[1:-1]] + rearranged: list[int] + + # 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: + return None + + rearranged = [sequence[0], sequence[-1], *sequence[1:-1]] log.debug("Rearranging base layer sequence") log.debug("'%s' -> '%s'", sequence, rearranged) @@ -491,11 +498,16 @@ def window_setup( # noqa gamescope_baselayer_sequence: list[int], game_window_ids: set[str], ) -> None: + rearranged_gamescope_baselayer: tuple[list[int], int] | None = None + if gamescope_baselayer_sequence: - # Rearrange the sequence - # TODO: Consider only rearranging the sequence when we need to. + rearranged_gamescope_baselayer = rearrange_gamescope_baselayer_order( + gamescope_baselayer_sequence + ) + + if rearranged_gamescope_baselayer: rearranged_sequence, steam_assigned_layer_id = ( - rearrange_gamescope_baselayer_order(gamescope_baselayer_sequence) + rearranged_gamescope_baselayer ) # Assign our window a STEAM_GAME id @@ -512,6 +524,7 @@ def monitor_baselayer( ) -> None: """Monitor for broken gamescope baselayer sequences.""" root_primary: Window = d_primary.screen().root + rearranged_gamescope_baselayer: tuple[list[int], int] | None = None atom = d_primary.get_atom("GAMESCOPECTRL_BASELAYER_APPID") root_primary.change_attributes(event_mask=X.PropertyChangeMask) @@ -528,7 +541,12 @@ def monitor_baselayer( if prop and prop.value == gamescope_baselayer_sequence: log.debug("Broken base layer sequence detected") log.debug("Property value for atom '%s': %s", atom, prop.value) - rearranged, _ = rearrange_gamescope_baselayer_order(prop.value) + rearranged_gamescope_baselayer = ( + rearrange_gamescope_baselayer_order(prop.value) + ) + + if rearranged_gamescope_baselayer: + rearranged, _ = rearranged_gamescope_baselayer set_gamescope_baselayer_order(d_primary, rearranged) continue diff --git a/umu/umu_test.py b/umu/umu_test.py index f39401e00..4d5a4cfeb 100644 --- a/umu/umu_test.py +++ b/umu/umu_test.py @@ -187,6 +187,20 @@ def tearDown(self): if self.test_usr.exists(): rmtree(self.test_usr.as_posix()) + def test_rearrange_gamescope_baselayer_none(self): + """Test rearrange_gamescope_baselayer_order when passed correct seq. + + A rearranged sequence should only be returned when the last element + is 769. Otherwise, None should be returned + """ + baselayer = [1, 2, 3, 769] + result = umu_run.rearrange_gamescope_baselayer_order(baselayer) + + self.assertTrue( + result is None, + f"Expected None to be returned for sequence {baselayer}", + ) + def test_rearrange_gamescope_baselayer_order_err(self): """Test rearrange_gamescope_baselayer_order for unexpected seq.""" baselayer = [] @@ -195,7 +209,7 @@ def test_rearrange_gamescope_baselayer_order_err(self): umu_run.rearrange_gamescope_baselayer_order(baselayer) def test_rearrange_gamescope_baselayer_order(self): - """Test rearrange_gamescope_baselayer_order for expected sequences.""" + """Test rearrange_gamescope_baselayer_order when passed a sequence.""" baselayer = [1, 2, 3, 4] expected = ( [baselayer[0], baselayer[-1], *baselayer[1:-1]],