Skip to content

Mouse clicks are never forwarded to the child process (Claude Code /diff, vim, lazygit…) #155

Closed

Description

@bastien-gallay

Blocked by #300 — the MCP pointer rung. The encoder half unit-tests today
the way wheel_bytes already does in pty::input; what nothing in the tree
can produce is the gesture itself against a real child, which is the half
that decides whether a TUI actually responds. #300 introduces the pointer
event path this encoder consumes.

What

Mouse clicks (and drag/motion) are never forwarded to the child process, so
mouse-mode apps like vim / less can't position the cursor on click.

Root cause

Only wheel notches are encoded to the PTY — wheel_bytes
(crates/pty/src/input.rs:146) handles SGR/X10 wheel reporting and
alternate-scroll. Button press/release/drag/motion are not encoded at all:
a left-press is consumed locally for text selection
(crates/app/src/shell/terminal/canvas.rs, around the SelectOp::Start arm)
and never reaches the child. So an app that enabled mouse reporting
(MOUSE_REPORT_CLICK / SGR_MOUSE in TermMode) gets wheel events but no
clicks.

Fix direction

  • Extend wheel_bytes' SGR/X10 encoder in pty::input to press, release,
    drag and motion. Do not write a second encoder beside it.
  • Gate on the app's mouse-reporting mode — reuse the existing
    mode.intersects(MOUSE_REPORT_CLICK | MOUSE_MOTION | MOUSE_DRAG) gate rather
    than adding another: when the child has mouse reporting on, forward
    click/drag to the PTY and bypass local text selection; when off, keep the
    current local-selection behaviour.
  • Extend the existing cell-addressed pointer path with button state — it is
    not new. Event::ScrollViewport already carries a ScrollTarget::Wheel { col, row, lines } and SelectOp already carries grid coordinates, both in
    crates/core/src/app.rs. The risk here is a second copy, not a missing one.

Blast radius: not just vim (2026-09-05)

Re-read of crates/pty/src/input.rs: wheel_bytes (line 146) is still the
only mouse encoder in the tree. There is no press / release / drag / motion
encoding at all, on any path.

So the defect is not "vim clicks don't work" — it is the mouse button is
never reported to the child, ever
. Every TUI that enables mouse reporting
gets wheel notches and nothing else:

Surface What breaks
Claude Code /diff, /resume, and its menus clicking an entry does nothing
vim / neovim cursor placement, clicking a split
lazygit, gitui, tig pane and entry selection
less, man, fzf, htop click-to-select
tmux with mouse on pane click, drag-resize

The Claude Code row is the one that matters for this product: termherd exists
to host Claude Code sessions, and one of Claude Code's own panels is
unusable with the mouse inside it. That is a stronger case for the severity
than the vim example the title carries.

Title updated accordingly; the fix direction below is unchanged.


Body corrected 2026-09-07 during a wrap pass. Four things: the blocked-by note
overstated what cannot be tested (the encoder half is unit-testable today); the
fix direction called the pointer event path new when it already exists and
needs extending; wheel_bytes was cited at crates/pty/src/lib.rs:834, which
#172 moved to crates/pty/src/input.rs:146, and shell/terminal.rs became a
directory in #168; and the What / Root cause / Fix direction sections were
stored with literal \n escapes, so they rendered as one run-on paragraph.

Activity

  1. bastien-gallay commented on Jul 11, 2026

    @bastien-gallay
    CollaboratorAuthor

    Refactor prerequisites: #168 (C1 terminal/canvas.rs — mouse dispatch) and #172 (D input.rs — mouse-protocol encoding to the PTY).

  2. added
    area:terminal
    on Jul 26, 2026
  3. changed the title [-]Vim mouse click not forwarded to the child process[/-] [+]Mouse clicks are never forwarded to the child process (Claude Code /diff, vim, lazygit…)[/+] on Sep 5, 2026
  4. bastien-gallay commented on Sep 5, 2026

    @bastien-gallay
    CollaboratorAuthor

    Blocked by #300: the SGR encoder here consumes the pointer event path that ticket introduces, and #300 is also what makes this fix verifiable end to end rather than only at the pty unit level. #301 is the sibling chrome-pointer rung and blocks nothing here.

  5. bastien-gallay commented on Sep 16, 2026

    @bastien-gallay
    CollaboratorAuthor

    Unblocked: #300 merged (#311). Starting on fix+155-mouse-forward.

    Root cause, re-read against main at 9bed9b6

    • pty::input::wheel_bytes is still the only mouse encoder; it gates on
      MOUSE_REPORT_CLICK | MOUSE_MOTION | MOUSE_DRAG and encodes buttons 64/65 only.
    • TermCmd::Pointer (MCP: place a mouse event inside a session's terminal (cell-addressed) #300) reaches the terminal thread but goes straight to
      apply_pointer → local selection; the child is never consulted.
    • The canvas's bare left press / drag / release publish Message::Select unconditionally,
      so even once the terminal thread forwards, a GUI click would still select locally.
    • Screen exposes bracketed_paste but no mouse-mode bit, so neither the canvas nor the
      MCP shell can tell whether the child reads the mouse.

    Shape of the fix

    One predicate, three readers. core::app::pointer gains
    MouseReporting { Click, Drag, Motion } (what the child asked for) and
    PointerEvent::route(Option<MouseReporting>) -> PointerRoute { Forward, Select(LocalGesture), Nothing }
    — the whole whether-rule, including "under any mouse mode the mouse belongs to the child,
    so a bare drag selects nothing". pty::input::mouse_reporting(TermMode) maps the mode
    bits once; Screen.mouse_reporting carries it; wheel_bytes keeps its gate through it.

    • Encoder: wheel_bytes' SGR/X10 body becomes a shared mouse_report also used by
      mouse_bytes(mode, PointerEvent) — press / release / drag / move, Click = press+release.
      No second encoder.
    • Terminal thread: TermCmd::Pointer routes with the live mode: Forward → write
      bytes; Select → pointer_select with the live offset; Nothing → nothing.
    • MCP: PointerOutcome::Forwarded beside Selection / Ignored, read off the
      session's last Screen (same lag class as the bounds check).
    • Canvas: bare press / drag / release / move route through Message::TermPointer →
      Event::TerminalPointer when the route is Forward; shift keeps the local
      selection (the xterm override), and the content-dependent gestures (double-click word,
      shift-extend, link click) stay where they are.

    Out of scope, noted for later: modifier bits in the report (no modifiers on the
    event since #311's cleanup; comes back as one shared type when something needs it), and
    folding the wheel into PointerKind (its three-way scrollback / alt-scroll fallback has
    no pointer equivalent).

    Tests (red first)

    Layer Test
    core::app::pointer route table: no reporting → today's gestures; Click mode → press/release/click forward, drag/move nothing; Drag → +drag; Motion → everything. PBT: under any reporting, route is never Select.
    pty::input SGR press \e[<0;5;3M, release \e[<0;5;3m, middle 1, right 2, drag 32+button, move 35, click = pair; X10 \e[M + biased bytes, release code 3; existing wheel_bytes cases unchanged.
    pty::grid snapshot reports None / Click / Drag / Motion after DECSET 1000 / 1002 / 1003; apply_pointer under mouse mode leaves the selection alone.
    app::shell pointer_action_*: forwarded under a mouse-mode screen, ignored for a drag under click-only mode, selection unchanged when off.
    app::mcp::handler pointer_str / sweep case carries forwarded.
    canvas mouse mode: left press → TermPointer not Select; shift+press still selects; drag under Drag, move under Motion, release all forward; right press forwards instead of pasting. Off: every existing test unchanged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area:terminal

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions