Skip to content

[Feature] Desktop: the frontmost application and its changes #570

Closed

Description

@houko

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 its animations.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.frontmostApplication and NSWorkspaceDidActivateApplicationNotification.
  • Windows: GetForegroundWindow with SetWinEventHook(EVENT_SYSTEM_FOREGROUND), the process path from QueryFullProcessImageNameW.
  • Linux X11: _NET_ACTIVE_WINDOW with WM_CLASS and _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 FrontmostApp within one frame on macOS, Windows and Linux X11, and the app's own activation reports itself.
  • FullScreen is true for a full-screen video player and false for a maximized window.
  • nsgotest can set the value.

Activity

  1. added a commit that references this issue on Nov 17, 2026
    63e76cd
  2. added a commit that references this issue on Nov 19, 2026
    92e27f0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions