Skip to content

Commit 6404004

Browse files
fix(mobile): Android terminal resizes the engine when only the cell size changes
applyGrid() skipped GhosttyBridge.nativeResize whenever the effective cols and rows were unchanged, so a text-size change under a grid pinned by another viewer left the engine on the old cell pixel size and sent no mode-2048 size report. Track the cell size given to the engine and resize when it changes too. Fixes #36008 Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent d06ba27 commit 6404004

1 file changed

Lines changed: 19 additions & 10 deletions

File tree

  • apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal

‎apps/mobile/modules/t3-terminal/android/src/main/java/expo/modules/t3terminal/T3TerminalView.kt‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(contex
6767
private var streamedOutput: TerminalOutputBuffer? = null
6868
private var cols = 0
6969
private var rows = 0
70+
private var cellWidth = 0
71+
private var cellHeight = 0
7072
private var measuredCols = 0
7173
private var measuredRows = 0
7274
private var clearingInput = false
@@ -356,25 +358,32 @@ class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(contex
356358
applyGrid()
357359
}
358360

361+
@Suppress("ComplexCondition")
359362
private fun applyGrid() {
360363
if (measuredCols <= 0 || measuredRows <= 0 || isCleanedUp) return
361364
val shared = sharedGrid.takeIf { it.size == 2 && it[0] > 0 && it[1] > 0 }
362365
val nextCols = shared?.get(0)?.coerceAtMost(measuredCols) ?: measuredCols
363366
val nextRows = shared?.get(1)?.coerceAtMost(measuredRows) ?: measuredRows
364-
if (nextCols == cols && nextRows == rows && terminalHandle != 0L) return
367+
val nextCellWidth = terminalCanvas.cellWidthPx.toInt()
368+
val nextCellHeight = terminalCanvas.cellHeightPx.toInt()
369+
if (
370+
nextCols == cols &&
371+
nextRows == rows &&
372+
nextCellWidth == cellWidth &&
373+
nextCellHeight == cellHeight &&
374+
terminalHandle != 0L
375+
) {
376+
return
377+
}
365378
cols = nextCols
366379
rows = nextRows
380+
cellWidth = nextCellWidth
381+
cellHeight = nextCellHeight
367382
val response = if (terminalHandle == 0L) {
368383
createTerminal()
369384
ByteArray(0)
370385
} else {
371-
GhosttyBridge.nativeResize(
372-
terminalHandle,
373-
cols,
374-
rows,
375-
terminalCanvas.cellWidthPx.toInt(),
376-
terminalCanvas.cellHeightPx.toInt(),
377-
)
386+
GhosttyBridge.nativeResize(terminalHandle, cols, rows, cellWidth, cellHeight)
378387
}
379388
emitResponse(response)
380389
if (!hasPendingBuffer) feedPendingBuffer()
@@ -387,8 +396,8 @@ class T3TerminalView(context: Context, appContext: AppContext) : ExpoView(contex
387396
terminalHandle = GhosttyBridge.nativeCreate(
388397
cols,
389398
rows,
390-
terminalCanvas.cellWidthPx.toInt(),
391-
terminalCanvas.cellHeightPx.toInt(),
399+
cellWidth,
400+
cellHeight,
392401
foregroundColorValue,
393402
backgroundColorValue,
394403
cursorColorValue,

0 commit comments

Comments
 (0)