Skip to content

Displays: the list is a startup snapshot, with no change event and no way to add a window later #146

Done

Description

@godismyjudge95

What happens

An app sees the displays once, in the window factory at startup. After that it cannot read the current display list, is not told when a monitor is added, removed or changes scale, and cannot create a new window or overlay. An app that needs one window per monitor (a screenshot region selector, a presentation app, a per-monitor bar) cannot follow a monitor that is plugged in after launch.

Where

At dev d03349e2:

  • window.rs#L236-L245: resumed builds Vec<Display> from available_monitors() once and hands it to the factory of run_windows* (tooling.rs#L193-L210).
  • app.rs#L248-L268: App::overlay and App::window take &mut self before run, so windows and overlays are fixed at startup.
  • I found no public display query on AppHandle, Tx or Cx, and no display-change callback.

Asks

  1. A display query that works while running, for example AppHandle::displays() -> Vec<Display> (and on Tx), with the same fields as the factory gets.
  2. A callback when the set of displays or their geometry or scale changes, for example App::on_displays_changed(fn(&mut S, &[Display], &mut Tx)). winit has no monitor event; the platforms do (macOS NSApplicationDidChangeScreenParametersNotification, Windows WM_DISPLAYCHANGE, Wayland wl_output globals added or removed, X11 RandR RRScreenChangeNotify).
  3. A way to open a new window or overlay after run, for example from Tx with a WindowSpec or ConfiguredOverlay.

Our workaround

We create the per-monitor overlay windows at startup from the factory's list, plus two extra hidden windows. When a capture starts, we place a spare on a monitor that has no window with AppHandle::place(DisplayTarget::Native(..), FullScreen). Our monitor list comes from our capture library, not from Rune. A third new monitor gets no overlay. Our test VM has one monitor, so we did not test hotplug; this is from the code.

Done when: an app can read the current displays while running, gets a callback within one second of a monitor being added or removed on macOS, Windows, X11 and Wayland, and can open a full-screen overlay on the new monitor without a restart.


Posted via Claude

Activity

  1. godismyjudge95 commented on Nov 6, 2026

    @godismyjudge95
    Author

    Related:


    Posted via Claude

  2. godismyjudge95 commented on Nov 6, 2026

    @godismyjudge95
    Author

    A cost number for the workaround in this issue. Because windows can only be made at startup, our app makes two spare hidden full-screen overlay windows for monitors plugged in later. On macOS each never-shown spare holds about 4 MB of GPU memory.

    macOS 26.6 VM (paravirtual Metal GPU), Rune 7ead7d63, our app idle with its main window shown, footprint -v 4 s after the first frame, 3 launches per side:

    spare windows footprint private GPU textures ("Owned physical footprint (unmapped) (graphics)")
    0 125, 127, 127 MB 24, 24, 24 MB
    2 135, 135, 135 MB 32, 32, 32 MB

    The spares never show, never draw and never get a drawable; the untagged CPU memory is the same (34 MB) in both. We did not trace which texture each spare makes. With a way to add a window after run (ask 3 here), the app would make an overlay only when a monitor comes, and these 8 MB would go.


    Posted via Claude

  3. purian23 commented on Nov 12, 2026

    @purian23

    We built the Wayland half of this for a desktop shell (a bar per output that comes and goes with monitors):

    pub enum DisplayEvent { Added(Display), Removed(Display) }
    impl App { pub fn on_displays(self, f: impl FnMut(&DisplayEvent, &[Display]) + 'static) -> Self; }
    impl AppHandle { pub fn overlay<T, C: Into<ConfiguredOverlay<T>>>(&self, build: impl FnOnce() -> (C, T) + Send + 'static) -> OverlayHandle<T>; }
    impl OverlayHandle<T> { pub fn close(&self); }
    • Outputs come from wl_output globals on a private queue. One thread, only while a hook is set, asleep in poll, with no timers.
    • AppHandle::overlay works after run. The overlay is built on the next loop turn, but the handle is usable at once (show, update and close queue until then).
    • close hides the overlay, releases its GPU surface and drops its host. Dropping a handle doesn't close it, so an app has to close an output's overlays when the output goes.
    • Trap: Display::name is empty for a headless output on Hyprland, so key by id.

    Tested with 50 headless output add/removes on Hyprland: every bar came back, and memory stayed flat after warm-up.

  4. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    Thanks for the detailed write-up and the memory numbers for the spare windows.

    Where each ask stands on dev today:

    1. Reading displays while running: still missing. The list is built from available_monitors() once in resumed (window.rs) and only the factory gets it. I found no query on AppHandle, Tx or Cx.
    2. A display-change callback: still missing. App::on_display_close exists, but it only fires once when the display connection shuts down. It does not report monitors being added, removed or changing scale.
    3. Opening a window after run: partly there. rune::open_window(WindowSpec) opens a window from the UI thread (a handler, an update, on_ready). It starts at the end of the turn and returns a WindowHandle. With WindowOptions::overlay(&display) that window is a transparent, borderless, topmost, click-through cover over one display, which might replace your hidden spares for the window case. ConfiguredOverlay overlays (App::overlay) can still only be made before run.

    We'll treat this as a feature request: a display query, a change callback on macOS, Windows, X11 and Wayland, and overlays that can be created and closed after run. @purian23, thanks for the notes on your Wayland version: the API shape, the wl_output thread that only runs while a hook is set, and keying by id because Display::name can be empty on Hyprland. They're useful input.

  5. opencodejr commented on Nov 25, 2026

    @opencodejr
    Contributor

    I updated the PR for part of this issue: rune::displays(), called on the UI thread, returns the current displays with the same fields the factory gets. A headless run now returns the displays from its --script, the same ones its place() uses.

    Opening a window on a new monitor already works with rune::windows::open_window and WindowOptions::overlay(&display), so the query is what was missing for that. The PR has not been compiled or tested yet, and nothing was tried with a real monitor being plugged in.

    Still open: a callback when displays change, and the query on AppHandle/Tx. Until there is a callback, an app has to call displays() when it needs the list, for example when a capture starts.

    Fixed in #2209.

  6. godismyjudge95 commented on Nov 27, 2026

    @godismyjudge95
    Author

    A result from an app, for the "open a window after run" part. Our screenshot app kept two spare hidden overlay windows for monitors that come after launch. We removed them. When a capture finds a monitor with no overlay, the app now calls rune::open_window with the same WindowSpec (WindowSpec::from_app with configured_options), and places it with AppHandle::place in the same turn.

    Tested on dev dacf5d89 in a macOS 26.6 VM. The VM has one monitor, so a test build opened no overlay at launch and opened each one at the first capture. Region and window captures worked (2 runs, 0 errors; region overlay on screen in 25 to 45 ms, window overlay in 6 to 9 ms). Memory without the two spares: 1.0 to 1.1 MB less in each state (5 runs per side, p = 0.008 to 0.03). On 7ead7d63 each spare cost about 4 MB, so dev already made a never-shown window cheaper.

    We did not test a real monitor plugged in at runtime.


    Posted via Claude

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