summaryrefslogtreecommitdiff
path: root/gui_theme.c
diff options
context:
space:
mode:
authorAndre Noll <maan@tuebingen.mpg.de>2026-11-27 22:44:01 +0100
committerAndre Noll <maan@tuebingen.mpg.de>2026-11-27 22:44:01 +0100
commit7c8ebfeb9bf9153763fbc744fb990469f402e733 (patch)
tree11450b4814233f69af5a4e182fda378492b2fd0f /gui_theme.c
parent089b2df7df2a0f4b6eea33cdaca506e111ec0fa8 (diff)
parent1acc099bdede18c1452de8fc2e691d7f6ebf57a1 (diff)
Merge topic branch t/status_items into pupu
Revamp the status items. ------------------------ First step towards getting rid of the status items which depend on the current time. * t/status_items: f f New status item: writer_start time. audiod: Move the global afi struct into struct status_task. audiod: Make the status task struct local. audiod: Don't dump status items from command context. audiod: Replace server_stream start slot info fields. gui: Fix return value of colorful_blackness_print_status_items().
Diffstat (limited to 'gui_theme.c')
-rw-r--r--gui_theme.c59
1 files changed, 57 insertions, 2 deletions
diff --git a/gui_theme.c b/gui_theme.c
index 5af032da..952e9ecb 100644
--- a/gui_theme.c
+++ b/gui_theme.c
@@ -5,6 +5,7 @@
#include <curses.h>
#include "para.h"
+#include "sched.h"
#include "gui.h"
#include "error.h"
#include "string.h"
@@ -172,7 +173,7 @@ struct stat_item_data {
};
static const struct stat_item_data colorful_blackness_data[NUM_STAT_ITEMS] = {
- [SI_play_time] = {
+ [SI_writer_start_time] = {
.prefix = "",
.postfix = "",
.color.fg = COLOR_CYAN,
@@ -436,11 +437,60 @@ static const struct stat_item_data colorful_blackness_data[NUM_STAT_ITEMS] = {
}
};
+static struct timeval play_time_barrier;
+
+static void colorful_blackness_pre_monitor(struct sched *s)
+{
+ sched_request_barrier(&play_time_barrier, s);
+}
+
+static bool print_play_time(uint64_t mask, char **items, WINDOW *win)
+{
+ char *i1, *i2, *pts;
+ struct timeval sss = {.tv_sec = 0}, wst = sss, delay;
+ struct stat_item_data d = colorful_blackness_data[SI_writer_start_time];
+
+ i1 = items[SI_stream_start];
+ i2 = items[SI_writer_start_time];
+ if (status_item_bit_set(SI_writer_start_time, mask))
+ goto print;
+ if (status_item_bit_set(SI_stream_start, mask))
+ goto print;
+ if (tv_diff(now, &play_time_barrier, NULL) < 0)
+ return false;
+print:
+ if (i1 && *i1 && tv_scan(i1, &sss) < 0)
+ goto fail;
+ if (i2) { /* new audiod */
+ if (*i2 && tv_scan(i2, &wst) < 0)
+ goto fail;
+ pts = make_time_string(&sss, wst.tv_sec? &wst : NULL, items);
+ } else
+ pts = items[SI_play_time];
+ wmove(win, d.y * getmaxy(win) / 100, d.x * COLS / 100);
+ wattron(win, COLOR_PAIR(SI_writer_start_time + 1));
+ align_str(win, pts, d.len * COLS / 100, d.align);
+ if (i2)
+ free(pts);
+ /* compute time of next play time string change */
+ tv_diff(now, &wst, &delay);
+ if (delay.tv_usec / 1000 > 500)
+ ms2tv(1500 - delay.tv_usec / 1000, &delay);
+ else
+ ms2tv(500 - delay.tv_usec / 1000, &delay);
+ tv_add(now, &delay, &play_time_barrier);
+ return true;
+fail:
+ PARA_WARNING_LOG("status item parse error, i1=%s, i2=%s\n\n", i1, i2);
+ return false;
+}
+
static bool colorful_blackness_print_status_items(uint64_t mask, char **items,
WINDOW *win)
{
static bool initialized;
int i, top_lines = getmaxy(win);
+ bool printed_an_item = false;
if (!initialized) {
FOR_EACH_STATUS_ITEM(i) {
@@ -451,6 +501,7 @@ static bool colorful_blackness_print_status_items(uint64_t mask, char **items,
}
initialized = true;
}
+ printed_an_item = print_play_time(mask, items, win);
FOR_EACH_STATUS_ITEM(i) {
struct stat_item_data d = colorful_blackness_data[i];
char *c = items[i];
@@ -461,15 +512,18 @@ static bool colorful_blackness_print_status_items(uint64_t mask, char **items,
continue;
if (i == SI_status_flags && c[0] == '\0')
c = "down";
+ if (i == SI_writer_start_time || i == SI_stream_start)
+ continue;
if (d.len > 0) {
char *tmp = make_message("%s%s%s", d.prefix, c, d.postfix);
wmove(win, d.y * top_lines / 100, d.x * COLS / 100);
wattron(win, COLOR_PAIR(i + 1));
align_str(win, tmp, d.len * COLS / 100, d.align);
free(tmp);
+ printed_an_item = true;
}
}
- return true;
+ return printed_an_item;
}
static const struct gui_theme themes[] = {
@@ -500,6 +554,7 @@ static const struct gui_theme themes[] = {
.dflt.bg = COLOR_BLACK,
.dflt.fg = COLOR_MAGENTA,
.print_status_items = colorful_blackness_print_status_items,
+ .pre_monitor = colorful_blackness_pre_monitor,
}, {
.name = "simple",
.lines_min = 5,