Repository navigation
tools: activate the guest window from inside the prefix - #69
Merged
Merged
Conversation
Under gamescope the game runs as a nested child of `explorer /desktop=<name>` and its X window is override-redirect (measured: 0x02400001, OR=1, child of the explorer desktop window; every child of that desktop is OR). Wine does not activate an override-redirect child, so a title comes up inactive and its input loop ignores every device: NFS Most Wanted sat on "press START" and no button did anything. A mouse click works only because wine's own click-to-focus activates the window on the first press. The activation cannot come from our side of the boundary. WM_ACTIVATE and WM_SETFOCUS are Win32 messages and only a process inside the prefix can raise them; the X-level substitute was measured and fails (XSetInputFocus on the game's window sticks, and wine received the focus change on a window it does not manage and never activated it). That is why gamescope's A48 patch reached winhandler.exe over UDP. gn-activate removes the whole hop: it waits for the window itself, so no compositor patch, no UDP and no IPC are involved. It matches the target by owning process image, not by WM_CLASS, so no class deny-list and no tabtip/explorer special cases; it enumerates children as well as top-levels, because the game's window is nested; and among matches it takes the largest visible one, which skips the unmapped 1x1 window a D3D9 title also creates. SetForegroundWindow is tried first, then the AttachThreadInput escalation; SendMessage WM_ACTIVATE is behind --force-messages because it convinces the game it is active while wine's input routing stays put, which produces a title that takes mouse but not keys. Measured on RP6, NFS Most Wanted, proton-11.0-2-arm64ec-10: gn-activate: joined desktop 'shell' gn-activate: window 0x0001008a nfs13.exe pid=472 1280x720 class=CgsGameWindowClass SetForegroundWindow: foreground and a second run reports "already foreground", so the plain call holds and the escalation goes unused. Two on-device constraints, both silent in confusing ways, are recorded in build-gn-activate.sh: the .exe must live inside the prefix (from a unix path outside it the translator faults before main with signal 11, and a hello-world PE built with the same toolchain fails identically, so it is the location and not the code), and the process must join the game's desktop (a fresh wine process starts on the default desktop, where EnumWindows returns nothing at all). The HWND is not the X id (0x0001008a for X window 0x02400001), which is why the image match is not merely tidier. xtree-probe gains -focus and -raise, each followed by a one-second read-back so "the server refused it" and "the compositor took it back" cannot be confused, plus a bottom-to-top sibling list. That is how the override-redirect tree above was measured, and how the X-level focus change was ruled out.
The app spawns this as a session helper, not per title: it knows only the launcher at session start (winhandler.exe "steam.exe"), and the game's window exists minutes later. One activation at session start would fire on steam and exit before there was anything to activate. So --watch polls and activates each eligible window once, when it first appears, which is A48's map-time semantics without its failure mode: a window already acted on is never retried, so a refused activation cannot turn into a focus fight with whatever the user is doing. With no image argument the target is chosen by rule, because no name is known yet: the largest visible window that is not wine's desktop window (class "#32769", DESKTOP_CLASS_ATOM in programs/explorer/desktop.c), not ours, and not already activated. The desktop exclusion is by class, which is exact rather than a guess; the size rule then picks a title's window over a launcher's splash without a deny-list of application names. join_desktop now waits for the desktop to exist instead of failing once. A helper spawned by the app arrives before `explorer /desktop=shell` has created it, and the failure is silent: a process on the default desktop enumerates no windows at all, so the tool would sit there looking idle. Waiting is the only correct answer, and the watcher exits by itself when the desktop disappears, so it ends with its session instead of lingering as an orphan. Both real tests of this shape were on-device: NFS Most Wanted under `explorer /desktop=shell,1280x720` (window 0x0001008a, class CgsGameWindowClass), where SetForegroundWindow was accepted on the first call and held.
gn-activate works, so the question worth answering before shipping it is whether
it has to exist at all: is any X-level request enough to make wine consider the
guest's window active? If one were, the helper could be deleted and gamescope's
xwm could do it in a few lines.
Two candidates, both sent as ClientMessages rather than property writes, because
a property is something the client has to poll and wine does not:
bin/gn-xtree-probe -activate EWMH _NET_ACTIVE_WINDOW to the root, source
indication 2 (pager, the caller a WM is least
likely to second-guess)
bin/gn-xtree-probe -take-focus ICCCM WM_TAKE_FOCUS to the window, then
XSetInputFocus as the client's own answer
gn-activate gains --query-fg: the only read-only way to ask what wine considers
foreground. X input focus is not that answer, and any activation call would mask
the thing being observed -- the earlier one-shot would have reported success
either way.
Measured on RP6, NFS Most Wanted, proton-11.0-2-arm64ec-10, real session, one
window (X 0x02400001 / HWND 0x0001008a), one run per arm:
lever X input focus wine foreground
baseline, nothing 0x00600004 desk <none>
_NET_ACTIVE_WINDOW ClientMessage reverted to desk <none>
WM_TAKE_FOCUS + XSetInputFocus 0x02400001 kept <none>
Win32 SetForegroundWindow from inside unchanged 0x0001008a nfs13
So no X-level request moves wine's foreground, and gamescope's xwm does more
than ignore the child: it actively returns focus to the desktop. The helper is
justified rather than merely convenient.
The baseline is worth recording on its own: wine's foreground was <none>, not the
desktop, while X focus sat on the desktop window. X focus is not weakly coupled
to wine's foreground, it is unrelated to it.
Scope limit: the target is an override-redirect child, and WM_TAKE_FOCUS is a
protocol wine's WM answers only for windows it manages. The result therefore
says X cannot activate a wine window in this arrangement, not that it never
could; if the launch line ever stops using a virtual desktop, re-run this before
trusting the conclusion.
… fix -watch-activate waits for the session's X socket and then for the guest's window, and needs no xid: the app has none at launch, and the ids are reallocated per session (0x02400001 became 0x02600001 between two runs of the same title). The window is chosen by depth, not by class. Under `explorer /desktop=shell` the desktop is the root child everything lives inside, and its WM_CLASS on the X side is `explorer.exe` (measured) -- not DESKTOP_CLASS_ATOM, which is a Win32-side fact -- so a class test matches nothing and the desktop wins on area. Only depth >= 2 can be a guest window, and among those a descendant must be strictly larger than its ancestor to replace it: the outer window and its inner child can share an area exactly, and the outer one is the meaningful target. Measured on RP6, NFS Most Wanted, with only this in play: connect(.../X0): No such file or directory x4 (socket not up yet) xtree-probe: connected ...; watching for the guest's window window 0x02400017 (921600 px): attempting X-level activation activate: _NET_ACTIVE_WINDOW ClientMessage -> root, for 0x02400017 take-focus: WM_TAKE_FOCUS ClientMessage -> 0x02400017 after 1s: X input focus=0x02400017 (kept) and, with the focus moved to the game's own window instead: focus: XSetInputFocus(0x02600001); after 1s: X input focus=0x02600001 (kept) Neither makes the title's START button work: X focus is kept by the server and the game still ignores injected input, because wine's foreground window is what input delivery follows and it stays <none>. That is the measurement this tool exists to reproduce -- and the reason a Win32 call inside the prefix is still required, which is what gn-activate.exe is for. Note the retry loop is deliberate and not an error path: the app arms this at session start, before gamescope's X socket exists, and the four failed connects above are that window being waited for.
--watch only ended when the desktop disappeared, and that never happens while a launcher owns the session: the launch line is `winhandler.exe "steam.exe"`, so exiting the title leaves the desktop and Steam alive and the helper polled every 400ms for the rest of the session, doing nothing. --idle-ms (default 60000, 0 disables) ends it instead: the clock starts at arm time and restarts whenever a window worth acting on is found, so the launcher sequence this exists for -- Steam's window, then the game minutes later -- is unaffected, and the process exits about a minute after the last thing it could act on is gone. The desktop-disappeared exit stays for the session-over case. Sixty seconds is a judgement, not a measurement: a title that shows no window for longer than that between launcher and game would lose its activation for that session, which is why the value is a flag rather than a constant.
joshuatam
added a commit
to joshuatam/GameNative
that referenced
this pull request
Nov 15, 2026
Under `explorer /desktop=shell` the guest's window is an override-redirect child of the desktop, and wine never activates it: the title comes up with no foreground window, so injected input has nowhere to land and buttons do nothing until something clicks the window. `bin/gn-activate.exe` (GameNative/gamenative-drm#69) fixes that with one Win32 call, which is the only lever that works -- X focus and the EWMH/ICCCM activation messages are accepted and leave wine's foreground at <none>, measured on RP6 with NFS Most Wanted. It does not raise or reorder anything; it only sets the foreground window, then watches for later windows and exits when it has nothing left to act on. Spawned once per gamescope session, eight seconds in, so the session's wineserver exists first. The exe runs from the payload by its `Z:` path, so nothing is copied into the container prefix. One requirement follows: the gamescope payload must contain `bin/gn-activate.exe`, which is what GameNative/gamescope#38 does.
joshuatam
added a commit
to joshuatam/GameNative
that referenced
this pull request
Nov 15, 2026
Under `explorer /desktop=shell` the guest's window is an override-redirect child of the desktop, and wine never activates it: the title comes up with no foreground window, so injected input has nowhere to land and buttons do nothing until something clicks the window. `bin/gn-activate.exe` (GameNative/gamenative-drm#69) fixes that with one Win32 call, which is the only lever that works -- X focus and the EWMH/ICCCM activation messages are accepted and leave wine's foreground at <none>, measured on RP6 with NFS Most Wanted. It does not raise or reorder anything; it only sets the foreground window, then watches for later windows and exits when it has nothing left to act on. Spawned once per gamescope session, eight seconds in, so the session's wineserver exists first. The exe runs from the payload by its `Z:` path, so nothing is copied into the container prefix. One requirement follows: the gamescope payload must contain `bin/gn-activate.exe`, which is what GameNative/gamescope#38 does.
utkarshdalal
pushed a commit
to utkarshdalal/GameNative
that referenced
this pull request
Nov 16, 2026
…he rendering engine is now open source (#2393) * gamescope: the present mode comes from the guest, not the container (payload 20261110.2) On the gamescope route the guest's own request is the present mode that counts: the shim records what DXVK asks for and forwards it, and the image count is the shim's to advertise (three, floored) because that is what the surface capabilities say. A present mode in the container therefore makes the shim declare one the guest never asked for, and a `WRAPPER_MAX_IMAGE_COUNT` ceiling competes with the capabilities the guest already read. `setupXEnvironment` now removes both variables when the display server is not X11, after the container, best-config, Environments-tab and game-fix merges have all landed - so the removal covers every source of the value rather than one of them. The X11 route keeps both, where Mesa's WSI is what consumes them. Measured on Hades II, same save and scene: the container's `mailbox` declaration became the guest's own `immediate`, and the swapchain went from four slots to the three the shim advertises. At the 120 Hz cap that arm costs nothing (the acquire is limiter-parked, not starved); see docs/performance/06 in gamenative-drm for the census that decides it. Also bumps the payload to 20261110.2 and rebuilds `libgamenative_drm.so` from gamenative-drm's performance work: reference-counted live-inode set, the atomic request decoded straight out of the payload, caller-owned pollfd buffers, and a cached JNI method id - 6.04 -> 1.04 allocations per commit, with no CPU claim. * update payload * gamescope: the payload carries the LSFG present mode, and the payload is re-stamped `nativeSetLsfgConfig` gains a `presentMode` argument — 1 for fifo, 0 for mailbox — so the layer knows which mode generation is served with, instead of assuming mailbox. The QuickMenu offers those two for generation and nothing else, and the value comes from the container's `presentMode` extra, which is the same setting the rest of the launch path reads. The wire struct grew with it (`LsfgConfig.present_mode`), so the payload version moves to `20261113.1`: an older payload would reject the longer frame and the session would get no generation settings at all, silently. The bundled `libgamenative_drm.so` is rebuilt from gamenative-drm at the head that carries the release-note pairing and the hidden-slot fixes. * notices: libgamenative_drm.so is GPL-3.0-or-later, and GNDRM_LOG_VKSHIM is an option The notice said `libgamenative_drm.so` was proprietary, all rights reserved and its source undistributed. It is GPL-3.0-or-later — the repository states it in `Cargo.toml` and names the holder in its README — and the same binary contains the ICD shim, so it is also the library shipped inside the gamescope payload. A proprietary notice over a GPL binary is the one error in this file that a distributor would have to answer for, so it now names the licence, the holder, the source repository, the build command, and the section 6 source offer. `GNDRM_LOG_VKSHIM` joins the environment options as a toggle. It turns on the shim's per-frame lines and the per-session census — `present mode:`, `proxy commit:`, `lsfg:`, `scanout frame cap:`, `proxy park timeout:` — which is what a frame-rate report has to quote; a toggle rather than free text because the shim reads it as a boolean and a typo would silently leave logging off. * gamescope: 20261114.1 — the daemon names the frame in its release note Payload re-stamp to `20261114.1`, carrying `libgamenative_drm.so` built from gamenative-drm `a5b28dc` (the two commits since `292d0dc`). What the daemon side of that change does, in the app's terms: - **A released buffer is now reported by the frame it carried**, not by its dma-buf inode. `BufferReleased` gained `ticket`, `latch_ns` and `source`; the shim mints the ticket, the daemon echoes it, and the shim frees that slot and no other. The inode only paired while gralloc handed the same object through to SurfaceFlinger — true for Portal 2 on Nova (6 % fallback) and false for Dave on the same device (84 %). - **A session with no release notes still runs.** Four unanswered parks free the slot on its fence, which is what took RP6 from 35.9 to 59.8 fps. - **A 32-byte mark no longer vanishes.** The daemon read the scan-out channel into a 24-byte buffer and SOCK_SEQPACKET truncates rather than failing, so every mark was dropped before it could be used. Readers use `wire::INBOUND_MAX` now, with a test that fails the build if a frame outgrows it. - **`sf mark:`** prints every ten seconds: hit/order/miss/skew/pending, so a session whose marks do not resolve is visible instead of silent. Measured on Dave the Diver at 1280x720, cap 60, 60 Hz: Nova 60.0 fps (`by_order` frozen, tickets answering every park), Odin 3 59.7 (`p95=17.2 ms`, `slow=0/118`, `repeated=0`), RP6 59.8 (on the fail-open, `channel=dead:true`). The census behind those numbers is `logf!`, so it needs `GNDRM_LOG_VKSHIM=1`; the `GNDRM_LOG_VKSHIM` toggle in `EnvVarInfo.kt` exists for that and a session without it is indistinguishable from a pre-census build. * gamescope: daemon at drm 31737b1 — the release note names the exact frame Pins `libgamenative_drm.so` to gamenative-drm `31737b1`, the head of `refactor/vsync`, and nothing else in the payload changes: `20261114.1` still carries the shim built from that same tree. Three fixes in the daemon since the last pin (`37e140015` carried `292d0dc`-plus): - **The release note names the frame the fence describes.** The daemon read the replaced buffer's ticket on SurfaceFlinger's binder thread, after the apply, and that field is overwritten by the buffer's next publish. A delayed callback could therefore name a newer frame, and the shim would free the slot still being scanned. The ticket is now snapshotted at the apply, where the buffer cannot be published again. Inert on the common path, and invisible in counters by design. - **The mark fallback is exact, not merely forward.** The next publish must take the next ticket; a permissive rule bound a mark to the wrong registration, which frees the wrong slot — a tear, not a reordering. `stale`/`resync`/`skew` in `sf mark:` now say which of the four outcomes happened, and `resync` is the first measurement of `sendmsg` dropping marks under load. - **The slot's ticket is `AtomicU64`**, stored `Release` against the `Acquire` load the acquire path performs under `shared`. As a plain integer the only ordering was temporal, and a stale read matching an unconsumed older note freed a slot early. Measured on RP6 with this build: `sf mark: hit=9617 order=1 miss=7 stale=1 resync=0 skew=0 pending=0`, `tick=12 of ~17 notes`, rate 59.7 unchanged. The exact-next rule is exercised there; the snapshot is verified by review, not by a counter. Nova and Odin, where `tick=` runs in the thousands, are still unmeasured on this build. * gamescope: daemon at drm e6ccad5 — the synced generation ceiling is the leftover Pins the daemon to gamenative-drm `e6ccad5` (head of `refactor/vsync`). What moved there: the synced generated ceiling is `min(cap × (m−1), refresh − acquire)` instead of `min(cap × (m−1), refresh)`. Counting the source frames outside the panel's budget let a cap 40 ×2 session on 60 Hz plan 80 commits a second, of which the compositor dropped 20. **This pin does not ship that rule by itself.** `limits.rs` is in the shim, which travels in the gamescope payload as `libadrenotools_gamescope.so`; the daemon carries the release-note and publish path. So the payload needs a rebuild to carry the new ceiling, and the daemon here is unchanged in content from the previous pin — only the build stamp and this pin move. The consequence is deliberate: at 60 Hz, cap 40, ×2 the panel leaves 20 generated against 40 source frames, half a frame each, which floors to none. Generation does nothing at any cap above half the refresh; cap 30 ×2 keeps one per source. Tests and `docs/10` state it rather than leaving it to be discovered. * gamescope: run the activation helper from the payload Under `explorer /desktop=shell` the guest's window is an override-redirect child of the desktop, and wine never activates it: the title comes up with no foreground window, so injected input has nowhere to land and buttons do nothing until something clicks the window. `bin/gn-activate.exe` (GameNative/gamenative-drm#69) fixes that with one Win32 call, which is the only lever that works -- X focus and the EWMH/ICCCM activation messages are accepted and leave wine's foreground at <none>, measured on RP6 with NFS Most Wanted. It does not raise or reorder anything; it only sets the foreground window, then watches for later windows and exits when it has nothing left to act on. Spawned once per gamescope session, eight seconds in, so the session's wineserver exists first. The exe runs from the payload by its `Z:` path, so nothing is copied into the container prefix. One requirement follows: the gamescope payload must contain `bin/gn-activate.exe`, which is what GameNative/gamescope#38 does. * update payload 20261116.1
4 of 8 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adds the Win32 helper that activates the guest's window, and the measurements that led to it.
Under
explorer /desktop=shellthe guest's window is an override-redirect child of the desktop. Wine never activates it, so a title comes up with no foreground window: injected input has nowhere to land and buttons do nothing until something clicks the window (NFS Most Wanted sat on "press START" until a click).Only a Win32 call fixes that. Measured on RP6 with NFS Most Wanted, one run per arm, X focus kept and wine's foreground after:
<none>_NET_ACTIVE_WINDOW<none>WM_TAKE_FOCUS+XSetInputFocus<none>SetForegroundWindowA later session focused the game's own window by X and the title's START still did nothing, which is the same result with the confound removed.
What it contains:
tools/gn-activate/gn-activate.c, a Win32 exe (mingw, both bitnesses) that sets the foreground window and then watches for later windows. It matches by process image, enumerates children as well as top-levels, and skips wine's desktop window.SetForegroundWindowis tried first, then theAttachThreadInputescalation;SendMessage WM_ACTIVATEis opt-in behind--force-messagesbecause it convinces the game it is active while wine's routing stays put.--query-fg, the only read-only way to ask what wine considers foreground.--idle-ms, so the watcher ends when it has nothing left to act on: a launcher session outlives its game, so "wait for the desktop to disappear" never fires.tools/xtree-probe.cgains-activate,-take-focusand-watch-activate, which is how the table above was produced and how anyone can re-test it if the launch line stops using a virtual desktop.Two launch traps, both silent, are documented in
build-gn-activate.sh: the exe must run from aZ:path to the payload (a bare unix path faults beforemain), and a fresh wine process starts on the default desktop, whereEnumWindowsreturns nothing at all.Ships with GameNative/gamescope#38, which puts the exe in the gamescope payload; the app runs it from there.