Repository navigation
Closed
Description
Context
Line numbers are at 4aea100 (main).
An app cannot ask which application is frontmost on the desktop, or hear when that changes. core.Env and the desktop package have nothing for it. The backends already touch the system calls internally: macOS reads NSWorkspace.frontmostApplication for the permission guide (internal/platform/macos/permissionguide.go:324), and Windows loads GetForegroundWindow (internal/platform/windows/env.go:37).
Why it matters
Several kinds of desktop apps react to what the user is doing in other apps:
- Desktop pets and companions switch animations by activity: the "Big Blue Fish" pet (github.com/Bai-Cute/big-blue-fish-desktop-pet) plays a "coding" animation while an editor or terminal is in front (
WorkKind: "Coding"in itsanimations.json). - Input methods keep a per-app input mode (English in a terminal, Chinese in a chat app).
- Time trackers, focus and break reminders, and "pause while a full-screen app or game is in front" logic in tray apps.
Proposal
A reactive desktop value, empty on platforms without one:
type FrontmostApp struct {
// ID is the macOS bundle identifier, the Windows executable path or AUMID, or the Linux desktop file ID / WM_CLASS.
ID string
// Name is the app's display name.
Name string
// PID is its process ID, 0 when unknown.
PID int
// FullScreen is whether its frontmost window covers the display.
FullScreen bool
}
// FrontmostApp returns the application in front, tracked: a scope reading it rerenders when another app comes to the front.
func FrontmostApp(cx *core.Scope) FrontmostApp- macOS:
NSWorkspace.frontmostApplicationandNSWorkspaceDidActivateApplicationNotification. - Windows:
GetForegroundWindowwithSetWinEventHook(EVENT_SYSTEM_FOREGROUND), the process path fromQueryFullProcessImageNameW. - Linux X11:
_NET_ACTIVE_WINDOWwithWM_CLASSand_NET_WM_PID; Wayland has no portable way, so it reports the value unavailable there. - Gated by
Access, since it reveals what the user runs.
Acceptance
- Switching between two other apps updates
FrontmostAppwithin one frame on macOS, Windows and Linux X11, and the app's own activation reports itself. FullScreenis true for a full-screen video player and false for a maximized window.- nsgotest can set the value.
Metadata
Metadata
Assignees
Labels
No labels
Activity
feat(desktop): report the application in front
feat(desktop): report the application in front