Skip to content

A terminal's size follows the viewer in use, not whoever fitted last - #229

Merged
pallaoro merged 2 commits into
mainfrom
apparently-if-i-have-the-same
Sep 5, 2026
Merged

pallaoro merged 2 commits into
mainfrom
apparently-if-i-have-the-same

Conversation

@pallaoro

@pallaoro pallaoro commented Sep 5, 2026

Copy link
Copy Markdown
Member

One task open on the desktop and the phone (or in two desktop windows) shares one PTY, and every viewer pushed its own xterm fit straight to it. Last writer won: the phone merely opening the task (or showing its keyboard) shrank the desktop's terminal to phone width, and the desktop never recovered because it only re-reports when its own grid changes.

Now the PTY follows the viewer in use, tmux's window-size latest rule:

  • The first viewer to report a size holds it; a second viewer that just opens the terminal has its size remembered, not applied.
  • Typing on a viewer hands the size over and applies that viewer's remembered size at once, so coming back to the desk and typing restores the desktop size with no window resize.
  • A closed connection releases its hold; the next report claims it.

Each serveRpc connection gets an id (desktop and phone are distinct viewers on a box), and the desktop IPC bridge names each window by its webContents so two local windows are distinct too. The policy is one pure module (size-arbiter.ts); the dispatcher routes only pty:write and pty:resize through it. The PTY daemon is untouched.

Known trade-off: a non-owner viewer still fits its xterm to its own screen, so the phone shows desktop-width output wrapped until you type on it. Follow-up: broadcast the PTY size so non-owner viewers render the PTY grid.

Tests: arbiter policy, dispatcher with two clients, and a two-WebSocket end-to-end run including release on close.

One task open on the desktop and the phone (or in two windows) shares one
PTY, and every viewer pushed its own fit straight to it: the phone opening
the task shrank the desktop's terminal to phone width, for good. Now the
first viewer to report a size holds it, typing on a viewer hands the size
over (applying its remembered size at once), and a closed connection
releases it. Each RPC connection and each desktop window is a distinct
viewer.
@pallaoro
pallaoro enabled auto-merge (squash) September 5, 2026 18:39
@pallaoro
pallaoro merged commit 01ed02e into main Sep 5, 2026
1 check passed
@pallaoro pallaoro mentioned this pull request Sep 5, 2026
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