Resize session to the most recently attached client
Replace the smallest-client sizing rule: the newest attach or resize now sets the session size, so reattaching from a larger terminal grows the session even while an older, smaller client is still connected. Smaller clients render only the top-left part that fits. Add Ctrl-A R to force the session back to the current client's size, and reap dead clients before drawing so a disconnect's size change lands in the same frame.
This commit is contained in:
parent
64035776ce
commit
7142ed7240
4 changed files with 60 additions and 25 deletions
|
|
@ -60,7 +60,7 @@ The client now reconciles its size with `TIOCGWINSZ` every `SIZE_CHECK_MS`
|
||||||
(250 ms) instead of only reacting to `SIGWINCH`. Some terminals update the pty
|
(250 ms) instead of only reacting to `SIGWINCH`. Some terminals update the pty
|
||||||
size without delivering a signal, or deliver it before the new size is
|
size without delivering a signal, or deliver it before the new size is
|
||||||
visible; the periodic check corrects both. Keep the SIGWINCH self-pipe and flag
|
visible; the periodic check corrects both. Keep the SIGWINCH self-pipe and flag
|
||||||
as the low-latency path. Note that the session is intentionally sized to the
|
as the low-latency path. The session size is set by the most recently attached
|
||||||
smallest attached client, so a larger client still shows the session centred
|
or resized client, so reattaching from a larger terminal grows the session even
|
||||||
with a border; use `Ctrl-A *` to check for extra attached clients when
|
if an older client is still connected; smaller clients show the top-left part.
|
||||||
diagnosing "it did not grow" reports.
|
Use `Ctrl-A *` to list attached clients when diagnosing size reports.
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,10 @@ sent straight to the pane.
|
||||||
- Real ptys per pane, a built-in VT100/xterm-ish screen emulator (colors,
|
- Real ptys per pane, a built-in VT100/xterm-ish screen emulator (colors,
|
||||||
256-color and truecolor SGR, alternate screen, scrolling, UTF-8, wide
|
256-color and truecolor SGR, alternate screen, scrolling, UTF-8, wide
|
||||||
characters).
|
characters).
|
||||||
- Multiple clients can attach to the same session. The session is sized to the
|
- Multiple clients can attach to the same session. The most recently attached
|
||||||
smallest attached client; a larger client shows the session centred in its
|
or resized client sets the session size; a larger client shows the session
|
||||||
terminal.
|
centred in its terminal, while a smaller client shows the top-left part.
|
||||||
|
`Ctrl-A R` forces the session back to the current client's terminal size.
|
||||||
- Panes run `$SHELL` as a login shell with `TERM=screen-256color`.
|
- Panes run `$SHELL` as a login shell with `TERM=screen-256color`.
|
||||||
|
|
||||||
## Keys
|
## Keys
|
||||||
|
|
@ -54,6 +55,7 @@ Prefix is `Ctrl-A`. Every shortcut below is `Ctrl-A`, then the key(s) shown.
|
||||||
| `Ctrl-A &` | kill window (confirm) |
|
| `Ctrl-A &` | kill window (confirm) |
|
||||||
| `Ctrl-A \` | kill server (confirm) |
|
| `Ctrl-A \` | kill server (confirm) |
|
||||||
| `Ctrl-A r` | show `Configuration Reloaded!` |
|
| `Ctrl-A r` | show `Configuration Reloaded!` |
|
||||||
|
| `Ctrl-A R` | force the session to this client's terminal size |
|
||||||
| `Ctrl-A *` | list attached clients |
|
| `Ctrl-A *` | list attached clients |
|
||||||
| `Ctrl-A d`, `Ctrl-A Ctrl-D` | detach |
|
| `Ctrl-A d`, `Ctrl-A Ctrl-D` | detach |
|
||||||
|
|
||||||
|
|
|
||||||
BIN
moerx
BIN
moerx
Binary file not shown.
69
moerx.c
69
moerx.c
|
|
@ -1008,6 +1008,7 @@ struct Client {
|
||||||
int fd;
|
int fd;
|
||||||
int cols, rows;
|
int cols, rows;
|
||||||
int attached;
|
int attached;
|
||||||
|
uint64_t order; /* attach/resize sequence, newest client wins */
|
||||||
int truecolor;
|
int truecolor;
|
||||||
unsigned char in[16384];
|
unsigned char in[16384];
|
||||||
size_t inlen;
|
size_t inlen;
|
||||||
|
|
@ -1050,7 +1051,9 @@ struct Session {
|
||||||
int nwin;
|
int nwin;
|
||||||
|
|
||||||
Client *clients;
|
Client *clients;
|
||||||
|
uint64_t client_order;
|
||||||
int running;
|
int running;
|
||||||
|
int redraw; /* a removed client changed the session size */
|
||||||
|
|
||||||
long long last_status;
|
long long last_status;
|
||||||
};
|
};
|
||||||
|
|
@ -1898,9 +1901,14 @@ static void draw_frame(Session *s, Client *c, Grid *scr) {
|
||||||
Buf b;
|
Buf b;
|
||||||
memset(&b, 0, sizeof b);
|
memset(&b, 0, sizeof b);
|
||||||
|
|
||||||
/* A client larger than the session gets the screen centred. */
|
/* A client larger than the session gets the screen centred, while a
|
||||||
|
smaller client sees the top-left part of the session. */
|
||||||
int offx = c->cols > scr->w ? (c->cols - scr->w) / 2 : 0;
|
int offx = c->cols > scr->w ? (c->cols - scr->w) / 2 : 0;
|
||||||
int offy = c->rows > scr->h ? (c->rows - scr->h) / 2 : 0;
|
int offy = c->rows > scr->h ? (c->rows - scr->h) / 2 : 0;
|
||||||
|
int vw = scr->w < c->cols ? scr->w : c->cols;
|
||||||
|
int vh = scr->h < c->rows ? scr->h : c->rows;
|
||||||
|
if (vw < 1) vw = 1;
|
||||||
|
if (vh < 1) vh = 1;
|
||||||
|
|
||||||
int invalid = !c->prev_valid || c->prev.w != scr->w || c->prev.h != scr->h;
|
int invalid = !c->prev_valid || c->prev.w != scr->w || c->prev.h != scr->h;
|
||||||
if (invalid) {
|
if (invalid) {
|
||||||
|
|
@ -1921,9 +1929,9 @@ static void draw_frame(Session *s, Client *c, Grid *scr) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int y = 0; y < scr->h; y++) {
|
for (int y = 0; y < vh; y++) {
|
||||||
int first = -1, last = -1;
|
int first = -1, last = -1;
|
||||||
for (int x = 0; x < scr->w; x++) {
|
for (int x = 0; x < vw; x++) {
|
||||||
Cell *a = grid_at(scr, x, y);
|
Cell *a = grid_at(scr, x, y);
|
||||||
Cell *p = grid_at(&c->prev, x, y);
|
Cell *p = grid_at(&c->prev, x, y);
|
||||||
if (!cell_same(a, p)) {
|
if (!cell_same(a, p)) {
|
||||||
|
|
@ -1933,7 +1941,7 @@ static void draw_frame(Session *s, Client *c, Grid *scr) {
|
||||||
}
|
}
|
||||||
if (first < 0) continue;
|
if (first < 0) continue;
|
||||||
if (first > 0 && grid_at(scr, first, y)->ch == WIDE_CONT) first--;
|
if (first > 0 && grid_at(scr, first, y)->ch == WIDE_CONT) first--;
|
||||||
if (last + 1 < scr->w && grid_at(scr, last + 1, y)->ch == WIDE_CONT) last++;
|
if (last + 1 < vw && grid_at(scr, last + 1, y)->ch == WIDE_CONT) last++;
|
||||||
buf_printf(&b, "\x1b[%d;%dH", y + 1 + offy, first + 1 + offx);
|
buf_printf(&b, "\x1b[%d;%dH", y + 1 + offy, first + 1 + offx);
|
||||||
|
|
||||||
int32_t cf = -3, cb = -3;
|
int32_t cf = -3, cb = -3;
|
||||||
|
|
@ -1959,7 +1967,7 @@ static void draw_frame(Session *s, Client *c, Grid *scr) {
|
||||||
int cx, cy, vis;
|
int cx, cy, vis;
|
||||||
cursor_for(s, c, &cx, &cy, &vis);
|
cursor_for(s, c, &cx, &cy, &vis);
|
||||||
buf_puts(&b, "\x1b[0m");
|
buf_puts(&b, "\x1b[0m");
|
||||||
if (vis && cy == 0) vis = 0;
|
if (vis && (cy == 0 || cx >= vw || cy >= vh)) vis = 0;
|
||||||
if (vis) {
|
if (vis) {
|
||||||
buf_printf(&b, "\x1b[%d;%dH\x1b[?25h", cy + 1 + offy, cx + 1 + offx);
|
buf_printf(&b, "\x1b[%d;%dH\x1b[?25h", cy + 1 + offy, cx + 1 + offx);
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -2018,19 +2026,24 @@ static void invalidate_clients(Session *s) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void session_recalc_size(Session *s) {
|
static void session_recalc_size(Session *s) {
|
||||||
int cols = 0, rows = 0, any = 0;
|
/* The most recently attached or resized client decides the session size.
|
||||||
|
This makes a reattach from a larger terminal grow the session even if an
|
||||||
|
older, smaller client is still connected. Such clients render only the
|
||||||
|
part of the session that fits (see draw_frame). */
|
||||||
|
Client *best = NULL;
|
||||||
for (Client *c = s->clients; c; c = c->next) {
|
for (Client *c = s->clients; c; c = c->next) {
|
||||||
if (!c->attached) continue;
|
if (!c->attached || c->dead || c->fd < 0) continue;
|
||||||
if (!any || c->cols < cols) cols = c->cols;
|
if (!best || c->order > best->order) best = c;
|
||||||
if (!any || c->rows < rows) rows = c->rows;
|
|
||||||
any = 1;
|
|
||||||
}
|
}
|
||||||
if (!any) return;
|
if (!best) return;
|
||||||
|
int cols = best->cols;
|
||||||
|
int rows = best->rows;
|
||||||
if (cols < MIN_COLS) cols = MIN_COLS;
|
if (cols < MIN_COLS) cols = MIN_COLS;
|
||||||
if (rows < MIN_ROWS) rows = MIN_ROWS;
|
if (rows < MIN_ROWS) rows = MIN_ROWS;
|
||||||
if (cols == s->w && rows == s->h) return;
|
if (cols == s->w && rows == s->h) return;
|
||||||
s->w = cols;
|
s->w = cols;
|
||||||
s->h = rows;
|
s->h = rows;
|
||||||
|
s->redraw = 1;
|
||||||
session_layout(s);
|
session_layout(s);
|
||||||
invalidate_clients(s);
|
invalidate_clients(s);
|
||||||
}
|
}
|
||||||
|
|
@ -2540,6 +2553,15 @@ static void prefix_command(Client *c, Session *s, int key) {
|
||||||
case 'r':
|
case 'r':
|
||||||
client_message(c, "Configuration Reloaded!");
|
client_message(c, "Configuration Reloaded!");
|
||||||
break;
|
break;
|
||||||
|
case 'R':
|
||||||
|
/* Make this client's terminal the size source again, even if another
|
||||||
|
client attached or resized more recently. */
|
||||||
|
c->order = ++s->client_order;
|
||||||
|
session_recalc_size(s);
|
||||||
|
invalidate_clients(s);
|
||||||
|
s->redraw = 1;
|
||||||
|
client_message(c, "Session resized to %dx%d", s->w, s->h);
|
||||||
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
split_pane(s, L_ROWS);
|
split_pane(s, L_ROWS);
|
||||||
break;
|
break;
|
||||||
|
|
@ -2873,6 +2895,8 @@ static void handle_message(Client *c, Session *s, uint32_t type, const unsigned
|
||||||
c->rows = (int)rows;
|
c->rows = (int)rows;
|
||||||
c->truecolor = (flags & 1) != 0;
|
c->truecolor = (flags & 1) != 0;
|
||||||
c->attached = 1;
|
c->attached = 1;
|
||||||
|
c->order = ++s->client_order;
|
||||||
|
client_invalidate(c);
|
||||||
session_recalc_size(s);
|
session_recalc_size(s);
|
||||||
invalidate_clients(s);
|
invalidate_clients(s);
|
||||||
}
|
}
|
||||||
|
|
@ -2887,6 +2911,8 @@ static void handle_message(Client *c, Session *s, uint32_t type, const unsigned
|
||||||
if (rows > 1000) rows = 1000;
|
if (rows > 1000) rows = 1000;
|
||||||
c->cols = (int)cols;
|
c->cols = (int)cols;
|
||||||
c->rows = (int)rows;
|
c->rows = (int)rows;
|
||||||
|
c->order = ++s->client_order;
|
||||||
|
client_invalidate(c);
|
||||||
session_recalc_size(s);
|
session_recalc_size(s);
|
||||||
invalidate_clients(s);
|
invalidate_clients(s);
|
||||||
}
|
}
|
||||||
|
|
@ -3050,6 +3076,19 @@ static void run_server(Session *s) {
|
||||||
free(pfds);
|
free(pfds);
|
||||||
free(cmap);
|
free(cmap);
|
||||||
|
|
||||||
|
/* Reap dead clients before drawing so a removed client's size change
|
||||||
|
is reflected in this frame instead of waiting for the next event. */
|
||||||
|
Client *c = s->clients;
|
||||||
|
while (c) {
|
||||||
|
Client *next = c->next;
|
||||||
|
if (c->dead) client_remove(s, c);
|
||||||
|
c = next;
|
||||||
|
}
|
||||||
|
if (s->redraw) {
|
||||||
|
s->redraw = 0;
|
||||||
|
dirty = 1;
|
||||||
|
}
|
||||||
|
|
||||||
long long t = now_ms();
|
long long t = now_ms();
|
||||||
if (t - s->last_status >= STATUS_INTERVAL * 1000) {
|
if (t - s->last_status >= STATUS_INTERVAL * 1000) {
|
||||||
s->last_status = t;
|
s->last_status = t;
|
||||||
|
|
@ -3066,13 +3105,6 @@ static void run_server(Session *s) {
|
||||||
}
|
}
|
||||||
dirty = 0;
|
dirty = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Client *c = s->clients;
|
|
||||||
while (c) {
|
|
||||||
Client *next = c->next;
|
|
||||||
if (c->dead) client_remove(s, c);
|
|
||||||
c = next;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
server_notify_all(s, "[server exited]");
|
server_notify_all(s, "[server exited]");
|
||||||
|
|
@ -3596,6 +3628,7 @@ static void print_help(FILE *out) {
|
||||||
" Ctrl-A Ctrl-X lock the client\n"
|
" Ctrl-A Ctrl-X lock the client\n"
|
||||||
" Ctrl-A * list attached clients\n"
|
" Ctrl-A * list attached clients\n"
|
||||||
" Ctrl-A r show \"Configuration Reloaded!\"\n"
|
" Ctrl-A r show \"Configuration Reloaded!\"\n"
|
||||||
|
" Ctrl-A R resize session to this terminal (force)\n"
|
||||||
" Ctrl-A d detach\n"
|
" Ctrl-A d detach\n"
|
||||||
" Ctrl-A Ctrl-D detach\n"
|
" Ctrl-A Ctrl-D detach\n"
|
||||||
" Ctrl-A \\ kill server (confirm)\n"
|
" Ctrl-A \\ kill server (confirm)\n"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue