Skip to content

XWayland: a prewarmed overlay that was never shown takes clicks, and fires the ones on its hit regions as presses at its first show #680

Closed

Description

@notpellew-agents

What happens

On GNOME Wayland, an overlay with prewarm: true and xwayland_input: true maps its XWayland window, with its input shape, before its first show():

  • With OverlayInput::All, clicks anywhere on the never-shown overlay reach neither the window below nor the overlay.
  • With OverlayInput::Regions, the same happens on its hit() regions.

When the overlay first shows, every click that landed on a hit() element arrives as a press, with no new input. Without prewarm, clicks pass through and nothing fires later. After one real show() and hide(), the hidden overlay has no X window and clicks pass through.

Likely cause

XwaylandSurface::new maps the window as it makes it ("mapped while it lives and destroyed when hidden", xwayland.rs#L85 at ba5e7c80). A prewarm makes that surface while the overlay is still hidden. warm_frame then calls publish_regions, which sets the hit regions as the input shape for Regions. All already has the whole window as its shape. The events the window takes while hidden are handled once it shows. This is from reading the code alongside the measurements; I didn't trace it in a debugger.

Repro

A windowless app (source below) with a 460×200 overlay at the top centre, with an 18×18 hit() button whose on_press prints press. Under it is a plain X11 window of the same size that takes all input and logs every ButtonPress. Clicks come from a Mutter RemoteDesktop session.

  1. Check that the window below takes a click.
  2. Start the app and don't show the overlay.
  3. Click 3 times mid-overlay and 3 times on the button's position.
  4. Count what the window below logged.
  5. show() the overlay with no further input, and count press.

In the source, ALL=1 selects OverlayInput::All and COLD=1 turns prewarm off. Every row ran with ANIM=1, which redraws at 30 fps.

Measured

GNOME Shell 50.1 headless, Xwayland 24.1.10, AMD Radeon iGPU (RADV), Rune ba5e7c80. The window below took the control click (step 1) before every row.

options window below got: mid-overlay window below got: button position press at the first show, no input
All, prewarm: true 0/3 0/3 3
All, prewarm: false 3/3 3/3 0
Regions, prewarm: true 3/3 0/3 (and 0/5, 0/3 in two earlier runs) 3 (5, 3)
Regions, prewarm: false — 5/5 0
Regions, prewarm: true, after one show() and hide() — 3/3 —

Rune dev c92e462e, Regions, prewarm: true: 5 presses fired at the first show after 5 clicks while hidden, in each of 2 runs.

Before the first show, xwininfo lists the overlay's window as mapped (IsViewable, override-redirect). For Regions, XShapeGetRectangles returns the button's rectangle as its input shape.

Expected

A prewarmed overlay that has never been shown takes no input, as after a hide, and nothing clicked while it was hidden turns into a press later.

Not checked

  • X11 sessions, Windows and macOS.
  • My own app uses All with prewarm and is not affected: it has no overlay window while hidden, before or after its first show. I haven't traced why. It calls OverlayHandle::place before the first show, which may matter.
Repro source (Rune at the revision above, default features off)
use std::time::{Duration, SystemTime, UNIX_EPOCH};
use rune::*;

struct S { t: f64, anim: bool }

fn srgb(r: u8, g: u8, b: u8) -> Color {
    let decode = |c: u8| rune::color::srgb_decode(f32::from(c) / 255.0);
    Color { r: decode(r), g: decode(g), b: decode(b), a: 1.0 }
}

fn now() -> f64 { SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs_f64() }

fn view(s: &S, _: &mut Cx<S>) -> El {
    let bar = 40.0 + 200.0 * (0.5 + 0.5 * (s.t * 3.0).sin()) as f32;
    el().w_full().h_full().fill(srgb(0x20, 0x22, 0x26)).radius(12.0)
        .child(el().size(bar, 8.0).pin(Some(20.0), Some(60.0), None, None).fill(srgb(0x80, 0xc0, 0xff)))
        .child(
            row().key("cancel").role("button").label("Cancel").size(18.0, 18.0)
                .pin(None, Some(6.0), Some(6.0), None).center().fill(srgb(0x5c, 0x5c, 0x60))
                .hit()
                .on_press(|_: &mut S| eprintln!("press {:.4}", now()))
                .child(text("×").color(srgb(0xff, 0xff, 0xff))),
        )
}

fn poll(s: &mut S, clock: f64, tx: &mut Tx) -> bool {
    if !s.anim { return false; }
    s.t = clock;
    tx.settle();
    tx.wake_after(Duration::from_millis(33));
    true
}

fn main() {
    // Shows and hides on command files `show` / `hide` dropped into the directory given as the first argument.
    let dir = std::env::args().nth(1).expect("command dir");
    let anim = std::env::var_os("ANIM").is_some();
    let mut app = App::new(AppSpec::new("repro", (1.0, 1.0), || (), |(), _| el())).windowless().args(Vec::new());
    let spec = OverlaySpec { name: "repro overlay", size: (460.0, 200.0), edge: ScreenEdge::Top, margin: 0.0, align: Align::Center, inset: 0.0, interactive: false, view };
    let input = if std::env::var_os("ALL").is_some() { OverlayInput::All } else { OverlayInput::Regions };
    let options = OverlayOptions { input, xwayland_input: true, prewarm: std::env::var_os("COLD").is_none(), ..OverlayOptions::default() };
    let handle = app.overlay(spec.options(options).poll(poll), S { t: 0.0, anim });
    std::thread::spawn(move || loop {
        for name in ["show", "hide"] {
            let path = format!("{dir}/{name}");
            if std::fs::remove_file(&path).is_ok() {
                if name == "show" { handle.show(); handle.update(|_, tx| tx.wake_after(Duration::ZERO)); } else { handle.hide(); }
                eprintln!("{name} {:.4}", now());
            }
        }
        std::thread::sleep(Duration::from_millis(10));
    });
    if let Err(e) = app.try_run() { eprintln!("run: {e}"); }
}

Found while evaluating Rune for NotPellew/Thalvi#242.


Posted via Claude

Activity

  1. Hona commented on Nov 23, 2026

    @Hona
    Member

    A prewarmed XWayland overlay mapped its window and set its input shape when it was made, before it was ever shown, so it took clicks and replayed them as presses at its first show. Fixed on dev in #1505 (816ad4c): the window now stays unmapped with no input until show().

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