aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2021-02-06 10:47:59 +0000
committerDaniel Eklöf <daniel@ekloef.se>2021-02-07 15:33:34 +0000
commit6726494f4c2836a5ed1c4611c181e4a57a4adbf1 (patch)
tree52ca12d22d6cc99a44b7c919425e9eef8eb221bc
parenturl-mode: make the end coordinate *inclusive* (diff)
url-mode: store absolute row numbers in start/end coordinates
This allows us to update the jump label positions when the viewport changes. This in turn allows us to stay in URL mode while the user is using the mouse to scroll in the scrollback history. Scrolling with the keyboard is currently not possible, since input handling in URL mode does not recognize “regular” key bindings. We _could_ add scrollback up/down bindings to URL mode too, but lets not, for the time being. (Note: an alternative to this patch is to disallow mouse scrolling too. Then we could have kept the URL start/end as viewport local coordinates).
-rw-r--r--commands.c2
-rw-r--r--render.c32
-rw-r--r--url-mode.c3
3 files changed, 34 insertions, 3 deletions
diff --git a/commands.c b/commands.c
index ac91ab19..01ad4e1e 100644
--- a/commands.c
+++ b/commands.c
@@ -83,6 +83,7 @@ cmd_scrollback_up(struct terminal *term, int rows)
} else
term_damage_view(term);
+ render_refresh_urls(term);
render_refresh(term);
}
@@ -157,5 +158,6 @@ cmd_scrollback_down(struct terminal *term, int rows)
} else
term_damage_view(term);
+ render_refresh_urls(term);
render_refresh(term);
}
diff --git a/render.c b/render.c
index d04fd5d4..fff280fc 100644
--- a/render.c
+++ b/render.c
@@ -2524,6 +2524,15 @@ render_urls(struct terminal *term)
struct wl_window *win = term->window;
xassert(tll_length(win->urls) > 0);
+ /* Calculate view start, counted from the *current* scrollback start */
+ const int scrollback_end
+ = (term->grid->offset + term->rows) & (term->grid->num_rows - 1);
+ const int view_start
+ = (term->grid->view
+ - scrollback_end
+ + term->grid->num_rows) & (term->grid->num_rows - 1);
+ const int view_end = view_start + term->rows - 1;
+
tll_foreach(win->urls, it) {
const struct url *url = it->item.url;
const wchar_t *text = url->text;
@@ -2535,6 +2544,18 @@ render_urls(struct terminal *term)
if (surf == NULL || sub_surf == NULL)
continue;
+ const struct coord *pos = &url->start;
+ const int _row
+ = (pos->row
+ - scrollback_end
+ + term->grid->num_rows) & (term->grid->num_rows - 1);
+
+ if (_row < view_start || _row > view_end) {
+ wl_surface_attach(surf, NULL, 0, 0);
+ wl_surface_commit(surf);
+ continue;
+ }
+
size_t text_len = wcslen(text);
size_t chars = wcslen(key) + (text_len > 0 ? 3 + text_len : 0);
@@ -2562,9 +2583,14 @@ render_urls(struct terminal *term)
struct buffer *buf = shm_get_buffer(
term->wl->shm, width, height, shm_cookie_url(url), false, 1);
- const struct coord *pos = &url->start;
- int x = pos->col * term->cell_width - 15 * term->cell_width / 10;
- int y = pos->row * term->cell_height - 5 * term->cell_height / 10;
+ int col = pos->col;
+ int row = pos->row - term->grid->view;
+ while (row < 0)
+ row += term->grid->num_rows;
+ row &= (term->grid->num_rows - 1);
+
+ int x = col * term->cell_width - 15 * term->cell_width / 10;
+ int y = row * term->cell_height - 5 * term->cell_height / 10;
if (x < 0)
x = 0;
diff --git a/url-mode.c b/url-mode.c
index 4feea2df..8f3b867e 100644
--- a/url-mode.c
+++ b/url-mode.c
@@ -294,6 +294,9 @@ auto_detected(struct terminal *term, enum url_action action)
url[len] = L'\0';
+ start.row += term->grid->view;
+ end.row += term->grid->view;
+
tll_push_back(
term->urls,
((struct url){