This is an automated email from the git hooks/post-receive script.
git pushed a commit to branch tymux-10-quiet-head
in repository terminology.
View the commit online.
commit 675f8e3d1d435fb7e9705ada802eb53fd8f864df
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 21 02:01:16 2026 -0600
termio: tell the backlog when a terminal gains or loses the focus
A backlog view lets go of the head once its terminal is quiet, so that
the store can compress it, unless the terminal has the focus. Nothing
told the views about the focus, so even the terminal the user types in
had its head released after 10 to 20 s without output, and a terminal
just attached to a tymux session did not fill its scrollback until it
printed.
The focus is kept on the pty rather than only on its view: clearing the
scrollback or changing its size makes a new view, and a tymux attach or
detach puts a new pty under a terminal that already has the focus.
Without it, a 'clear' in the focused terminal would leave it unfocused
to the backlog.
The new live test waits for tymuxd's own quiet delay, so it runs as a
test of its own, next to the other live tests.
This completes the series that compresses the head of quiet,
unfocused terminals. Measured against 9297f854 (before the series),
each instance printing 131072 lines of ~103 coloured cells into a
131072 line scrollback, with an idle baseline of 34.4 MB RssAnon: an
unfocused instance went from 67.5 MB to 61.5 MB, its 6.6 MB raw head
compressed 22 to 27 s after its output stopped. The focused instance
is unchanged (69.3 MB vs 69.4 MB, head kept raw).
A line printed into an unfocused terminal whose head is compressed
does not stall the main loop: the longest busy stretch in the
following second was 1.7-2.1 ms, against 1.8-3.1 ms before the series
(main thread under strace).
---
src/bin/backlog.c | 12 +++++
src/bin/backlog.h | 7 +++
src/bin/termio.c | 4 ++
src/bin/termpty.c | 30 ++++++++++++
src/bin/termpty.h | 3 ++
src/bin/tytest.c | 2 +
src/bin/tytest_tymux.c | 124 +++++++++++++++++++++++++++++++++++++++++++++++--
src/bin/tytest_tymux.h | 1 +
src/bin/unit_tests.h | 1 +
src/bin/win.c | 17 ++++++-
tests/meson.build | 7 +++
11 files changed, 201 insertions(+), 7 deletions(-)
diff --git a/src/bin/backlog.c b/src/bin/backlog.c
index 767559f2..eee7f684 100644
--- a/src/bin/backlog.c
+++ b/src/bin/backlog.c
@@ -84,6 +84,16 @@ termpty_backlog_viewport_set(Termpty *ty, int scroll)
backlog_view_viewport_set(ty->backlog_view, scroll);
}
+void
+termpty_backlog_focus_set(Termpty *ty, Eina_Bool focus)
+{
+ if (!ty)
+ return;
+ ty->backlog_focused = !!focus;
+ if (ty->backlog_view)
+ backlog_view_focus_set(ty->backlog_view, focus);
+}
+
void
termpty_backlog_follow(Termpty *ty)
{
@@ -263,6 +273,8 @@ _ring_view_new(Termpty *ty, size_t backsize)
if (!ty->backlog_view)
return EINA_FALSE;
backlog_view_local_sync(ty->backlog_view);
+ if (ty->backlog_focused)
+ backlog_view_focus_set(ty->backlog_view, EINA_TRUE);
return EINA_TRUE;
}
diff --git a/src/bin/backlog.h b/src/bin/backlog.h
index fbd1e38f..f6c29c5c 100644
--- a/src/bin/backlog.h
+++ b/src/bin/backlog.h
@@ -52,6 +52,13 @@ termpty_backlog_follow(Termpty *ty);
void
termpty_backlog_viewport_set(Termpty *ty, int scroll);
+/* Whether the terminal of ty has the focus: while it does, its backlog
+ * keeps the newest page mapped, and gets it back at once if it was
+ * compressed (see backlog_view_focus_set()). Kept for the views made
+ * later, when the scrollback is cleared or resized. */
+void
+termpty_backlog_focus_set(Termpty *ty, Eina_Bool focus);
+
/* Point a new newest entry at w cells, of page_id of the store. */
void
termpty_backlog_push(Termpty *ty, Termcell *cells, ssize_t w,
diff --git a/src/bin/termio.c b/src/bin/termio.c
index 3d3bb69e..db7e850b 100644
--- a/src/bin/termio.c
+++ b/src/bin/termio.c
@@ -2980,6 +2980,7 @@ termio_focus_in(Evas_Object *termio)
sd->cursor.last_key = ecore_loop_time_get();
_cursor_focus_signals_emit(sd, EINA_TRUE);
_cursor_blink_timer_update(sd);
+ termpty_backlog_focus_set(sd->pty, EINA_TRUE);
if (!sd->win) return;
termpty_focus_report(sd->pty, EINA_TRUE);
}
@@ -2992,6 +2993,7 @@ termio_focus_out(Evas_Object *termio)
_cursor_blink_unfocus(sd);
_cursor_focus_signals_emit(sd, EINA_FALSE);
+ termpty_backlog_focus_set(sd->pty, EINA_FALSE);
if (!sd->win) return;
sd->pty->selection.last_click = 0;
if (!sd->ctxpopup)
@@ -4940,6 +4942,8 @@ _termio_pty_cb_wire(Evas_Object *obj, Termio *sd)
sd->pty->cb.progress.data = ""
sd->pty->cb.program_status.func = _smart_pty_program_status;
sd->pty->cb.program_status.data = ""
+ /* a pty taking over a focused terminal, from or to a tymux session */
+ termpty_backlog_focus_set(sd->pty, term_is_focused(sd->term));
}
static void
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index d48962fc..106bb926 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -6617,6 +6617,36 @@ tytest_backlog_view_daemon_short_head(void)
return 0;
}
+/* Test: the focus of a terminal reaches its backlog view, and the views
+ * made later: by a clear of the scrollback, a change of its size, or once
+ * a pty that had none gets one. */
+int
+tytest_backlog_focus_kept(void)
+{
+ Termpty ty;
+
+ _ty_test_init(&ty, 80, 24);
+ termpty_backlog_size_set(&ty, 0);
+ assert(!ty.backlog_view);
+ termpty_backlog_focus_set(&ty, EINA_TRUE);
+
+ termpty_backlog_size_set(&ty, 2000);
+ assert(ty.backlog_view && ty.backlog_view->focused);
+ _ty_padded_feed(&ty, 1, 100, 0);
+ termpty_backlog_follow(&ty);
+ termpty_clear_backlog(&ty);
+ assert(ty.backlog_view && ty.backlog_view->focused);
+ termpty_backlog_size_set(&ty, 4000);
+ assert(ty.backlog_view && ty.backlog_view->focused);
+
+ termpty_backlog_focus_set(&ty, EINA_FALSE);
+ assert(!ty.backlog_view->focused);
+ termpty_clear_backlog(&ty);
+ assert(ty.backlog_view && !ty.backlog_view->focused);
+ _ty_test_shutdown(&ty);
+ return 0;
+}
+
/* Test: a window that reaches compressed pages has them rebuilt on a
* thread, rather than on the next read. */
int
diff --git a/src/bin/termpty.h b/src/bin/termpty.h
index bff0c468..d03515cf 100644
--- a/src/bin/termpty.h
+++ b/src/bin/termpty.h
@@ -344,6 +344,9 @@ struct tag_Termpty
/* Nothing renders the pty, as in tymuxd: its view keeps only the head
* mapped, with no window around a viewport. */
unsigned int backlog_head_only : 1;
+ /* the terminal has the focus: its backlog views are told, those made
+ * later included */
+ unsigned int backlog_focused : 1;
/* how far the scan of the incomplete sequence at the head of buf went */
unsigned int seq_scanned;
/* bumped on each palette rewrite (OSC 4); scopes the truecolour cache */
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index 93fedc5a..1d935282 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -50,6 +50,7 @@ static struct {
{ "backlog_view_busy_unread", tytest_backlog_view_busy_unread},
{ "backlog_view_focus_in_restores", tytest_backlog_view_focus_in_restores},
{ "backlog_view_daemon_short_head", tytest_backlog_view_daemon_short_head},
+ { "backlog_focus_kept", tytest_backlog_focus_kept},
{ "backlog_wide_entry_rows", tytest_backlog_wide_entry_rows},
{ "backlog_external", tytest_backlog_external},
{ "backlog_store_termpty", tytest_backlog_store_termpty},
@@ -322,6 +323,7 @@ static const struct {
{ "tymux_live_page_async", tytest_tymux_live_page_async},
{ "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},
#endif
{ NULL, NULL},
};
diff --git a/src/bin/tytest_tymux.c b/src/bin/tytest_tymux.c
index 563c472e..f0b27de3 100644
--- a/src/bin/tytest_tymux.c
+++ b/src/bin/tytest_tymux.c
@@ -223,9 +223,10 @@ _client_find(Termpty *ty)
return ty->write_hook.data;
}
-Eina_Bool
-tytest_tymux_start(const char *name, int cols, int rows,
- TermTymux **ts, Termpty **ty)
+/* A client of a terminal without the focus */
+static Eina_Bool
+_tymux_attach(const char *name, int cols, int rows,
+ TermTymux **ts, Termpty **ty)
{
if (!_config)
{
@@ -234,10 +235,17 @@ tytest_tymux_start(const char *name, int cols, int rows,
_config->scrollback = DAEMON_SCROLLBACK;
}
*ts = termtymux_new(name, cols, rows, _config, TSRV_ATTACH_HIJACK, ty);
- if (!*ts)
+ return *ts != NULL;
+}
+
+Eina_Bool
+tytest_tymux_start(const char *name, int cols, int rows,
+ TermTymux **ts, Termpty **ty)
+{
+ if (!_tymux_attach(name, cols, rows, ts, ty))
return EINA_FALSE;
/* the terminal the user works in, whose view holds the head */
- backlog_view_focus_set((*ts)->view, EINA_TRUE);
+ termpty_backlog_focus_set(*ty, EINA_TRUE);
return EINA_TRUE;
}
@@ -2266,3 +2274,109 @@ tytest_tymux_live_pages_read_only(void)
{
return tytest_tymux_live_run(_live_pages_read_only_body);
}
+
+/* Pages of the session hold 1024 entries: with these lines the head is
+ * about half full, so that what is printed once focused lands in it. */
+#define QUIET_LINES 2500
+#define QUIET_MARKER "quiet-done"
+#define FOCUS_MARKER "focus-done"
+/* how long the client's view waits for more output before it lets go of
+ * the head; the daemon's view and store still wait BACKLOG_QUIET_SECONDS */
+#define CLIENT_QUIET_SECONDS 0.5
+
+static Eina_Bool
+_quiet_marker_done(void *data)
+{
+ return _backlog_find(data, QUIET_MARKER) != 0;
+}
+
+/* The client maps no page, and the daemon compressed every page, the head
+ * included: only raw pages are in memfds. */
+static Eina_Bool
+_head_compressed_done(void *data)
+{
+ TermTymux *ts = data;
+
+ return !_client_pages_mapped(ts) &&
+ tytest_tymux_daemon_memfds(ts, "ty-backlog-") == 0;
+}
+
+/* An unfocused client of a session that printed QUIET_LINES lines, once
+ * the daemon compressed the head that nobody holds any more. */
+static void
+_quiet_session_start(TermTymux **ts, Termpty **ty)
+{
+ char cmd[64];
+
+ backlog_view_test_quiet_seconds_set(CLIENT_QUIET_SECONDS);
+ assert(_tymux_attach(SESSION, 80, 24, ts, ty));
+ termtymux_resize(*ts, 80, SCREEN_ROWS);
+ assert(tytest_tymux_wait(_screen_rows_done, *ty, 5.0));
+ assert(tytest_tymux_wait(_prompt_done, *ty, 5.0));
+ snprintf(cmd, sizeof(cmd), "seq 1 %d; echo %s; seq 1 30\n",
+ QUIET_LINES, QUIET_MARKER);
+ assert(tytest_tymux_type(*ts, *ty, cmd));
+ assert(tytest_tymux_wait(_quiet_marker_done, *ty, 30.0));
+ assert(!(*ts)->view->focused);
+ termpty_backlog_viewport_set((*ts)->shadow_pty, 0);
+ assert(tytest_tymux_wait(_head_compressed_done, *ts,
+ 3 * BACKLOG_QUIET_SECONDS));
+ assert(_client_page_mappings() == 0);
+ assert((*ts)->view->pages_count > 1);
+}
+
+static Eina_Bool
+_quiet_lines_done(void *data)
+{
+ return _backlog_run(data, QUIET_LINES) >= QUIET_LINES / 10;
+}
+
+static Eina_Bool
+_focus_marker_done(void *data)
+{
+ return _backlog_find(data, FOCUS_MARKER) != 0;
+}
+
+/* A session whose only client does not have the focus compresses its head
+ * once quiet. Focusing the client gets it the head back, restored
+ * in place by the daemon rather than exported: what the shell prints next
+ * is read through the client's mapping of it. */
+static int
+_focus_restores_body(void)
+{
+ TermTymux *ts;
+ Termpty *ty;
+ const BacklogViewPage *head;
+ const Termsave *save;
+ uint32_t head_id;
+ int y;
+
+ _quiet_session_start(&ts, &ty);
+ head_id = ts->view->pages[ts->view->pages_count - 1].id;
+
+ termpty_backlog_focus_set(ty, EINA_TRUE);
+ assert(tytest_tymux_wait(_head_mapped_done, ts, 10.0));
+ assert(tytest_tymux_daemon_memfds(ts, "ty-backlog-") == 1);
+ assert(tytest_tymux_daemon_memfds(ts, "ty-export-") == 0);
+ assert(tytest_tymux_wait(_quiet_lines_done, ty, 10.0));
+ termpty_backlog_viewport_set(ts->shadow_pty, 0);
+
+ assert(tytest_tymux_type(ts, ty, "echo " FOCUS_MARKER "; seq 1 30\n"));
+ assert(tytest_tymux_wait(_focus_marker_done, ty, 10.0));
+ head = &ts->view->pages[ts->view->pages_count - 1];
+ assert(head->id == head_id);
+ y = _backlog_find(ty, FOCUS_MARKER);
+ save = _backlog_row(ty, y);
+ assert((const char *)save->cells > (const char *)head->mapped);
+ assert((const char *)save->cells <
+ (const char *)head->mapped + head->mapped_size);
+
+ tytest_tymux_stop(ts);
+ return 0;
+}
+
+int
+tytest_tymux_live_focus_restores(void)
+{
+ return tytest_tymux_live_run(_focus_restores_body);
+}
diff --git a/src/bin/tytest_tymux.h b/src/bin/tytest_tymux.h
index 6dd6ddca..c897690b 100644
--- a/src/bin/tytest_tymux.h
+++ b/src/bin/tytest_tymux.h
@@ -58,5 +58,6 @@ int tytest_tymux_live_fd_starved(void);
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);
#endif
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index cb37b31c..face6b9e 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -20,6 +20,7 @@ int tytest_backlog_view_quiet_head_sealed(void);
int tytest_backlog_view_busy_unread(void);
int tytest_backlog_view_focus_in_restores(void);
int tytest_backlog_view_daemon_short_head(void);
+int tytest_backlog_focus_kept(void);
int tytest_backlog_wide_entry_rows(void);
int tytest_backlog_external(void);
int tytest_backlog_store_termpty(void);
diff --git a/src/bin/win.c b/src/bin/win.c
index e63be829..017f6a05 100644
--- a/src/bin/win.c
+++ b/src/bin/win.c
@@ -15,6 +15,7 @@
#include "media.h"
#include "termio.h"
#include "termptystatus.h"
+#include "backlog.h"
#include "theme.h"
#include "sel.h"
#include "controls.h"
@@ -830,6 +831,18 @@ _solo_unfocus(Term_Container *tc, Term_Container *relative)
}
}
+/* A solo taken out of its container, as for a drag, loses the focus without
+ * _solo_unfocus(): only its backlog is told, the program running in it is
+ * not, as a drag that is dropped or cancelled focuses it again. */
+static void
+_solo_detached_unfocus(Term_Container *tc)
+{
+ Solo *solo = (Solo*) tc;
+
+ tc->is_focused = EINA_FALSE;
+ termpty_backlog_focus_set(termio_pty_get(solo->term->termio), EINA_FALSE);
+}
+
/* Title shown in a tab or window for term: its own title, prefixed with
* "[session]" when its terminal is attached to a tymux session (see
* termio_tymux_title_get()). *allocated is set to the stringshare to
@@ -3234,7 +3247,7 @@ _split_detach(Term_Container *tc, Term_Container *solo_child)
assert (solo_child->type == TERM_CONTAINER_TYPE_SOLO);
_split_close(tc, solo_child);
- solo_child->is_focused = EINA_FALSE;
+ _solo_detached_unfocus(solo_child);
o = solo_child->get_evas_object(solo_child);
evas_object_hide(o);
@@ -5781,7 +5794,7 @@ _tabs_detach(Term_Container *tc, Term_Container *solo_child)
assert (solo_child->type == TERM_CONTAINER_TYPE_SOLO);
_tabs_close(tc, solo_child);
- solo_child->is_focused = EINA_FALSE;
+ _solo_detached_unfocus(solo_child);
o = solo_child->get_evas_object(solo_child);
evas_object_hide(o);
diff --git a/tests/meson.build b/tests/meson.build
index fb6b33b2..144246f0 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -110,6 +110,13 @@ if tests
'tymux_live_pages_read_only'],
depends: [tymuxd],
timeout: 120)
+ # Waits for the daemon to find its session quiet: apart, so that it
+ # runs alongside the other live tests.
+ test('tymux-live-quiet',
+ tytest,
+ args: ['tymux_live_focus_restores'],
+ depends: [tymuxd],
+ timeout: 120)
endif
endif
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.