Windows and panels
Size, place and layer desktop windows, open panels and tray icons, bind global shortcuts, and read the pointer, displays and full screen.
Size and placement
Section titled “Size and placement”desktop.SetWindowConstraints limits content size and controls resizing, minimizing and maximizing; set WindowOptions.Constraints when opening a window or use nsgo.WindowConstraints for the main window. Linux applies nonfixed maximums on X11 and removes forbidden minimize/maximize buttons from GTK’s native titlebar on X11 and Wayland. Wayland currently supports fixed sizes only for an upper bound.
Desktop resizes on macOS, Windows and Linux wait up to 16 ms for the new layout before drawing. Keep reactive computations and event handlers quick so layout can meet that deadline; perform slow I/O on a goroutine and post results through cx.Post. A busy app continues resizing and shows its layout when it catches up.
desktop.SetWindowFrame moves a window when WindowFrame.Move is true, using X and Y in points from the main screen’s top left. Unset dimensions keep their current sizes. Check desktop.CanPlaceWindows: macOS, Windows and Linux on X11 support positioning; an ordinary Wayland toplevel keeps the compositor’s position. desktop.Frame follows the native window’s position on these desktops.
On macOS and Windows, WindowFrame{Animated: true} eases a visible panel to its new frame, including a docked panel’s size. Hidden panels and reduced motion apply the new frame immediately. Ordinary macOS windows use AppKit’s animation.
desktop.SetWindowLevel floats a window above the others, and desktop.SetWindowWorkspaces(cx, desktop.WindowWorkspacesAll) or WindowOptions.Workspaces keeps it on every workspace, as a desktop pet, a HUD or a timer is: on macOS on every Space and over other apps’ full screen spaces, out of Cmd-, and on Linux on every virtual desktop of an X11 window manager. Windows and Wayland leave it on the one it opened on, and desktop.CanSetWindowWorkspacessays whether it takes effect: true on macOS and under an X11 window manager that supports_NET_WM_DESKTOP. A main window goes on every workspace by calling desktop.SetWindowWorkspacesfrom its content. In tests,nsgotest.App.Windowlists the requests, andnsgotest.EnvironmentsetsCanSetWindowWorkspaces`.
Set desktop.WindowOptions.Parent to an open window of the app to close both when the parent closes. On desktops the child stays above its parent and follows it when it hides or minimizes; a child explicitly hidden stays hidden when the parent returns. On macOS it also centers over its parent when Frame is unset and follows it into full screen.
WindowOptions.NoShadow and desktop.SetWindowShadow(cx, false) also take the shadow from a Windows window whose title bar is hidden, which draws its own chrome; a window with the system’s title bar keeps its frame and shadow, as does a Linux window its window manager decorates, where NoShadow only clears the shadow of GTK’s own decorations.
Title bars
Section titled “Title bars”A window’s default title bar, desktop.TitleBarDefault, blends with the app: it takes the opaque color along the top of the content, the root view’s background or the first view that fills the window’s top edge with one, and its title and buttons read on that color. On macOS the title bar turns transparent over a window background of that color, the content staying below it; Windows 11 draws the caption in it, and Windows 10 picks the light or dark caption closest to it; Linux paints GTK’s header bar in it. The title, dragging, double-click zoom, Windows 11’s snap layouts and the menus stay the system’s, and the color follows the content as it or the appearance changes. Content without an opaque color at its top, or under a window material, keeps the system’s title bar. desktop.SetTitleBar(cx, desktop.TitleBarSystem, 0) keeps the system’s opaque title bar whatever the content shows. In tests, nsgotest.App.WindowBackground is the color the title bar takes.
With desktop.TitleBarHidden, Windows and Linux offer the application menu as a popup on Alt pressed and released alone or F10. Alt with a top-level label’s first letter or digit opens that submenu or chooses that command, in the label’s script. App bindings keep their keys; Shift+F10 remains the context-menu key, and other Alt chords stay with the system. Escape closes the popup and restores keyboard focus.
Click-through windows
Section titled “Click-through windows”desktop.SetWindowPointerEvents lets the pointer through a window to the windows below it, of any app: WindowPointerNone everywhere, as a heads-up display does, and WindowPointerPainted wherever no view draws something or hears the pointer, as around a desktop pet that still takes presses, drags and right clicks on itself; the title bar the system draws counts as nothing drawn. WindowOptions.PointerEvents and PanelOptions.PointerEvents open a window so. A Desktop.WindowDrag region still drags inside a pressable ancestor; a nearer pressable or editing control keeps its own input instead of dragging the window. A window that takes no pointer hears no presses, so the app gives it back from a shortcut, a tray icon or another window. Code an Access holds needs core.AccessOverlay.
desktop.OpenPanel(cx, desktop.PanelOptions{Width: 600, Height: 400, PointerEvents: desktop.WindowPointerPainted}, Pet)On macOS and Windows, an image in a painted window can set Image.HitTestAlpha to a value above 0 and at most 1. For example, 0.5 takes the pointer on picture pixels that are at least half opaque. The threshold also applies to the image’s OnPress. A view background or border still counts as painted. Zero uses the whole image view, as do images on Linux.
In a painted macOS window, Video.HitTestAlpha applies the same threshold to decoded video frames. It works with Controls off and an untransformed video track, such as HEVC with alpha for a desktop pet. Zero, an unavailable frame, and the other desktop hosts use the video view’s bounds.
Panels
Section titled “Panels”desktop.OpenPanel opens a panel such a shortcut or a tray icon shows: a borderless window above the others. Like desktop.OpenWindow, desktop.NewTray, mobile.OpenOverlay, audio.NewPlayer, audio.LoadSound and core.NewHolder, it belongs directly to the cx you pass rather than the running handler’s owner, so passing the app’s scope from a button’s OnPress keeps the window, panel or player alive after that button’s scope goes; reactive primitives (Effect, Cleanup, AfterFunc, OnKey) instead belong to the running owner, which cx.Run switches. A popup card draws itself on a panel with Transparent, which has no background, frame or shadow of its own, so the card’s rounded corners and BoxShadow are all that shows, with room for the shadow inside the panel; FitContent sizes the panel to its content, up to Width and Height, before it first shows and as the content changes. desktop.Transparent says whether the panel draws nothing of its own now, as it does for a transparent window, where desktop.CanMakeWindowsTransparent only says whether a window could be: where it is false, as on Linux without a compositor, give the content a background.
On macOS, a panel without Transparent uses square corners when either dimension is below 24 points and restores its rounded corners at normal sizes.
lookup := desktop.OpenPanel(cx, desktop.PanelOptions{Width: 380, Height: 520, Transparent: true, FitContent: true, HideOnBlur: true}, Card)desktop.RegisterHotKey(cx, "alt+space", lookup.Toggle)On macOS, a view of a transparent panel or window whose backdrop blur names a material, View.IOS.BackdropMaterial other than core.BackdropUltraThin, frosts the desktop and the windows behind it, within the view’s corner radius, as a recorder’s controls or a launcher’s card do; outside its corners nothing shows. Such a material shows the desktop even over what the app draws behind it in that window, so give a view over the app’s own drawing a blur by its radius alone, which keeps blurring that drawing. The material’s corners all take the top-left radius. A blur by its radius alone, and Windows and Linux, blur only what the app draws behind the view.
desktop.OpenPanel(cx, desktop.PanelOptions{Width: 320, Height: 64, Transparent: true}, func(cx *core.Scope) core.Node { return core.View{ Style: core.Style{CornerRadius: 16, BackdropFilters: []core.Filter{core.Blur(30)}}, IOS: core.IOSViewProps{BackdropMaterial: core.BackdropThin}, }})PanelOptions.Dock keeps a panel centered along a display’s usable edge through Show, Focus, Toggle and content resizing. Set Edge to core.PlaceTop, PlaceBottom, PlaceLeft or PlaceRight, Display to an Env.Displays ID (empty for the primary display), and Margin to the distance from that edge in points. A docked panel cannot use ShowAt or MoveTo; SetWindowFrame changes only its size. A tray icon shows it at its dock rather than under the icon.
panel := desktop.OpenPanel(cx, desktop.PanelOptions{ Width: 320, Height: 80, NoActivate: true, Dock: desktop.PanelDock{Edge: core.PlaceBottom, Margin: 12},}, Candidates)panel.OnPlacementError(cx, func(err error) { /* offer another presentation */ })panel.Show()desktop.CanDockPanels(cx) reports docking support separately from arbitrary window placement. macOS, Windows and X11 support it; Wayland needs the optional runtime library libgtk4-layer-shell.so.0 and a compositor implementing zwlr_layer_shell_v1. NSGo loads that library before GTK; an embedding host that already loaded Wayland must preload gtk4-layer-shell before starting the host. A missing library, protocol or selected display leaves the panel hidden and calls OnPlacementError. A Wayland dock uses the top layer without reserving workspace: NoActivate leaves the keyboard with the current window, while a panel without it takes exclusive keyboard focus until hidden. Ordinary Wayland windows retain their usual compositor placement.
Tray icons
Section titled “Tray icons”desktop.NewTray can draw a live icon with TrayOptions.View on macOS, Windows and Linux. Windows fits the view’s transparent rendering to the notification area’s icon size, and Linux draws it at the icon sizes of StatusNotifierItem hosts such as KDE Plasma and GNOME’s AppIndicator extension; both update it when the view changes or an image finishes loading. Use TrayOptions.OnClick, Panel and Menu for its actions.
desktop.NewTray shows TrayOptions.Title beside its image or drawn view on macOS. For a custom popup, read tray.ClickBounds() inside OnClick or Menu and pass the available rectangle to panel.ShowAt(bounds, core.PlaceBottom). It uses the same screen points as Env.Displays and includes the title. Bounds are unavailable before the first click, after removal, on Linux, and when the Windows shell cannot supply them. Each click replaces the previous bounds, so an unavailable result never reuses an old rectangle. Setting TrayOptions.Panel keeps the built-in click-to-toggle behavior instead.
macOS hides a menu bar icon it has no room for, behind a MacBook’s notch or past a crowded menu bar, without telling the app. tray.Visible() reports whether the user can see the icon and is tracked, so a view or an effect that reads it follows it: an app whose icon is its only indicator, such as a recorder’s elapsed time, can show a control of its own while it is false. On macOS it follows the status item’s window, so it is also false while the menu bar is out of sight, as under another app’s full screen or while a menu bar set to hide automatically is hidden; an app that shows its control then can wait a moment before showing it. On Linux it is false while no StatusNotifierWatcher took the icon, as on GNOME without the AppIndicator extension, and on Windows while the shell has no notification area yet, before Explorer starts. Otherwise Windows and Linux report true, as they say nothing of an icon the notification area’s overflow or a tray host hides. It is false after removal.
tray := desktop.NewTray(app, desktop.TrayOptions{Title: "0:42"})controls := desktop.OpenPanel(app, desktop.PanelOptions{Width: 160, Height: 44, NoActivate: true}, recordingControls)app.Effect(func() { if tray.Visible() { controls.Hide() } else { controls.Show() }})Global shortcuts
Section titled “Global shortcuts”desktop.RegisterHotKey binds a global shortcut, which works while any app is frontmost, on macOS, on Linux and in a Windows app run with nsgo.Run(App). Its handle’s State says whether the system took it: HotKeyPending until it answers, then HotKeyRegistered, HotKeyTaken when another registration holds the combination, or HotKeyUnsupported for a key or a platform without global shortcuts, so a shortcut recorder can ask for another combination. On macOS a combination counts as taken only when the app holds it already or another app registered it exclusively. On Wayland the compositor asks the user to bind the shortcut: it is registered once they have, and taken when they or the compositor leave it out. In tests, nsgotest.HotKeyTaken and nsgotest.HotKeyUnsupported make combinations answer so.
shortcut := desktop.RegisterHotKey(cx, "alt+space", launcher.Toggle)warning := core.Text{ContentFunc: func() string { if shortcut.State() == desktop.HotKeyTaken { return "Another app uses Alt+Space" } return ""}}The pointer and idle time
Section titled “The pointer and idle time”desktop.CursorPoint(cx, func(p core.Point, available bool) { ... }) reads the pointer even outside the app’s windows on macOS, Windows and X11. It takes one sample per call. The point is in the same screen coordinates as desktop.Monitors(cx) and Window.ShowAt. On Wayland and other unsupported targets, or if the scope lacks core.AccessCursorPoint, available is false.
desktop.IdleTime(cx, func(idle time.Duration, available bool) { ... }) reads how long ago the user last pressed a key or moved or clicked the pointer, in any app, so an app can tell whether the user is at the computer rather than only whether it is in use (Lifecycle): a chat client shows a banner while they are there and sends a notification to their phone once they are away. desktop.WatchIdle(cx, 5*time.Minute, func(idle bool) { ... }) calls back once as the user goes idle for that long and once as they come back, sampling on a coarse timer, and returns its stop. Both work on macOS and Windows, and on Linux under GNOME, X11 with the XScreenSaver extension, and KDE Plasma. desktop.CanReadIdleTime(cx) is false, and available too, on other Wayland compositors, phones, the web and mini programs, or where the scope lacks core.AccessIdleTime. In tests, app.SetIdleTime(d) makes the user’s last input d ago, and the idle time grows as app.Advance moves the clock.
Full screen
Section titled “Full screen”desktop.SetFullScreen(cx, true, displayID) fills the display named by cx.Env().Displays() on macOS, Windows and Linux. Omit the ID to use the window’s current display. An unknown ID leaves the window where it is. Repeating the same request has no effect. desktop.SetFullScreen(cx, false) leaves full screen and restores the window’s previous frame. On the web, enter from a press handler. The browser chooses the display, and cx.Env().FullScreen() follows entry and exit, including Esc.
Displays
Section titled “Displays”cx.Env().Display() returns the window’s current core.DisplayInfo and updates bindings when the window moves to another display or display settings change. cx.Env().Displays() lists the displays the platform reports. RefreshRate and MaxRefreshRate are in Hz, with zero for an unavailable rate. HDR and HDRSupported report active and capable HDR output, with HDRHeadroom (peak relative to SDR white), SDRWhiteLevel (nits) and MaxLuminance (nits) where available on macOS, iOS, Windows and Wayland Linux. iOS reports the panel’s maximum. On macOS, a change of HDRHeadroom alone, as during a brightness ramp, updates the environment at most four times a second and ends with the value the display settles at. HarmonyOS reports the window’s display, its current rate and its highest supported rate. The web reports the current screen and marks its frame callback measurement with RefreshRateEstimated. In tests, set Displays and DisplayID through nsgotest.Environment.