Skip to content

Persistent pinch-to-zoom and mouseMode parameter#131

Open
GlassOnTin wants to merge 2 commits intoconnectbot:mainfrom
GlassOnTin:upstream-pr
Open

Persistent pinch-to-zoom and mouseMode parameter#131
GlassOnTin wants to merge 2 commits intoconnectbot:mainfrom
GlassOnTin:upstream-pr

Conversation

@GlassOnTin
Copy link

Summary

  • popScrollbackLine: Restores lines from scrollback buffer on terminal resize (shrink then grow preserves content)
  • Pinch-to-zoom: Replaces viewport graphicsLayer zoom with direct font size adjustment. Pinch changes calculatedFontSize which triggers terminal resize (more/fewer rows+cols). Adds onFontSizeChanged callback for persistence and mouseMode parameter to suppress selection/tap when TUI apps enable mouse tracking.

Changes to Terminal composable API

New optional parameters on Terminal() and TerminalWithAccessibility():

  • onFontSizeChanged: ((TextUnit) -> Unit)? — called on pinch gesture end with the new font size
  • mouseMode: Boolean — when true, skips long-press selection and tap handling (caller handles mouse events)

Pinch-to-zoom details

  • Removed zoomScale, zoomOffset, zoomOrigin, isZooming state variables
  • Removed graphicsLayer transform from Canvas
  • Font size clamped to 6–32 sp during pinch
  • Cumulative zoom factor for smooth, monotonic scaling
  • Skipped when forcedSize != null
  • Removed baseCharHeight from pointerInput key to prevent gesture cancellation during pinch

Test plan

  • Pinch in terminal → font size changes live, terminal resizes (rows/cols change)
  • Lift fingers → font size stays (not reset)
  • forcedSize mode unaffected (pinch disabled)
  • mouseMode=true → long-press doesn't trigger selection, taps don't trigger hyperlink/focus
  • mouseMode=false → existing behavior unchanged
  • Terminal shrink then grow restores scrollback lines (popScrollbackLine)

When the terminal grows taller (e.g. on-screen keyboard hides on
mobile), libvterm calls popScrollbackLine to pull lines from the
scrollback buffer back onto the screen. This keeps the cursor at
the bottom of the visible area instead of leaving blank rows below.

The previous stub returned 0 unconditionally, so growing the
terminal always produced empty rows at the bottom. This converts
the most recently pushed TerminalLine back to ScreenCell format
(reversing pushScrollbackLine) and returns 1 to signal success.

Tested on Android with SSH and mosh connections using bash, tmux,
and zellij — the cursor now stays at the bottom after keyboard
hide/show cycles.
Replace graphicsLayer zoom/pan transform with direct font size adjustment.
Pinch gesture now changes calculatedFontSize (clamped 6-32 sp), which
triggers terminal resize for more/fewer rows+cols.

- Add onFontSizeChanged callback to persist font size on gesture end
- Add mouseMode parameter to skip long-press selection and tap handling
  when a TUI app has mouse tracking enabled
- Remove zoomScale/zoomOffset/zoomOrigin/isZooming state vars
- Remove graphicsLayer transform from Canvas
- Remove baseCharHeight from pointerInput key to prevent gesture
  cancellation during pinch
- Use cumulative zoom factor for smooth, monotonic scaling
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