Skip to content

fix(titlebar): defer Linux mouse window drags past 8 pt so Wayland and X11 titlebar double-clicks work - #2252

Merged
Hona merged 1 commit into
devfrom
fix/2224-wayland-titlebar-double-click
Nov 25, 2026
Merged

Hona merged 1 commit into
devfrom
fix/2224-wayland-titlebar-double-click

Conversation

@Hona

@Hona Hona commented Nov 25, 2026

Copy link
Copy Markdown
Member

Fixes #2224

Root cause

  • On Linux, pressing the primary mouse button on a bare .window_drag() region stepped TitlebarPress (crates/rune/src/runtime/input/titlebar.rs) directly into TitlebarAction::Drag on mouse-down.
  • WindowEvent::MouseInput (crates/rune/src/window/host/events.rs) immediately called window.drag_window() (crates/rune/src/window/surface/win.rs), sending xdg_toplevel.move on Wayland (or _NET_WM_MOVERESIZE on X11) for stationary clicks.
  • Starting the compositor move grab on mouse-down causes wl_pointer.leave (and can briefly trigger tiling overlays or focus flicker, clearing the armed pair), so a double-click either showed tiling UI or sent a second xdg_toplevel.move instead of TitlebarAction::DoubleClick (toggle_maximized).

What changed

  • Extended TitlebarPress (crates/rune/src/runtime/input/titlebar.rs) with a Holding(Pair) state and Event::{Move, Release, Leave, OtherPress}:
    • On Linux / desktop Unix (DEFER_MOUSE_DRAG), a primary mouse press on a bare .window_drag() region enters Holding(Pair) without emitting TitlebarAction::Drag.
    • Moving >= 8.0 points on either axis (DRAG_THRESHOLD = 8.0, matching GTK's gtk-dnd-drag-threshold and Chromium's WindowEventFilterLinux) transitions Holding(pair) -> Armed(pair) and emits TitlebarAction::Drag once. Winit's Wayland backend preserves latest_button_serial across Motion events, so xdg_toplevel.move carries the original press serial; X11's drag_window() queries pointer coordinates and sends _NET_WM_MOVERESIZE while button 1 is held.
    • Releasing or receiving Event::Leave transitions Holding(pair) -> Armed(pair) with no drag, so stationary double-clicks (press -> release -> press, press -> small motion < 8 pt -> release -> press, and press -> leave -> enter -> press with no release in between) emit TitlebarAction::DoubleClick when the second press lands within double_click_interval and CLICK_SLOP (4 pt). Following Chromium's WindowEventFilterLinux, double-click pairing is judged by press time and distance even if a slight drag crossed the threshold on the first press.
    • Event::Clear (focus loss / cancel_pointer) resets to Rest.
  • Wired move_pointer, observe_pointer, pointer_up, and pointer_leave (crates/rune/src/runtime/input/pointer.rs) into TitlebarPress, and drained take_titlebar_action() from WindowEvent::CursorMoved (crates/rune/src/window/host/events.rs) and OverlayCore::cursor_moved (crates/rune/src/overlay/input.rs).
  • Unchanged: macOS (keeps immediate Drag on press for AppKit's performWindowDragWithEvent:), Windows (keeps WM_NCHITTEST HTCAPTION hit-testing and immediate fallback), touch (keeps Mode::WindowDragPending / TOUCH_SLOP / long-press in touch.rs), .window_drag() regions with their own on_double_press, and interactive title bar children.
stateDiagram-v2
    [*] --> Rest
    Rest --> Holding: Region (defer=true)
    Holding --> Holding: Move (< 8 pt)
    Holding --> Armed: Move (>= 8 pt) / Drag
    Holding --> Armed: Release | Leave
    Armed --> Rest: Region (within interval & 4 pt) / DoubleClick
    Armed --> Holding: Region (outside interval or 4 pt, defer=true)
    Holding --> Rest: Clear | Resize | OtherPress
    Armed --> Rest: Clear | Resize
Loading

Verification

  • Headless unit and integration tests covering TitlebarPress::step, Runtime, cursor_moved_core, OverlayCore, touch, title bar buttons, custom on_double_press, and rune-kit shells:
    • Windows: cargo test -p rune --lib -- titlebar runtime::input overlay::input pointer_hit cursor_moved_core_wakes (298 passed), cargo clippy -p rune -p rune-kit --lib --bins --tests --features rune-kit/markdown,rune-kit/mermaid (pass), cargo check -p rune --no-default-features --target wasm32-unknown-unknown (pass).
    • Linux (aarch64 headless container): cargo test -p rune --lib -- titlebar runtime::input overlay::input pointer_hit cursor_moved_core_wakes (295 non-GPU tests passed), cargo test -p rune --test integration titlebar (1 passed), cargo test -p rune-kit --test integration --features rune-kit/markdown,rune-kit/mermaid shell (48 passed), cargo clippy -p rune --lib --bins (pass).
    • macOS (arm64): cargo test -p rune --lib -- titlebar runtime::input overlay::input pointer_hit cursor_moved_core_wakes (298 passed), cargo test -p rune --test integration titlebar (1 passed), cargo test -p rune-kit --test integration --features rune-kit/markdown,rune-kit/mermaid shell (48 passed).
    • scripts/file-size.sh (0 errors).
  • Not verified: a live GNOME Shell or KDE Wayland/X11 desktop session with a physical mouse (the Linux test environment is a headless container with no display server).

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom title bars on Wayland can miss mouse double-clicks when a native move starts on mouse-down

1 participant