Repository navigation
Description
We're trying to show menus, lists and tooltips past the window's edges while they stay part of the window's element tree, but we're missing a way to host an element subtree in a native popup window of its own.
What we're trying to do
Menus, combo box lists, autocomplete lists and tooltips must be able to reach past the window's edges, as native menus do. A list opened from a field near the bottom of a small window must open below the field, over the desktop, at its full height. On Wayland, where an app cannot place its own windows, the compositor must place it. The popup stays part of the window's element tree: same state, handlers and coordinates, so the app writes it like any other element. The app says where the popup goes relative to an element, and the platform keeps it on screen: it flips or slides it at the edge of the display. The popup takes clicks, the wheel and keys, closes on a mouse button down outside it, on Escape, or when the window goes to the background, never takes the focus from the window, is drawn at the scale of the display it is on, shows its first frame at the right place, and is gone in the frame it closes. Today an app has to keep every popup inside the window, so the list moves up or is cut short.
Missing
Read in source at Rune ba5e7c80, except the search, which was run:
- A window has one native window and one surface, and draws its whole instance stream on it (
window/win.rs:66,window/draw.rs:305). Nothing in the stream says which element an instance belongs to. - The paint culls every element to the window's viewport and to its ancestors' clip (
runtime/paint/build.rs:59,:141), so a subtree laid out below the window's edge paints nothing. - A second renderer cannot share the window's text atlas (
render/upload.rs:211,text/atlas.rs:239). - Nothing makes a window a child or an owned window of another, and nothing asks a Wayland compositor for an
xdg_popup:git grepfinds noaddChildWindow, no ownedWS_POPUPand noxdg_positioner. The only override-redirect windows belong to overlays (overlay/lifetime.rs:270,platform/x11/xwayland.rs:71). An overlay has its own surface, but also its own state andRuntime, is placed in screen coordinates and does not follow a window (app.rs:315,overlay.rs:317,overlay/options.rs:107). On GNOME Wayland an overlay shows only as an XWayland override-redirect window: it takes the pointer only when the app opts in, never takes the keyboard, and is not tied to the app's window. - winit 0.30.13 gives no access to a Wayland window's
xdg_surfaceor to the X11 server time of the last input, which anxdg_popupand an X11 grab need.
API (as built in the prototype)
The app describes the popup relative to its window and never sees a screen position. It calls place from its view each time the view builds the popup, and lays the popup root out at the rect it gets back:
// rune::runtime::popup_api
pub fn place<S: 'static>(cx: &Cx<S>, name: &str, request: &PopupRequest, on_event: Option<OnPopup<S>>)
-> Option<Placement>;
pub struct PopupRequest {
pub anchor: Anchor, // an element's key, or a rect in window points
pub position: PopupPosition, // anchor edge, gravity, offset, gap, flip/slide/resize, reactive
pub size: [f32; 2],
pub min_size: [f32; 2],
pub input: PopupInput, // None, or Grab(InputToken) for a menu
}
pub enum PopupEvent { Placed(Placement), Dismissed(DismissReason), InWindow }
pub struct Placement { pub rect: [f32; 4], pub flipped_x: bool, pub flipped_y: bool,
pub constrained: bool, pub scale: f32 }
pub enum DismissReason { OutsideClick, Escape, ParentDeactivated, ParentMoved,
ParentResized, ParentClosed, GrabFailed, System }
impl El { pub fn native_popup(self, name: &str) -> Self; } // marks the popup root
// The app's side:
let req = PopupRequest::new(Anchor::Key("combo".into()), PopupPosition::below(2.0), [w, h]);
if let Some(p) = popup_api::place(cx, "combo-list", &req, Some(on_popup)) {
root = root.child(list().absolute(p.rect[0], p.rect[1]).size(p.rect[2], p.rect[3])
.native_popup("combo-list"));
}- The positioning model is Wayland's
xdg_positioner. On macOS, Windows and X11, Rune places the popup itself with the same rules, in the work area of the display that holds the anchor. On Wayland the compositor places it, andplacereturns the compositor's rect in the same frame. - The paint does not cull or clip a popup to the window. The window draws its stream without the popups; each popup is drawn by its own renderer at its display's scale, with the glyphs it needs copied into an atlas of its own. Renderers are reused, so a later open costs no new GPU setup.
- Pointer events on the popup's native window reach the popup's handlers as if they were in the window. Keys come through the window, which keeps the focus. On Wayland, keys that the compositor sends to a menu's surface are passed on to the popup the same way. A mouse button down outside the popup, Escape, the window losing the active state, and the window closing dismiss the popup, with the reason.
- Where no native host exists, the window draws the popup clipped to itself and reports
InWindow, so an app works the same everywhere.
Platforms
| Platform | Native window | Who places it |
|---|---|---|
| macOS | A borderless, non-activating NSPanel, added as a child window (addChildWindow:ordered:), so AppKit moves it with the window. A global monitor sees mouse button down events in other apps |
Rune |
| Windows | A WS_POPUP owned by the app's window, WS_EX_NOACTIVATE, per-monitor DPI |
Rune |
| X11 | An override-redirect window, with a pointer grab for menus | Rune |
| Wayland | An xdg_popup on the window's xdg_surface, with an xdg_positioner and, for menus, a grab with the serial of the opening input. Needs the winit patch below |
The compositor |
Evidence
- Prototype: seven Rune patches, each owning its own files (added lines: shared surface 1072, shared API 1847, macOS 569, Windows 772, X11 729, Wayland 862, measuring probe 451). A winit patch of 45 added lines adds two accessors,
xdg_surface()for Wayland andx11_timestamp()for X11 grabs, and fixes the X11 cursor position on pointer enter. On macOS the host builds without the probe patch; the Windows host should too, but was not compiled without it. The X11 and Wayland hosts still call the probe's clock and need it. - Tests:
cargo test -p rune --lib popuppasses 76 tests on macOS, 81 on Windows and 75 on Linux. Each fix found while measuring has a test that fails without it, except three Linux fixes that probe runs check: a 300 s hang in the present mode, a stale X11 pointer after a drag, and the first click after a grab on sway. An independent check removed three fixes and saw each test fail.
| Check | macOS (2x) | Windows 11 (physical displays, 2x and 1x) | X11 (Xvfb, 1x and 2x) | Wayland (headless sway, 1, 1.5, 2) |
|---|---|---|---|---|
| Placement and flip/slide at the screen edge | Plain placement only; edges not measured | 7/7 cases with the window on each display; 5/5 at the edge between the two displays, each on the right display at its scale | Pass | 32/32 on sway; on GNOME Shell one placement (a flip above) only |
| A flipped popup keeps its gap from the anchor | — | — | Pass (2 pt) | Pass (2 pt), also GNOME Shell |
| First frame at the right place and scale | 0 wrong frames in 10 opens | Pass, drawn while hidden; no blur at either scale | Pass | Pass |
| Popup text with the default font smoothing (label pixels, popup / window) | Not affected (read in code) | 147–156 / 186 at 1x, 527 / 625 at 2x | 156 / 187 at 1x, 528 / 625 at 2x | 156 / 187, 319 / 383, 528 / 625 |
| Later opens (renderer reuse) | 8–15 ms | 15–38 ms; first open in a new process 92–201 ms | 10–17 ms | 44–48 ms |
| Clicks, keys and wheel reach the popup; window keeps focus | Pass | Pass with injected input at 1x (SendInput): click, keys, Escape, a click outside. A touch tap (InjectTouchInput) reaches the popup without moving focus. Wheel not recorded |
Pass | Pass, including a menu opened from a key |
| Dismissal: mouse button down outside, Escape, window deactivated | Pass | Outside click 40 ms, Escape 34–50 ms; deactivation not recorded | Pass | Pass |
| Window moves with a popup open | 0.00 pt lag in 31 moves | 0 px lag in 31 moves; a popup that is not reactive closes; moving to the other display redraws at its scale | Closes with ParentMoved (11 ms; 30 ms at 2x), as designed for X11 |
Moved by the compositor; two outputs redraw at the new scale |
Not covered
- After the window moves to a display with another scale,
Placed.scaleis not reported again when the popup's rect in window points stays the same. - Not measured: on macOS, placement at the screen edges, a second display and a mouse button down in another app; on Windows, the wheel and the window being deactivated; on GNOME Shell, everything except one placement and the open time (no text, input, dismissal or window moves); the gap on macOS and Windows; KWin, Hyprland and client-side decorations on Wayland; a menu that holds the keyboard on a real compositor; calling
placeoutside a view run; the companion proposals working with a native popup on Windows at 100 % scale (Key layers: keys for an open popup while another element keeps the focus #1365, Elements that block the pointer hover of what is drawn under them #1366, Observe a mouse button down without taking it #1367). - The popup root must be a trailing child of the window's root. A popup renderer does not share the window's pipelines; sharing them needs a change to Rune's renderer.
Related
This generalises the Linux part of #529 (menus and anchored popovers as xdg_popup surfaces on Wayland and override-redirect windows on X11) to every anchored popup on every platform. Placement.flipped_x / flipped_y above also answer #362.
Activity
opencodejr commentedon Nov 25, 2026
Thanks for the detailed write-up and the prototype numbers.
I checked current
dev(64220d5f), and it matches what you describe:git grepincrates/finds noxdg_positioner,xdg_popup,addChildWindowor owned no-activateWS_POPUP. The only override-redirect windows belong to overlays (overlay/lifetime.rs) and the X11 helpers (platform/x11/xwayland.rs,platform/x11/activation.rs). Some paths have moved sinceba5e7c80:window/win.rsandwindow/draw.rsaren't at those locations any more.#529 was closed by #2025. That change added in-window submenu clamping and scrolling (
anchored_fiton both axes) and theApp::on_field_menufallback. It left native popups to this issue, so this is the tracker for host-backed popups on all four platforms, with the in-windowInWindowfallback where no native host exists.I'm treating this as a feature request. A few notes for the work:
xdg_surface(),x11_timestamp()). Those go throughvendor/winit.patchandscripts/vendor-winit.sh.PopupRequest,PopupPositionandPlacementshould get builder methods where apps would otherwise construct them as literals.opencodejr commentedon Nov 25, 2026
I haven't opened a PR for this. It's a multi-platform subsystem, about 6,300 added Rune lines over seven patches plus the winit accessors, and most of it can only be checked on real macOS, Windows and Wayland desktops. A single change made without those platforms would go largely untested.
Since your prototype is already split by file ownership, it looks easiest to land it as separate PRs on
dev:xdg_surface(),x11_timestamp(), the X11 enter-position fix), added tovendor/winit.patchthroughscripts/vendor-winit.sh.InWindowfallback.A few repo conventions affect the shape:
machine::stepstate machine.changelog/unreleased/entry for each PR.rock3r commentedon Nov 25, 2026
Thanks. One note on the split: this repository does not take pull requests from outside authors, so we cannot open these PRs ourselves. The split you list matches how the prototype is organised (one patch per area, plus the winit accessors). When a part lands on
dev, we can run it on macOS, Windows, X11 and Wayland and report the results here.