diff --git a/foreground_fix.py b/foreground_fix.py index 8af89ea..b1178d9 100644 --- a/foreground_fix.py +++ b/foreground_fix.py @@ -77,7 +77,8 @@ def find_game_window(pids: set[int]) -> int | None: win32gui.EnumWindows(callback, None) if not found: return None - found.sort(key=lambda x: x[2] * x[3], reverse=True) + # Fenster mit Titel bevorzugen, dann nach Größe sortieren + found.sort(key=lambda x: (bool(x[1]), x[2] * x[3]), reverse=True) return found[0][0] @@ -155,7 +156,8 @@ def bring_to_front(hwnd: int) -> bool: def main() -> None: parser = argparse.ArgumentParser() parser.add_argument("--timeout", type=int, default=120) - parser.add_argument("--process", type=str, default="CrimsonDesert") + parser.add_argument("--process", type=str, required=True, + help="Prozessname des Spiels (ohne .exe)") args = parser.parse_args() deadline = time.time() + args.timeout @@ -199,11 +201,18 @@ def main() -> None: current_hwnd = find_game_window(pids) if current_hwnd and current_hwnd != hwnd: - logging.info("Window changed: old=%s new=%s title=%r", - hwnd, current_hwnd, win32gui.GetWindowText(current_hwnd)) - hwnd = current_hwnd - focused_hwnd = None # neues Fenster muss neu fokussiert werden - time.sleep(1) + new_title = win32gui.GetWindowText(current_hwnd) + old_title = win32gui.GetWindowText(hwnd) if hwnd else "" + # Nicht von einem Fenster mit Titel auf ein titelloses wechseln + if not new_title and old_title: + logging.debug("Ignoring titleless window hwnd=%s (keeping %s title=%r)", + current_hwnd, hwnd, old_title) + else: + logging.info("Window changed: old=%s new=%s title=%r", + hwnd, current_hwnd, new_title) + hwnd = current_hwnd + focused_hwnd = None # neues Fenster muss neu fokussiert werden + time.sleep(1) if not hwnd: time.sleep(FOCUS_RETRY_DELAY) diff --git a/launch.vbs b/launch.vbs index 38bb6f8..b25254b 100644 --- a/launch.vbs +++ b/launch.vbs @@ -1,7 +1,13 @@ Set WshShell = CreateObject("WScript.Shell") +' Prozessname aus dem ersten Argument (Steam %command%) extrahieren +Dim exePath, fso, exeName +Set fso = CreateObject("Scripting.FileSystemObject") +exePath = WScript.Arguments(0) +exeName = fso.GetBaseName(exePath) + ' Foreground-Fix Script unsichtbar starten (pythonw = kein Konsolenfenster) -WshShell.Run """C:\Projekte\Steam_backgroud_fix\.venv\Scripts\pythonw.exe"" ""C:\Projekte\Steam_backgroud_fix\foreground_fix.py""", 0, False +WshShell.Run """C:\Projekte\Steam_backgroud_fix\.venv\Scripts\pythonw.exe"" ""C:\Projekte\Steam_backgroud_fix\foreground_fix.py"" --process """ & exeName & """", 0, False ' Spiel starten: alle Argumente (= Steam %command%) zusammensetzen und ausführen Dim gameCmd, i