Skip to content

feat(linux): set window levels on X11 and report window stacking and placement - #583

Merged
houko merged 3 commits into
mainfrom
fix/linux-window-level
Nov 17, 2026
Merged

houko merged 3 commits into
mainfrom
fix/linux-window-level

Conversation

@houko

@houko houko commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes #573.

SetWindowLevel now works on Linux under X11: GTK 4 has no keep-above, so NSGo asks the window manager for _NET_WM_STATE_ABOVE or _NET_WM_STATE_BELOW through the EWMH client message, and sends the request again each time the window maps (the GtkWindow "map" signal), so a level set while the window is hidden still takes effect.

Env.CanSetWindowLevel and Env.CanPlaceWindows, with desktop.CanSetWindowLevel and desktop.CanPlaceWindows, tell an app whether the window level and SetWindowFrame's position take effect:

  • macOS and Windows: both true.
  • Linux under X11: only the level.
  • Linux under Wayland, an embedded view, or the app's own hidden surface and a tray icon's scope (on every desktop platform, matching macOS): both false.

Docs (docs/architecture/services.md, public components docs in English and Chinese), the roadmap (TSX's nsgo/desktop does not report the capabilities yet) and the changelog are updated.

Targets

  • Linux X11: implemented and run under Xvfb with GDK_BACKEND=x11, where no window manager answers the requests; not yet checked under GNOME on Xorg or KDE.
  • Linux Wayland: capabilities report false; run on the default (Wayland) backend under Xvfb.
  • macOS: reports both capabilities; compiled and vetted only (check -target all), not run.
  • Windows: reports both capabilities, false for the app surface and tray scope; compiled and vetted only. There is no Windows machine, so the new Windows test never ran.
  • Shared core / desktop / nsgotest: tests run on Ubuntu.
  • Android: an overlay reports CanPlaceWindows; compiled and vetted only, checked through nsgotest.

Screenshots

None: no visual change. This sets window-manager stacking hints and reports capabilities; it does not change how anything is drawn.

Verification

All commands were run from the branch's worktree.

  • ubuild mise exec [email protected] -- go tool nsgo check -target linux_x64,linux_arm64,windows_x64,windows_arm64,web,android_arm64: all vetted, exit 0.
  • rbuild mise exec [email protected] -- go tool nsgo check -target all: catalogs, vet, dev client and every listed target (macOS arm64/x64, Windows, Linux, iOS and simulator, tvOS and simulator, watchOS and simulator, android_arm64, web) vetted, exit 0.
  • ubuild ... nsgo check -target linux_x64,windows_x64: exit 0.
  • ubuild ... nsgo test ./core: 663 passed, 0 failed. This includes the new TestEnvironmentWindowCapabilities and the existing TestWindowFrameAndLevel.
  • ubuild ... nsgo test ./desktop: 2 passed, including the new TestWindowLevelAndPlacementFollowTheEnvironment.
  • ubuild ... nsgo test ./nsgotest: 70 passed.
  • ubuild ... nsgo test ./internal/driver: 133 passed.
  • ubuild ... nsgo test ./internal/moduletest (layering, skill and docs checks): 9 passed.
  • ubuild env GDK_BACKEND=x11 xvfb-run -a mise exec [email protected] -- go tool nsgo test ./internal/platform/linux -- -run TestWindowLevelAsksTheWindowManager -count=3: 3 passed.
  • I broke one expected value on purpose and the X11 run failed with "normal: request [0 253 254], want [1 253 254]", which shows the test really reaches the X11 path. I then put the value back.
  • ubuild xvfb-run -a ... -run TestWindowLevelAsksTheWindowManager on the default backend (Wayland on that host): passed. On Wayland it checks that both capabilities are false.
  • ubuild env GDK_BACKEND=x11 xvfb-run -a ... nsgo test ./internal/platform/linux: 133 passed, 0 failed, 1 skipped.
  • A logging run showed the re-sent level requests arrive after MapNotify, i.e. after the window is mapped.
  • Bug found and fixed along the way: the first version re-sent the level on the GdkSurface notify::mapped signal, which never fired when the window was hidden and shown again. It now uses the GtkWindow "map" signal.

After review fixes (second commit: capabilities false for the app's own surface and tray scope on Linux and Windows):

  • go tool nsgo check -target windows_x64,windows_arm64 and -target windows_x64,linux_x64 on Ubuntu: passed. This vets the Windows code and test files; they were only compiled.
  • go tool nsgo test ./core/... (663 tests) and ./desktop/...: passed.
  • In ./internal/platform/linux, -run 'WindowLevel|AppSurfaceHasNoWindowLevel': both tests passed. These runs were on the default backend, so they do not prove anything about X11: with the Linux fix temporarily reverted, TestAppSurfaceHasNoWindowLevel still passed because drawsOnX11() is false there, and TestWindowLevelAsksTheWindowManager most likely took its early return for a non-X11 window. Both need a real X11 session (GDK_BACKEND=x11) to be meaningful.
  • macOS code is unchanged by the second commit, so it was not rebuilt on macOS.
  • gofmt -l is clean on every changed file.

After the review fix (third commit: an Android overlay reports CanPlaceWindows true, as SetWindowFrame places it; docs and roadmap corrected):

  • rbuild mise exec [email protected] -- go tool nsgo check -target all: every target vetted, exit 0.
  • ubuild ... nsgo check -target linux_x64,linux_arm64,windows_x64,windows_arm64,android_arm64,web: exit 0. The Android change is compiled and vetted only, not run on a device.
  • ubuild ... nsgo test ./nsgotest (70 passed, including TestOverlayMovesHidesAndCloses, which now checks the overlay's content sees CanPlaceWindows), ./desktop (2), ./core (663), ./internal/moduletest (9).
  • ubuild env GDK_BACKEND=x11 xvfb-run -a ... nsgo test ./internal/platform/linux -- -run 'WindowLevel|AppSurfaceHasNoWindowLevel' -count=2: 4 passed.

Failures not caused by this change:

  • On the default (Wayland) backend, TestTheWindowClassIsTheAppID crashes with SIGSEGV in XGetClassHint; this branch does not touch it.
  • A recursive nsgo test . on Ubuntu fails GUI tests in other packages for lack of a display.

Checklist

  • Conventional Commit title.
  • Changelog, architecture and public documentation, and roadmap updated.
  • No new dependencies or third-party assets.

…placement in Env

SetWindowLevel now asks an X11 window manager for _NET_WM_STATE_ABOVE or _NET_WM_STATE_BELOW through EWMH's client message, again each time the window maps, as GTK 4 has no keep-above. Env.CanSetWindowLevel and Env.CanPlaceWindows, with desktop.CanSetWindowLevel and desktop.CanPlaceWindows, tell an app whether the level and SetWindowFrame's position take effect: both on macOS and Windows, only the level on Linux under X11, neither on Wayland or for an embedded view.

Fixes #573
… the surface's own

Linux and Windows now report CanSetWindowLevel and CanPlaceWindows false for the app's own hidden surface and a tray icon's, as macOS does, so the app function's scope gets the same answer everywhere. Narrow the capability's comments to desktop windows, since an Android overlay is placed by mobile and reports false, and record in the roadmap that TSX's nsgo/desktop does not report the capabilities yet.
@github-actions github-actions Bot added documentation Improvements or additions to documentation macOS Windows Linux core enhancement New feature or request size/M labels Nov 17, 2026
…11 level was checked under

SetWindowFrame moves an Android overlay (Overlays.java keeps it on the screen), so CanPlaceWindows is true for one on Android and in nsgotest, rather than false as the docs said. The roadmap now says the X11 level was checked under Xvfb with no window manager, not only built.
@houko houko mentioned this pull request Nov 17, 2026
8 tasks done
@houko
houko merged commit 23b625e into main Nov 17, 2026
16 of 18 checks passed
@houko
houko deleted the fix/linux-window-level branch November 17, 2026 11:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android core documentation Improvements or additions to documentation enhancement New feature or request Linux macOS size/M Windows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linux: SetWindowLevel does nothing, so a floating window drops behind others (X11), with no way to tell on Wayland

1 participant