From 8d45a75782ffc563fc707c6bc9f937de63b248f2 Mon Sep 17 00:00:00 2001 From: onelin Date: Fri, 1 May 2026 19:31:22 +0200 Subject: Add "update all" functionality --- status.c | 47 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 34 insertions(+), 13 deletions(-) (limited to 'status.c') diff --git a/status.c b/status.c index dfdffa6..9e77bdb 100644 --- a/status.c +++ b/status.c @@ -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; + } } } -- cgit v1.3