Skip to content

Report pixel coordinates in SGR-Pixels mouse mode - #820

Merged
dakra merged 1 commit into
mainfrom
fix/sgr-pixel-mouse
Nov 14, 2026
Merged

dakra merged 1 commit into
mainfrom
fix/sgr-pixel-mouse

Conversation

@dakra

@dakra dakra commented Nov 14, 2026 •

Copy link
Copy Markdown
Owner

With DEC mode 1016 set, libghostty's mouse encoder writes the position as it gets it. encodeMouse gave it the cell index on a screen of one-pixel cells, so a program using the mode, such as terminal-browser in a Herdr pane, saw every click in the top left corner. The cell formats divide by the cell size and were not affected.

  • encodeMouse gives the encoder the cell size the terminal reports for CSI 14/16 t and TIOCGWINSZ, and the pixel at the centre of the cell. Reports in the cell formats (SGR, urxvt, UTF-8, X10) are the same as before.
  • The cell is clamped to the grid. A position outside it, in a window larger than the terminal, is reported at the nearest cell; a press more than one cell past the grid was dropped before and went to Emacs.
  • An in-band switch to 132 columns (DECCOLM) leaves the terminal's pixel size stale, so the cell is at least one pixel and the screen is the grid times the cell.
  • The position is the cell's centre, not the pointer's pixel: the elisp side passes a cell, and drag motion is forwarded once per cell.

Checked live in a GUI frame (11x22 px cells) and a TTY frame (1x1) with printf '\e[?1000h\e[?1006h\e[?1016h'; cat -v: clicks, drag motion and wheel report the cell's centre, and the same cells as before with 1016 off. Not checked with Herdr or terminal-browser.

make -j8 all passes on top of current main.

Closes #818.

With DEC mode 1016 set the mouse encoder writes the position as it
gets it, and it got the cell index, on a screen of one-pixel cells.
A program using the mode saw every click in the top left corner.

Give the encoder the cell size the terminal reports for CSI 14/16 t
and the pixel at the centre of the cell.  The cell formats divide by
the cell size and report the same cells as before.

The cell is clamped to the grid, so a position outside it, in a
window larger than the terminal, is reported at the nearest cell.

Closes #818.
@dakra
dakra merged commit 2d57545 into main Nov 14, 2026
33 checks passed
@dakra
dakra deleted the fix/sgr-pixel-mouse branch November 14, 2026 13:11

This branch was previously deployed

1 inactive deployment
github-pages — 2d575456 Deployed Nov 14, 2026 by dakra via deploy #275
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.

SGR pixel mouse (1016) reports cell coordinates, breaking apps that trust pixel mode

1 participant