Repository navigation
feat(desktop): report the application in front - #579
Merged
Merged
Conversation
desktop.Frontmost returns the application in front on the desktop, the app itself included: its ID, name, process ID and whether its frontmost window is in full screen. It is part of the environment, so effects reading it run again as another app comes to the front, and it is held to the new core.AccessFrontmostApp capability. - macOS: NSWorkspace's frontmost application, followed through its activation and active Space notifications; full screen from the window server's window list. - Windows: the foreground window's process, followed through SetWinEventHook (foreground, and location changes of the process in front); the name from the executable's file description. - Linux X11: _NET_ACTIVE_WINDOW with _GTK_APPLICATION_ID, WM_CLASS, _NET_WM_PID and _NET_WM_STATE_FULLSCREEN, followed through PropertyNotify; zero on Wayland. Fixes #570
Rename desktop.Frontmost to desktop.FrontmostApp and its type to desktop.FrontmostAppInfo (core.FrontmostAppInfo, driver.FrontmostAppInfo), keeping Scope.FrontmostApp, as with DisplayInfo. Add desktop.CanReadFrontmostApp, backed by Environment.CanReadFrontmostApp: true on macOS, Windows and Linux on X11, false on Wayland, phones, the web and mini programs, and for code whose Access refuses AccessFrontmostApp, without logging a refusal. Scope.FrontmostApp now reads zero wherever the platform does not follow the app in front, and the test host pins both fields.
houko
force-pushed
the
feat/frontmost-app
branch
from
November 17, 2026 11:30
5a04a39 to
bc135a3
Compare
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.
Summary
Fixes #570.
desktop.FrontmostApp(cx)returns the application in front on the desktop, the app itself included, as adesktop.FrontmostAppInfo(an alias ofcore.FrontmostAppInfo): its ID, name, process ID and whether its frontmost window is in full screen.desktop.CanReadFrontmostApp(cx)says whether the platform follows it. Both are part of the environment, so effects and bindings reading them run again as another app comes to the front or the one in front enters or leaves full screen. Both are held to the newcore.AccessFrontmostAppcapability, since they say what else the user runs: refused code reads zero andfalse, and askingCanReadFrontmostApplogs no refusal.FrontmostAppis zero whereverCanReadFrontmostAppis false. Tests set them throughnsgotest.Environment(core.Environment{FrontmostApp: ..., CanReadFrontmostApp: true}), which the test host pins over the platform's values.NSWorkspace.frontmostApplication, followed through its activation and active Space notifications; full screen from the window server's window list, which needs no permission.CanReadFrontmostAppis true.SetWinEventHook(foreground, and location changes of the process in front) on the UI thread, whose message loop receives the out-of-context events; the path fromQueryFullProcessImageNameWwithPROCESS_QUERY_LIMITED_INFORMATION, the name from the executable's file description. A process Windows will not open reports its PID with no ID or name.CanReadFrontmostAppis true._NET_ACTIVE_WINDOWwith_GTK_APPLICATION_ID,WM_CLASS,_NET_WM_PIDand_NET_WM_STATE_FULLSCREEN, followed throughPropertyNotify.CanReadFrontmostAppis true only when GDK draws on X11.CanReadFrontmostAppfalse, on Wayland, phones, the web and mini programs. The remaining gaps (Wayland, UWP apps reporting their frame host, macOS full screen that changes no Space) are recorded in the roadmap.Targets
nsgo test -target macosand under plaingo testover SSH.TestWMClass). The live X11 tracking was not run, because the build host has no GUI session.CanReadFrontmostAppfalse by design. Android, web and iOS compiled and vetted.Screenshots
None: this adds a non-visual API and changes no UI.
Verification
All commands run from the branch's worktree at the head commit.
ubuild mise exec [email protected] -- go tool nsgo check -target all: exit 0. Vetted macos_arm64/x64, windows_arm64/x64, linux_arm64/x64, android_arm64 and web; ios/tvos/watchos skipped there ("need macOS with Xcode").rbuild mise exec [email protected] -- go tool nsgo check -target ios: exit 0.ubuild ... go tool nsgo test ./desktop: 3 passed (TestFrontmostAppFollowsTheAppInFront,TestFrontmostAppIsHeldToAccess).ubuild ... go tool nsgo test ./core: 662 passed, 0 failed (includesTestServicesGoThroughTheGateandTestGateRules).ubuild ... go tool nsgo test ./nsgotest: 70 passed.ubuild ... go tool nsgo test ./internal/testhost: 1 passed (TestPinSetsTheTestsDisplaySettings).ubuild ... go tool nsgo test -run TestWMClass ./internal/platform/linux: 1 passed.rbuild ... go tool nsgo test -target macos ./desktop: 3 passed, 0 skipped.rbuild ... go tool nsgo test -target macos -run 'TestReadFrontmost|TestFrontmostFollows|TestCoversDisplay' ./internal/platform/macos: 3 passed, 0 skipped.rbuild ... go test -run 'TestReadFrontmost|TestFrontmostFollows|TestCoversDisplay' -v ./internal/platform/macos: all threePASS, none skipped. The earlier statement thatTestReadFrontmostskips over SSH on the Mac Studio does not hold at this head: run over SSH there, it reads the app in front and passes.Not checked:
FullScreenagainst a real full-screen player and a maximized window was not checked on any platform, and the live X11 tracking was not run.Checklist