diff options
| author | onelin <oscar@nelin.dk> | 2026-05-01 17:31:22 +0000 |
|---|---|---|
| committer | onelin <oscar@nelin.dk> | 2026-05-01 17:31:22 +0000 |
| commit | 8d45a75782ffc563fc707c6bc9f937de63b248f2 (patch) | |
| tree | c3e18a0f5d1955ed9e65b148c56df8ae5e423229 /status.c | |
| parent | 4332b32f6007d3c50f043972f16a55af65caa998 (diff) | |
Add "update all" functionality
Diffstat (limited to 'status.c')
| -rw-r--r-- | status.c | 47 |
1 files changed, 34 insertions, 13 deletions
@@ -404,26 +404,47 @@ update_element_thread(union sigval sv) { // Empty queue while (mq_receive(mq_data.mqfd, (char*)&msg, sizeof(struct message_t), NULL) != -1) { fprintf(stderr, "%d on %d\n", msg.action, msg.element); - if (msg.action != update || msg.element <= ELEMENT_INVALID || msg.element >= ELEMENT_MAX) { + if (msg.action != update || msg.element <= ELEMENT_INVALID || msg.element > ELEMENT_MAX) { fprintf(stderr, "Invalid action/element\n"); continue; } - struct element* e = &statusbar[msg.element]; - assert(e->f != NULL); - struct timespec now; - struct timespec next_fire = time_add(e->fire_previous, e->fire_interval); - clock_gettime(CLOCK_REALTIME, &now); + if (msg.element == ELEMENT_MAX) { + for (int i = 1; i < ELEMENT_MAX; i++) { + struct element* e = &statusbar[i]; + assert(e->f != NULL); + struct timespec now; + struct timespec next_fire = time_add(e->fire_previous, e->fire_interval); + clock_gettime(CLOCK_REALTIME, &now); + + memset(e->buf, 0, ELEMENT_STRBUF_SZ); - memset(e->buf, 0, ELEMENT_STRBUF_SZ); + e->f(e->buf, e->a); + e->fire_previous = now; - e->f(e->buf, e->a); - e->fire_previous = now; + /* Check if this element needs to be refreshed next, again */ + next_fire = time_add(now, e->fire_interval); + if (time_lt(next_fire, ((struct mq_data*)(sv.sival_ptr))->next_update)) { + ((struct mq_data*)(sv.sival_ptr))->next_update = next_fire; + } + } + } else { + struct element* e = &statusbar[msg.element]; + assert(e->f != NULL); + struct timespec now; + struct timespec next_fire = time_add(e->fire_previous, e->fire_interval); + clock_gettime(CLOCK_REALTIME, &now); - /* Check if this element needs to be refreshed next, again */ - next_fire = time_add(now, e->fire_interval); - if (time_lt(next_fire, ((struct mq_data*)(sv.sival_ptr))->next_update)) { - ((struct mq_data*)(sv.sival_ptr))->next_update = next_fire; + memset(e->buf, 0, ELEMENT_STRBUF_SZ); + + e->f(e->buf, e->a); + e->fire_previous = now; + + /* Check if this element needs to be refreshed next, again */ + next_fire = time_add(now, e->fire_interval); + if (time_lt(next_fire, ((struct mq_data*)(sv.sival_ptr))->next_update)) { + ((struct mq_data*)(sv.sival_ptr))->next_update = next_fire; + } } } |
