X11 foreground scroll intermittently loses the first wheel clicks after the raise
Summary
On X11, a foreground scroll sometimes delivers only part of its wheel clicks when it follows the focus-guard raise. The call reports success.
Evidence
CI run 36459141345, job 109052999112 (Desktop Linux QA) on PR #9128, head 765863050f. That PR changes only descriptions and docs, not engine code. The scenario was x11-scroll-direction-foreground, using the same dy: 120 px (3 notches of 40 px) and a line height of 17 px:
| Step | Line | Moved |
|---|---|---|
| start | 101 | |
| +dy 120 | 106 | 5 lines (85 px) |
| -dy 120 | 98 | 8 lines (136 px) |
negative_dy_returns_to_start failed because the first positive scroll came up short. In the same job, x11-scroll-direction-background moved 8 lines in both directions. On the last 8 dev pushes the foreground scenario passed, so the failure is intermittent.
Hypothesis
This is the X11 counterpart of #9095 (Windows, fixed by waiting for the compositor after the raise). The foreground path raises the target window and moves the pointer, then sends XTEST button 4/5 clicks. The first click(s) can reach the X server before the window manager has finished restacking or focusing the target, or before the pointer's window under the cursor is updated, so they go nowhere. In the observed run one of three notches, or part of the pixel budget, was lost.
Expected
A foreground scroll delivers exactly the requested distance, or it fails. Before sending the first button event, the engine confirms that the target is the window under the pointer (XQueryPointer child chain) after the raise, and syncs with the server (XSync or a round trip).
Acceptance
- A deterministic reproduction on Xvfb with a window manager (repeat the foreground scroll N times right after a raise) that fails before the fix.
- After the fix,
x11-scroll-direction-foregroundpasses repeatedly (e.g. 20/20) in CI.
Source: code-yeongyu/oh-my-openagent