Skip to content

Panels that never take the keyboard and can be placed at a screen rectangle (candidate windows, on-screen keyboards) #243

Closed

Description

@houko

Context

An app can open a panel with OpenPanel(PanelOptions{...}), but it cannot say where the panel goes or keep it from taking the keyboard. As of 27f4e39:

  • PanelOptions holds only Width, Height, HideOnBlur and Material (core/window.go:58-66). Window has Show, Hide, Toggle, Focus and Close but no way to move it (core/window.go:218-264). The only placement is showAt(tray), under a tray icon.
  • macOS: NsgoPanel answers YES to canBecomeKeyWindow (internal/platform/macos/app.go:142-145), so a click in the panel makes it key and takes the keyboard from the app the user is typing in, even though the style mask includes non-activating.
  • Windows: an embedded view calls SetFocus on every button-down (internal/platform/windows/windows.go:2172-2178), and nothing handles WM_MOUSEACTIVATE or sets WS_EX_NOACTIVATE.
  • Linux: setFrame ignores the position (internal/platform/linux/system.go:612-614). That is right for an ordinary toplevel on Wayland, but there is no other surface kind an app could use instead.

#31 brought panels and tray icons to Windows and Linux; this issue is about a different kind of panel.

Why it matters

A whole class of desktop UI is a small surface placed next to something on screen that must never take the keyboard from the app underneath:

  • an input method's candidate window, placed at the text caret of another app
  • an on-screen keyboard, handwriting pad or emoji/symbol picker docked to a screen edge or near the caret
  • a color picker loupe, a dictionary lookup popup, a screen annotation toolbar

Today such an app has to write these surfaces natively on every platform and leave NSGo for them. The rest of the app can be NSGo, but these panels are often where most of its UI lives.

