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 9d8a7db614616892a272ec2b0c5805ba41687faa
Author: Cedric BAIL <[email protected]>
AuthorDate: Sat Nov 21 01:38:41 2026 -0600

    backlog_view: hold pages by focus and activity
    
    A view held its head page for as long as it lived, so the store never
    compressed the head of a terminal idling in the background, and with
    many terminals open those heads are the bulk of the scrollback memory.
    
    A view is now active while its terminal has the focus, or while output
    reached its backlog within BACKLOG_QUIET_SECONDS. The per-line path
    only sets a flag, which a timer armed when output makes the view active
    looks at, so the clock is never read per line. At the bottom, an active
    view holds the head, and the page before it while the head has fewer
    entries than the screen has rows; a quiet one holds nothing, and the
    store compresses the head once it is quiet too. tymuxd's own view
    follows the same rule without ever being focused, but holds only the
    head, as it renders no screen; a tymux client view takes new entries in
    its head, or a new head, as output. Without a
    protocol change, a client head that was let go of does not see its own
    growth until a new page appears or it is mapped again.
    
    A local view that lets go of its head points the newest entry at a
    copy of its cells: the resize path reads it to rejoin a wrapped line,
    and the store's copy only lives until the main loop runs again. Taking
    the newest entry back counts as activity, so that the ring follows the
    pop through the head mapped again. A head mapped while a thread
    restores it reads blank before backlog_store_page_ready_from() until
    the restore ends.
    
    Tests that relied on the head always being held now focus their view,
    as termio will for the terminal the user works in. Unit tests and
    tybench initialise ecore, as the view keeps a timer.
    
    tybench -t -i 10 -s 2000, best MB/s, median of interleaved runs against
    the previous commit: scroll 108.6 -> 107.9 (5 runs) and 108.2 -> 108.1
    (6 more), plain-ascii 323.8 -> 324.8: within the noise.
---
 src/bin/backlog.c      |   1 +
 src/bin/backlog_view.c | 388 ++++++++++++++++++++++++++++++++++++++++++++--
 src/bin/backlog_view.h |  53 +++++--
 src/bin/termpty.c      | 407 ++++++++++++++++++++++++++++++++++++++++++++++++-
 src/bin/tybench.c      |   3 +
 src/bin/tytest.c       |   9 ++
 src/bin/tytest_tymux.c |   6 +-
 src/bin/unit_tests.h   |   9 ++
 8 files changed, 847 insertions(+), 29 deletions(-)

diff --git a/src/bin/backlog.c b/src/bin/backlog.c
index 277696dd..767559f2 100644
--- a/src/bin/backlog.c
+++ b/src/bin/backlog.c
@@ -209,6 +209,7 @@ termpty_backlog_pop(Termpty *ty)
    backlog_view_local_follow(ty->backlog_view);
    if (!backlog_store_pop(ty->backlog_store))
      return EINA_FALSE;
+   backlog_view_local_saved(ty->backlog_view);
    backlog_view_local_sync(ty->backlog_view);
    return EINA_TRUE;
 }
diff --git a/src/bin/backlog_view.c b/src/bin/backlog_view.c
index 74d3a594..11af7cf0 100644
--- a/src/bin/backlog_view.c
+++ b/src/bin/backlog_view.c
@@ -20,6 +20,13 @@
 
 static Termcell *_blank_cells = NULL;
 
+#if defined(BINARY_TYTEST)
+static double _test_quiet_seconds = BACKLOG_QUIET_SECONDS;
+# define VIEW_QUIET_SECONDS _test_quiet_seconds
+#else
+# define VIEW_QUIET_SECONDS BACKLOG_QUIET_SECONDS
+#endif
+
 /* What the entries of the pages that are not mapped point at: one
  * read-only anonymous mapping, which takes no memory however wide the
  * entries, shared by every view of the process. It is never unmapped:
@@ -112,6 +119,9 @@ _page_entry_get(const BacklogViewPage *page, uint32_t k, uint32_t *w)
         off = 0;
         *w = 0;
      }
+   /* a thread is still writing those cells */
+   if (k < page->ready_from)
+     return _blank_cells_get();
    return (Termcell *)((char *)mapped + page->header_size) + off;
 }
 
@@ -157,9 +167,22 @@ _page_entries_repoint(BacklogView *view, BacklogViewPage *page)
      }
 }
 
+/* Frees the copy of the newest entry of page, once no entry points at it
+ * any more. */
+static void
+_tail_drop(BacklogView *view, const BacklogViewPage *page)
+{
+   if (view->tail && (view->tail_page_id == page->id))
+     {
+        free(view->tail);
+        view->tail = NULL;
+     }
+}
+
 static void
 _page_unmap(BacklogView *view, BacklogViewPage *page)
 {
+   _tail_drop(view, page);
    view->pushed_total -= page->pushed;
    if (page->mapped)
      {
@@ -511,14 +534,34 @@ _sync(BacklogView *view)
    return changed;
 }
 
+static void _output_record(BacklogView *view);
+static void _bottom_follow(BacklogView *view);
+
 Eina_Bool
 backlog_view_sync(BacklogView *view)
 {
+   const BacklogViewPage *head;
+   uint32_t head_id = 0, head_entries = 0;
    Eina_Bool changed;
 
    EINA_SAFETY_ON_NULL_RETURN_VAL(view, EINA_FALSE);
+   if (view->pages_count)
+     {
+        head = &view->pages[view->pages_count - 1];
+        head_id = head->id;
+        head_entries = head->dropped + head->pushed;
+     }
    changed = _sync(view) || view->changed;
    view->changed = EINA_FALSE;
+   /* a local view hears of output from backlog_view_local_saved() */
+   if (!view->store && view->pages_count)
+     {
+        head = &view->pages[view->pages_count - 1];
+        if ((head->id == head_id) &&
+            (head->dropped + head->pushed > head_entries))
+          _output_record(view);
+     }
+   _bottom_follow(view);
    return changed;
 }
 
@@ -545,31 +588,106 @@ _window_head_only(const BacklogView *view)
    return view->ty->backlog_head_only || !view->viewport_scrolled;
 }
 
+static Eina_Bool
+_view_active(const BacklogView *view)
+{
+   return view->focused || view->quiet_timer;
+}
+
+/* At the bottom, an active view keeps the head, and the page before it
+ * while the head holds fewer entries than the screen has rows: an entry
+ * covers a row at least, so a screen of rows above the bottom is in those
+ * two pages. tymuxd's own view renders no screen, so it keeps only the
+ * head. A quiet view keeps nothing, for the store to compress the head. */
+static Eina_Bool
+_bottom_keeps(const BacklogView *view, const BacklogViewPage *page)
+{
+   const BacklogViewPage *head = &view->pages[view->pages_count - 1];
+   Eina_Bool known;
+
+   if (!_view_active(view))
+     return EINA_FALSE;
+   if (page == head)
+     return EINA_TRUE;
+   return !view->ty->backlog_head_only && (page + 1 == head) &&
+      (_page_entries_get(head, &known) < (uint32_t)MAX(view->ty->h, 0));
+}
+
 static Eina_Bool
 _page_kept(const BacklogView *view, const BacklogViewPage *page)
 {
+   if (_window_head_only(view))
+     return _bottom_keeps(view, page);
    if (_page_is_head(view, page))
      return EINA_TRUE;
-   if (_window_head_only(view))
-     return EINA_FALSE;
    return backlog_window_keeps((int)(page - view->pages), _anchor_index(view));
 }
 
