mirror of
https://github.com/tmate-io/tmate.git
synced 2025-02-22 21:31:16 +01:00
Give clock mode its own timer.
This commit is contained in:
parent
75d10058a4
commit
6419f66523
9
server.c
9
server.c
@ -504,8 +504,6 @@ server_child_stopped(pid_t pid, int status)
|
||||
void
|
||||
server_second_callback(unused int fd, unused short events, unused void *arg)
|
||||
{
|
||||
struct window *w;
|
||||
struct window_pane *wp;
|
||||
struct timeval tv;
|
||||
|
||||
if (options_get_number(&global_s_options, "lock-server"))
|
||||
@ -513,13 +511,6 @@ server_second_callback(unused int fd, unused short events, unused void *arg)
|
||||
else
|
||||
server_lock_sessions();
|
||||
|
||||
RB_FOREACH(w, windows, &windows) {
|
||||
TAILQ_FOREACH(wp, &w->panes, entry) {
|
||||
if (wp->mode != NULL && wp->mode->timer != NULL)
|
||||
wp->mode->timer(wp);
|
||||
}
|
||||
}
|
||||
|
||||
evtimer_del(&server_ev_second);
|
||||
memset(&tv, 0, sizeof tv);
|
||||
tv.tv_sec = 1;
|
||||
|
1
tmux.h
1
tmux.h
@ -777,7 +777,6 @@ struct window_mode {
|
||||
void (*resize)(struct window_pane *, u_int, u_int);
|
||||
void (*key)(struct window_pane *, struct client *, struct session *,
|
||||
int, struct mouse_event *);
|
||||
void (*timer)(struct window_pane *);
|
||||
};
|
||||
|
||||
/* Structures for choose mode. */
|
||||
|
@ -57,7 +57,6 @@ const struct window_mode window_choose_mode = {
|
||||
window_choose_free,
|
||||
window_choose_resize,
|
||||
window_choose_key,
|
||||
NULL,
|
||||
};
|
||||
|
||||
struct window_choose_mode_item {
|
||||
|
@ -29,8 +29,8 @@ void window_clock_free(struct window_pane *);
|
||||
void window_clock_resize(struct window_pane *, u_int, u_int);
|
||||
void window_clock_key(struct window_pane *, struct client *,
|
||||
struct session *, int, struct mouse_event *);
|
||||
void window_clock_timer(struct window_pane *);
|
||||
|
||||
void window_clock_timer_callback(int, short, void *);
|
||||
void window_clock_draw_screen(struct window_pane *);
|
||||
|
||||
const struct window_mode window_clock_mode = {
|
||||
@ -38,12 +38,12 @@ const struct window_mode window_clock_mode = {
|
||||
window_clock_free,
|
||||
window_clock_resize,
|
||||
window_clock_key,
|
||||
window_clock_timer,
|
||||
};
|
||||
|
||||
struct window_clock_mode_data {
|
||||
struct screen screen;
|
||||
time_t tim;
|
||||
struct event timer;
|
||||
};
|
||||
|
||||
const char window_clock_table[14][5][5] = {
|
||||
@ -119,15 +119,42 @@ const char window_clock_table[14][5][5] = {
|
||||
{ 1,0,0,0,1 } },
|
||||
};
|
||||
|
||||
void
|
||||
window_clock_timer_callback(unused int fd, unused short events, void *arg)
|
||||
{
|
||||
struct window_pane *wp = arg;
|
||||
struct window_clock_mode_data *data = wp->modedata;
|
||||
struct tm now, then;
|
||||
time_t t;
|
||||
struct timeval tv = { .tv_sec = 1 };
|
||||
|
||||
evtimer_del(&data->timer);
|
||||
evtimer_add(&data->timer, &tv);
|
||||
|
||||
t = time(NULL);
|
||||
gmtime_r(&t, &now);
|
||||
gmtime_r(&data->tim, &then);
|
||||
if (now.tm_min == then.tm_min)
|
||||
return;
|
||||
data->tim = t;
|
||||
|
||||
window_clock_draw_screen(wp);
|
||||
server_redraw_window(wp->window);
|
||||
}
|
||||
|
||||
struct screen *
|
||||
window_clock_init(struct window_pane *wp)
|
||||
{
|
||||
struct window_clock_mode_data *data;
|
||||
struct screen *s;
|
||||
struct timeval tv = { .tv_sec = 1 };
|
||||
|
||||
wp->modedata = data = xmalloc(sizeof *data);
|
||||
data->tim = time(NULL);
|
||||
|
||||
evtimer_set(&data->timer, window_clock_timer_callback, wp);
|
||||
evtimer_add(&data->timer, &tv);
|
||||
|
||||
s = &data->screen;
|
||||
screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
|
||||
s->mode &= ~MODE_CURSOR;
|
||||
@ -142,6 +169,7 @@ window_clock_free(struct window_pane *wp)
|
||||
{
|
||||
struct window_clock_mode_data *data = wp->modedata;
|
||||
|
||||
evtimer_del(&data->timer);
|
||||
screen_free(&data->screen);
|
||||
free(data);
|
||||
}
|
||||
@ -163,24 +191,6 @@ window_clock_key(struct window_pane *wp, unused struct client *c,
|
||||
window_pane_reset_mode(wp);
|
||||
}
|
||||
|
||||
void
|
||||
window_clock_timer(struct window_pane *wp)
|
||||
{
|
||||
struct window_clock_mode_data *data = wp->modedata;
|
||||
struct tm now, then;
|
||||
time_t t;
|
||||
|
||||
t = time(NULL);
|
||||
gmtime_r(&t, &now);
|
||||
gmtime_r(&data->tim, &then);
|
||||
if (now.tm_min == then.tm_min)
|
||||
return;
|
||||
data->tim = t;
|
||||
|
||||
window_clock_draw_screen(wp);
|
||||
server_redraw_window(wp->window);
|
||||
}
|
||||
|
||||
void
|
||||
window_clock_draw_screen(struct window_pane *wp)
|
||||
{
|
||||
|
@ -91,7 +91,6 @@ const struct window_mode window_copy_mode = {
|
||||
window_copy_free,
|
||||
window_copy_resize,
|
||||
window_copy_key,
|
||||
NULL,
|
||||
};
|
||||
|
||||
enum window_copy_input_type {
|
||||
|
Loading…
Reference in New Issue
Block a user