Annotation of src/usr.bin/tmux/window-clock.c, Revision 1.8
1.8 ! nicm 1: /* $OpenBSD: window-clock.c,v 1.7 2012/07/10 11:53:01 nicm Exp $ */
1.1 nicm 2:
3: /*
4: * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net>
5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15: * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16: * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: */
18:
19: #include <sys/types.h>
20:
1.7 nicm 21: #include <stdlib.h>
1.1 nicm 22: #include <string.h>
23: #include <time.h>
24:
25: #include "tmux.h"
26:
27: struct screen *window_clock_init(struct window_pane *);
28: void window_clock_free(struct window_pane *);
29: void window_clock_resize(struct window_pane *, u_int, u_int);
1.6 nicm 30: void window_clock_key(struct window_pane *, struct session *, int);
1.1 nicm 31: void window_clock_timer(struct window_pane *);
32:
33: void window_clock_draw_screen(struct window_pane *);
34:
35: const struct window_mode window_clock_mode = {
36: window_clock_init,
37: window_clock_free,
38: window_clock_resize,
39: window_clock_key,
40: NULL,
41: window_clock_timer,
42: };
43:
44: struct window_clock_mode_data {
45: struct screen screen;
46: time_t tim;
47: };
48:
49: struct screen *
50: window_clock_init(struct window_pane *wp)
51: {
52: struct window_clock_mode_data *data;
53: struct screen *s;
54:
55: wp->modedata = data = xmalloc(sizeof *data);
56: data->tim = time(NULL);
57:
58: s = &data->screen;
59: screen_init(s, screen_size_x(&wp->base), screen_size_y(&wp->base), 0);
60: s->mode &= ~MODE_CURSOR;
61:
62: window_clock_draw_screen(wp);
63:
64: return (s);
65: }
66:
67: void
68: window_clock_free(struct window_pane *wp)
69: {
70: struct window_clock_mode_data *data = wp->modedata;
71:
72: screen_free(&data->screen);
1.7 nicm 73: free(data);
1.1 nicm 74: }
75:
76: void
77: window_clock_resize(struct window_pane *wp, u_int sx, u_int sy)
78: {
79: struct window_clock_mode_data *data = wp->modedata;
80: struct screen *s = &data->screen;
81:
1.8 ! nicm 82: screen_resize(s, sx, sy, 0);
1.1 nicm 83: window_clock_draw_screen(wp);
84: }
85:
1.3 nicm 86: /* ARGSUSED */
1.1 nicm 87: void
88: window_clock_key(
1.6 nicm 89: struct window_pane *wp, unused struct session *sess, unused int key)
1.1 nicm 90: {
91: window_pane_reset_mode(wp);
92: }
93:
94: void
95: window_clock_timer(struct window_pane *wp)
96: {
97: struct window_clock_mode_data *data = wp->modedata;
1.2 nicm 98: struct tm now, then;
1.1 nicm 99: time_t t;
100:
101: t = time(NULL);
1.2 nicm 102: gmtime_r(&t, &now);
103: gmtime_r(&data->tim, &then);
104: if (now.tm_min == then.tm_min)
1.1 nicm 105: return;
106: data->tim = t;
107:
108: window_clock_draw_screen(wp);
109: server_redraw_window(wp->window);
110: }
111:
112: void
113: window_clock_draw_screen(struct window_pane *wp)
114: {
115: struct window_clock_mode_data *data = wp->modedata;
116: struct screen_write_ctx ctx;
1.4 nicm 117: int colour, style;
1.1 nicm 118:
119: colour = options_get_number(&wp->window->options, "clock-mode-colour");
120: style = options_get_number(&wp->window->options, "clock-mode-style");
121:
122: screen_write_start(&ctx, NULL, &data->screen);
123: clock_draw(&ctx, colour, style);
124: screen_write_stop(&ctx);
125: }