diff options
| author | eunhhu <[email protected]> | 2026-10-18 23:54:06 +0100 |
|---|---|---|
| committer | eunhhu <[email protected]> | 2026-10-18 23:54:06 +0100 |
| commit | a2ad1a7a9cd3e608f3fb4e5a694540a9cfef9c69 (patch) | |
| tree | f40556ac45d36bb749ea64948f5e19659a882ee6 /surfaces | |
| parent | da79f1e2b8d49dabe2290f5d795f8809c8b15c0f (diff) | |
| download | vega-master.tar.gz vega-master.zip | |
Size to the module what is the module's (Pure 027's 4f-3a): timers grow to its inputs, the focus marks to its views, the accessibility tree's children to their count; a table shows its first VEGA_COLUMNS (64) columns, Vega's own countHEADmaster
Diffstat (limited to 'surfaces')
| -rw-r--r-- | surfaces/access.c | 13 | ||||
| -rw-r--r-- | surfaces/draw.c | 4 | ||||
| -rw-r--r-- | surfaces/main.c | 4 | ||||
| -rw-r--r-- | surfaces/screen.c | 21 | ||||
| -rw-r--r-- | surfaces/vega.h | 7 | ||||
| -rw-r--r-- | surfaces/web.c | 2 |
6 files changed, 31 insertions, 20 deletions
diff --git a/surfaces/access.c b/surfaces/access.c index 24e3d00..a0255f3 100644 --- a/surfaces/access.c +++ b/surfaces/access.c @@ -162,13 +162,16 @@ static Object parent_of(const Object *o) { } static size_t index_in_parent(const VegaAccess *a, const Object *o) { - Object parent = parent_of(o), kids[VEGA_PARTS + PURE_MODULE_INPUTS + 4]; + Object parent = parent_of(o); if (o->kind == ROW) return o->row; if (o->kind == CELL) return o->column; - size_t n = children(a, &parent, kids, sizeof(kids) / sizeof(*kids)); - for (size_t i = 0; i < n && i < sizeof(kids) / sizeof(*kids); ++i) - if (kids[i].kind == o->kind && kids[i].part == o->part && kids[i].key == o->key) return i; - return 0; + size_t n = children(a, &parent, NULL, 0), at = 0; + Object *kids = malloc((n + 1) * sizeof(*kids)); + if (kids) n = children(a, &parent, kids, n); + for (size_t i = 0; kids && i < n; ++i) + if (kids[i].kind == o->kind && kids[i].part == o->part && kids[i].key == o->key) { at = i; break; } + free(kids); + return at; } static int role_of(const VegaAccess *a, const Object *o) { diff --git a/surfaces/draw.c b/surfaces/draw.c index e02a4ec..fecbed7 100644 --- a/surfaces/draw.c +++ b/surfaces/draw.c @@ -64,7 +64,7 @@ static void print_list(FILE *out, PureApp *app, const VegaPart *part, bool color static void print_table(FILE *out, PureApp *app, const VegaPart *part, bool color) { const PureModule *m = app->module; size_t rows = vega_rows(app, part), focus = vega_focus(app, part); - unsigned widths[PURE_MODULE_VIEWS]; + unsigned widths[VEGA_COLUMNS]; char text[VEGA_TEXT]; size_t length; for (unsigned c = 0; c < part->column_count; ++c) { @@ -416,7 +416,7 @@ static void draw_table(VegaGrid *grid, PureApp *app, const VegaPart *part, int i const PureModule *m = app->module; char text[VEGA_TEXT]; size_t length, rows = vega_rows(app, part), focus = vega_focus(app, part); - unsigned visible = height ? height - 1 : 0, widths[PURE_MODULE_VIEWS], total = 2; + unsigned visible = height ? height - 1 : 0, widths[VEGA_COLUMNS], total = 2; /* Columns as wide as their header and the rows on screen, shared out when too wide. */ for (unsigned c = 0; c < part->column_count; ++c) { const char *name = m->view_names[part->columns[c]]; diff --git a/surfaces/main.c b/surfaces/main.c index da0e4b8..037ff48 100644 --- a/surfaces/main.c +++ b/surfaces/main.c @@ -516,7 +516,7 @@ static int interactive(void) { signal(SIGWINCH, on_resize); VegaGrid grid = {0}; drawn = &grid; - VegaTimers timers; + VegaTimers timers = {0}; vega_timers_start(&timers, app.module, vega_clock()); for (;;) { if (resized) { @@ -688,7 +688,7 @@ static int live(VegaInput *input, unsigned columns, unsigned rows, bool recorded signal(SIGINT, on_stop); signal(SIGTERM, on_stop); } - VegaTimers timers; + VegaTimers timers = {0}; vega_timers_start(&timers, app.module, vega_clock()); char path[512] = ""; unsigned long differing = 0; diff --git a/surfaces/screen.c b/surfaces/screen.c index eeaaa8d..9c5d3fa 100644 --- a/surfaces/screen.c +++ b/surfaces/screen.c @@ -3,6 +3,7 @@ #include "module-text.h" #include <inttypes.h> #include <math.h> +#include <stdlib.h> #include <string.h> #include <time.h> @@ -19,14 +20,18 @@ double vega_clock(void) { } void vega_timers_start(VegaTimers *timers, const PureModule *m, double clock) { - for (uint32_t i = 0; i < m->inputs; ++i) + if (timers->count < m->inputs) { + double *grown = realloc(timers->next, m->inputs * sizeof(*grown)); + if (grown) timers->next = grown, timers->count = m->inputs; /* else its timers past count never tick */ + } + for (uint32_t i = 0; i < m->inputs && i < timers->count; ++i) timers->next[i] = m->input[i].binding == PURE_BIND_TIMER ? clock + m->input[i].period : 0; } long vega_timers_run(VegaTimers *timers, PureApp *app, double clock, bool *ticked) { const PureModule *m = app->module; double soonest = -1; - for (uint32_t i = 0; i < m->inputs; ++i) { + for (uint32_t i = 0; i < m->inputs && i < timers->count; ++i) { if (m->input[i].binding != PURE_BIND_TIMER) continue; if (timers->next[i] <= clock) { app->now = vega_now(); @@ -59,16 +64,16 @@ void vega_screen(VegaScreen *screen, const PureModule *m) { if (m->input[i].binding == PURE_BIND_FRAME) screen->frame = (int)i; } /* A <table>_focus view belongs to its table, not to the fields. */ - bool focus_view[PURE_MODULE_VIEWS] = {false}; + bool *focus_view = calloc(m->views + 1, sizeof(*focus_view)); /* (without room, none is) */ for (uint32_t i = 0; i < m->views; ++i) { if (m->view_type[i] != PURE_VIEW_LIST || m->view_table[i]) continue; char name[PURE_MODULE_NAME + 8]; snprintf(name, sizeof(name), "%s_focus", m->view_names[i]); int focus = pure_module_view(m, name); - if (focus >= 0 && m->view_type[focus] == PURE_VIEW_NUM) focus_view[focus] = true; + if (focus >= 0 && m->view_type[focus] == PURE_VIEW_NUM && focus_view) focus_view[focus] = true; } for (uint32_t i = 0; i < m->views && screen->count < VEGA_PARTS; ++i) { - if (m->view_table[i] || (int)i == screen->title || focus_view[i]) continue; + if (m->view_table[i] || (int)i == screen->title || (focus_view && focus_view[i])) continue; VegaPart *part = &screen->parts[screen->count++]; *part = (VegaPart){.kind = VEGA_FIELD, .view = i, .focus = -1, .pointer = -1, .label = -1, .tone = -1, .detail = -1, .badge = -1}; @@ -76,7 +81,7 @@ void vega_screen(VegaScreen *screen, const PureModule *m) { char name[PURE_MODULE_NAME + 8]; snprintf(name, sizeof(name), "%s_focus", m->view_names[i]); part->focus = pure_module_view(m, name); - if (part->focus >= 0 && !focus_view[part->focus]) part->focus = -1; + if (part->focus >= 0 && !(focus_view && focus_view[part->focus])) part->focus = -1; for (uint32_t k = 0; part->focus >= 0 && k < m->inputs; ++k) if (m->input[k].binding == PURE_BIND_POINT && m->input[k].view == i) part->pointer = (int)k; part->label = column(m, i, "label", PURE_VIEW_TEXT); @@ -87,8 +92,10 @@ void vega_screen(VegaScreen *screen, const PureModule *m) { part->badge = column(m, i, "badge", PURE_VIEW_TEXT); } for (uint32_t k = 0; k < m->views; ++k) - if (m->view_table[k] == i + 1 && (int)k != part->tone) part->columns[part->column_count++] = k; + if (m->view_table[k] == i + 1 && (int)k != part->tone && part->column_count < VEGA_COLUMNS) + part->columns[part->column_count++] = k; } + free(focus_view); } static bool is_view(const PureModule *m, int view, uint8_t type) { diff --git a/surfaces/vega.h b/surfaces/vega.h index 7cf26ed..1ffcd8d 100644 --- a/surfaces/vega.h +++ b/surfaces/vega.h @@ -15,7 +15,8 @@ * - every other number or text view is a field. * A tone says what a value means (lib/vega.aup); each surface decides how it * looks or sounds. Surfaces evaluate only the cells they present. */ -enum { VEGA_PARTS = 64, VEGA_TEXT = 1024 }; +/* The parts a screen shows and the columns a table shows, at most: a surface's own counts (not a module's). */ +enum { VEGA_PARTS = 64, VEGA_COLUMNS = 64, VEGA_TEXT = 1024 }; typedef enum { VEGA_NORMAL, VEGA_MUTED, VEGA_ACCENT, VEGA_GOOD, VEGA_WARNING, VEGA_DANGER, VEGA_TONES } VegaTone; typedef enum { VEGA_FIELD, VEGA_LIST, VEGA_TABLE } VegaKind; @@ -25,7 +26,7 @@ typedef struct { int focus; /* number view with the focused row, or -1 */ int pointer; /* the input pointing at this table's rows (focus = at.position), or -1 */ int label, tone, detail, badge; /* columns, or -1 */ - uint32_t columns[PURE_MODULE_VIEWS]; /* a table's shown columns, in order */ + uint32_t columns[VEGA_COLUMNS]; /* a table's shown columns, in order (its first VEGA_COLUMNS) */ unsigned column_count; } VegaPart; @@ -50,7 +51,7 @@ double vega_clock(void); * at clock (a tick sees the wall clock, vega_now) and gives the * milliseconds until the next, or -1 without timers; ticked says whether * any did. Missed ticks are not made up. */ -typedef struct { double next[PURE_MODULE_INPUTS]; } VegaTimers; +typedef struct { double *next; uint32_t count; } VegaTimers; /* zeroed before its first start; one an input */ void vega_timers_start(VegaTimers *, const PureModule *, double clock); long vega_timers_run(VegaTimers *, PureApp *, double clock, bool *ticked); /* What a module seems to mean but does not meet: a list label that is not diff --git a/surfaces/web.c b/surfaces/web.c index 4e81614..9447dd1 100644 --- a/surfaces/web.c +++ b/surfaces/web.c @@ -422,7 +422,7 @@ int vega_web(PureApp *app, const VegaScreen *screen, const char *listen_on, unsi signal(SIGPIPE, SIG_IGN); static Client clients[CLIENTS]; for (unsigned i = 0; i < CLIENTS; ++i) clients[i].fd = -1; - VegaTimers timers; + VegaTimers timers = {0}; vega_timers_start(&timers, app->module, vega_clock()); while (!stopping) { /* Tick what is due; every page hears of it this round, without waiting. */ |
