Annotation of src/usr.bin/tmux/screen-redraw.c, Revision 1.40
1.40 ! nicm 1: /* $OpenBSD: screen-redraw.c,v 1.39 2016/10/10 21:29:23 nicm Exp $ */
1.1 nicm 2:
3: /*
1.35 nicm 4: * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com>
1.1 nicm 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:
21: #include <string.h>
22:
23: #include "tmux.h"
24:
1.39 nicm 25: static int screen_redraw_cell_border1(struct window_pane *, u_int, u_int);
26: static int screen_redraw_cell_border(struct client *, u_int, u_int);
27: static int screen_redraw_check_cell(struct client *, u_int, u_int, int,
28: struct window_pane **);
29: static int screen_redraw_check_is(u_int, u_int, int, int, struct window *,
30: struct window_pane *, struct window_pane *);
31:
32: static int screen_redraw_make_pane_status(struct client *, struct window *,
33: struct window_pane *);
34: static void screen_redraw_draw_pane_status(struct client *, int);
35:
36: static void screen_redraw_draw_borders(struct client *, int, int, u_int);
37: static void screen_redraw_draw_panes(struct client *, u_int);
38: static void screen_redraw_draw_status(struct client *, u_int);
39: static void screen_redraw_draw_number(struct client *, struct window_pane *,
40: u_int);
1.1 nicm 41:
1.6 nicm 42: #define CELL_INSIDE 0
1.7 nicm 43: #define CELL_LEFTRIGHT 1
44: #define CELL_TOPBOTTOM 2
45: #define CELL_TOPLEFT 3
46: #define CELL_TOPRIGHT 4
47: #define CELL_BOTTOMLEFT 5
48: #define CELL_BOTTOMRIGHT 6
49: #define CELL_TOPJOIN 7
50: #define CELL_BOTTOMJOIN 8
51: #define CELL_LEFTJOIN 9
52: #define CELL_RIGHTJOIN 10
53: #define CELL_JOIN 11
54: #define CELL_OUTSIDE 12
1.6 nicm 55:
1.17 nicm 56: #define CELL_BORDERS " xqlkmjwvtun~"
57:
1.36 nicm 58: #define CELL_STATUS_OFF 0
59: #define CELL_STATUS_TOP 1
60: #define CELL_STATUS_BOTTOM 2
61:
1.15 nicm 62: /* Check if cell is on the border of a particular pane. */
1.39 nicm 63: static int
1.15 nicm 64: screen_redraw_cell_border1(struct window_pane *wp, u_int px, u_int py)
65: {
66: /* Inside pane. */
67: if (px >= wp->xoff && px < wp->xoff + wp->sx &&
68: py >= wp->yoff && py < wp->yoff + wp->sy)
69: return (0);
70:
71: /* Left/right borders. */
72: if ((wp->yoff == 0 || py >= wp->yoff - 1) && py <= wp->yoff + wp->sy) {
73: if (wp->xoff != 0 && px == wp->xoff - 1)
74: return (1);
75: if (px == wp->xoff + wp->sx)
1.36 nicm 76: return (2);
1.15 nicm 77: }
78:
79: /* Top/bottom borders. */
80: if ((wp->xoff == 0 || px >= wp->xoff - 1) && px <= wp->xoff + wp->sx) {
81: if (wp->yoff != 0 && py == wp->yoff - 1)
1.36 nicm 82: return (3);
1.15 nicm 83: if (py == wp->yoff + wp->sy)
1.36 nicm 84: return (4);
1.15 nicm 85: }
86:
87: /* Outside pane. */
88: return (-1);
89: }
90:
1.7 nicm 91: /* Check if a cell is on the pane border. */
1.39 nicm 92: static int
1.7 nicm 93: screen_redraw_cell_border(struct client *c, u_int px, u_int py)
1.1 nicm 94: {
95: struct window *w = c->session->curw->window;
96: struct window_pane *wp;
1.15 nicm 97: int retval;
1.1 nicm 98:
1.7 nicm 99: /* Check all the panes. */
1.1 nicm 100: TAILQ_FOREACH(wp, &w->panes, entry) {
1.3 nicm 101: if (!window_pane_visible(wp))
102: continue;
1.15 nicm 103: if ((retval = screen_redraw_cell_border1(wp, px, py)) != -1)
1.36 nicm 104: return (!!retval);
1.7 nicm 105: }
106:
107: return (0);
108: }
109:
110: /* Check if cell inside a pane. */
1.39 nicm 111: static int
1.36 nicm 112: screen_redraw_check_cell(struct client *c, u_int px, u_int py, int pane_status,
1.24 nicm 113: struct window_pane **wpp)
1.7 nicm 114: {
115: struct window *w = c->session->curw->window;
116: struct window_pane *wp;
117: int borders;
1.36 nicm 118: u_int right, line;
1.7 nicm 119:
1.39 nicm 120: *wpp = NULL;
121:
1.7 nicm 122: if (px > w->sx || py > w->sy)
123: return (CELL_OUTSIDE);
124:
1.36 nicm 125: if (pane_status != CELL_STATUS_OFF) {
126: TAILQ_FOREACH(wp, &w->panes, entry) {
127: if (!window_pane_visible(wp))
128: continue;
129:
130: if (pane_status == CELL_STATUS_TOP)
131: line = wp->yoff - 1;
132: else
133: line = wp->yoff + wp->sy;
134: right = wp->xoff + 2 + wp->status_size - 1;
135:
136: if (py == line && px >= wp->xoff + 2 && px <= right)
137: return (CELL_INSIDE);
138: }
139: }
140:
1.7 nicm 141: TAILQ_FOREACH(wp, &w->panes, entry) {
142: if (!window_pane_visible(wp))
143: continue;
1.24 nicm 144: *wpp = wp;
1.7 nicm 145:
146: /* If outside the pane and its border, skip it. */
147: if ((wp->xoff != 0 && px < wp->xoff - 1) ||
148: px > wp->xoff + wp->sx ||
149: (wp->yoff != 0 && py < wp->yoff - 1) ||
150: py > wp->yoff + wp->sy)
151: continue;
152:
153: /* If definitely inside, return so. */
154: if (!screen_redraw_cell_border(c, px, py))
155: return (CELL_INSIDE);
156:
1.14 nicm 157: /*
1.7 nicm 158: * Construct a bitmask of whether the cells to the left (bit
159: * 4), right, top, and bottom (bit 1) of this cell are borders.
160: */
161: borders = 0;
162: if (px == 0 || screen_redraw_cell_border(c, px - 1, py))
163: borders |= 8;
164: if (px <= w->sx && screen_redraw_cell_border(c, px + 1, py))
165: borders |= 4;
1.36 nicm 166: if (pane_status == CELL_STATUS_TOP) {
167: if (py != 0 && screen_redraw_cell_border(c, px, py - 1))
168: borders |= 2;
169: } else {
170: if (py == 0 || screen_redraw_cell_border(c, px, py - 1))
171: borders |= 2;
172: }
1.7 nicm 173: if (py <= w->sy && screen_redraw_cell_border(c, px, py + 1))
174: borders |= 1;
175:
1.14 nicm 176: /*
1.7 nicm 177: * Figure out what kind of border this cell is. Only one bit
178: * set doesn't make sense (can't have a border cell with no
179: * others connected).
180: */
181: switch (borders) {
182: case 15: /* 1111, left right top bottom */
183: return (CELL_JOIN);
184: case 14: /* 1110, left right top */
185: return (CELL_BOTTOMJOIN);
186: case 13: /* 1101, left right bottom */
187: return (CELL_TOPJOIN);
188: case 12: /* 1100, left right */
189: return (CELL_TOPBOTTOM);
190: case 11: /* 1011, left top bottom */
191: return (CELL_RIGHTJOIN);
192: case 10: /* 1010, left top */
193: return (CELL_BOTTOMRIGHT);
194: case 9: /* 1001, left bottom */
195: return (CELL_TOPRIGHT);
196: case 7: /* 0111, right top bottom */
197: return (CELL_LEFTJOIN);
198: case 6: /* 0110, right top */
199: return (CELL_BOTTOMLEFT);
200: case 5: /* 0101, right bottom */
201: return (CELL_TOPLEFT);
202: case 3: /* 0011, top bottom */
203: return (CELL_LEFTRIGHT);
1.1 nicm 204: }
205: }
206:
1.6 nicm 207: return (CELL_OUTSIDE);
1.1 nicm 208: }
209:
1.32 nicm 210: /* Check if the border of a particular pane. */
1.39 nicm 211: static int
1.36 nicm 212: screen_redraw_check_is(u_int px, u_int py, int type, int pane_status,
213: struct window *w, struct window_pane *wantwp, struct window_pane *wp)
1.24 nicm 214: {
1.36 nicm 215: int border;
216:
1.24 nicm 217: /* Is this off the active pane border? */
1.36 nicm 218: border = screen_redraw_cell_border1(wantwp, px, py);
219: if (border == 0 || border == -1)
220: return (0);
221: if (pane_status == CELL_STATUS_TOP && border == 4)
222: return (0);
223: if (pane_status == CELL_STATUS_BOTTOM && border == 3)
1.24 nicm 224: return (0);
225:
226: /* If there are more than two panes, that's enough. */
227: if (window_count_panes(w) != 2)
228: return (1);
229:
230: /* Else if the cell is not a border cell, forget it. */
231: if (wp == NULL || (type == CELL_OUTSIDE || type == CELL_INSIDE))
232: return (1);
233:
1.36 nicm 234: /* With status lines mark the entire line. */
235: if (pane_status != CELL_STATUS_OFF)
236: return (1);
237:
1.24 nicm 238: /* Check if the pane covers the whole width. */
239: if (wp->xoff == 0 && wp->sx == w->sx) {
240: /* This can either be the top pane or the bottom pane. */
241: if (wp->yoff == 0) { /* top pane */
1.32 nicm 242: if (wp == wantwp)
1.24 nicm 243: return (px <= wp->sx / 2);
244: return (px > wp->sx / 2);
245: }
246: return (0);
247: }
248:
249: /* Check if the pane covers the whole height. */
250: if (wp->yoff == 0 && wp->sy == w->sy) {
251: /* This can either be the left pane or the right pane. */
252: if (wp->xoff == 0) { /* left pane */
1.32 nicm 253: if (wp == wantwp)
1.24 nicm 254: return (py <= wp->sy / 2);
255: return (py > wp->sy / 2);
256: }
257: return (0);
258: }
259:
1.36 nicm 260: return (1);
261: }
262:
263: /* Update pane status. */
1.39 nicm 264: static int
1.36 nicm 265: screen_redraw_make_pane_status(struct client *c, struct window *w,
266: struct window_pane *wp)
267: {
268: struct grid_cell gc;
269: const char *fmt;
270: struct format_tree *ft;
271: char *out;
1.40 ! nicm 272: size_t outlen;
1.36 nicm 273: struct screen_write_ctx ctx;
1.40 ! nicm 274: struct screen old;
1.36 nicm 275:
276: if (wp == w->active)
277: style_apply(&gc, w->options, "pane-active-border-style");
278: else
279: style_apply(&gc, w->options, "pane-border-style");
280:
281: fmt = options_get_string(w->options, "pane-border-format");
282:
283: ft = format_create(NULL, 0);
284: format_defaults(ft, c, NULL, NULL, wp);
285:
1.40 ! nicm 286: memcpy(&old, &wp->status_screen, sizeof old);
1.36 nicm 287: screen_init(&wp->status_screen, wp->sx, 1, 0);
288: wp->status_screen.mode = 0;
289:
290: out = format_expand(ft, fmt);
291: outlen = screen_write_cstrlen("%s", out);
292: if (outlen > wp->sx - 4)
293: outlen = wp->sx - 4;
294: screen_resize(&wp->status_screen, outlen, 1, 0);
295:
296: screen_write_start(&ctx, NULL, &wp->status_screen);
297: screen_write_cursormove(&ctx, 0, 0);
298: screen_write_clearline(&ctx);
299: screen_write_cnputs(&ctx, outlen, &gc, "%s", out);
300: screen_write_stop(&ctx);
301:
302: format_free(ft);
303:
304: wp->status_size = outlen;
1.40 ! nicm 305:
! 306: if (grid_compare(wp->status_screen.grid, old.grid) == 0) {
! 307: screen_free(&old);
! 308: return (0);
! 309: }
! 310: screen_free(&old);
! 311: return (1);
1.36 nicm 312: }
313:
314: /* Draw pane status. */
1.39 nicm 315: static void
1.36 nicm 316: screen_redraw_draw_pane_status(struct client *c, int pane_status)
317: {
318: struct window *w = c->session->curw->window;
319: struct options *oo = c->session->options;
320: struct tty *tty = &c->tty;
321: struct window_pane *wp;
322: int spos;
323: u_int yoff;
324:
325: spos = options_get_number(oo, "status-position");
326: TAILQ_FOREACH(wp, &w->panes, entry) {
1.40 ! nicm 327: if (!window_pane_visible(wp))
! 328: continue;
1.36 nicm 329: if (pane_status == CELL_STATUS_TOP)
330: yoff = wp->yoff - 1;
331: else
332: yoff = wp->yoff + wp->sy;
333: if (spos == 0)
334: yoff += 1;
335:
336: tty_draw_line(tty, NULL, &wp->status_screen, 0, wp->xoff + 2,
337: yoff);
338: }
339: tty_cursor(tty, 0, 0);
1.24 nicm 340: }
341:
1.38 nicm 342: /* Update status line and change flags if unchanged. */
343: void
344: screen_redraw_update(struct client *c)
345: {
346: struct window *w = c->session->curw->window;
347: struct window_pane *wp;
348: struct options *wo = w->options;
349: int redraw;
350:
351: if (c->message_string != NULL)
352: redraw = status_message_redraw(c);
353: else if (c->prompt_string != NULL)
354: redraw = status_prompt_redraw(c);
355: else
356: redraw = status_redraw(c);
357: if (!redraw)
358: c->flags &= ~CLIENT_STATUS;
359:
360: if (options_get_number(wo, "pane-border-status") != CELL_STATUS_OFF) {
361: redraw = 0;
362: TAILQ_FOREACH(wp, &w->panes, entry) {
363: if (screen_redraw_make_pane_status(c, w, wp))
364: redraw = 1;
365: }
366: if (redraw)
367: c->flags |= CLIENT_BORDERS;
368: }
369: }
370:
1.4 nicm 371: /* Redraw entire screen. */
1.1 nicm 372: void
1.26 nicm 373: screen_redraw_screen(struct client *c, int draw_panes, int draw_status,
374: int draw_borders)
1.1 nicm 375: {
1.36 nicm 376: struct options *oo = c->session->options;
377: struct tty *tty = &c->tty;
378: struct window *w = c->session->curw->window;
1.38 nicm 379: struct options *wo = w->options;
1.36 nicm 380: u_int top;
381: int status, pane_status, spos;
1.18 nicm 382:
383: /* Suspended clients should not be updated. */
384: if (c->flags & CLIENT_SUSPENDED)
385: return;
1.1 nicm 386:
387: /* Get status line, er, status. */
1.21 nicm 388: spos = options_get_number(oo, "status-position");
1.4 nicm 389: if (c->message_string != NULL || c->prompt_string != NULL)
390: status = 1;
391: else
1.21 nicm 392: status = options_get_number(oo, "status");
393: top = 0;
394: if (status && spos == 0)
395: top = 1;
1.26 nicm 396: if (!status)
397: draw_status = 0;
398:
1.36 nicm 399: /* Draw the elements. */
1.38 nicm 400: if (draw_borders) {
401: pane_status = options_get_number(wo, "pane-border-status");
1.36 nicm 402: screen_redraw_draw_borders(c, status, pane_status, top);
1.38 nicm 403: if (pane_status != CELL_STATUS_OFF)
404: screen_redraw_draw_pane_status(c, pane_status);
405: }
1.26 nicm 406: if (draw_panes)
407: screen_redraw_draw_panes(c, top);
408: if (draw_status)
409: screen_redraw_draw_status(c, top);
410: tty_reset(tty);
411: }
1.4 nicm 412:
1.26 nicm 413: /* Draw a single pane. */
414: void
415: screen_redraw_pane(struct client *c, struct window_pane *wp)
416: {
417: u_int i, yoff;
418:
419: if (!window_pane_visible(wp))
1.4 nicm 420: return;
1.1 nicm 421:
1.26 nicm 422: yoff = wp->yoff;
423: if (status_at_line(c) == 0)
424: yoff++;
425:
426: for (i = 0; i < wp->sy; i++)
1.30 nicm 427: tty_draw_pane(&c->tty, wp, i, wp->xoff, yoff);
1.26 nicm 428: tty_reset(&c->tty);
429: }
430:
431: /* Draw the borders. */
1.39 nicm 432: static void
1.36 nicm 433: screen_redraw_draw_borders(struct client *c, int status, int pane_status,
434: u_int top)
1.26 nicm 435: {
1.32 nicm 436: struct session *s = c->session;
437: struct window *w = s->curw->window;
1.33 nicm 438: struct options *oo = w->options;
1.26 nicm 439: struct tty *tty = &c->tty;
440: struct window_pane *wp;
1.32 nicm 441: struct grid_cell m_active_gc, active_gc, m_other_gc, other_gc;
442: struct grid_cell msg_gc;
1.28 nicm 443: u_int i, j, type, msgx = 0, msgy = 0;
1.32 nicm 444: int active, small, flags;
1.28 nicm 445: char msg[256];
446: const char *tmp;
447: size_t msglen = 0;
448:
449: small = (tty->sy - status + top > w->sy) || (tty->sx > w->sx);
450: if (small) {
451: flags = w->flags & (WINDOW_FORCEWIDTH|WINDOW_FORCEHEIGHT);
452: if (flags == (WINDOW_FORCEWIDTH|WINDOW_FORCEHEIGHT))
453: tmp = "force-width, force-height";
454: else if (flags == WINDOW_FORCEWIDTH)
455: tmp = "force-width";
456: else if (flags == WINDOW_FORCEHEIGHT)
457: tmp = "force-height";
458: else
459: tmp = "a smaller client";
460: xsnprintf(msg, sizeof msg, "(size %ux%u from %s)",
461: w->sx, w->sy, tmp);
462: msglen = strlen(msg);
463:
464: if (tty->sy - 1 - status + top > w->sy && tty->sx >= msglen) {
465: msgx = tty->sx - msglen;
466: msgy = tty->sy - 1 - status + top;
467: } else if (tty->sx - w->sx > msglen) {
468: msgx = tty->sx - msglen;
469: msgy = tty->sy - 1 - status + top;
470: } else
471: small = 0;
472: }
1.26 nicm 473:
1.25 nicm 474: style_apply(&other_gc, oo, "pane-border-style");
475: style_apply(&active_gc, oo, "pane-active-border-style");
1.26 nicm 476: active_gc.attr = other_gc.attr = GRID_ATTR_CHARSET;
1.15 nicm 477:
1.32 nicm 478: memcpy(&m_other_gc, &other_gc, sizeof m_other_gc);
479: m_other_gc.attr ^= GRID_ATTR_REVERSE;
480: memcpy(&m_active_gc, &active_gc, sizeof m_active_gc);
481: m_active_gc.attr ^= GRID_ATTR_REVERSE;
482:
1.1 nicm 483: for (j = 0; j < tty->sy - status; j++) {
484: for (i = 0; i < tty->sx; i++) {
1.36 nicm 485: type = screen_redraw_check_cell(c, i, j, pane_status,
486: &wp);
1.15 nicm 487: if (type == CELL_INSIDE)
488: continue;
1.32 nicm 489: if (type == CELL_OUTSIDE && small &&
490: i > msgx && j == msgy)
1.28 nicm 491: continue;
1.36 nicm 492: active = screen_redraw_check_is(i, j, type, pane_status,
493: w, w->active, wp);
1.34 nicm 494: if (server_is_marked(s, s->curw, marked_pane.wp) &&
1.36 nicm 495: screen_redraw_check_is(i, j, type, pane_status, w,
1.34 nicm 496: marked_pane.wp, wp)) {
1.32 nicm 497: if (active)
498: tty_attributes(tty, &m_active_gc, NULL);
499: else
500: tty_attributes(tty, &m_other_gc, NULL);
501: } else if (active)
1.30 nicm 502: tty_attributes(tty, &active_gc, NULL);
1.15 nicm 503: else
1.30 nicm 504: tty_attributes(tty, &other_gc, NULL);
1.21 nicm 505: tty_cursor(tty, i, top + j);
1.17 nicm 506: tty_putc(tty, CELL_BORDERS[type]);
1.1 nicm 507: }
1.28 nicm 508: }
509:
510: if (small) {
511: memcpy(&msg_gc, &grid_default_cell, sizeof msg_gc);
1.30 nicm 512: tty_attributes(tty, &msg_gc, NULL);
1.28 nicm 513: tty_cursor(tty, msgx, msgy);
514: tty_puts(tty, msg);
1.1 nicm 515: }
1.26 nicm 516: }
1.1 nicm 517:
1.26 nicm 518: /* Draw the panes. */
1.39 nicm 519: static void
1.26 nicm 520: screen_redraw_draw_panes(struct client *c, u_int top)
521: {
522: struct window *w = c->session->curw->window;
523: struct tty *tty = &c->tty;
524: struct window_pane *wp;
525: u_int i;
1.15 nicm 526:
1.1 nicm 527: TAILQ_FOREACH(wp, &w->panes, entry) {
1.3 nicm 528: if (!window_pane_visible(wp))
1.1 nicm 529: continue;
1.26 nicm 530: for (i = 0; i < wp->sy; i++)
1.30 nicm 531: tty_draw_pane(tty, wp, i, wp->xoff, top + wp->yoff);
1.10 nicm 532: if (c->flags & CLIENT_IDENTIFY)
1.31 nicm 533: screen_redraw_draw_number(c, wp, top);
1.1 nicm 534: }
535: }
536:
1.26 nicm 537: /* Draw the status line. */
1.39 nicm 538: static void
1.26 nicm 539: screen_redraw_draw_status(struct client *c, u_int top)
1.1 nicm 540: {
1.26 nicm 541: struct tty *tty = &c->tty;
1.23 nicm 542:
1.26 nicm 543: if (top)
1.30 nicm 544: tty_draw_line(tty, NULL, &c->status, 0, 0, 0);
1.26 nicm 545: else
1.30 nicm 546: tty_draw_line(tty, NULL, &c->status, 0, 0, tty->sy - 1);
1.10 nicm 547: }
548:
549: /* Draw number on a pane. */
1.39 nicm 550: static void
1.31 nicm 551: screen_redraw_draw_number(struct client *c, struct window_pane *wp, u_int top)
1.10 nicm 552: {
553: struct tty *tty = &c->tty;
554: struct session *s = c->session;
1.33 nicm 555: struct options *oo = s->options;
1.16 nicm 556: struct window *w = wp->window;
1.10 nicm 557: struct grid_cell gc;
1.12 nicm 558: u_int idx, px, py, i, j, xoff, yoff;
1.16 nicm 559: int colour, active_colour;
1.10 nicm 560: char buf[16], *ptr;
561: size_t len;
562:
1.19 nicm 563: if (window_pane_index(wp, &idx) != 0)
564: fatalx("index not found");
1.10 nicm 565: len = xsnprintf(buf, sizeof buf, "%u", idx);
566:
567: if (wp->sx < len)
568: return;
1.16 nicm 569: colour = options_get_number(oo, "display-panes-colour");
570: active_colour = options_get_number(oo, "display-panes-active-colour");
1.10 nicm 571:
1.12 nicm 572: px = wp->sx / 2; py = wp->sy / 2;
573: xoff = wp->xoff; yoff = wp->yoff;
1.31 nicm 574:
575: if (top)
576: yoff++;
1.12 nicm 577:
1.10 nicm 578: if (wp->sx < len * 6 || wp->sy < 5) {
1.12 nicm 579: tty_cursor(tty, xoff + px - len / 2, yoff + py);
1.20 nicm 580: goto draw_text;
1.10 nicm 581: }
1.14 nicm 582:
1.10 nicm 583: px -= len * 3;
584: py -= 2;
585:
1.25 nicm 586: memcpy(&gc, &grid_default_cell, sizeof gc);
1.16 nicm 587: if (w->active == wp)
1.37 nicm 588: gc.bg = active_colour;
1.16 nicm 589: else
1.37 nicm 590: gc.bg = colour;
1.30 nicm 591: tty_attributes(tty, &gc, wp);
1.10 nicm 592: for (ptr = buf; *ptr != '\0'; ptr++) {
593: if (*ptr < '0' || *ptr > '9')
594: continue;
595: idx = *ptr - '0';
1.14 nicm 596:
1.10 nicm 597: for (j = 0; j < 5; j++) {
598: for (i = px; i < px + 5; i++) {
1.12 nicm 599: tty_cursor(tty, xoff + i, yoff + py + j);
1.27 nicm 600: if (window_clock_table[idx][j][i - px])
1.11 nicm 601: tty_putc(tty, ' ');
1.10 nicm 602: }
603: }
604: px += 6;
605: }
1.20 nicm 606:
607: len = xsnprintf(buf, sizeof buf, "%ux%u", wp->sx, wp->sy);
608: if (wp->sx < len || wp->sy < 6)
609: return;
610: tty_cursor(tty, xoff + wp->sx - len, yoff);
611:
612: draw_text:
1.25 nicm 613: memcpy(&gc, &grid_default_cell, sizeof gc);
1.20 nicm 614: if (w->active == wp)
1.37 nicm 615: gc.fg = active_colour;
1.20 nicm 616: else
1.37 nicm 617: gc.fg = colour;
1.30 nicm 618: tty_attributes(tty, &gc, wp);
1.20 nicm 619: tty_puts(tty, buf);
620:
621: tty_cursor(tty, 0, 0);
1.1 nicm 622: }