Skip to content

Fixed(app): Prevent stale bottom margin during non-IME layout passes - #5442

Open
qwerty123yucy wants to merge 1 commit into
termux:masterfrom
qwerty123yucy:pr/fix-non-ime-margin-jitter
Open

qwerty123yucy wants to merge 1 commit into
termux:masterfrom
qwerty123yucy:pr/fix-non-ime-margin-jitter

Conversation

@qwerty123yucy

@qwerty123yucy qwerty123yucy commented Nov 17, 2026 •

Copy link
Copy Markdown

Problem

In TermuxActivityRootView.onGlobalLayout(), once the soft keyboard has been opened and closed at least twice (lastMarginBottom != null), the isVisible && !setMargin branch ("Bottom margin already equals 0") executes:

marginBottom = lastMarginBottom;

This pre-arms marginBottom with the previous keyboard height while the keyboard is closed, assuming the next onMeasure() call will be caused by the keyboard reopening. However, any unrelated layout pass while the keyboard is closed—such as opening/closing the left DrawerLayout session drawer or toggling toolbar visibility—also invokes TermuxActivityRootView.onMeasure(), applying the stale lastMarginBottom for one layout pass before onGlobalLayout() resets it back to 0.

That transient shrink/expand cycle causes TerminalView.onSizeChanged() -> updateSize() to resize the PTY twice (SIGWINCH), visibly jumping the viewport and causing running shells/TUIs to reflow when opening the session drawer.

Changes & Trade-offs

  • Set marginBottom = null instead of lastMarginBottom in the Bottom margin already equals 0 branch so non-IME layout passes while the keyboard is closed keep marginBottom = 0.
    • Trade-off: As noted in the original comment, pre-arming lastMarginBottom tried to avoid a 1-frame adjustment on devices where SOFT_INPUT_ADJUST_RESIZE fails to push up the extra-keys/candidates row when reopening the keyboard. Not pre-arming while closed means those specific fallback cases adjust on onGlobalLayout() rather than onMeasure(), in exchange for eliminating guaranteed false-positive PTY resizes (SIGWINCH) during every non-IME layout pass while the keyboard is closed.
  • On Android 11+ (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R, where platform WindowInsets.Type.ime() reliably reports IME state, unlike Android 7–10 as noted in KeyboardUtils), guard the hidden-bottom branch with isImeVisibleApi30() so transient non-IME layout occlusions cannot apply a bottom margin when no IME is visible.

Testing

  • ./gradlew test and ./gradlew assembleDebug in CI.
  • Same patch backported onto v0.118.3 for Android device testing.

@qwerty123yucy
qwerty123yucy force-pushed the pr/fix-non-ime-margin-jitter branch from 8816791 to f7c2dad Compare November 17, 2026 05:04
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