render: use a timer instead of relying on the frame callback for title update throttling

Using the frame callback works most of the time, but e.g. Sway doesn’t
call it while the window is hidden, and thus prevents us from updating
the title in e.g. stacked views.

This patch uses a timer FD instead. We store a timestamp from when the
title was last updated. When the application wants to update the
title, we first check if we already have a timer running, and if so,
does nothing.

If no timer is running, check the timestamp. If enough time has
passed, update the title immediately.

If not, instantiate a timer and wait for it to trigger.

Set the minimum time between two updates to ~8ms (twice per frame, for
a 60Hz output, and ~once per frame on a 120Hz output).

Closes #591
This commit is contained in:
Daniel Eklöf 2021-06-15 17:27:50 +02:00
parent b77dbc341b
commit 535c82d628
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 64 additions and 18 deletions

View file

@ -1113,6 +1113,9 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
.render = {
.scrollback_lines = conf->scrollback.lines,
.app_sync_updates.timer_fd = app_sync_updates_fd,
.title = {
.timer_fd = -1,
},
.workers = {
.count = conf->render_worker_count,
.queue = tll_init(),
@ -1289,6 +1292,7 @@ term_shutdown(struct terminal *term)
fdm_del(term->fdm, term->selection.auto_scroll.fd);
fdm_del(term->fdm, term->render.app_sync_updates.timer_fd);
fdm_del(term->fdm, term->render.title.timer_fd);
fdm_del(term->fdm, term->delayed_render_timer.lower_fd);
fdm_del(term->fdm, term->delayed_render_timer.upper_fd);
fdm_del(term->fdm, term->blink.fd);
@ -1304,6 +1308,7 @@ term_shutdown(struct terminal *term)
term->selection.auto_scroll.fd = -1;
term->render.app_sync_updates.timer_fd = -1;
term->render.title.timer_fd = -1;
term->delayed_render_timer.lower_fd = -1;
term->delayed_render_timer.upper_fd = -1;
term->blink.fd = -1;
@ -1354,6 +1359,7 @@ term_destroy(struct terminal *term)
fdm_del(term->fdm, term->selection.auto_scroll.fd);
fdm_del(term->fdm, term->render.app_sync_updates.timer_fd);
fdm_del(term->fdm, term->render.title.timer_fd);
fdm_del(term->fdm, term->delayed_render_timer.lower_fd);
fdm_del(term->fdm, term->delayed_render_timer.upper_fd);
fdm_del(term->fdm, term->cursor_blink.fd);
@ -2670,9 +2676,7 @@ term_enable_app_sync_updates(struct terminal *term)
/* Disable pending refresh *iff* the grid is the *only* thing
* scheduled to be re-rendered */
if (!term->render.refresh.csd && !term->render.refresh.search &&
!term->render.refresh.title &&
!term->render.pending.csd && !term->render.pending.search &&
!term->render.pending.title)
!term->render.pending.csd && !term->render.pending.search)
{
term->render.refresh.grid = false;
term->render.pending.grid = false;