Skip to content

Terminal: report the mouse to programs that ask for it - #2902

Open
insjang wants to merge 3 commits into
eclipse-platform:masterfrom
insjang:mouse-reporting
Open

Terminal: report the mouse to programs that ask for it#2902
insjang wants to merge 3 commits into
eclipse-platform:masterfrom
insjang:mouse-reporting

Conversation

@insjang

@insjang insjang commented Sep 3, 2026

Copy link
Copy Markdown

Depends on #2901 (the DEC private mode parsing change): ncurses turns the mouse on with CSI ? 1006 ; 1000 h, which needs every parameter of a set/reset to be taken. This PR shows that commit as well until #2901 is merged; only the second commit is new here.

Programs that draw their own screen — htop, ncurses menus, and lately CLIs with clickable options and wheel scrolling — ask the terminal for mouse events with DEC modes 1000 (presses and releases), 1002 (also drags) and 1003 (every move), in xterm's legacy encoding or the SGR one (mode 1006). The terminal ignored the request and kept every click for its own selection, so such programs could not be clicked on or scrolled.

  • The canvas hands presses, releases, moves and the wheel to the control while a program has asked for them, with the Alt and Ctrl keys folded into the button as xterm does.
  • Shift keeps the mouse for the terminal — the convention every terminal uses to still allow a selection while a program is listening.
  • A press that went to the program takes the terminal's selection away and moves the selection anchor to the click, so a later shift-drag starts from where the user last clicked.
  • A release goes wherever its press went, whatever the keyboard state by then, so press and release always reach the same side.
  • Mode 1004 reports focus gained/lost; mode 2026 (synchronized output) lets a program mark a redraw, during which the view leaves the screen alone rather than showing it half drawn.

Tests: MouseReportTest (both encodings, modifiers, wide columns) and mode handling in VT100EmulatorTest.

… on request, and support bracketed paste

DEC private mode sequences may carry several modes at once, and
ncurses does exactly that when it turns the mouse on: CSI ? 1006 ; 1000 h.
The emulator looked at the first parameter only and dropped the rest,
so a program could end up with half of what it asked for. Every
parameter is now set or reset.

DECTCEM (mode 25) lets a program hide the cursor while it draws, or for
good; a full screen program that hides it, such as htop, showed a
cursor wandering over its screen. The request is passed to the view,
which keeps its own blinking and focus handling and simply does not
draw the cursor while a program has hidden it.

Bracketed paste (mode 2004) marks pasted text with CSI 200~ and
CSI 201~ so that a program can take it as text rather than as keys
typed - a shell does not run every line of a pasted snippet, an editor
does not auto-indent it. Programs that ask for it and do not get it
misread multi-line pastes. An end marker inside the text is removed so
the paste cannot close its own bracket early.
Programs that draw their own screen - htop, ncurses menus, and lately
CLIs with clickable options and wheel scrolling - ask the terminal for
mouse events with DEC modes 1000 (presses and releases), 1002 (also
drags) and 1003 (every move), in xterm's legacy encoding or the SGR one
(mode 1006). The terminal ignored the request and kept every click for
its own selection, so such programs could not be clicked on or scrolled.

The canvas now hands presses, releases, moves and the wheel to the
control while a program has asked for them, with the alt and control
keys folded into the button as xterm does. Shift keeps the mouse for the
terminal, which is the convention every terminal uses to still allow a
selection while a program is listening. A press that went to the
program takes the terminal's selection away and moves the selection
anchor to the click, so a later shift-drag starts from where the user
last clicked rather than from a selection made long before. A release
goes wherever its press went, whatever the keyboard state by then, so
press and release always reach the same side.

Mode 1004 tells the program when the terminal gains or loses focus, and
mode 2026 (synchronized output) lets it mark the beginning and end of a
redraw, during which the view leaves the screen alone rather than
showing it half drawn.

This builds on the DEC private mode parsing change (every parameter in
a set/reset), since ncurses turns the mouse on with CSI ? 1006 ; 1000 h.
Package-private static access does not cross an OSGi bundle boundary
even within the same package name; MouseReportTest lives in a
separate test bundle and failed with IllegalAccessError.
insjang added a commit to insjang/eclipse.platform that referenced this pull request Sep 3, 2026
Same cross-bundle package-private access problem as mouseReport in
eclipse-platform#2902 -- the test bundle is a separate OSGi bundle, so package-private
static does not reach it even under the same package name.
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.

1 participant