fix(dual-screen): the bottom-screen terminal keeps its shell when another app covers that screen (#2366)

* fix(dual-screen): the bottom-screen terminal keeps its shell when another app covers that screen

* fix(session): sweep the kept terminal shell's process tree when the session ends
This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-11-15 10:16:01 -05:00
1 parent 4e3eeea5e2
commit d0398fd853
5 files changed
+128 -8

No files matched your search

@@ -364,7 +364,7 @@ class SecondScreenPresentation(
private fun renderTerminal() {
bar(SecondScreenMode.TERMINAL)
val panel = SessionTerminalPanel(context)
val panel = SessionTerminalPanel(context, keepShell = true)
terminalPanel = panel
root.addView(panel, weightParams())
}
@@ -21,7 +21,7 @@ import com.termux.terminal.TerminalSessionClient
import com.termux.view.TerminalView
import com.termux.view.TerminalViewClient
class SessionTerminalPanel(context: Context) : LinearLayout(context) {
class SessionTerminalPanel(context: Context, private val keepShell: Boolean = false) : LinearLayout(context) {
private var terminalSession: TerminalSession? = null
private var terminalView: TerminalView? = null
private var terminalPid = -1
@@ -45,7 +45,8 @@ class SessionTerminalPanel(context: Context) : LinearLayout(context) {
isFocusableInTouchMode = true
}
terminalView = view
val session = SessionTerminal.create(terminalClient)
val session = (if (keepShell) SessionTerminal.reuse(terminalClient) else null)
?: SessionTerminal.create(terminalClient)?.also { if (keepShell) SessionTerminal.keep(it) }
if (session == null) {
addView(TextView(context).apply {
text = context.getString(R.string.second_terminal_not_ready)
@@ -121,8 +122,12 @@ class SessionTerminalPanel(context: Context) : LinearLayout(context) {
(context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)
.hideSoftInputFromWindow(view.windowToken, 0)
}
val pid = terminalPid.takeIf { it > 1 } ?: (terminalSession?.pid ?: -1)
if (pid > 1) SessionService.stopTerminalProcess(context, pid)
val session = terminalSession
if (!keepShell || session?.isRunning != true) {
val pid = terminalPid.takeIf { it > 1 } ?: (session?.pid ?: -1)
if (pid > 1) SessionService.stopTerminalProcess(context, pid)
SessionTerminal.release(session)
}
terminalPid = -1
terminalSession = null
terminalView = null
@@ -140,6 +145,7 @@ class SessionTerminalPanel(context: Context) : LinearLayout(context) {
override fun onSessionFinished(finishedSession: TerminalSession) {
val pid = terminalPid.takeIf { it > 1 } ?: finishedSession.pid
if (pid > 1) SessionService.terminalProcessExited(context, pid)
SessionTerminal.release(finishedSession)
terminalPid = -1
terminalView?.onScreenUpdated()
}