introduce rate-limiting timer for setting the app ID

This commit is contained in:
delthas 2023-09-06 18:33:29 +02:00
parent d21190289b
commit 0568c7d0ad
3 changed files with 33 additions and 1 deletions

2
osc.c
View file

@ -911,7 +911,7 @@ osc_dispatch(struct terminal *term)
break; break;
case 176: case 176:
xdg_toplevel_set_app_id(term->window->xdg_toplevel, *string ? string : term->conf->app_id); term_set_app_id(term, string);
break; break;
case 555: case 555:

View file

@ -1662,6 +1662,7 @@ term_destroy(struct terminal *term)
composed_free(term->composed); composed_free(term->composed);
free(term->app_id);
free(term->window_title); free(term->window_title);
tll_free_and_free(term->window_title_stack, free); tll_free_and_free(term->window_title_stack, free);
@ -3246,6 +3247,34 @@ term_set_window_title(struct terminal *term, const char *title)
term->window_title_has_been_set = true; term->window_title_has_been_set = true;
} }
void
term_set_app_id(struct terminal *term, const char *app_id)
{
if (app_id != NULL && *app_id == '\0')
app_id = NULL;
if (term->app_id == NULL && app_id == NULL)
return;
if (term->app_id != NULL && app_id != NULL && strcmp(term->app_id, app_id) == 0)
return;
struct timespec now;
if (clock_gettime(CLOCK_MONOTONIC, &now) < 0)
return;
struct timespec diff;
timespec_sub(&now, &term->app_id_last_update, &diff);
if (diff.tv_sec == 0 && diff.tv_nsec < 8333 * 1000)
return;
term->app_id_last_update = now;
free(term->app_id);
if (app_id != NULL) {
term->app_id = xstrdup(app_id);
} else {
term->app_id = NULL;
}
xdg_toplevel_set_app_id(term->window->xdg_toplevel, term->app_id ? term->app_id : term->conf->app_id);
}
void void
term_flash(struct terminal *term, unsigned duration_ms) term_flash(struct terminal *term, unsigned duration_ms)
{ {

View file

@ -477,6 +477,8 @@ struct terminal {
bool window_title_has_been_set; bool window_title_has_been_set;
char *window_title; char *window_title;
tll(char *) window_title_stack; tll(char *) window_title_stack;
char *app_id;
struct timespec app_id_last_update;
struct { struct {
bool active; bool active;
@ -824,6 +826,7 @@ void term_xcursor_update_for_seat(struct terminal *term, struct seat *seat);
void term_set_user_mouse_cursor(struct terminal *term, const char *cursor); void term_set_user_mouse_cursor(struct terminal *term, const char *cursor);
void term_set_window_title(struct terminal *term, const char *title); void term_set_window_title(struct terminal *term, const char *title);
void term_set_app_id(struct terminal *term, const char *app_id);
void term_flash(struct terminal *term, unsigned duration_ms); void term_flash(struct terminal *term, unsigned duration_ms);
void term_bell(struct terminal *term); void term_bell(struct terminal *term);
bool term_spawn_new(const struct terminal *term); bool term_spawn_new(const struct terminal *term);