Proposal

  1. PanelOptions.Activates bool (default false keeps today's behavior for tray panels, or a separate NoActivate field if the default should stay as is). When the panel must not activate:
    • macOS: a panel subclass whose canBecomeKeyWindow returns NO, with becomesKeyOnlyIfNeeded.
    • Windows: WS_EX_NOACTIVATE | WS_EX_TOPMOST | WS_EX_TOOLWINDOW, answer WM_MOUSEACTIVATE with MA_NOACTIVATE, and skip the SetFocus on button-down.
    • Linux X11: _NET_WM_WINDOW_TYPE_UTILITY or _NOTIFICATION with input hints off.
  2. Window.ShowAt(rect Rect, edge Edge): shows the panel next to a screen rectangle in global points (for example under it, flipping above when it would leave the screen), and Window.MoveTo(rect, edge) to follow the caret without hiding. On each desktop:
    • macOS: setFrameOrigin in screen coordinates on the screen that holds the rect.
    • Windows: SetWindowPos with SWP_NOACTIVATE, using the monitor that holds the rect and its DPI.
    • Linux X11: gtk_window_move or the X11 surface's position.
    • Linux Wayland: a regular toplevel cannot be placed, so this needs a layer-shell surface (zwlr_layer_shell_v1, where the compositor has it) for edge-docked panels. A panel at another app's caret is only possible through the compositor's input-method protocol, so on Wayland ShowAt should report that it cannot place the panel instead of silently ignoring the rect.
  3. A way for the app to learn that placement failed (a returned error or a Placed() bool), so it can choose another UI.

Acceptance

  • On macOS and Windows, a non-activating panel shown with ShowAt while another app's text field has the focus appears at the given rect. Clicking a button in it runs the handler, and the other app's text field keeps the keyboard and its caret.
  • MoveTo repositions a visible panel without a flash or a focus change, on a second monitor with a different scale factor too.
  • On Linux X11 the same holds. On Wayland with layer-shell, an edge-docked panel works; without it, ShowAt reports that it could not place the panel.
  • nsgotest can assert a panel's frame and that showing it did not change the focused window.

Activity

  1. houko commented on Nov 15, 2026

    @houko
    CollaboratorAuthor

    Another concrete case for this issue, checked at aadbe7e: a dictionary app's quick-lookup panel. A global shortcut opens a HideOnBlur panel, and the app wants it next to the mouse pointer rather than in the upper middle of the screen. #243 already lists "a dictionary lookup popup" under Why it matters. This adds two things it does not cover yet: how the current placement code interacts with SetWindowFrame, and the fact that the app has no public way to get the point it would pass to ShowAt.

    What happens today

    • Every show places the panel again. On macOS, WindowShow goes through show to showPanel (internal/platform/macos/app.go:200-206), and WindowOrderFront calls showPanel for panels too (internal/platform/macos/desktop.go:131-137). showPanel puts the panel under its tray icon, or else reads NSEvent mouseLocation only to pick the screen and then centers the panel two thirds up it before setFrameOrigin (internal/platform/macos/app.go:211-250). Windows does the same in WindowShow and WindowOrderFront (internal/platform/windows/chrome.go:281-302) through placePanel, which reads GetCursorPos only to pick the monitor (internal/platform/windows/system.go:864-887). Toggle goes through Focus, so it places the panel again too (core/window.go:239-257).
    • So a desktop.SetWindowFrame with Move sent before Show is silently overwritten. One sent from the panel's own content scope after Show lands, because both go on the panel's command list in order (core/desktop.go:13-18, core/desktop.go:36-40, core/window.go:208-221). That only works by accident of ordering. The app has to keep the content cx around and send the frame again after every Show, Focus and Toggle, and nothing promises the panel will not first appear at the default spot for a moment. Neither SetWindowFrame's doc (desktop/desktop.go:157-163) nor docs/architecture/application.md:82 says that showing a panel discards its frame.
    • There is no public pointer location. NSGo reads the pointer itself (NSEvent mouseLocation, GetCursorPos), but only inside the platform layers. core, desktop and Env export nothing for it: Env.Displays gives display frames only (core/env.go:280), EventHotKey carries only the shortcut ID (internal/driver/events.go:228-229), and PopupMenu's point is in surface coordinates. To place a panel at the pointer, the app has to call NSEvent mouseLocation through purego and flip y against the main screen on macOS, and call GetCursorPos and convert physical pixels into NSGo's point space with Env.Displays on Windows. That is the same platform code NSGo already has internally, written again in every app.
    • The other workaround, a frameless floating OpenWindow with Frame.Move, gets a taskbar button on Windows (SkipTaskbar is still a roadmap row, docs/roadmap.md:107), and the app has to hide it on blur itself.

    Minimal repro

    var panel *desktop.Window
    var panelCx *core.Scope
    
    panel = desktop.OpenPanel(cx, desktop.PanelOptions{Width: 360, Height: 420, HideOnBlur: true}, func(cx *core.Scope) core.Node {
    	panelCx = cx
    	return lookupView(cx)
    })
    
    desktop.RegisterHotKey(cx, quickLookupShortcut, func() {
    	// Lost: Show places the panel in the upper middle of the screen again.
    	desktop.SetWindowFrame(panelCx, core.WindowFrame{X: 200, Y: 200, Move: true})
    	panel.Show()
    	// Lands only because it is queued after Show on the same list, and has to be sent again after every Show, Focus and Toggle. The app also has no public way to get the pointer's X and Y.
    	desktop.SetWindowFrame(panelCx, core.WindowFrame{X: 200, Y: 200, Move: true})
    })

    On macOS and Windows the first frame is discarded. The panel ends up at 200,200 only because of the second call.

    Proposal (additions to the proposal above)

    1. Let ShowAt (or a PanelOptions placement field) take the pointer as its anchor, for example ShowAt(desktop.AtPointer, edge), so the backend that already reads NSEvent mouseLocation and GetCursorPos uses that point instead of only the screen. Where the rect is known it should be a global rect in SetWindowFrame's coordinate space, as proposed above.
    2. Or, separately, a public desktop.PointerLocation(cx) (core.Point, bool) in the same coordinate space as SetWindowFrame and Env.Displays. It would report false on Wayland and on platforms without a global pointer.
    3. Until then, document that showing or focusing a panel resets its position, so SetWindowFrame before Show is known to be lost.

    Acceptance

    • On macOS and Windows, a panel shown at the pointer from a global shortcut opens next to the pointer, kept inside the visible frame of the display under the pointer, on a second monitor with a different scale factor too, and does not flash at the upper-middle spot first.
    • Toggle and Focus on that panel keep the placement the app asked for, with no need to resend a frame.
    • If a pointer location API is added, it returns the same point SetWindowFrame would need to put the panel's top-left corner at the pointer, and reports false on Wayland.
  2. self-assigned this
    on Nov 20, 2026
  3. houko commented on Nov 20, 2026

    @houko
    CollaboratorAuthor

    The current source now covers the requested panel behavior. PanelOptions.NoActivate provides non-activating panels, Window.ShowAt and MoveTo place and follow a screen-space anchor, Show, Focus and Toggle preserve placement, and OnPlacementError reports platforms such as Wayland that cannot place the panel. The Windows, macOS and Linux backends contain the corresponding placement/non-activation paths. I am closing this issue as resolved by the current implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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