mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-04-26 06:46:45 -04:00
eventually apply last app ID when throttling
...instead of just dropping those app IDs.
This commit is contained in:
parent
f4dd7a7878
commit
239561ffbf
4 changed files with 69 additions and 12 deletions
22
render.c
22
render.c
|
|
@ -4488,6 +4488,28 @@ render_refresh_title(struct terminal *term)
|
||||||
render_refresh_csd(term);
|
render_refresh_csd(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
render_refresh_app_id(struct terminal *term)
|
||||||
|
{
|
||||||
|
struct timespec now;
|
||||||
|
if (clock_gettime(CLOCK_MONOTONIC, &now) < 0)
|
||||||
|
return;
|
||||||
|
|
||||||
|
struct timespec diff;
|
||||||
|
timespec_sub(&now, &term->render.app_id.last_update, &diff);
|
||||||
|
|
||||||
|
if (diff.tv_sec == 0 && diff.tv_nsec < 8333 * 1000) {
|
||||||
|
const struct itimerspec timeout = {
|
||||||
|
.it_value = {.tv_nsec = 8333 * 1000 - diff.tv_nsec},
|
||||||
|
};
|
||||||
|
|
||||||
|
timerfd_settime(term->render.app_id.timer_fd, 0, &timeout, NULL);
|
||||||
|
} else {
|
||||||
|
term->render.app_id.last_update = now;
|
||||||
|
xdg_toplevel_set_app_id(term->window->xdg_toplevel, term->app_id ? term->app_id : term->conf->app_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
render_refresh(struct terminal *term)
|
render_refresh(struct terminal *term)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
1
render.h
1
render.h
|
|
@ -14,6 +14,7 @@ bool render_resize(struct terminal *term, int width, int height);
|
||||||
bool render_resize_force(struct terminal *term, int width, int height);
|
bool render_resize_force(struct terminal *term, int width, int height);
|
||||||
|
|
||||||
void render_refresh(struct terminal *term);
|
void render_refresh(struct terminal *term);
|
||||||
|
void render_refresh_app_id(struct terminal *term);
|
||||||
void render_refresh_csd(struct terminal *term);
|
void render_refresh_csd(struct terminal *term);
|
||||||
void render_refresh_search(struct terminal *term);
|
void render_refresh_search(struct terminal *term);
|
||||||
void render_refresh_title(struct terminal *term);
|
void render_refresh_title(struct terminal *term);
|
||||||
|
|
|
||||||
52
terminal.c
52
terminal.c
|
|
@ -628,6 +628,30 @@ fdm_title_update_timeout(struct fdm *fdm, int fd, int events, void *data)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool
|
||||||
|
fdm_app_id_update_timeout(struct fdm *fdm, int fd, int events, void *data)
|
||||||
|
{
|
||||||
|
if (events & EPOLLHUP)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
struct terminal *term = data;
|
||||||
|
uint64_t unused;
|
||||||
|
ssize_t ret = read(term->render.app_id.timer_fd, &unused, sizeof(unused));
|
||||||
|
|
||||||
|
if (ret < 0) {
|
||||||
|
if (errno == EAGAIN)
|
||||||
|
return true;
|
||||||
|
LOG_ERRNO("failed to read app ID update throttle timer");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct itimerspec reset = {{0}};
|
||||||
|
timerfd_settime(term->render.app_id.timer_fd, 0, &reset, NULL);
|
||||||
|
|
||||||
|
render_refresh_app_id(term);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
initialize_render_workers(struct terminal *term)
|
initialize_render_workers(struct terminal *term)
|
||||||
{
|
{
|
||||||
|
|
@ -1068,6 +1092,7 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
||||||
int delay_upper_fd = -1;
|
int delay_upper_fd = -1;
|
||||||
int app_sync_updates_fd = -1;
|
int app_sync_updates_fd = -1;
|
||||||
int title_update_fd = -1;
|
int title_update_fd = -1;
|
||||||
|
int app_id_update_fd = -1;
|
||||||
|
|
||||||
struct terminal *term = malloc(sizeof(*term));
|
struct terminal *term = malloc(sizeof(*term));
|
||||||
if (unlikely(term == NULL)) {
|
if (unlikely(term == NULL)) {
|
||||||
|
|
@ -1102,6 +1127,12 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
||||||
goto close_fds;
|
goto close_fds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((app_id_update_fd = timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC | TFD_NONBLOCK)) < 0)
|
||||||
|
{
|
||||||
|
LOG_ERRNO("failed to create app ID update throttle timer FD");
|
||||||
|
goto close_fds;
|
||||||
|
}
|
||||||
|
|
||||||
if (ioctl(ptmx, (unsigned int)TIOCSWINSZ,
|
if (ioctl(ptmx, (unsigned int)TIOCSWINSZ,
|
||||||
&(struct winsize){.ws_row = 24, .ws_col = 80}) < 0)
|
&(struct winsize){.ws_row = 24, .ws_col = 80}) < 0)
|
||||||
{
|
{
|
||||||
|
|
@ -1132,7 +1163,8 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
||||||
!fdm_add(fdm, delay_lower_fd, EPOLLIN, &fdm_delayed_render, term) ||
|
!fdm_add(fdm, delay_lower_fd, EPOLLIN, &fdm_delayed_render, term) ||
|
||||||
!fdm_add(fdm, delay_upper_fd, EPOLLIN, &fdm_delayed_render, term) ||
|
!fdm_add(fdm, delay_upper_fd, EPOLLIN, &fdm_delayed_render, term) ||
|
||||||
!fdm_add(fdm, app_sync_updates_fd, EPOLLIN, &fdm_app_sync_updates_timeout, term) ||
|
!fdm_add(fdm, app_sync_updates_fd, EPOLLIN, &fdm_app_sync_updates_timeout, term) ||
|
||||||
!fdm_add(fdm, title_update_fd, EPOLLIN, &fdm_title_update_timeout, term))
|
!fdm_add(fdm, title_update_fd, EPOLLIN, &fdm_title_update_timeout, term) ||
|
||||||
|
!fdm_add(fdm, app_id_update_fd, EPOLLIN, &fdm_app_id_update_timeout, term))
|
||||||
{
|
{
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
@ -1229,6 +1261,9 @@ term_init(const struct config *conf, struct fdm *fdm, struct reaper *reaper,
|
||||||
.is_armed = false,
|
.is_armed = false,
|
||||||
.timer_fd = title_update_fd,
|
.timer_fd = title_update_fd,
|
||||||
},
|
},
|
||||||
|
.app_id = {
|
||||||
|
.timer_fd = app_id_update_fd,
|
||||||
|
},
|
||||||
.workers = {
|
.workers = {
|
||||||
.count = conf->render_worker_count,
|
.count = conf->render_worker_count,
|
||||||
.queue = tll_init(),
|
.queue = tll_init(),
|
||||||
|
|
@ -1336,6 +1371,7 @@ close_fds:
|
||||||
fdm_del(fdm, delay_upper_fd);
|
fdm_del(fdm, delay_upper_fd);
|
||||||
fdm_del(fdm, app_sync_updates_fd);
|
fdm_del(fdm, app_sync_updates_fd);
|
||||||
fdm_del(fdm, title_update_fd);
|
fdm_del(fdm, title_update_fd);
|
||||||
|
fdm_del(fdm, app_id_update_fd);
|
||||||
|
|
||||||
free(term);
|
free(term);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
@ -1528,6 +1564,7 @@ term_shutdown(struct terminal *term)
|
||||||
|
|
||||||
fdm_del(term->fdm, term->selection.auto_scroll.fd);
|
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.app_sync_updates.timer_fd);
|
||||||
|
fdm_del(term->fdm, term->render.app_id.timer_fd);
|
||||||
fdm_del(term->fdm, term->render.title.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.lower_fd);
|
||||||
fdm_del(term->fdm, term->delayed_render_timer.upper_fd);
|
fdm_del(term->fdm, term->delayed_render_timer.upper_fd);
|
||||||
|
|
@ -1566,6 +1603,7 @@ term_shutdown(struct terminal *term)
|
||||||
|
|
||||||
term->selection.auto_scroll.fd = -1;
|
term->selection.auto_scroll.fd = -1;
|
||||||
term->render.app_sync_updates.timer_fd = -1;
|
term->render.app_sync_updates.timer_fd = -1;
|
||||||
|
term->render.app_id.timer_fd = -1;
|
||||||
term->render.title.timer_fd = -1;
|
term->render.title.timer_fd = -1;
|
||||||
term->delayed_render_timer.lower_fd = -1;
|
term->delayed_render_timer.lower_fd = -1;
|
||||||
term->delayed_render_timer.upper_fd = -1;
|
term->delayed_render_timer.upper_fd = -1;
|
||||||
|
|
@ -1619,6 +1657,7 @@ term_destroy(struct terminal *term)
|
||||||
|
|
||||||
fdm_del(term->fdm, term->selection.auto_scroll.fd);
|
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.app_sync_updates.timer_fd);
|
||||||
|
fdm_del(term->fdm, term->render.app_id.timer_fd);
|
||||||
fdm_del(term->fdm, term->render.title.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.lower_fd);
|
||||||
fdm_del(term->fdm, term->delayed_render_timer.upper_fd);
|
fdm_del(term->fdm, term->delayed_render_timer.upper_fd);
|
||||||
|
|
@ -3257,22 +3296,13 @@ term_set_app_id(struct terminal *term, const char *app_id)
|
||||||
if (term->app_id != NULL && app_id != NULL && strcmp(term->app_id, app_id) == 0)
|
if (term->app_id != NULL && app_id != NULL && strcmp(term->app_id, app_id) == 0)
|
||||||
return;
|
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);
|
free(term->app_id);
|
||||||
if (app_id != NULL) {
|
if (app_id != NULL) {
|
||||||
term->app_id = xstrdup(app_id);
|
term->app_id = xstrdup(app_id);
|
||||||
} else {
|
} else {
|
||||||
term->app_id = NULL;
|
term->app_id = NULL;
|
||||||
}
|
}
|
||||||
xdg_toplevel_set_app_id(term->window->xdg_toplevel, term->app_id ? term->app_id : term->conf->app_id);
|
render_refresh_app_id(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
||||||
|
|
@ -478,7 +478,6 @@ struct terminal {
|
||||||
char *window_title;
|
char *window_title;
|
||||||
tll(char *) window_title_stack;
|
tll(char *) window_title_stack;
|
||||||
char *app_id;
|
char *app_id;
|
||||||
struct timespec app_id_last_update;
|
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
bool active;
|
bool active;
|
||||||
|
|
@ -603,6 +602,11 @@ struct terminal {
|
||||||
int timer_fd;
|
int timer_fd;
|
||||||
} title;
|
} title;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
struct timespec last_update;
|
||||||
|
int timer_fd;
|
||||||
|
} app_id;
|
||||||
|
|
||||||
uint32_t scrollback_lines; /* Number of scrollback lines, from conf (TODO: move out from render struct?) */
|
uint32_t scrollback_lines; /* Number of scrollback lines, from conf (TODO: move out from render struct?) */
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue