Skip to content

grill run: hand the foreground back after the Battle.net window takes it - #93

Merged
Frotty merged 1 commit into
masterfrom
battlenet-window-hand-back
Nov 18, 2026
Merged

Frotty merged 1 commit into
masterfrom
battlenet-window-hand-back

Conversation

@Frotty

@Frotty Frotty commented Nov 18, 2026

Copy link
Copy Markdown
Member

Problem

Each sign-in renewal asks the Battle.net app to launch Warcraft III. The app opens a new window, and that window takes the foreground about 0.7 s later. battlenet-window.ps1 minimises it 40–60 ms afterwards, but minimising the foreground window does not reliably hand the foreground back.

Measured with a EVENT_SYSTEM_FOREGROUND logger: in the first run, all four requests left no window in front until the user clicked something, 12 s later in one case. A fullscreen program loses the foreground at that point: exclusive fullscreen minimises itself, and borderless stops receiving keyboard input. So every Run Map or grill run interrupts whatever the user is doing.

Change

  • The watcher notes the window in front when it starts, and follows the foreground as long as it runs. Battle.net windows and the renewal's own client are skipped.
  • When a Battle.net window takes the foreground, the watcher minimises it as before. Once the app has lost the foreground, the watcher hands it back to that window and restores it if it minimised itself.
  • Windows refuses SetForegroundWindow while the app still holds the foreground, so the hand-back waits up to 0.5 s for the app to lose it, then tries until 1 s has passed.
  • Nothing happens if Windows has already given the foreground to another window.
  • With -Log, each hand-back outcome is printed.
  • The script stays byte-identical to WurstSetup's copy.

Validation

  • ./gradlew test: 157 tests, 0 failures, 2 skipped.
  • Four live runs, each with the foreground logger, the watcher with -Log, and the renewal script against the running Battle.net app:
    • Before the change, 5 of 5 requests left no window in front.
    • After the change, in 9 of 9 requests the user's window was back in front 16–27 ms after the minimise. In all of them Windows reactivated it itself, so the watcher logged "another window is in front" and did not need to act.
  • The display size never changed, and the renewal's short-lived Warcraft III clients never took the foreground.
  • Not verified: the watcher's own SetForegroundWindow in the "nothing in front" case. That state did not recur in the later runs.
  • Not done: a live Run Map with an exclusive-fullscreen program in front.

The same script goes to Run Map in wurstscript/WurstScript#1632. grill run runs it with -FocusGame: once the watcher focuses the map's client, that client becomes the window it hands the foreground back to.

Each renewal request makes the app open a window that takes the foreground.
The watcher minimized it, but that could leave no window in front, so a
fullscreen program the user was in lost the foreground for good. The watcher
now follows the window in front and, once the app has lost the foreground,
hands it back to that window unless Windows already gave it to another.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-18T17:30:36.569098Z 6de077b PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Frotty
Frotty merged commit 30b5278 into master Nov 18, 2026
1 check passed
@Frotty
Frotty deleted the battlenet-window-hand-back branch November 18, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant