refactor: Steam-Wrapper-Logik nach focusfix.py verlagert , launch.vbs jetzt obsolet/optional

- Projektname auf FocusFix geändert
This commit is contained in:
Andre
2026-04-18 16:10:59 +02:00
parent 654a094cb5
commit a00bd1ed30
4 changed files with 208 additions and 214 deletions
+12 -11
View File
@@ -4,12 +4,12 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
## Purpose
Windows utility that forces a game window into the foreground after launch. Works with **Steam** (automatic process name extraction from `%command%`) and **Sunshine/Moonlight** (manual `--process` argument).
FocusFix is a Windows utility that forces a game window into the foreground after launch. Works with **Steam** (directly via `%command%`) and **Sunshine/Moonlight** (manual `--process` argument).
## Architecture
- **`launch.vbs`** — VBScript entry point called from Steam launch options. Extracts the game executable name from `%command%` via `FileSystemObject.GetBaseName()`, passes it as `--process` to `foreground_fix.py`, then launches the actual game. No console window is created.
- **`foreground_fix.py`** — Python script that polls for the game process, waits for its main window (filtered by size to skip splash screens, preferring windows with titles over titleless overlays), waits for the window size to stabilize, then brings the game window to foreground using Win32 API workarounds (`AttachThreadInput` + `Alt` key simulation to bypass `SetForegroundWindow` restrictions). Monitors for window changes (splash → main window) and re-focuses automatically. Retries up to 15 times. Runtime logging goes to `foreground_fix.log`.
- **`focusfix.py`** — Python script that supports two modes: `--process Name` for monitoring an already-known process, or direct Steam wrapper mode where `%command%` is passed as positional arguments. In wrapper mode it derives the process name from the target executable, launches the game itself, then polls for the game process, waits for its main window (filtered by size to skip splash screens, preferring windows with titles over titleless overlays), waits for the window size to stabilize, then brings the game window to foreground using Win32 API workarounds (`AttachThreadInput` + `Alt` key simulation to bypass `SetForegroundWindow` restrictions). Monitors for window changes (splash → main window) and re-focuses automatically. Retries up to 15 times. Runtime logging goes to `focusfix.log`.
- **`launch.vbs`** — Legacy Steam wrapper. No longer required for normal usage, but still present in the repository.
## Setup
@@ -22,29 +22,30 @@ pip install psutil pywin32
## Steam Launch Options
```
wscript "C:\Projekte\Steam_backgroud_fix\launch.vbs" %command%
"C:\Projekte\Steam_backgroud_fix\.venv\Scripts\pythonw.exe" "C:\Projekte\Steam_backgroud_fix\focusfix.py" %command%
```
Same launch option works for all Steam games — process name is extracted automatically.
Same launch option works for all Steam games with similar foreground/focus issues — the process name is extracted automatically.
## Sunshine / Moonlight
Use as command preparation in Sunshine (full venv path required):
```
"C:\Projekte\Steam_backgroud_fix\.venv\Scripts\pythonw.exe" "C:\Projekte\Steam_backgroud_fix\foreground_fix.py" --process "ProcessName"
"C:\Projekte\Steam_backgroud_fix\.venv\Scripts\pythonw.exe" "C:\Projekte\Steam_backgroud_fix\focusfix.py" --process "ProcessName"
```
## Running Manually (for testing)
```
.venv\Scripts\python foreground_fix.py --process CrimsonDesert
.venv\Scripts\python foreground_fix.py --process CrimsonDesert --timeout 180
.venv\Scripts\python focusfix.py --process CrimsonDesert
.venv\Scripts\python focusfix.py --process CrimsonDesert --timeout 180
.venv\Scripts\python focusfix.py "C:\Games\CrimsonDesert.exe"
```
`--process` is required (no default). Runtime logging goes to `foreground_fix.log`. When started with `pythonw.exe`, no console window is shown; manual runs with `python.exe` can still print argument or interpreter errors to the console.
Use either `--process` or a game command. Runtime logging goes to `focusfix.log`. When started with `pythonw.exe`, no console window is shown; manual runs with `python.exe` can still print argument or interpreter errors to the console.
## Key Constants in foreground_fix.py
## Key Constants in focusfix.py
- `MIN_WINDOW_WIDTH = 800` — distinguishes game window from splash screen
- `FOCUS_RETRIES = 15` / `FOCUS_RETRY_DELAY = 2.0` — retry parameters for foreground focus
@@ -54,5 +55,5 @@ Use as command preparation in Sunshine (full venv path required):
- `SetForegroundWindow` is restricted by Windows unless the calling process owns the foreground. Workaround: simulate an `Alt` keypress + `AttachThreadInput` to the foreground thread.
- Alt key release is in a `finally` block to prevent it from staying pressed on errors.
- `pythonw.exe` (not `python.exe`) is required for invisible background execution.
- VBScript `WshShell.Run` with window style `0` ensures no console window appears.
- `launch.vbs` is legacy-only; normal Steam usage now calls `focusfix.py` directly.
- Window selection prefers titled windows over titleless ones (prevents overlay issues like in Wuthering Waves).