+/* Lets go of the head of a local view, its newest entry pointing at a copy
+ * of its cells rather than at the blank: the resize that wraps it again
+ * reads it, and what the store gives for it lives only until the store
+ * runs again. */
+static void
+_local_head_release(BacklogView *view, BacklogViewPage *head)
+{
+   const Termcell *cells;
+   Termcell *tail = NULL;
+   uint32_t w = 0;
+   Eina_Bool known;
+
+   if (head->pushed)
+     {
+        /* the newest entry of the ring must be the newest of the head */
+        if (head->dropped + head->pushed != _page_entries_get(head, &known))
+          return;
+        cells = backlog_store_head_tail_get(view->store, &w);
+        if (!cells)
+          return;
+        tail = malloc(MAX(w, 1) * sizeof(Termcell));
+        if (!tail)
+          return;
+        memcpy(tail, cells, w * sizeof(Termcell));
+     }
+   _page_release(view, head);
+   if (head->mapped)
+     {
+        free(tail);
+        return;
+     }
+   _tail_drop(view, head);
+   if (!tail)
+     return;
+   view->tail = tail;
+   view->tail_page_id = head->id;
+   termpty_backlog_external_set(view->ty, 1, tail, w);
+}
+
+static void
+_page_let_go(BacklogView *view, BacklogViewPage *page)
+{
+   if (view->store && _page_is_head(view, page))
+     _local_head_release(view, page);
+   else
+     _page_release(view, page);
+}
+
 static Eina_Bool
 _release_idler_cb(void *data)
 {
    BacklogView *view = data;
    unsigned int i;
 
+   /* the sync of a stale view would schedule this pass again */
+   backlog_view_local_follow(view);
    view->release_idler = NULL;
    if (!view->pages_count)
      return ECORE_CALLBACK_CANCEL;
-   for (i = 0; i + 1 < view->pages_count; i++)
+   for (i = 0; i < view->pages_count; i++)
      {
         BacklogViewPage *page = &view->pages[i];
 
         if (page->mapped && !_page_kept(view, page))
-          _page_release(view, page);
+          _page_let_go(view, page);
      }
    view->released = EINA_TRUE;
    view->release_anchor_id = view->pages[_anchor_index(view)].id;
@@ -594,15 +712,19 @@ _page_wanted(const BacklogViewPage *page)
 static void
 _pages_request_next(BacklogView *view)
 {
-   BacklogViewPage *page = NULL;
+   BacklogViewPage *page = NULL, *head;
    int anchor, i, d;
    uint32_t id;
 
    if (view->page_pending || view->source_lost || !view->pages_count)
      return;
    anchor = _anchor_index(view);
-   if (_page_wanted(&view->pages[view->pages_count - 1]))
-     page = &view->pages[view->pages_count - 1];
+   head = &view->pages[view->pages_count - 1];
+   if (_page_wanted(head) && _page_kept(view, head))
+     page = head;
+   else if (_window_head_only(view) && (head > view->pages) &&
+            _page_wanted(head - 1) && _page_kept(view, head - 1))
+     page = head - 1;
    for (d = 0; d <= BACKLOG_KEEP_BEHIND && !page &&
         !_window_head_only(view); d++)
      {
@@ -642,6 +764,81 @@ _window_update(BacklogView *view)
    _pages_request_next(view);
 }
 
+/* Output keeps the view active until a whole period of the timer saw
+ * none. */
+static Eina_Bool
+_quiet_timer_cb(void *data)
+{
+   BacklogView *view = data;
+
+   if (view->output_seen)
+     {
+        view->output_seen = EINA_FALSE;
+        return ECORE_CALLBACK_RENEW;
+     }
+   view->quiet_timer = NULL;
+   _window_update(view);
+   return ECORE_CALLBACK_CANCEL;
+}
+
+static void
+_quiet_timer_start(BacklogView *view)
+{
+   view->output_seen = EINA_FALSE;
+   view->quiet_timer = ecore_timer_add(VIEW_QUIET_SECONDS, _quiet_timer_cb,
+                                       view);
+}
+
+static void
+_output_record(BacklogView *view)
+{
+   view->output_seen = EINA_TRUE;
+   if (!view->quiet_timer)
+     _quiet_timer_start(view);
+}
+
+/* At the bottom, what an active view keeps changes as the head fills up,
+ * and when the view becomes active. */
+static void
+_bottom_follow(BacklogView *view)
+{
+   unsigned int i;
+
+   if (!view->pages_count || !_window_head_only(view))
+     return;
+   for (i = (view->pages_count > 1) ? view->pages_count - 2 : 0;
+        i < view->pages_count; i++)
+     {
+        if (view->pages[i].mapped && !_page_kept(view, &view->pages[i]))
+          {
+             _release_pass_schedule(view);
+             break;
+          }
+     }
+   _pages_request_next(view);
+}
+
+/* A head that was let go of kept the widths it had then: it may have taken
+ * more entries before it was sealed, which are asked for again. Its newest
+ * entry no longer has to be read right. */
+static void
+_head_sealed(BacklogView *view, BacklogViewPage *page)
+{
+   if (page->mapped || !page->widths)
+     return;
+   if (page->pushed && view->tail && (view->tail_page_id == page->id))
+     {
+        int y = _pages_pushed_after(view, page) + 1;
+
+        termpty_backlog_external_set(view->ty, y, _blank_cells,
+                                     BACKLOG_ROW_GET(view->ty, y)->w);
+     }
+   _tail_drop(view, page);
+   free(page->widths);
+   page->widths = NULL;
+   page->num_widths = 0;
+}
+
 /* Lets the pages whose widths did not come be asked for again, and the
  * pages that could not be mapped too if failed_too */
 static void
@@ -744,6 +941,7 @@ _pages_range_set(BacklogView *view, uint32_t first_id, uint32_t count)
    Eina_Bool changed = EINA_FALSE;
    uint32_t old_first = view->pages_count ? view->pages[0].id : 0;
    uint32_t old_count = view->pages_count;
+   uint32_t old_next_id = view->pages_next_id;
 
    if (count > pages_max)
      {
@@ -762,6 +960,8 @@ _pages_range_set(BacklogView *view, uint32_t first_id, uint32_t count)
      view->page_pending = EINA_FALSE;
    if (view->pages_next_id < first_id)
      view->pages_next_id = first_id;
+   if (view->pages_count && (view->pages_next_id - first_id < count))
+     _head_sealed(view, &view->pages[view->pages_count - 1]);
    while (view->pages_next_id - first_id < count)
      {
         BacklogViewPage *page;
@@ -784,6 +984,9 @@ _pages_range_set(BacklogView *view, uint32_t first_id, uint32_t count)
    /* a page that could not be mapped is not asked for at every range */
    _pages_retry_allow(view, (old_count != view->pages_count) ||
                       (view->pages_count && old_first != view->pages[0].id));
+   /* a new head: there was output */
+   if (old_count && (view->pages_next_id > old_next_id))
+     _output_record(view);
    _pages_map_request(view);
    _window_update(view);
    return changed;
@@ -865,11 +1068,14 @@ backlog_view_page_set(BacklogView *view, uint32_t page_id,
    page->entries_per_page = entries_per_page;
    page->generation = atomic_load_explicit(&mapped->generation,
                                            memory_order_acquire);
+   page->ready_from = view->store ?
+      backlog_store_page_ready_from(view->store, page_id) : 0;
    free(page->widths);
    page->widths = NULL;
    page->num_widths = 0;
    view->settled = MIN(view->settled, (unsigned int)(page - view->pages));
    _page_entries_repoint(view, page);
+   _tail_drop(view, page);
    view->changed = EINA_TRUE;
    /* A local view syncs where its pty reads the ring, which may be the one
     * mapping the page, in the middle of a walk over the ring. */
@@ -1028,14 +1234,29 @@ _local_page_request(void *data, uint32_t page_id)
    return EINA_TRUE;
 }
 
-/* A page that was read meanwhile is not waited for any more */
+/* A page that was read meanwhile is not waited for any more. The entries
+ * of a head mapped while it was restored can now point at their cells. */
 static void
 _local_page_prefetched(void *data, uint32_t page_id)
 {
    BacklogView *view = data;
+   BacklogViewPage *page = backlog_view_page_find(view, page_id);
 
    termpty_backlog_maintain_wake();
-   if (view->page_pending && (view->page_pending_id == page_id))
+   if (page && page->mapped && page->ready_from)
+     {
+        page->ready_from = 0;
+        _page_entries_repoint(view, page);
+        view->changed = EINA_TRUE;
+     }
+   if (!view->page_pending || (view->page_pending_id != page_id))
+     return;
+   if (page && page->mapped)
+     {
+        view->page_pending = EINA_FALSE;
+        _pages_request_next(view);
+     }
+   else
      _local_page_map(view, page_id);
 }
 
@@ -1133,13 +1354,14 @@ backlog_view_local_sync(BacklogView *view)
         /* a page sealed, or one went */
         termpty_backlog_maintain_wake();
      }
-   /* The head's entries go in with their cells, even while a rebuild
-    * keeps the view waiting: the newest row must be read right, to wrap it
-    * again on a resize. A head is never compressed. */
+   /* The head's entries go in with their cells while the view keeps it,
+    * even while a rebuild keeps the view waiting or a thread restores it:
+    * the newest row must be read right, to wrap it again on a resize. A
+    * head let go of keeps its widths, and its newest entry a copy. */
    if (view->pages_count)
      {
         head = &view->pages[view->pages_count - 1];
-        if (!head->mapped)
+        if (!head->mapped && (!head->widths || _page_kept(view, head)))
           _local_page_map(view, head->id);
      }
    return backlog_view_sync(view);
@@ -1150,6 +1372,10 @@ backlog_view_local_saved(BacklogView *view)
 {
    EINA_SAFETY_ON_NULL_RETURN(view);
    view->stale = EINA_TRUE;
+   /* called for every line: the clock is only read by the timer */
+   view->output_seen = EINA_TRUE;
+   if (EINA_UNLIKELY(!view->quiet_timer))
+     _quiet_timer_start(view);
 }
 
 Eina_Bool
@@ -1175,7 +1401,7 @@ backlog_view_entry_map(BacklogView *view, const Termsave *ts)
 
         view->read_page = EINA_FALSE;
         if (read && read->mapped && !_page_kept(view, read))
-          _page_release(view, read);
+          _page_let_go(view, read);
      }
    if (!page->mapped)
      _local_page_map(view, page_id);
@@ -1186,10 +1412,37 @@ backlog_view_entry_map(BacklogView *view, const Termsave *ts)
      {
         view->read_page = EINA_TRUE;
         view->read_page_id = page_id;
+        _release_pass_schedule(view);
      }
    return EINA_TRUE;
 }
 
+void
+backlog_view_focus_set(BacklogView *view, Eina_Bool focus)
+{
+   EINA_SAFETY_ON_NULL_RETURN(view);
+   if (view->focused == !!focus)
+     return;
+   view->focused = !!focus;
+   backlog_view_local_follow(view);
+   _window_update(view);
+}
+
+Eina_Bool
+backlog_view_active_get(const BacklogView *view)
+{
+   EINA_SAFETY_ON_NULL_RETURN_VAL(view, EINA_FALSE);
+   return _view_active(view);
+}
+
+#if defined(BINARY_TYTEST)
+void
+backlog_view_test_quiet_seconds_set(double seconds)
+{
+   _test_quiet_seconds = seconds;
+}
+#endif
+
 BacklogView *
 backlog_view_new(Termpty *ty, const BacklogViewSource *src, void *data)
 {
@@ -1213,6 +1466,8 @@ backlog_view_free(BacklogView *view)
      return;
    if (view->release_idler)
      ecore_idler_del(view->release_idler);
+   if (view->quiet_timer)
+     ecore_timer_del(view->quiet_timer);
    if (view->store)
      {
         backlog_store_prefetch_cb_set(view->store, NULL, NULL);
@@ -1222,6 +1477,7 @@ backlog_view_free(BacklogView *view)
      _page_forget_oldest(view);
    if (view->ty->backlog_view == view)
      view->ty->backlog_view = NULL;
+   free(view->tail);
    free(view->pages);
    free(view);
 }
@@ -1308,6 +1564,8 @@ _test_pty_new(int w, int h, size_t backsize)
    Termpty *ty = calloc(1, sizeof(Termpty));
 
    assert(ty);
+   /* the view keeps its activity on a timer */
+   ecore_init();
    ty->w = w;
    ty->h = h;
    ty->fd = -1;
@@ -1399,6 +1657,7 @@ _test_view_free(BacklogView *view, Termpty *ty)
 {
    backlog_view_free(view);
    termpty_free(ty);
+   ecore_shutdown();
 }
 
 /* Test: backlog_view_sync() pushes the entries of the pages whose widths
@@ -1518,6 +1777,8 @@ tytest_backlog_view_map_again(void)
    Test_Source src;
    BacklogView *view = _test_view_new(ty, &src);
 
+   /* an active view, for the head to be asked for */
+   backlog_view_focus_set(view, EINA_TRUE);
    src.connected = EINA_TRUE;
    /* page 0 is the head, asked for */
    _pages_range_set(view, 0, 1);
@@ -1636,8 +1897,9 @@ tytest_backlog_view_local_grow(void)
                                NULL));
    view = backlog_view_local_new(ty, bs);
    assert(view);
