From 3cbe4f72b013e92a456c6cf0436a9331f77f0d75 Mon Sep 17 00:00:00 2001 From: m4ko Date: Sun, 6 Sep 2026 22:03:12 +0200 Subject: [PATCH] Fixed the on top issue with the game window, it should not pop up when alt tabbing to some other programs now. --- ptlinux/gamebox_runtime.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/ptlinux/gamebox_runtime.py b/ptlinux/gamebox_runtime.py index cc06fcb..7c73ded 100644 --- a/ptlinux/gamebox_runtime.py +++ b/ptlinux/gamebox_runtime.py @@ -972,6 +972,11 @@ class _X11: """Raise the mapped game client and give it keyboard focus.""" self.library.XMapRaised(self.display, window) + self.restore_input_focus(window) + + def restore_input_focus(self, window: int) -> None: + """Give a mapped client keyboard focus without raising its host window.""" + self.library.XSetInputFocus( self.display, window, @@ -1437,6 +1442,27 @@ def _repair_game_window_focus(mapper: _X11, window: int) -> bool: return False +def _repair_gamescope_game_window_focus(mapper: _X11, window: int) -> bool: + """Restore nested focus without asking the desktop to activate Gamescope.""" + + try: + if mapper.window_is_focused(window): + return True + except Exception: + return False + try: + mapper.restore_input_focus(window) + return mapper.window_is_focused(window) + except Exception as exc: + print( + f"Warning: could not restore nested game input focus ({exc}); " + "continuing normally", + file=sys.stderr, + flush=True, + ) + return False + + def _enable_game_window_scaling(mapper: _X11, window: int) -> bool: """Enable confirmed resize/maximize actions without risking game startup.""" @@ -1572,7 +1598,7 @@ def _maintain_gamescope_game_window_focus( now = time.monotonic() if now < next_focus_repair_at: continue - _repair_game_window_focus(mapper, window) + _repair_gamescope_game_window_focus(mapper, window) next_focus_repair_at = ( time.monotonic() + GAMESCOPE_FOCUS_REPAIR_INTERVAL_SECONDS )