render: pace title updates

Synchronize window title updates with window rendering.
This commit is contained in:
Daniel Eklöf 2020-03-25 18:23:55 +01:00
parent b46ad6a50a
commit 9bbbd26c7a
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
4 changed files with 34 additions and 16 deletions

View file

@ -1602,6 +1602,24 @@ render_search_box(struct terminal *term)
quirk_weston_subsurface_desync_off(term->window->search_sub_surface);
}
static void
render_update_title(struct terminal *term)
{
/* TODO: figure out what the limit actually is */
static const size_t max_len = 100;
const char *title = term->window_title != NULL ? term->window_title : "foot";
char *copy = NULL;
if (strlen(title) > max_len) {
copy = strndup(title, max_len);
title = copy;
}
xdg_toplevel_set_title(term->window->xdg_toplevel, title);
free(copy);
}
static void
frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_data)
{
@ -1614,10 +1632,12 @@ frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_da
bool grid = term->render.pending.grid;
bool csd = term->render.pending.csd;
bool search = term->render.pending.search;
bool title = term->render.pending.title;
term->render.pending.grid = false;
term->render.pending.csd = false;
term->render.pending.search = false;
term->render.pending.title = false;
if (csd && term->window->use_csd == CSD_YES) {
quirk_weston_csd_on(term);
@ -1625,6 +1645,9 @@ frame_callback(void *data, struct wl_callback *wl_callback, uint32_t callback_da
quirk_weston_csd_off(term);
}
if (title)
render_update_title(term);
if (search && term->is_searching)
render_search_box(term);
@ -1957,10 +1980,12 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data)
bool grid = term->render.refresh.grid;
bool csd = term->render.refresh.csd;
bool search = term->render.refresh.search;
bool title = term->render.refresh.title;
term->render.refresh.grid = false;
term->render.refresh.csd = false;
term->render.refresh.search = false;
term->render.refresh.title = false;
if (term->window->frame_callback == NULL) {
if (csd && term->window->use_csd == CSD_YES) {
@ -1968,6 +1993,8 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data)
render_csd(term);
quirk_weston_csd_off(term);
}
if (title)
render_update_title(term);
if (search)
render_search_box(term);
if (grid)
@ -1977,6 +2004,7 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data)
term->render.pending.grid |= grid;
term->render.pending.csd |= csd;
term->render.pending.search |= search;
term->render.pending.title |= title;
}
}
@ -1991,21 +2019,9 @@ fdm_hook_refresh_pending_terminals(struct fdm *fdm, void *data)
}
void
render_set_title(struct terminal *term, const char *_title)
render_refresh_title(struct terminal *term)
{
/* TODO: figure out what the limit actually is */
static const size_t max_len = 100;
const char *title = _title;
char *copy = NULL;
if (strlen(title) > max_len) {
copy = strndup(_title, max_len);
title = copy;
}
xdg_toplevel_set_title(term->window->xdg_toplevel, title);
free(copy);
term->render.refresh.title = true;
}
void

View file

@ -12,10 +12,10 @@ void render_destroy(struct renderer *renderer);
bool render_resize(struct terminal *term, int width, int height);
bool render_resize_force(struct terminal *term, int width, int height);
void render_set_title(struct terminal *term, const char *title);
void render_refresh(struct terminal *term);
void render_refresh_csd(struct terminal *term);
void render_refresh_search(struct terminal *term);
void render_refresh_title(struct terminal *term);
bool render_xcursor_set(struct terminal *term);
struct render_worker_context {

View file

@ -1943,7 +1943,7 @@ term_set_window_title(struct terminal *term, const char *title)
{
free(term->window_title);
term->window_title = strdup(title);
render_set_title(term, term->window_title);
render_refresh_title(term);
}
void

View file

@ -336,6 +336,7 @@ struct terminal {
bool grid;
bool csd;
bool search;
bool title;
} refresh;
/* Scheduled for rendering, in the next frame callback */
@ -343,6 +344,7 @@ struct terminal {
bool grid;
bool csd;
bool search;
bool title;
} pending;
int scrollback_lines; /* Number of scrollback lines, from conf (TODO: move out from render struct?) */