+   /* an active view, that maps the head it is told of */
+   backlog_view_focus_set(view, EINA_TRUE);
    _pages_range_set(view, 0, 1);
-   _local_page_map(view, 0);
    page = &view->pages[0];
    assert(page->mapped);
    old_size = backlog_store_page_map_size(bs, 0);
@@ -1755,6 +2017,8 @@ tytest_backlog_view_pending_evicted(void)
    Test_Source src;
    BacklogView *view = _test_view_new(ty, &src);
 
+   /* an active view, for the head to be asked for */
+   backlog_view_focus_set(view, EINA_TRUE);
    src.connected = EINA_TRUE;
    _pages_range_set(view, 5, 1);
    assert(_test_sent(&src.page_requests) == 1);
@@ -2048,4 +2312,98 @@ tytest_backlog_view_retract_short(void)
    return 0;
 }
 
+static Eina_Bool
+_test_loop_quit_cb(void *data EINA_UNUSED)
+{
+   ecore_main_loop_quit();
+   return ECORE_CALLBACK_CANCEL;
+}
+
+/* Runs the main loop, idlers and timers included, for a while */
+static void
+_test_loop_run(double seconds)
+{
+   ecore_timer_add(seconds, _test_loop_quit_cb, NULL);
+   ecore_main_loop_begin();
+}
+
+static void
+_test_page_give(BacklogView *view, TermSrvBacklogPage *page)
+{
+   backlog_view_page_set(view, page->page_id, page,
+                         termsrv_backlog_page_size(page->header_size));
+}
+
+/* Test: at the bottom, an active view of a remote source asks for the page
+ * before the head while the head does not fill the screen, and lets go of
+ * it once it does; quiet, it lets go of the head too. A new head makes it
+ * active: the new head is asked for, then the page before it. */
+int
+tytest_backlog_view_remote_short_head(void)
+{
+   const uint32_t sealed_w[] = { 3, 3 }, head_w[] = { 2, 2, 2, 2 };
+   TermSrvBacklogPage *head;
+   Termpty *ty = _test_pty_new(10, 4, 32);
+   Test_Source src;
+   BacklogView *view = _test_view_new(ty, &src);
+   uint32_t k;
+   int i;
+
+   backlog_view_test_quiet_seconds_set(0.05);
+   src.connected = EINA_TRUE;
+   backlog_view_focus_set(view, EINA_TRUE);
+   _pages_range_set(view, 0, 2);
+   assert(_test_sent(&src.page_requests) == 1);
+   assert(src.page_request_id == 1);
+   head = _test_page_new(1, 1, head_w, 'w');
+   _test_page_give(view, head);
+   assert(_test_sent(&src.page_requests) == 1);
+   assert(src.page_request_id == 0);
+   _test_page_give(view, _test_page_new(0, 2, sealed_w, 'a'));
+   backlog_view_sync(view);
+   assert(termpty_backlog_length(ty) == 2 + 1);
+
+   /* the head fills the 4 rows of the screen */
+   for (k = 1; k < 4; k++)
+     {
+        termsrv_backlog_entry_off(head)[k] = 2 * k;
+        atomic_store(&termsrv_backlog_entry_w(head,
+                                              _TEST_ENTRIES_PER_PAGE)[k], 2);
+     }
+   atomic_store(&head->num_entries, 4);
+   assert(backlog_view_sync(view));
+   _test_sent(&src.releases);
+   _test_loop_run(0.01);
+   assert(!view->pages[0].mapped && view->pages[1].mapped);
+   assert(_test_sent(&src.releases) == 1);
+   assert(src.release_id == 0);
+
+   backlog_view_focus_set(view, EINA_FALSE);
+   for (i = 0; (i < 1000) && backlog_view_active_get(view); i++)
+     _test_loop_run(0.01);
+   _test_loop_run(0.01);
+   assert(!view->pages[1].mapped);
+   assert(_test_sent(&src.releases) == 1);
+   assert(src.release_id == 1);
+   assert(BACKLOG_ROW_GET(ty, 1)->cells == _blank_cells);
+   assert(BACKLOG_ROW_GET(ty, 1)->w == 2);
+
+   _pages_range_set(view, 0, 3);
+   assert(backlog_view_active_get(view));
+   assert(_test_sent(&src.page_requests) == 1);
+   assert(src.page_request_id == 2);
+   _test_page_give(view, _test_page_new(2, 1, head_w, 'z'));
+   assert(_test_sent(&src.page_requests) == 1);
+   assert(src.page_request_id == 1);
+   _test_page_give(view, _test_page_new(1, 4, head_w, 'w'));
+   backlog_view_sync(view);
+   assert(termpty_backlog_length(ty) == 2 + 4 + 1);
+   assert(BACKLOG_ROW_GET(ty, 1)->cells[0].codepoint == 'z');
+   assert(BACKLOG_ROW_GET(ty, 2)->cells[0].codepoint == 'w' + 3);
+
+   _test_view_free(view, ty);
+   backlog_view_test_quiet_seconds_set(BACKLOG_QUIET_SECONDS);
+   return 0;
+}
+
 #endif /* BINARY_TYTEST */
