Skip to content

Added: Add soft-keyboard-pan-main-screen property to avoid PTY resize on IME toggle - #5444

Open
qwerty123yucy wants to merge 1 commit into
termux:masterfrom
qwerty123yucy:pr/ime-visual-viewport
Open

qwerty123yucy wants to merge 1 commit into
termux:masterfrom
qwerty123yucy:pr/ime-visual-viewport

Conversation

@qwerty123yucy

@qwerty123yucy qwerty123yucy commented Nov 17, 2026 •

Copy link
Copy Markdown

Problem

When the soft keyboard opens or closes, Android shrinks/expands TerminalView and updateSize() resizes the PTY row count (TIOCGWINSZ + SIGWINCH) on both the alternate screen and the main screen.

While resizing the PTY is desirable for full-screen alternate-buffer apps (vim, less, htop, tmux), on the main screen (!isAlternateBufferActive()) every keyboard toggle triggers TerminalBuffer.resize() and sends SIGWINCH to foreground shells and inline TUIs (e.g. multi-line prompts, fzf --height, CLI REPLs), causing line reflows, duplicate prompt redraws, or broken cursor-relative inline layouts.

Changes

  • Opt-in property (default: false):
    • Add soft-keyboard-pan-main-screen to TermuxPropertyConstants (TERMUX_APP_PROPERTIES_LIST and TERMUX_DEFAULT_FALSE_BOOLEAN_BEHAVIOUR_PROPERTIES_LIST), TermuxSharedProperties.shouldSoftKeyboardPanMainScreen(), TermuxTerminalViewClient.onReloadProperties(), and TerminalView.setSoftKeyboardPansMainScreen(boolean).
    • When false (the default), TerminalView, TerminalEmulator, and PTY sizing behave identically to master.
  • Decoupled visual viewport vs. main-screen PTY rows when enabled:
    • Track unobscured layout height in TerminalView.resolveLayoutHeight() (using API-guarded WindowInsets on API 23+ / WindowInsets.Type.ime() on API 30+ and root content margin, invalidated on non-IME toolbar changes via onToolbarGeometryChanged()). In multi-window / floating-window mode (Activity.isInMultiWindowMode(), unwrapping ContextWrapper), fall back directly to viewHeight so global IME insets are not misapplied when the keyboard is detached or pan-handled by the window manager.
    • Keep main-screen PTY rows (mEmulator.mRows) sized to layoutRows while setting mEmulator.setVisualRows(visibleRows) to the visible area above the IME.
    • Allow mTopRow on the main screen to pan positively within [0, mEmulator.getMaxTopRow()] where getMaxTopRow() bounds the viewport to the active cursor row and getLowestNonEmptyScreenRow(), keeping the active prompt or inline status bar above the keyboard without sending SIGWINCH.
    • Preserve full PTY resizing (targetPtyRows = visibleRows) whenever the alternate screen buffer (?1049h) is active, syncing PTY rows across ?1049h / ?1049l transitions.
  • Unit tests (ResizeTest):
    • Add testMainScreenVisualRowsDecoupledFromPtyRows() testing fresh prompts, bottom inline status bars, ?1049h/?1049l alternate-buffer transitions, and viewport restoration.

(Note for reviewers: This PR is independent of #5443, though both touch TerminalView / TerminalRenderer / TerminalEmulator. Happy to rebase whichever is reviewed second.)

Testing

…ze on IME toggle

Add an opt-in `soft-keyboard-pan-main-screen` boolean property in
`termux.properties` (default: `false`) and `TerminalView.setSoftKeyboardPansMainScreen()`
to decouple the visual viewport height (`mVisualRows`) from the main-screen
PTY row count (`mRows`) when the soft keyboard opens or closes.

- Keep main-screen PTY dimensions (`TIOCGWINSZ` / `SIGWINCH`) fixed to the
  unobscured terminal height while panning `mTopRow` up to `getMaxTopRow()`
  so inline TUIs, multi-line prompts, and ongoing shell output do not
  reflow or redraw destructively on every keyboard toggle.
- Preserve standard PTY resizing whenever the alternate screen buffer
  (`?1049h`, e.g. `vim`, `less`, `htop`, `tmux`) is active so full-screen
  applications continue to fit the visible area above the keyboard.
- Preserve existing behavior completely when `soft-keyboard-pan-main-screen`
  is `false` (the default).
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