From 54b5ae95c1bb01c5103b3ce97a8faebe75e142bb Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Mon, 22 Feb 2021 10:22:41 +0100 Subject: url-mode: snapshot screen state when entering URL mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, we automatically exited URL mode whenever we received data on the PTY. This was done since we don’t know _what_ has changed on the screen, and we don’t want to display misleading jump labels. However, this becomes a problem in curses-like applications that periodically updates part of the screen. For example, a statusbar with a clock. This patch changes this behavior; instead of cancelling URL mode when receiving PTY data, we snapshot the grid when entering URL mode. When *rendering*, we use the snapshot:ed grid, while PTY updates modify the “real” grid. Snapshot:ing the grid means taking a full/deep copy of the current grid, including sixel images etc. Finally, it isn’t necessary to “damage” the entire view when *entering* URL mode, since we’re at that point the renderer is in sync with the grid. But we *do* need to damage the entire view when exiting URL mode, since the grid changes on the “real” grid hasn’t been tracked by the renderer. --- url-mode.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'url-mode.c') diff --git a/url-mode.c b/url-mode.c index cea099e9..7fb60845 100644 --- a/url-mode.c +++ b/url-mode.c @@ -637,6 +637,9 @@ urls_render(struct terminal *term) tag_cells_for_url(term, &it->item, true); } + /* Snapshot the current grid */ + term->url_grid_snapshot = grid_snapshot(term->grid); + render_refresh_urls(term); render_refresh(term); } @@ -651,8 +654,15 @@ url_destroy(struct url *url) void urls_reset(struct terminal *term) { - if (likely(tll_length(term->urls) == 0)) + if (likely(tll_length(term->urls) == 0)) { + xassert(term->url_grid_snapshot == NULL); return; + } + + grid_free(term->url_grid_snapshot); + free(term->url_grid_snapshot); + term->url_grid_snapshot = NULL; + term->render.last_cursor.row = NULL; if (term->window != NULL) { tll_foreach(term->window->urls, it) { @@ -669,5 +679,7 @@ urls_reset(struct terminal *term) term->urls_show_uri_on_jump_label = false; memset(term->url_keys, 0, sizeof(term->url_keys)); + + term_damage_view(term); render_refresh(term); } -- cgit v1.3 From aa10cd54eabf592d5ad79a972009887495841652 Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 23 Feb 2021 09:16:13 +0100 Subject: url-mode: no need to damage the entire view when exiting URL mode The renderer will simply apply *all* accumulated damage at once, when we render the real grid. --- url-mode.c | 1 - 1 file changed, 1 deletion(-) (limited to 'url-mode.c') diff --git a/url-mode.c b/url-mode.c index 7fb60845..8b1b9795 100644 --- a/url-mode.c +++ b/url-mode.c @@ -680,6 +680,5 @@ urls_reset(struct terminal *term) term->urls_show_uri_on_jump_label = false; memset(term->url_keys, 0, sizeof(term->url_keys)); - term_damage_view(term); render_refresh(term); } -- cgit v1.3 From bc71e06d5f5b9f27aca373e523627c70670e979c Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Tue, 23 Feb 2021 09:24:50 +0100 Subject: url-mode: dirty the “last cursor” cell before taking the snapshot MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This ensures the “last cursor” cell is re-drawn (without a cursor, if the cursor has moved), both in the snapshot:ed grid, and later, when we switch back to the real grid. We must also be careful and reset term->render.last_cursor.row both when *entering* and *leaving* URL mode, to ensure it doesn’t point to an invalid row. --- url-mode.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'url-mode.c') diff --git a/url-mode.c b/url-mode.c index 8b1b9795..54edc524 100644 --- a/url-mode.c +++ b/url-mode.c @@ -637,6 +637,17 @@ urls_render(struct terminal *term) tag_cells_for_url(term, &it->item, true); } + /* Dirty the last cursor, to ensure it is erased */ + { + struct row *cursor_row = term->render.last_cursor.row; + if (cursor_row != NULL) { + struct cell *cell = &cursor_row->cells[term->render.last_cursor.col]; + cell->attrs.clean = 0; + cursor_row->dirty = true; + } + } + term->render.last_cursor.row = NULL; + /* Snapshot the current grid */ term->url_grid_snapshot = grid_snapshot(term->grid); @@ -662,6 +673,15 @@ urls_reset(struct terminal *term) grid_free(term->url_grid_snapshot); free(term->url_grid_snapshot); term->url_grid_snapshot = NULL; + + /* + * Make sure “last cursor” doesn’t point to a row in the just + * free:d snapshot grid. + * + * Note that it will still be erased properly (if hasn’t already), + * since we marked the cell as dirty *before* taking the grid + * snapshot. + */ term->render.last_cursor.row = NULL; if (term->window != NULL) { -- cgit v1.3 From ae0f20a53603c3e3657cbab5c548575d4d1147bb Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 24 Feb 2021 21:39:29 +0100 Subject: url-mode: damage current view before entering URL mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Clear scroll damage and damage the entire viewport before entering URL mode. This will cause us to do a full screen redraw both when entering URL mode, and later when exiting it. Clearing the scroll damage is necessary to ensure we don’t apply it twice (once for the snapshot:ed grid, and later again for the real grid), as that would result in an incorrect pixmap. But, since we’ve cleared the scroll damage, we need to damage the entire view to ensure we redraw the contents correctly. --- url-mode.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'url-mode.c') diff --git a/url-mode.c b/url-mode.c index 54edc524..791b4ce0 100644 --- a/url-mode.c +++ b/url-mode.c @@ -648,6 +648,14 @@ urls_render(struct terminal *term) } term->render.last_cursor.row = NULL; + /* Clear scroll damage, to ensure we don’t apply it twice (once on + * the snapshot:ed grid, and then later again on the real grid) */ + tll_free(term->grid->scroll_damage); + + /* Damage the entire view, to ensure a full screen redraw, both + * now, when entering URL mode, and later, when exiting it. */ + term_damage_view(term); + /* Snapshot the current grid */ term->url_grid_snapshot = grid_snapshot(term->grid); -- cgit v1.3