diff --git a/src/bin/backlog_view.h b/src/bin/backlog_view.h
index 69fa1747..1ca5e8d0 100644
--- a/src/bin/backlog_view.h
+++ b/src/bin/backlog_view.h
@@ -4,8 +4,9 @@
 /* The entries of a Termpty's backlog, over the pages of a backlog store
  * (see TermSrvBacklogPage in termsrv.h) that a source hands out: each entry
  * points into the mapping of its page, or into a shared read-only blank
- * while the page is not mapped. Only the pages around the viewport, and the
- * head, are kept mapped. Include termpty.h and termsrv.h first. */
+ * while the page is not mapped. Only the pages around the viewport are kept
+ * mapped, and at the bottom those that backlog_view_focus_set() tells.
+ * Include termpty.h and termsrv.h first. */
 
 typedef struct tag_BacklogView BacklogView;
 
@@ -43,6 +44,9 @@ typedef struct
    uint32_t                  last_w;     /* width the last of them was given */
    uint32_t                  generation; /* of the mapping, when they were
                                           * pointed at its cells */
+   uint32_t                  ready_from; /* the entries before point at the
+                                          * blank while a thread restores
+                                          * their cells */
    Eina_Bool                 failed;     /* could not be mapped, not asked
                                           * again before the range of pages
                                           * changes or the viewport moves */
@@ -85,6 +89,15 @@ struct tag_BacklogView
    Eina_Bool               released;      /* a release pass ran */
    uint32_t                release_anchor_id; /* anchor_id of the last pass */
    Ecore_Idler            *release_idler;
+   Eina_Bool               focused;
+   /* output reached the backlog since quiet_timer last looked */
+   Eina_Bool               output_seen;
+   /* armed while output keeps the view active */
+   Ecore_Timer            *quiet_timer;
+   /* a copy of the newest entry, that a local view points it at while it
+    * does not hold the head, tail_page_id */
+   Termcell               *tail;
+   uint32_t                tail_page_id;
 };
 
 /* A view filling the backlog of ty, which has no store of its own, from the
@@ -104,7 +117,8 @@ BacklogView *backlog_view_local_new(Termpty *ty, struct tag_BacklogStore *bs);
 Eina_Bool backlog_view_local_sync(BacklogView *view);
 
 /* A row was saved into the store, or the newest entry taken back: the
- * ring follows at the next backlog_view_local_follow(). */
+ * ring follows at the next backlog_view_local_follow(), and the view is
+ * active for a while. */
 void backlog_view_local_saved(BacklogView *view);
 
 /* Bring the ring of a view made by backlog_view_local_new() up to date,
@@ -118,15 +132,34 @@ backlog_view_local_follow(BacklogView *view)
 
 /* Make sure that the entry ts of the pty of a view made by
  * backlog_view_local_new() points at its cells rather than at the blank,
- * mapping its page if it is not, rebuilt if it was compressed. This only
- * points entries at cells: it does not sync, so it may be called in the
- * middle of a walk over the ring. Of the pages it maps beyond the window,
- * only the last one stays held; a walk over the whole scrollback thus
- * rebuilds every compressed page in turn, and the store keeps each rebuilt
- * copy for 60 s once let go of. Returns EINA_FALSE if the page could not be
- * mapped. */
+ * mapping its page if it is not, rebuilt if it was compressed. A compressed
+ * head is mapped at once while a thread restores it: its entries before
+ * backlog_store_page_ready_from() keep reading blank until the restore
+ * ends. This only points entries at cells: it does not sync, so it may be
+ * called in the middle of a walk over the ring. Of the pages it maps beyond
+ * what the view keeps, only the last one stays held, until the main loop
+ * runs again; a walk over the whole scrollback thus rebuilds every
+ * compressed page in turn, and the store keeps each rebuilt copy for 60 s
+ * once let go of. Returns EINA_FALSE if the page could not be mapped. */
 Eina_Bool backlog_view_entry_map(BacklogView *view, const Termsave *ts);
 
+/* Whether the terminal of the view has the focus. A view is active while
+ * focused, or after output reached its backlog: it goes quiet between
+ * BACKLOG_QUIET_SECONDS and twice that after the last output, as the timer
+ * that watches for output only looks once a period. At the bottom, an
+ * active view holds the head, and the page before it while the head has
+ * fewer entries than the screen has rows, but for tymuxd's own view, which
+ * renders nothing; a quiet one holds no page, so that the store may
+ * compress the head. Focusing a view asks for those pages at once. */
+void backlog_view_focus_set(BacklogView *view, Eina_Bool focus);
+Eina_Bool backlog_view_active_get(const BacklogView *view);
+
+#if defined(BINARY_TYTEST)
+/* Views go quiet after seconds without output, rather than after
+ * BACKLOG_QUIET_SECONDS. */
+void backlog_view_test_quiet_seconds_set(double seconds);
+#endif
+
 /* Lets go of every page and drops the entries of ty that point at them. */
 void backlog_view_free(BacklogView *view);
 
diff --git a/src/bin/termpty.c b/src/bin/termpty.c
index 339a435d..d48962fc 100644
--- a/src/bin/termpty.c
+++ b/src/bin/termpty.c
@@ -1315,7 +1315,8 @@ termpty_cellrow_get(Termpty *ty, int y_requested, ssize_t *wret)
 }
 
 /* Write accessor: always returns the live (mutable) row, or NULL for a
- * backlog row of a pty without a store, whose cells termpty does not own.
+ * backlog row of a pty without a store, whose cells termpty does not own,
+ * or for the newest entry while the view does not hold its page.
  * A backlog row is in a page of the store, which is told of the write.
  * Snapshot was taken eagerly at BSU, so no per-write COW is needed here. */
 Termcell *
@@ -1326,7 +1327,9 @@ termpty_cellrow_get_writeable(Termpty *ty, int y_requested, ssize_t *wret)
 
    if (!ts)
      return cells;
-   if (!ty->backlog_store || !backlog_view_entry_map(ty->backlog_view, ts))
+   /* a copy of the newest entry: what is written there would be lost */
+   if (!ty->backlog_store || !backlog_view_entry_map(ty->backlog_view, ts) ||
+       (ts->cells == ty->backlog_view->tail))
      return NULL;
    backlog_store_page_dirty(ty->backlog_store, ts->page_id);
    return cells;
@@ -5946,6 +5949,8 @@ tytest_backlog_view_local_grow_moved(void)
         termpty_backlog_size_set(&ty, 0);
         termpty_backlog_store_backing_set(&ty, backing);
         termpty_backlog_size_set(&ty, 2000);
+        /* the view holds the head however long the test takes */
+        backlog_view_focus_set(ty.backlog_view, EINA_TRUE);
         geo = backlog_store_geometry(ty.backlog_store);
         _ty_padded_feed(&ty, 1, 50 + 23, 0);
         head = backlog_store_first_id(ty.backlog_store) +
@@ -5976,6 +5981,7 @@ tytest_backlog_view_local_grow_moved(void)
         termpty_backlog_store_backing_set(&ty, backing);
         /* 64 entries a page, 5 pages */
         termpty_backlog_size_set(&ty, 300);
+        backlog_view_focus_set(ty.backlog_view, EINA_TRUE);
         geo = backlog_store_geometry(ty.backlog_store);
         _ty_padded_feed(&ty, 1, 4 * 64 + 1 + 23, 0);
         prev = backlog_store_first_id(ty.backlog_store) + 3;
@@ -6144,6 +6150,8 @@ tytest_backlog_view_head_only(void)
         _ty_padded_feed(&ty, 1000 + i * 128, 1000 + i * 128 + 127, 0);
         termpty_backlog_follow(&ty);
         _ty_loop_run(0.01);
+        /* never focused, it holds the head while output flows */
+        assert(backlog_view_active_get(ty.backlog_view));
         assert(_ty_view_mapped_count(&ty) == 1);
         assert(ty.backlog_view->pages[ty.backlog_view->pages_count - 1]
                .mapped);
@@ -6185,10 +6193,13 @@ tytest_backlog_view_bottom_head_only(void)
    _ty_test_init(&ty, 80, 24);
    termpty_backlog_size_set(&ty, 0);
    termpty_backlog_size_set(&ty, 2000);
+   view = ty.backlog_view;
+   /* the terminal the user works in holds its head however long the test
+    * takes */
+   backlog_view_focus_set(view, EINA_TRUE);
    _ty_padded_feed(&ty, 1, 128 * 6, 0);
    termpty_backlog_follow(&ty);
    _ty_loop_run(0.01);
-   view = ty.backlog_view;
    assert(view->pages_count > 3);
    /* at the bottom, only the head */
    assert(_ty_view_mapped_count(&ty) == 1);
@@ -6216,6 +6227,396 @@ tytest_backlog_view_bottom_head_only(void)
    return 0;
 }
 
