diff options
Diffstat (limited to 'colitur-x.c')
| -rw-r--r-- | colitur-x.c | 39 |
1 files changed, 32 insertions, 7 deletions
diff --git a/colitur-x.c b/colitur-x.c index 5307c24..dffbbe6 100644 --- a/colitur-x.c +++ b/colitur-x.c @@ -198,6 +198,14 @@ static void redraw(void) } fill(col_bg, 0, 0, wa.width, wa.height); + /* Cells are sized from the window, not from a constant, so the grid + fills its tile. Six rows is the most a month can need: 31 days + starting on a Saturday spans six Sunday-started weeks. */ + int CELL_W = (wa.width - 2 * PAD) / 7; + int CELL_H = (wa.height - HEAD_H - DETAIL_H) / 6; + if (CELL_W < CELL_W_MIN) CELL_W = CELL_W_MIN; + if (CELL_H < CELL_H_MIN) CELL_H = CELL_H_MIN; + XftColor head, detail, sel_dark, sel_light, grid; alloc(col_head, &head); alloc(col_detail, &detail); alloc(col_sel_dark, &sel_dark); alloc(col_sel_light, &sel_light); @@ -256,8 +264,11 @@ static void redraw(void) character count, so it is right for any font in config.h. */ const char *nm = rows[i].f[6]; int avail = CELL_W - 12, ty = y + bigh + 8 + fnt->ascent; + int room = (CELL_H - 2 - (bigh + 8)) / lh; /* lines that fit */ + if (room > NAME_LINES_MAX) room = NAME_LINES_MAX; + if (room < 1) room = 1; const char *p = nm; - for (int ln = 0; ln < NAME_LINES && *p; ln++) { + for (int ln = 0; ln < room && *p; ln++) { size_t take = strlen(p), best = 0; XGlyphInfo gi; for (size_t k = 1; k <= take; k++) { @@ -298,8 +309,20 @@ static void redraw(void) } } -int main(void) +static void usage(void) { + fputs("usage: colitur-x [-g WxH] < calendar.csv\n", stderr); + exit(2); +} + +int main(int argc, char **argv) +{ + int w = WIN_W, h = WIN_H; + for (int i = 1; i < argc; i++) { + if (!strcmp(argv[i], "-g") && i + 1 < argc) { + if (sscanf(argv[++i], "%dx%d", &w, &h) != 2) usage(); + } else usage(); + } load(); if (!nrows) { fputs("colitur-x: no rows on stdin\n", stderr); return 2; } select_today(); @@ -309,17 +332,19 @@ int main(void) vis = DefaultVisual(dpy, scr); cmap = DefaultColormap(dpy, scr); - int w = PAD*2 + 7*CELL_W, h = HEAD_H + 6*CELL_H + DETAIL_H; win = XCreateSimpleWindow(dpy, RootWindow(dpy, scr), 0, 0, w, h, 0, BlackPixel(dpy, scr), BlackPixel(dpy, scr)); XStoreName(dpy, win, window_title); - { /* Ask the window manager for exactly the grid we drew. Without - this a tiling or maximising WM picks its own size and the grid - floats in a field of background. */ + { /* A PREFERRED size and a MINIMUM, never a fixed one. Pinning the + size was the earlier mistake: it fights a tiling window manager, + which ignores it anyway, and it stops the grid making use of a + larger tile. The layout reflows, so any size above the minimum + is legitimate. */ XSizeHints *sh = XAllocSizeHints(); sh->flags = PSize | PMinSize; sh->width = w; sh->height = h; - sh->min_width = w; sh->min_height = h; + sh->min_width = PAD*2 + 7*CELL_W_MIN; + sh->min_height = HEAD_H + 6*CELL_H_MIN + DETAIL_H; XSetWMNormalHints(dpy, win, sh); XFree(sh); } |
