=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/window-clock.c,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- src/usr.bin/tmux/window-clock.c 2015/04/19 21:34:21 1.11 +++ src/usr.bin/tmux/window-clock.c 2015/08/28 12:25:42 1.12 @@ -1,4 +1,4 @@ -/* $OpenBSD: window-clock.c,v 1.11 2015/04/19 21:34:21 nicm Exp $ */ +/* $OpenBSD: window-clock.c,v 1.12 2015/08/28 12:25:42 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -29,8 +29,8 @@ 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 @@ 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 @@ { 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 @@ { struct window_clock_mode_data *data = wp->modedata; + evtimer_del(&data->timer); screen_free(&data->screen); free(data); } @@ -161,24 +189,6 @@ unused struct session *sess, unused int key, unused struct mouse_event *m) { 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