+/* Runs the main loop until the view of ty went quiet, then lets its
+ * release pass run. */
+static void
+_ty_view_quiet_wait(Termpty *ty)
+{
+   int i;
+
+   for (i = 0; (i < 1000) && backlog_view_active_get(ty->backlog_view); i++)
+     _ty_loop_run(0.01);
+   assert(!backlog_view_active_get(ty->backlog_view));
+   _ty_loop_run(0.01);
+}
+
+static uint32_t
+_ty_store_head_id(Termpty *ty)
+{
+   return backlog_store_first_id(ty->backlog_store) +
+      backlog_store_count(ty->backlog_store) - 1;
+}
+
+/* Lets maintain see the last appends, then runs it as if nothing had been
+ * appended for an hour, until it has nothing left to do: a head that
+ * nobody holds is then compressed. */
+static void
+_ty_head_compress(Termpty *ty)
+{
+   double now = ecore_time_get();
+   int i;
+
+   backlog_store_maintain(ty->backlog_store, now);
+   for (i = 0; i < 1000; i++)
+     {
+        if (!backlog_store_maintain(ty->backlog_store, now + 3600.0))
+          break;
+        _ty_loop_run(0.01);
+     }
+   assert(!backlog_store_page_ready(ty->backlog_store,
+                                    _ty_store_head_id(ty)));
+}
+
+/* Test: at the bottom, an active view keeps the page before the head while
+ * the head holds fewer entries than the screen has rows, then only the
+ * head. */
+int
+tytest_backlog_view_active_short_head(void)
+{
+   BacklogView *view;
+   Termpty ty;
+
+   _ty_test_init(&ty, 80, 24);
+   termpty_backlog_size_set(&ty, 0);
+   /* 128 entries a page */
+   termpty_backlog_size_set(&ty, 2000);
+   view = ty.backlog_view;
+   backlog_view_focus_set(view, EINA_TRUE);
+   _ty_padded_feed(&ty, 1, 128 + 5 + 23, 0);
+   termpty_backlog_follow(&ty);
+   _ty_loop_run(0.01);
+   assert(view->pages_count == 2);
+   assert(view->pages[0].mapped && view->pages[1].mapped);
+
+   _ty_padded_feed(&ty, 1000, 1000 + 23, 0);
+   termpty_backlog_follow(&ty);
+   _ty_loop_run(0.01);
+   assert(view->pages_count == 2);
+   assert(!view->pages[0].mapped && view->pages[1].mapped);
+   _ty_backlog_rows_check(&ty);
+   _ty_test_shutdown(&ty);
+   return 0;
+}
+
+/* Test: a view without the focus and without output for a while lets go
+ * of the head too, so that the store compresses it; its newest entry still
+ * reads, without the head being asked for again. */
+int
+tytest_backlog_view_quiet_releases(void)
+{
+   Termpty ty;
+   size_t memory;
+   ssize_t w = 0;
+   uint32_t head;
+   int i;
+
+   backlog_view_test_quiet_seconds_set(0.05);
+   _ty_test_init(&ty, 80, 24);
+   termpty_backlog_size_set(&ty, 0);
+   termpty_backlog_size_set(&ty, 2000);
+   _ty_padded_feed(&ty, 1, 100 + 23, 0);
+   termpty_backlog_follow(&ty);
+   assert(backlog_view_active_get(ty.backlog_view));
+   assert(_ty_view_mapped_count(&ty) == 1);
+   memory = backlog_store_memory_get(ty.backlog_store);
+
+   _ty_view_quiet_wait(&ty);
+   assert(_ty_view_mapped_count(&ty) == 0);
+   assert(_ty_backlog_number(&ty, 1) == 100);
+   _ty_head_compress(&ty);
+   assert(backlog_store_memory_get(ty.backlog_store) < memory);
+   assert(_ty_backlog_number(&ty, 1) == 100);
+   assert(_ty_view_mapped_count(&ty) == 0);
+   assert(!termpty_cellrow_get_writeable(&ty, -1, &w));
+
+   /* a read of an older row maps the head, which is let go of again */
+   head = _ty_store_head_id(&ty);
+   _ty_backlog_text(&ty, 2);
+   assert(_ty_view_mapped_count(&ty) == 1);
+   /* and so is a head read again while mapped, its release pass not
+    * scheduled by the mapping any more */
+   assert(ty.backlog_view->release_idler);
+   ecore_idler_del(ty.backlog_view->release_idler);
+   ty.backlog_view->release_idler = NULL;
+   assert(BACKLOG_ROW_GET(&ty, 3)->cells[0].codepoint == 0);
+   _ty_backlog_text(&ty, 3);
+   assert(ty.backlog_view->release_idler);
+   for (i = 0; (i < 1000) &&
+        !backlog_store_page_ready(ty.backlog_store, head); i++)
+     _ty_loop_run(0.01);
+   _ty_loop_run(0.01);
+   assert(_ty_view_mapped_count(&ty) == 0);
+   _ty_test_shutdown(&ty);
+   backlog_view_test_quiet_seconds_set(BACKLOG_QUIET_SECONDS);
+   return 0;
+}
+
+/* Test: a resize of a quiet terminal, whose compressed head ends with a
+ * line that wrapped, rejoins that line once. */
+int
+tytest_backlog_view_quiet_resize(void)
+{
+   const Termcell *cells;
+   Termpty ty;
+   ssize_t w = 0;
+   int i;
+
+   backlog_view_test_quiet_seconds_set(0.05);
+   _ty_test_init(&ty, 80, 24);
+   termpty_backlog_size_set(&ty, 0);
+   termpty_backlog_size_set(&ty, 2000);
+   _ty_padded_feed(&ty, 1, 100 + 23, 0);
+   _ty_feed(&ty, "\033[2J\033[H");
+   for (i = 0; i < 100; i++)
+     _ty_feed(&ty, "w");
+   _ty_feed(&ty, "\r\n");
+   for (i = 0; i < 22; i++)
+     _ty_feed(&ty, "z\r\n");
+   termpty_backlog_follow(&ty);
+   _ty_view_quiet_wait(&ty);
+   _ty_head_compress(&ty);
+   assert(_ty_view_mapped_count(&ty) == 0);
+   assert(BACKLOG_ROW_GET(&ty, 1)->w == 80);
+   assert(BACKLOG_ROW_GET(&ty, 1)->cells[79].att.autowrapped);
+
+   termpty_resize(&ty, 120, 24);
+   /* the whole line, once, scrolled back off the screen it fills */
+   cells = termpty_cellrow_get(&ty, -1, &w);
+   assert(cells && (w == 100) && (cells[99].codepoint == 'w'));
+   assert(_ty_backlog_number(&ty, 2) == 100);
+   _ty_backlog_rows_check(&ty);
+   _ty_backlog_pages_check(&ty);
+   _ty_test_shutdown(&ty);
+   backlog_view_test_quiet_seconds_set(BACKLOG_QUIET_SECONDS);
+   return 0;
+}
+
+/* Test: a line saved into a compressed head is read at once, along with
+ * the newest entry before it, while the older entries read blank until the
+ * thread restoring the head is done. */
+int
+tytest_backlog_view_restoring_reads(void)
+{
+   const char *mapped, *older;
+   Termpty ty;
+   uint32_t head;
+   size_t size;
+   int i;
+
+   backlog_view_test_quiet_seconds_set(0.05);
+   _ty_test_init(&ty, 80, 24);
+   termpty_backlog_size_set(&ty, 0);
+   termpty_backlog_size_set(&ty, 2000);
+   _ty_padded_feed(&ty, 1, 100 + 23, 0);
+   termpty_backlog_follow(&ty);
+   _ty_view_quiet_wait(&ty);
+   _ty_head_compress(&ty);
+   head = _ty_store_head_id(&ty);
+
+   /* 101 leaves the screen */
+   _ty_padded_feed(&ty, 2000, 2000, 0);
+   termpty_backlog_follow(&ty);
+   assert(!backlog_store_page_ready(ty.backlog_store, head));
+   assert(_ty_view_mapped_count(&ty) == 1);
+   assert(_ty_backlog_number(&ty, 1) == 101);
+   assert(_ty_backlog_number(&ty, 2) == 100);
+   assert(_ty_backlog_text(&ty, 3)[0] == '\0');
+   /* not even zeros of the mapping the thread writes to */
+   mapped = (const char *)backlog_store_page_get(ty.backlog_store, head);
+   size = backlog_store_page_map_size(ty.backlog_store, head);
+   older = (const char *)BACKLOG_ROW_GET(&ty, 3)->cells;
+   assert((older < mapped) || (older >= mapped + size));
+
+   for (i = 0; (i < 1000) &&
+        !backlog_store_page_ready(ty.backlog_store, head); i++)
+     _ty_loop_run(0.01);
+   assert(backlog_store_page_ready(ty.backlog_store, head));
+   for (i = 1; i <= 101; i++)
+     assert(_ty_backlog_number(&ty, i) == 102 - i);
+   _ty_backlog_rows_check(&ty);
+   _ty_test_shutdown(&ty);
+   backlog_view_test_quiet_seconds_set(BACKLOG_QUIET_SECONDS);
+   return 0;
+}
+
+/* Test: output that seals a quiet, compressed head within one follow: the
+ * head's entries are taken in full, the newest no longer points at the copy
+ * made when the head was let go of, and the old head comes back as the page
+ * before the new short head. */
+int
+tytest_backlog_view_quiet_head_sealed(void)
+{
+   const Termcell *tail;
+   BacklogView *view;
+   Termpty ty;
+   uint32_t old_head;
+   int i;
+
+   backlog_view_test_quiet_seconds_set(0.05);
+   _ty_test_init(&ty, 80, 24);
+   termpty_backlog_size_set(&ty, 0);
+   /* 128 entries a page */
+   termpty_backlog_size_set(&ty, 2000);
+   view = ty.backlog_view;
+   _ty_padded_feed(&ty, 1, 100 + 23, 0);
+   termpty_backlog_follow(&ty);
+   _ty_view_quiet_wait(&ty);
+   _ty_head_compress(&ty);
+   old_head = _ty_store_head_id(&ty);
+   tail = BACKLOG_ROW_GET(&ty, 1)->cells;
+   assert(tail == view->tail);
+
+   /* 101 to 140 leave the screen: 28 fill the head, 12 start a new one */
+   _ty_padded_feed(&ty, 124, 163, 0);
+   termpty_backlog_follow(&ty);
+   assert(_ty_store_head_id(&ty) == old_head + 1);
+   assert(view->pages_count == 2);
+   assert(!view->tail);
+   assert(BACKLOG_ROW_GET(&ty, 1)->cells != tail);
+   assert(termpty_backlog_length(&ty) == 140);
+   _ty_backlog_rows_check(&ty);
+   for (i = 1; i <= 12; i++)
+     assert(_ty_backlog_number(&ty, i) == 141 - i);
+
+   for (i = 0; (i < 1000) && !(view->pages[0].mapped &&
+        backlog_store_page_ready(ty.backlog_store, old_head)); i++)
+     _ty_loop_run(0.01);
+   assert(view->pages[0].mapped && view->pages[1].mapped);
+   for (i = 1; i <= 140; i++)
+     assert(_ty_backlog_number(&ty, i) == 141 - i);
+   _ty_backlog_rows_check(&ty);
+   _ty_backlog_pages_check(&ty);
+   _ty_test_shutdown(&ty);
+   backlog_view_test_quiet_seconds_set(BACKLOG_QUIET_SECONDS);
+   return 0;
+}
+
+/* Test: a terminal without the focus that keeps printing stays active even
+ * though nothing reads its ring: its head is held, and not compressed. */
+int
+tytest_backlog_view_busy_unread(void)
+{
+   BacklogView *view;
+   Termpty ty;
+   uint32_t head;
+   double now;
+   int i;
+
+   /* a line every fifth of the quiet delay */
+   backlog_view_test_quiet_seconds_set(0.2);
+   _ty_test_init(&ty, 80, 24);
+   termpty_backlog_size_set(&ty, 0);
+   termpty_backlog_size_set(&ty, 2000);
+   _ty_padded_feed(&ty, 1, 50 + 23, 0);
+   termpty_backlog_follow(&ty);
+   view = ty.backlog_view;
+   head = _ty_store_head_id(&ty);
+   for (i = 0; i < 20; i++)
+     {
+        _ty_padded_feed(&ty, 100 + i, 100 + i, 0);
+        _ty_loop_run(0.04);
+        assert(backlog_view_active_get(view));
+        assert(view->pages[view->pages_count - 1].mapped);
+     }
+   now = ecore_time_get();
+   backlog_store_maintain(ty.backlog_store, now);
+   backlog_store_maintain(ty.backlog_store, now + 3600.0);
+   _ty_loop_run(0.01);
+   assert(head == _ty_store_head_id(&ty));
+   assert(backlog_store_page_ready(ty.backlog_store, head));
+
+   /* once it stops, it goes quiet */
+   _ty_view_quiet_wait(&ty);
+   _ty_head_compress(&ty);
+   _ty_test_shutdown(&ty);
+   backlog_view_test_quiet_seconds_set(BACKLOG_QUIET_SECONDS);
+   return 0;
+}
+
+/* Test: focusing a quiet terminal whose head is compressed starts its
+ * restore at once, and the head ends mapped and ready without anything
+ * being printed. */
+int
+tytest_backlog_view_focus_in_restores(void)
+{
+   BacklogView *view;
+   Termpty ty;
+   uint32_t head;
+   int i;
+
+   backlog_view_test_quiet_seconds_set(0.05);
+   _ty_test_init(&ty, 80, 24);
+   termpty_backlog_size_set(&ty, 0);
+   termpty_backlog_size_set(&ty, 2000);
+   _ty_padded_feed(&ty, 1, 100 + 23, 0);
+   termpty_backlog_follow(&ty);
+   view = ty.backlog_view;
+   _ty_view_quiet_wait(&ty);
+   _ty_head_compress(&ty);
+   head = _ty_store_head_id(&ty);
+
+   backlog_view_focus_set(view, EINA_TRUE);
+   assert(backlog_view_active_get(view));
+   assert(backlog_store_page_ready_from(ty.backlog_store, head) > 0);
+   for (i = 0; (i < 1000) && !view->pages[view->pages_count - 1].mapped;
+        i++)
+     _ty_loop_run(0.01);
+   assert(view->pages[view->pages_count - 1].mapped);
+   assert(backlog_store_page_ready(ty.backlog_store, head));
+   for (i = 1; i <= 100; i++)
+     assert(_ty_backlog_number(&ty, i) == 101 - i);
+   /* focused, it stays so */
+   _ty_loop_run(0.2);
+   assert(view->pages[view->pages_count - 1].mapped);
+   _ty_test_shutdown(&ty);
+   backlog_view_test_quiet_seconds_set(BACKLOG_QUIET_SECONDS);
+   return 0;
+}
+
+/* Test: tymuxd's own view renders nothing, so even active at the bottom
+ * with a short head it holds only the head: the compressed page before it
+ * is neither held nor rebuilt, and the head is restored without waiting. */
+int
+tytest_backlog_view_daemon_short_head(void)
+{
+#if defined(__linux__)
+   BacklogView *view;
+   Termpty ty;
+   uint32_t head;
+
+   backlog_view_test_quiet_seconds_set(0.05);
+   _ty_test_init(&ty, 80, 24);
+   termpty_backlog_size_set(&ty, 0);
+   termpty_backlog_store_backing_set(&ty, BACKLOG_STORE_MEMFD);
+   /* 128 entries a page */
+   termpty_backlog_size_set(&ty, 2000);
+   ty.backlog_head_only = 1;
+   view = ty.backlog_view;
+   /* a head short of a screen, yet worth compressing */
+   _ty_padded_feed(&ty, 1, 128 + 20 + 23, 0);
+   termpty_backlog_follow(&ty);
+   _ty_view_quiet_wait(&ty);
+   _ty_head_compress(&ty);
+   head = _ty_store_head_id(&ty);
+   assert(view->pages_count == 2);
+   assert(!backlog_store_page_ready(ty.backlog_store, head - 1));
+
+   /* 149 leaves the screen */
+   _ty_padded_feed(&ty, 2000, 2000, 0);
+   termpty_backlog_follow(&ty);
+   assert(backlog_view_active_get(view));
+   assert(view->pages[1].mapped);
+   assert(backlog_store_page_ready_from(ty.backlog_store, head) > 0);
+   _ty_loop_run(0.01);
+   assert(!view->pages[0].mapped);
+   assert(!backlog_store_page_ready(ty.backlog_store, head - 1));
+   assert(!backlog_store_page_map_size(ty.backlog_store, head - 1));
+   _ty_test_shutdown(&ty);
+   backlog_view_test_quiet_seconds_set(BACKLOG_QUIET_SECONDS);
+#endif
+   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/tybench.c b/src/bin/tybench.c
index ad6e02b7..0abce81b 100644
--- a/src/bin/tybench.c
+++ b/src/bin/tybench.c
@@ -235,6 +235,8 @@ main(int argc, char **argv)
     * eina's "unknown domain" complaint path instead of the cheap level check
     * that production takes. */
    termpty_init();
+   /* the backlog view keeps a timer while output flows, as in terminology */
+   ecore_init();
    tytest_common_init();
 
    if (!tsv)
@@ -290,6 +292,7 @@ main(int argc, char **argv)
    free(corpus);
 
    tytest_common_shutdown();
+   ecore_shutdown();
    eina_shutdown();
 
    return 0;
diff --git a/src/bin/tytest.c b/src/bin/tytest.c
index b7fd9be4..93fedc5a 100644
--- a/src/bin/tytest.c
+++ b/src/bin/tytest.c
@@ -42,6 +42,14 @@ static struct {
        { "backlog_clear_ids", tytest_backlog_clear_ids},
        { "backlog_view_head_only", tytest_backlog_view_head_only},
        { "backlog_view_bottom_head_only", tytest_backlog_view_bottom_head_only},
+       { "backlog_view_active_short_head", tytest_backlog_view_active_short_head},
+       { "backlog_view_quiet_releases", tytest_backlog_view_quiet_releases},
+       { "backlog_view_quiet_resize", tytest_backlog_view_quiet_resize},
+       { "backlog_view_restoring_reads", tytest_backlog_view_restoring_reads},
+       { "backlog_view_quiet_head_sealed", tytest_backlog_view_quiet_head_sealed},
+       { "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_wide_entry_rows", tytest_backlog_wide_entry_rows},
        { "backlog_external", tytest_backlog_external},
        { "backlog_store_termpty", tytest_backlog_store_termpty},
@@ -232,6 +240,7 @@ static struct {
        { "backlog_view_anchor", tytest_backlog_view_anchor},
        { "backlog_view_head_shrink", tytest_backlog_view_head_shrink},
        { "backlog_view_retract_short", tytest_backlog_view_retract_short},
+       { "backlog_view_remote_short_head", tytest_backlog_view_remote_short_head},
        { "backlog_view_local_slide", tytest_backlog_view_local_slide},
        { "backlog_view_local_compressed_read", tytest_backlog_view_local_compressed_read},
        { "backlog_view_link_after_rebuild", tytest_backlog_view_link_after_rebuild},
diff --git a/src/bin/tytest_tymux.c b/src/bin/tytest_tymux.c
index 0ef54a58..563c472e 100644
--- a/src/bin/tytest_tymux.c
+++ b/src/bin/tytest_tymux.c
@@ -234,7 +234,11 @@ 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);
-   return *ts != NULL;
+   if (!*ts)
+     return EINA_FALSE;
+   /* the terminal the user works in, whose view holds the head */
+   backlog_view_focus_set((*ts)->view, EINA_TRUE);
+   return EINA_TRUE;
 }
 
 static Eina_Bool
diff --git a/src/bin/unit_tests.h b/src/bin/unit_tests.h
index 9459a49b..cb37b31c 100644
--- a/src/bin/unit_tests.h
+++ b/src/bin/unit_tests.h
@@ -12,6 +12,14 @@ int tytest_backlog_append_fail(void);
 int tytest_backlog_clear_ids(void);
 int tytest_backlog_view_head_only(void);
 int tytest_backlog_view_bottom_head_only(void);
+int tytest_backlog_view_active_short_head(void);
+int tytest_backlog_view_quiet_releases(void);
+int tytest_backlog_view_quiet_resize(void);
+int tytest_backlog_view_restoring_reads(void);
+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_wide_entry_rows(void);
 int tytest_backlog_external(void);
 int tytest_backlog_store_termpty(void);
@@ -172,6 +180,7 @@ int tytest_backlog_view_release(void);
 int tytest_backlog_view_anchor(void);
 int tytest_backlog_view_head_shrink(void);
 int tytest_backlog_view_retract_short(void);
+int tytest_backlog_view_remote_short_head(void);
 int tytest_backlog_view_local_slide(void);
 int tytest_backlog_view_local_compressed_read(void);
 int tytest_backlog_view_link_after_rebuild(void);

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.

Reply via email to