mirror of
https://github.com/tmux/tmux.git
synced 2024-12-12 17:38:48 +00:00
Better take on reducing the name timer. Again check for name changes in
the main loop after events that may have changed the pane, but do so at most once every 500 millis. If the pane changed too soon, use a timer to ensure that a check happens later.
This commit is contained in:
parent
73bd816076
commit
b7861f34ba
@ -180,9 +180,7 @@ cmd_set_option_exec(struct cmd *self, struct cmd_q *cmdq)
|
||||
if (strcmp(oe->name, "automatic-rename") == 0) {
|
||||
RB_FOREACH(w, windows, &windows) {
|
||||
if (options_get_number(&w->options, "automatic-rename"))
|
||||
queue_window_name(w);
|
||||
else if (event_initialized(&w->name_timer))
|
||||
evtimer_del(&w->name_timer);
|
||||
w->active->flags |= PANE_CHANGED;
|
||||
}
|
||||
}
|
||||
if (strcmp(oe->name, "status") == 0 ||
|
||||
|
63
names.c
63
names.c
@ -25,47 +25,76 @@
|
||||
|
||||
#include "tmux.h"
|
||||
|
||||
void window_name_callback(unused int, unused short, void *);
|
||||
void name_time_callback(int, short, void *);
|
||||
int name_time_expired(struct window *, struct timeval *);
|
||||
|
||||
void
|
||||
queue_window_name(struct window *w)
|
||||
name_time_callback(unused int fd, unused short events, void *arg)
|
||||
{
|
||||
struct timeval tv;
|
||||
struct window *w = arg;
|
||||
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = NAME_INTERVAL * 1000L;
|
||||
/* The event loop will call check_window_name for us on the way out. */
|
||||
log_debug("@%u name timer expired", w->id);
|
||||
}
|
||||
|
||||
if (event_initialized(&w->name_timer))
|
||||
evtimer_del(&w->name_timer);
|
||||
evtimer_set(&w->name_timer, window_name_callback, w);
|
||||
evtimer_add(&w->name_timer, &tv);
|
||||
int
|
||||
name_time_expired(struct window *w, struct timeval *tv)
|
||||
{
|
||||
struct timeval offset;
|
||||
|
||||
timersub(tv, &w->name_time, &offset);
|
||||
if (offset.tv_sec != 0 || offset.tv_usec > NAME_INTERVAL)
|
||||
return (0);
|
||||
return (NAME_INTERVAL - offset.tv_usec);
|
||||
}
|
||||
|
||||
void
|
||||
window_name_callback(unused int fd, unused short events, void *data)
|
||||
check_window_name(struct window *w)
|
||||
{
|
||||
struct window *w = data;
|
||||
struct timeval tv, next;
|
||||
char *name;
|
||||
int left;
|
||||
|
||||
if (w->active == NULL)
|
||||
return;
|
||||
|
||||
if (!options_get_number(&w->options, "automatic-rename")) {
|
||||
if (event_initialized(&w->name_timer))
|
||||
event_del(&w->name_timer);
|
||||
if (!options_get_number(&w->options, "automatic-rename"))
|
||||
return;
|
||||
|
||||
if (~w->active->flags & PANE_CHANGED) {
|
||||
log_debug("@%u active pane not changed", w->id);
|
||||
return;
|
||||
}
|
||||
queue_window_name(w);
|
||||
log_debug("@%u active pane changed", w->id);
|
||||
|
||||
if (~w->active->flags & PANE_CHANGED)
|
||||
gettimeofday(&tv, NULL);
|
||||
left = name_time_expired(w, &tv);
|
||||
if (left != 0) {
|
||||
if (!event_initialized(&w->name_event))
|
||||
evtimer_set(&w->name_event, name_time_callback, w);
|
||||
if (!evtimer_pending(&w->name_event, NULL)) {
|
||||
log_debug("@%u name timer queued (%d left)", w->id, left);
|
||||
timerclear(&next);
|
||||
next.tv_usec = left;
|
||||
event_add(&w->name_event, &next);
|
||||
} else
|
||||
log_debug("@%u name timer already queued (%d left)", w->id, left);
|
||||
return;
|
||||
}
|
||||
memcpy(&w->name_time, &tv, sizeof w->name_time);
|
||||
if (event_initialized(&w->name_event))
|
||||
evtimer_del(&w->name_event);
|
||||
|
||||
w->active->flags &= ~PANE_CHANGED;
|
||||
|
||||
name = format_window_name(w);
|
||||
if (strcmp(name, w->name) != 0) {
|
||||
log_debug("@%u new name %s (was %s)", w->id, name, w->name);
|
||||
window_set_name(w, name);
|
||||
server_status_window(w);
|
||||
}
|
||||
} else
|
||||
log_debug("@%u name not changed (still %s)", w->id, w->name);
|
||||
|
||||
free(name);
|
||||
}
|
||||
|
||||
|
@ -49,6 +49,7 @@ server_window_loop(void)
|
||||
server_status_session(s);
|
||||
}
|
||||
}
|
||||
check_window_name(w);
|
||||
}
|
||||
}
|
||||
|
||||
|
11
tmux.h
11
tmux.h
@ -47,8 +47,8 @@ extern char **environ;
|
||||
*/
|
||||
#define PANE_MINIMUM 2
|
||||
|
||||
/* Automatic name refresh interval, in milliseconds. */
|
||||
#define NAME_INTERVAL 500
|
||||
/* Automatic name refresh interval, in microseconds. Must be < 1 second. */
|
||||
#define NAME_INTERVAL 500000
|
||||
|
||||
/*
|
||||
* UTF-8 data size. This must be big enough to hold combined characters as well
|
||||
@ -869,8 +869,11 @@ RB_HEAD(window_pane_tree, window_pane);
|
||||
/* Window structure. */
|
||||
struct window {
|
||||
u_int id;
|
||||
|
||||
char *name;
|
||||
struct event name_timer;
|
||||
struct event name_event;
|
||||
struct timeval name_time;
|
||||
|
||||
struct timeval silence_timer;
|
||||
struct timeval activity_time;
|
||||
|
||||
@ -2209,7 +2212,7 @@ void window_choose_collapse_all(struct window_pane *);
|
||||
void window_choose_set_current(struct window_pane *, u_int);
|
||||
|
||||
/* names.c */
|
||||
void queue_window_name(struct window *);
|
||||
void check_window_name(struct window *);
|
||||
char *default_window_name(struct window *);
|
||||
char *format_window_name(struct window *);
|
||||
char *parse_window_name(const char *);
|
||||
|
6
window.c
6
window.c
@ -299,8 +299,6 @@ window_create1(u_int sx, u_int sy)
|
||||
fatal("gettimeofday failed");
|
||||
|
||||
options_init(&w->options, &global_w_options);
|
||||
if (options_get_number(&w->options, "automatic-rename"))
|
||||
queue_window_name(w);
|
||||
|
||||
w->references = 0;
|
||||
|
||||
@ -349,8 +347,8 @@ window_destroy(struct window *w)
|
||||
layout_free_cell(w->saved_layout_root);
|
||||
free(w->old_layout);
|
||||
|
||||
if (event_initialized(&w->name_timer))
|
||||
evtimer_del(&w->name_timer);
|
||||
if (event_initialized(&w->name_event))
|
||||
evtimer_del(&w->name_event);
|
||||
|
||||
options_free(&w->options);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user