Skip to content

x11: don't write _NET_WM_USER_TIME 0 when there is no user time - #256

Open
danjboyd wants to merge 1 commit into
gnustep:masterfrom
danjboyd:ai-policy/x11-user-time
Open

danjboyd wants to merge 1 commit into
gnustep:masterfrom
danjboyd:ai-policy/x11-user-time

Conversation

@danjboyd

Copy link
Copy Markdown
Contributor

-[XGServer setinputfocus:] writes _NET_WM_USER_TIME from -lastTime. -lastTime answers CurrentTime, which is 0, before the backend has seen an event and again once the last event is more than half a second old. In this property 0 means the window should not get the focus when it is mapped, and Mutter stacks such a window below the focused one. So under GNOME an application's first window can open behind whatever the user was looking at, and it can look as if the application didn't start.

This is the symptom of #62. #65 (0504204), which closed that issue, passes on DESKTOP_STARTUP_ID and doesn't touch this property. It is in master, and this still reproduces on master when the application is started without a startup ID.

The change writes the property only when -lastTime has a real time. A window that already has one keeps it. XSetInputFocus is unchanged.

Under GNOME Shell 48.7 (X11, private Xvfb), with another application's window focused, a small program opened a window with -makeKeyAndOrderFront: when launching finished, and a second one 3 seconds later, after the other application had been activated again. 3 runs each:

master (d378734) with this change
First window's _NET_WM_USER_TIME 0 no property
First window below the other application's window on top
Second window stays behind on top

The last row is a change in behaviour you may want to weigh. On master, a window opened more than half a second after the application's last event stays behind, as a side effect of the 0. With this change the backend reports no time for it, so it's left to the window manager's own rules, and under Mutter it came up over the application the user had moved to. If you'd rather keep that behaviour, the check could be limited to the case before the first event, but -lastTime doesn't separate the two today.

Testing: Tests/x11/usertime.m starts the x11 tests' stand-in EWMH window manager, because the backend writes the property only under one, and reads _NET_WM_USER_TIME back after -setinputfocus:.

  • A window focused before any event, and one focused once the last event is out of date, must have no property.
  • A window focused just after an event must have that event's time. That guards against the write being lost altogether.
  • Focusing that window again later must leave its time alone.

It reads only the property, so it catches the 0 being written but not what a window manager does with it. Without the change 3 of the 4 checks fail; with it all 4 pass. The whole suite, with libs-gui 549f63913: 290 passed, none failed. On master with the new test added: 287 passed, and only those 3 failed. The changed file and the test also pass a syntax check with GCC's Objective-C front end.

Not covered: a real Wayland session (XWayland), other window managers, windows the gui decorates, and a launch with a startup ID (the runs above had none). The test depends on the half-second limit in XGServerEvent.m.

AI assistance: this change, its test and this description were written with Claude (Anthropic's Claude Code).

🤖 Generated with Claude Code

-setinputfocus: writes _NET_WM_USER_TIME from -lastTime.  -lastTime answers
CurrentTime, which is 0, before the backend has seen an event and again
once the last event is more than half a second old.  In this property 0
means the window should not get the focus when it is mapped, so Mutter
stacks the window below the focused one.  An application's first window
opens behind whatever the user was looking at, and it can look as if the
application didn't start.

-setinputfocus: now writes the property only when -lastTime has a real
time.  A window that had one keeps it.  XSetInputFocus is unchanged.

Testing: Tests/x11/usertime.m starts the x11 tests' stand-in EWMH window
manager, because the backend writes the property only under one, and reads
_NET_WM_USER_TIME back after -setinputfocus:.  A window focused before any
event, and one focused once the last event is out of date, must have no
property.  A window focused just after an event must have that event's
time, which guards against the write being lost altogether.  Focusing that
window again later must leave its time alone.  It reads only the property,
so that is enough to catch the 0 being written; what a window manager does
with the property isn't tested there.  Without this change 3 of the 4 checks
fail; with it all 4 pass.  The whole suite, with libs-gui 549f63913: 290
passed, none failed; on master with the new test added, 287 passed and only
those 3 failed.

Under GNOME Shell 48.7 (X11, private Xvfb), with another application's
window focused, a small program opened a window with -makeKeyAndOrderFront:
when launching finished, 3 runs each:
- master: the window has _NET_WM_USER_TIME 0 and stays below the other
  application's window;
- with this change: it has no property and comes up on top.

The same runs opened a second window 3 seconds later, after the other
application had been activated again.  On master it stays behind; with this
change it comes up on top, because the choice is then left to the window
manager's own rules.

Not covered: a real Wayland session (XWayland), other window managers, and
windows the gui decorates.

AI assistance: this change, its test and this description were written
with Claude (Anthropic's Claude Code).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@danjboyd
danjboyd requested a review from fredkiefer as a code owner November 12, 2026 21:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant