This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-12-session-parity
in repository terminology.
View the commit online.
commit fbe438c13340c49be1ba134d4338fe9742a22895
Author: Cedric BAIL <[email protected]>
AuthorDate: Sun Nov 22 22:20:11 2026 -0600
termd_tymux: show the session to a client as it attaches
Only a client that resized got a first frame. A shared or read-only
client showed nothing, and a proxy lacked the application's input
modes, until the session next changed. A client now gets a NOTIFY for
the current frame when it attaches.
That must not expose a mode 2026 update in progress, so neither the
attach, a resize to the same size, nor an animator armed before the
update ships a frame until it ends.
---
src/bin/termd_tymux.c | 50 +++++++++++-----
src/bin/tytest.c | 2 +
src/bin/tytest_tymux.c | 160 +++++++++++++++++++++++++++++++++++++++++++++++++
src/bin/tytest_tymux.h | 2 +
tests/meson.build | 3 +-
tests/tymux.py | 5 +-
6 files changed, 206 insertions(+), 16 deletions(-)
diff --git a/src/bin/termd_tymux.c b/src/bin/termd_tymux.c
index 07aa377a..dd4e6cf7 100644
--- a/src/bin/termd_tymux.c
+++ b/src/bin/termd_tymux.c
@@ -536,20 +536,27 @@ _cb_pty_command(void *data)
}
static void
-_flush_and_notify(TermDTymux *td)
+_notify_fill(const TermDTymux *td, TermSrvMsgNotify *notify)
{
Termpty *ty = td->pty;
+
+ notify->appcursor = ty->termstate.appcursor;
+ notify->appkeypad = ty->termstate.alt_kp;
+ notify->mouse_mode = ty->mouse_mode;
+ notify->mouse_ext = ty->mouse_ext;
+ notify->bracketed_paste = ty->bracketed_paste;
+ notify->focus_reporting = ty->focus_reporting;
+ notify->has_blocks = ty->block.published;
+ notify->first_page_id = backlog_store_first_id(ty->backlog_store);
+ notify->page_count = backlog_store_count(ty->backlog_store);
+}
+
+static void
+_flush_and_notify(TermDTymux *td)
+{
Eina_List *l;
Client *client;
- TermSrvMsgNotify notify = {
- .appcursor = ty->termstate.appcursor,
- .appkeypad = ty->termstate.alt_kp,
- .mouse_mode = ty->mouse_mode,
- .mouse_ext = ty->mouse_ext,
- .bracketed_paste = ty->bracketed_paste,
- .focus_reporting = ty->focus_reporting,
- .has_blocks = ty->block.published,
- };
+ TermSrvMsgNotify notify = { 0 };
td->dirty = EINA_FALSE;
if (td->notify_anim)
@@ -558,8 +565,7 @@ _flush_and_notify(TermDTymux *td)
td->notify_anim = NULL;
}
- notify.first_page_id = backlog_store_first_id(ty->backlog_store);
- notify.page_count = backlog_store_count(ty->backlog_store);
+ _notify_fill(td, ¬ify);
EINA_LIST_FOREACH(td->clients, l, client)
_client_pages_prune(client);
@@ -573,6 +579,8 @@ _cb_notify_anim(void *data)
TermDTymux *td = data;
td->notify_anim = NULL;
+ if (td->pty->sync_output.active)
+ return ECORE_CALLBACK_CANCEL;
_flush_and_notify(td);
return ECORE_CALLBACK_CANCEL;
}
@@ -649,6 +657,7 @@ _client_attach(Client *client, TermSrvAttachMode mode)
Termpty *ty = td->pty;
Eina_List *l;
Client *other;
+ TermSrvMsgNotify notify = { 0 };
if (termsrv_send_attached(client->fd, td->shm_fd, ty->w, ty->h,
ty->pid > 0 ? ty->pid : -1,
@@ -681,6 +690,16 @@ _client_attach(Client *client, TermSrvAttachMode mode)
break;
}
_actions_update(td);
+ if (td->dirty && !ty->sync_output.active)
+ {
+ _flush_and_notify(td);
+ return;
+ }
+ _notify_fill(td, ¬ify);
+ notify.write_seq = atomic_load_explicit(&td->shm->write_seq,
+ memory_order_relaxed);
+ if (!_client_send(client, TSRV_MSG_NOTIFY, ¬ify, sizeof(notify)))
+ _client_hang_up(client);
}
static void
@@ -694,8 +713,11 @@ _client_resize(Client *client, const TermSrvMsgResize *resize)
resize->cols > TERMSRV_MAX_COLS || resize->rows > TERMSRV_MAX_ROWS)
return;
termpty_resize(td->pty, resize->cols, resize->rows);
- /* termpty_resize() ends any synchronized update without calling the
- * change callback: flush now so that clients get the new size. */
+ /* A resize ends a synchronized update without calling the change
+ * callback: flush now so that clients get the new size. One still active
+ * was not a resize (the size is the same): its end ships the frame. */
+ if (td->pty->sync_output.active)
+ return;
_flush_and_notify(td);
}
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index adb72b5d..926fd3f9 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -347,6 +347,8 @@ static const struct {
{ "tymux_live_paste", tytest_tymux_live_paste},
{ "tymux_live_pages_read_only", tytest_tymux_live_pages_read_only},
{ "tymux_live_focus_restores", tytest_tymux_live_focus_restores},
+ { "tymux_live_attach_frame", tytest_tymux_live_attach_frame},
+ { "tymux_live_attach_sync", tytest_tymux_live_attach_sync},
{ "tymux_live_resume_size", tytest_tymux_live_resume_size},
{ "tymux_live_links", tytest_tymux_live_links},
{ "tymux_live_blocks", tytest_tymux_live_blocks},
diff --git a/src/bin/tytest_tymux.c b/src/bin/tytest_tymux.c
index b8a4f51a..87b80191 100644
--- a/src/bin/tytest_tymux.c
+++ b/src/bin/tytest_tymux.c
@@ -1484,6 +1484,166 @@ tytest_tymux_live_clear(void)
return tytest_tymux_live_run(_live_clear_body);
}
+#define ATTACH_MARK "ATTACHMARK"
+
+static Eina_Bool
+_attach_frame_ready(void *data)
+{
+ Termpty *ty = data;
+
+ return ty->bracketed_paste;
+}
+
+static Eina_Bool
+_shm_has_text(const TermSrvShmHeader *shm, const char *text)
+{
+ const TermSrvCell *cells = TERMSRV_SHM_CELLS(shm);
+ size_t len = strlen(text);
+ uint32_t y, x, i;
+
+ for (y = 0; y < shm->rows; y++)
+ for (x = 0; x + len <= shm->cols; x++)
+ {
+ for (i = 0; i < len; i++)
+ if (cells[y * shm->cols + x + i].codepoint != (uint32_t)text[i])
+ break;
+ if (i == len) return EINA_TRUE;
+ }
+ return EINA_FALSE;
+}
+
+/* A client that attaches is sent the frame and the modes of the session at
+ * once, with the session idle: a read-only one has nothing else to wait
+ * for. */
+static int
+_live_attach_frame_body(void)
+{
+ TermTymux *ts;
+ Termpty *ty;
+ TermSrvReader reader = { 0 };
+ TermSrvMsgAttached attached;
+ TermSrvMsgNotify notify;
+ TermSrvShmHeader *shm;
+ void *payload;
+ uint32_t size;
+ int fd, shm_fd, type;
+ uint8_t mode = TSRV_ATTACH_READONLY;
+
+ assert(tytest_tymux_start(SESSION, 80, 24, &ts, &ty));
+ assert(tytest_tymux_wait(_prompt_done, ty, 5.0));
+ assert(tytest_tymux_type(ts, ty, "printf 'ATTACH%s\\033[?2004h' MARK; "
+ "sleep 600\n"));
+ assert(tytest_tymux_wait(_attach_frame_ready, ty, 5.0));
+ assert(!tytest_tymux_wait(_never_done, NULL, 1.0));
+
+ fd = termsrv_connect(SESSION);
+ assert(fd >= 0);
+ assert(termsrv_msg_send(fd, TSRV_MSG_ATTACH, &mode, sizeof(mode)) == 0);
+ assert(termsrv_recv_attached(fd, &shm_fd, &attached) == 0);
+ type = _pages_recv(&reader, fd, 2000, &payload, &size, NULL);
+ assert(type == TSRV_MSG_NOTIFY);
+ assert(size == sizeof(notify));
+ memcpy(¬ify, payload, sizeof(notify));
+ free(payload);
+ assert(notify.bracketed_paste);
+ assert(notify.first_page_id == attached.first_page_id);
+ assert(notify.page_count == attached.page_count);
+ shm = mmap(NULL, TERMSRV_SHM_TOTAL_SIZE, PROT_READ, MAP_SHARED, shm_fd, 0);
+ assert(shm != MAP_FAILED);
+ assert(notify.write_seq == atomic_load(&shm->write_seq));
+ assert(_shm_has_text(shm, ATTACH_MARK));
+
+ munmap(shm, TERMSRV_SHM_TOTAL_SIZE);
+ termsrv_reader_clear(&reader);
+ close(shm_fd);
+ close(fd);
+ tytest_tymux_stop(ts);
+ return 0;
+}
+
+int
+tytest_tymux_live_attach_frame(void)
+{
+ return tytest_tymux_live_run(_live_attach_frame_body);
+}
+
+#define SYNC_STARTED "sync-started"
+
+static Eina_Bool
+_sync_started_done(void *data)
+{
+ return access(data, F_OK) == 0;
+}
+
+/* Attaching, or resizing to the same size, in the middle of a synchronized
+ * update (mode 2026) shows the last complete frame, not the half drawn one;
+ * the end of the update then ships the whole. */
+static int
+_live_attach_sync_body(void)
+{
+ TermTymux *ts;
+ Termpty *ty;
+ TermSrvReader reader = { 0 };
+ TermSrvMsgAttached attached;
+ TermSrvShmHeader *shm;
+ void *payload;
+ uint32_t size;
+ int fd, shm_fd, type;
+ uint8_t mode = TSRV_ATTACH_READONLY;
+ char started[256], cmd[512];
+
+ assert(tytest_tymux_start(SESSION, 80, 24, &ts, &ty));
+ assert(tytest_tymux_wait(_prompt_done, ty, 5.0));
+ snprintf(started, sizeof(started), "%s/" SYNC_STARTED,
+ getenv("XDG_RUNTIME_DIR"));
+ /* The reply to the query of mode 2026 is what tells the shell the
+ * update is on, and so the file that it then makes the test. */
+ snprintf(cmd, sizeof(cmd),
+ "printf '\\033[?2026hSYNC%%s\\033[?2026$p' PART; "
+ "read -r -s -t 5 -d y reply; printf '\\033[?2026h'; : > %s; "
+ "for i in $(seq 100); do printf '\\033[?2026h'; sleep 0.02; "
+ "done; printf '\\033[?2026l'\n", started);
+ assert(tytest_tymux_type(ts, ty, cmd));
+ assert(tytest_tymux_wait(_sync_started_done, started, 5.0));
+
+ fd = termsrv_connect(SESSION);
+ assert(fd >= 0);
+ assert(termsrv_msg_send(fd, TSRV_MSG_ATTACH, &mode, sizeof(mode)) == 0);
+ assert(termsrv_recv_attached(fd, &shm_fd, &attached) == 0);
+ shm = mmap(NULL, TERMSRV_SHM_TOTAL_SIZE, PROT_READ, MAP_SHARED, shm_fd, 0);
+ assert(shm != MAP_FAILED);
+ type = _pages_recv(&reader, fd, 2000, &payload, &size, NULL);
+ assert(type == TSRV_MSG_NOTIFY);
+ free(payload);
+ assert(!_shm_has_text(shm, "SYNCPART"));
+
+ termtymux_resize(ts, 80, 24);
+ assert(!tytest_tymux_wait(_never_done, NULL, 0.3));
+ assert(!_shm_has_text(shm, "SYNCPART"));
+
+ do
+ {
+ type = _pages_recv(&reader, fd, 5000, &payload, &size, NULL);
+ assert(type > 0);
+ free(payload);
+ }
+ while (type != TSRV_MSG_NOTIFY);
+ assert(_shm_has_text(shm, "SYNCPART"));
+
+ munmap(shm, TERMSRV_SHM_TOTAL_SIZE);
+ termsrv_reader_clear(&reader);
+ close(shm_fd);
+ close(fd);
+ tytest_tymux_stop(ts);
+ return 0;
+}
+
+int
+tytest_tymux_live_attach_sync(void)
+{
+ return tytest_tymux_live_run(_live_attach_sync_body);
+}
+
#define CONFIG_SCROLLBACK 300
/* The numbers up to the last one are in the backlog, and the shell is back
diff --git a/src/bin/tytest_tymux.h b/src/bin/tytest_tymux.h
index 2a484a8d..f508fe77 100644
--- a/src/bin/tytest_tymux.h
+++ b/src/bin/tytest_tymux.h
@@ -59,6 +59,8 @@ int tytest_tymux_live_page_async(void);
int tytest_tymux_live_paste(void);
int tytest_tymux_live_pages_read_only(void);
int tytest_tymux_live_focus_restores(void);
+int tytest_tymux_live_attach_frame(void);
+int tytest_tymux_live_attach_sync(void);
int tytest_tymux_live_resume_size(void);
int tytest_tymux_live_links(void);
int tytest_tymux_live_blocks(void);
diff --git a/tests/meson.build b/tests/meson.build
index 7c59db1f..47dea0d9 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -110,7 +110,8 @@ if tests
'tymux_live_pages_read_only', 'tymux_live_resume_size',
'tymux_live_blocks', 'tymux_live_commands',
'tymux_live_commands_full', 'tymux_live_commands_replay',
- 'tymux_live_commands_flood'],
+ 'tymux_live_commands_flood', 'tymux_live_attach_frame',
+ 'tymux_live_attach_sync'],
depends: [tymuxd, tysend],
timeout: 120)
# Sends tens of MiB of links through a session: apart, for its time.
diff --git a/tests/tymux.py b/tests/tymux.py
index f3a5aa4b..6ac1367a 100644
--- a/tests/tymux.py
+++ b/tests/tymux.py
@@ -940,11 +940,14 @@ def main():
os.close(fd)
check(len(msg) == 28 and struct.unpack_from("=II", msg)[0] == 2,
"kill-exit: ATTACHED is received")
+ buf4 = bytearray()
+ got = recv_msg(raw4, buf4, timeout=5)
+ check(got is not None and got[0] == 6,
+ "kill-exit: the attach is followed by the current frame")
result = tymux("kill", NAME8)
check(result.returncode == 0, "kill-exit: kill succeeds")
- buf4 = bytearray()
got = recv_msg(raw4, buf4, timeout=5)
check(got is not None and got[0] == 9,
"kill-exit: a raw client sees TSRV_MSG_EXIT, not just EOF, when"
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.