diff options
| author | Lukasz Kasprzak <lukasz@arcofasiagroup.com> | 2026-08-21 10:16:51 +0200 |
|---|---|---|
| committer | Lukasz Kasprzak <lukasz@arcofasiagroup.com> | 2026-08-21 10:16:51 +0200 |
| commit | 69add3767988d0dfc6ecac37405cfb10abe8dbb7 (patch) | |
| tree | 8154e3f62a0415e7c99880c24a1f1a56665c143c /colitur-x.c | |
| parent | 31db51d7fb782c8e79bf1df067dadc1a8be63255 (diff) | |
| download | colitur-x-69add3767988d0dfc6ecac37405cfb10abe8dbb7.tar.gz colitur-x-69add3767988d0dfc6ecac37405cfb10abe8dbb7.zip | |
feat(colitur-x): fill the window instead of a fixed grid
Cell size is now computed from the window -- width divided seven ways,
height six -- and the number of lines a feast name gets is whatever fits
the resulting cell. config.h holds minimums rather than sizes.
Under a tiling window manager the calendar now uses its whole tile. It
previously drew a fixed 196x116 grid and left the rest of the tile black,
which is what every screenshot of it has shown.
The size hint is now PREFERRED plus MINIMUM, never fixed. Pinning it
fought the WM, which ignored it anyway, and stopped the grid using a
larger tile.
Added -g WxH, the same flag st takes, mainly because it makes the reflow
testable: verified at 1365x687 (two name lines) and 1852x1024 (three).
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); } |
