Skip to content

Linux: popup_menu is unsupported, so a text field's menu shows nothing, and in-window submenus can't leave the window #529

Done

Description

@wmfeht

Context: we're doing preliminary work on porting Strata (lgse/strata) from GTK 4 to Rune. Strata
has context menus with an "Open With" submenu, a small file chooser window, and text fields
everywhere.

What's missing (5d421fd, unchanged at 29aacb6):

  • popup_menu_supported() is false off macOS and Windows (popup_menu/mod.rs:40 and :51). A
    right-click in a text field with no on_secondary_press queues the native field menu (Cut,
    Copy, Paste, Select All); on Linux it answers None and nothing shows. Headless --trace
    logs popup-menu:open, so tests see a menu no Linux user does.
  • In-window menus scroll to fit, but rune-kit submenus only flip and shift. In a 420 × 400
    window (Rune's default minimum), an 8-row "Open With" submenu sits at [288, 90, 160, 228],
    28 pt past the right edge; a 20-row one shifts to [288, 8, 160, 564] and runs 172 pt past
    the bottom (the program below, at 5d421fd and 2a44156).

Repro (headless, rune-kit at the same rev; run with --tree t.json --size 420x400 --at 1,
then again with --long, and read the ctx-item1-sub-menu rect):

use rune::*;
use rune_kit::{Kit, MenuEntry, MenuItem, context_menu};
struct S;
fn view(_: &S, _: &mut Cx<S>) -> El {
    let k = Kit::neutral(true);
    let rows = if rune::tooling::extra_args().iter().any(|a| a == "--long") { 20 } else { 8 };
    let sub = (0..rows).map(|i| MenuEntry::item(MenuItem::new(format!("App {i}")))).collect();
    let mut layer = Vec::new();
    let trigger = context_menu("ctx", el(), Some(PointerPress { x: 130.0, y: 60.0 }))
        .item(MenuItem::new("Open"))
        .item(MenuItem::new("Open With").submenu(sub, true))
        .item(MenuItem::new("Copy"))
        .build(&k, &mut layer);
    rune_kit::root(col().w_full().h_full().fill(k.c.bg_base).child(trigger), layer)
}
fn main() { App::new(AppSpec::new("menus", (420.0, 400.0), || S, view)).run(); }

Ask, either of:

  • Menus, submenus and anchored popovers as xdg_popup surfaces on Wayland (override-redirect
    windows on X11), with the native field menu among them; or
  • where native pop-ups aren't available, an in-window fallback: Rune draws the field menu itself
    (or hands the app the request: field, point and Rune's items, e.g.
    AppSpec::on_field_menu(|s, request, tx|)), and submenus shrink and scroll as menus do.

Why. Today every text field needs an app-drawn menu attached by hand, rune-kit fields can't
take one at all (#530), and a menu's submenu is clipped in small windows.

Related: #255 (overlays ignore right clicks on Windows and macOS).

Activity

  1. Hona commented on Nov 24, 2026

    @Hona
    Member

    Landed on dev in #2025 (00af793d2):

    • Submenu viewport clamping & scrolling: fit_anchored (crates/rune/src/runtime/anchor.rs) now clamps overflowing El::anchored_fit surfaces on both the main axis and cross axis (8 pt inside the window or El::anchored_in boundary, following Floating UI's size middleware), and rune_kit::popover::fit applies anchored_fit for Side::Left | Side::Right as well as Top | Bottom. Overflowing rune_kit::Menu submenus in small windows (such as 420×400) now shrink to fit and scroll vertically, while surfaces that already fit stay unchanged.
    • In-window text-field menu fallback: Added FieldMenuRequest, App::on_field_menu (also on WindowSpec and ConfiguredOverlay), and Tx::resolve_field_menu. When !popup_menu_supported() (e.g. Linux), right-clicking a text field or pressing Menu / Shift+F10 delivers the ready-built PopupMenu (inspectable via PopupMenu::entries()) so an app can render it in-window with rune_kit::Menu, leaving macOS and Windows native menus unchanged. The hook lives on App rather than AppSpec so existing AppSpec struct literals keep compiling — let us know if that shape misses a case you need. Native Linux xdg_popup surfaces remain tracked in Real popups: a popup of the window's tree, shown in a native window of its own #1369.
    App::new(spec).on_field_menu(|s: &mut MyApp, req: FieldMenuRequest, _| {
        s.field_menu = Some(req);
    });
    // When the user picks an item from req.menu().entries():
    tx.resolve_field_menu(Some(id));

    See examples/kit-gallery stories rune-menu--submenu-small-window and rune-menu--field-menu-fallback. Verified with headless tests and clippy on Windows, headless tests on macOS, and cargo check-wasm / cargo check-webgl. Not verified in a live desktop window, on a real Linux Wayland/X11 desktop, or in a live browser.

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