X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=osdd.c;h=98a35a6d09d23285afed741cc992664e8b264b32;hb=a883082ba08cf9e8acb0360056b240ebd77ab110;hp=800f6ab9467a61e81fde8f394a7cb8886e547233;hpb=66ea7419541d01ea378523d106e8946b667cbe61;p=osdd.git diff --git a/osdd.c b/osdd.c index 800f6ab..98a35a6 100644 --- a/osdd.c +++ b/osdd.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -18,11 +19,81 @@ #include "util.h" static xosd *osd; -#define MAX_LINES 4 typedef uint64_t timestamp_t; static timestamp_t now; +/*** Options ***/ + +static int num_lines = 4; +static char *font_name = "-bitstream-bitstream vera sans-bold-r-normal-*-*-320-*-*-p-*-*"; +static char *default_color = "green"; +static char *default_outline_color = "black"; +static int default_duration = 1000; +static int default_min_duration = 1000; + +static const char short_opts[] = "c:d:f:l:m:o:"; + +static const struct option long_opts[] = { + { "color", required_argument, NULL, 'c' }, + { "duration", required_argument, NULL, 'd' }, + { "font", required_argument, NULL, 'f' }, + { "lines", required_argument, NULL, 'l' }, + { "min-duration", required_argument, NULL, 'm' }, + { "outline-color", required_argument, NULL, 'o' }, + { NULL, 0, NULL, 0 }, +}; + +static void NONRET +usage(void) +{ + fprintf(stderr, "Usage: osdd \n\n\ +Options:\n\ +-c, --color=\t\tDefault color (#rgb, #rrggbb or a name from rgb.txt)\n\ +-d, --duration=\tDefault message duration in milliseconds\n\ +-f, --font=\t\tFont to use for the OSD\n\ +-l, --lines=\t\tNumber of lines of the OSD\n\ +-m, --min-duration=\tDefault minimum message duration in milliseconds\n\ +-o, --outline-color=\tDefault outline color\n\ +"); + exit(1); +} + +static void +parse_opts(int argc, char **argv) +{ + int opt; + while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) >= 0) + switch (opt) + { + case 'c': + default_color = optarg; + break; + case 'd': + default_duration = atoi(optarg); + break; + case 'f': + font_name = optarg; + break; + case 'l': + num_lines = atoi(optarg); + if (num_lines < 1) + usage(); + break; + case 'm': + default_min_duration = atoi(optarg); + break; + case 'o': + default_outline_color = optarg; + break; + default: + usage(); + } + + if (optind < argc) + usage(); +} + /*** Displaying of messages ***/ struct msg { @@ -34,13 +105,17 @@ struct msg { static void display_msg(struct msg *msg) { - msg->min_light = msg->max_light = now + 1000; + DBG("## Displaying message\n"); + msg->min_light = now + default_min_duration; + msg->max_light = now + default_duration; + xosd_set_colour(osd, default_color); + xosd_set_outline_colour(osd, default_outline_color); char *line = msg->text; int row = 0; while (*line) { - // The parser it destructive, but it does not harm, since we display each message only once. + // The parser it destructive, but it does not do any harm, since we display each message only once. char *nl = strchr(line, '\n'); *nl++ = 0; @@ -56,16 +131,33 @@ display_msg(struct msg *msg) key = ""; val = line; } + DBG("\t%s:%s\n", key, val); if (!key[0]) { - if (row < MAX_LINES) + if (row < num_lines) xosd_display(osd, row++, XOSD_string, val); } + else if (!strcmp(key, "percentage") || !strcmp(key, "percent")) + { + if (row < num_lines) + xosd_display(osd, row++, XOSD_percentage, atoi(val)); + } + else if (!strcmp(key, "slider")) + { + if (row < num_lines) + xosd_display(osd, row++, XOSD_slider, atoi(val)); + } else if (!strcmp(key, "duration")) msg->max_light = now + atoi(val); else if (!strcmp(key, "min-duration")) msg->min_light = now + atoi(val); + else if (!strcmp(key, "color")) + xosd_set_colour(osd, val); + else if (!strcmp(key, "outline-color")) + xosd_set_outline_colour(osd, val); + else + DBG("\tPARSE ERROR\n"); line = nl; } @@ -77,7 +169,9 @@ display_msg(struct msg *msg) static void hide_msg(struct msg *msg) { - xosd_scroll(osd, MAX_LINES); + DBG("## Hiding message\n"); + for (int i=0; i\n", (int) pty_items, pty_buf); - parse_input(pty_buf, pty_items); - } + parse_input(pty_buf, pty_items); if (pty_buf) XFree(pty_buf); }