mirror of
https://github.com/Andre-Bzk/FocusFix.git
synced 2026-11-15 09:33:14 +01:00
3.0 KiB
3.0 KiB
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Purpose
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
focusfix.py— Python script that supports two modes:--process Namefor 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+Altkey simulation to bypassSetForegroundWindowrestrictions). Monitors for window changes (splash → main window) and re-focuses automatically. Retries up to 15 times. Runtime logging goes tofocusfix.log.launch.vbs— Legacy Steam wrapper. No longer required for normal usage, but still present in the repository.
Setup
py -m venv .venv
.venv\Scripts\activate
pip install psutil pywin32
Steam Launch Options
"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 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\focusfix.py" --process "ProcessName"
Running Manually (for testing)
.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"
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 focusfix.py
MIN_WINDOW_WIDTH = 800— distinguishes game window from splash screenFOCUS_RETRIES = 15/FOCUS_RETRY_DELAY = 2.0— retry parameters for foreground focus
Windows API Notes
SetForegroundWindowis restricted by Windows unless the calling process owns the foreground. Workaround: simulate anAltkeypress +AttachThreadInputto the foreground thread.- Alt key release is in a
finallyblock to prevent it from staying pressed on errors. pythonw.exe(notpython.exe) is required for invisible background execution.launch.vbsis legacy-only; normal Steam usage now callsfocusfix.pydirectly.- Window selection prefers titled windows over titleless ones (prevents overlay issues like in Wuthering Waves).