From 7a69401dada55e2d4935ce3a37f04f8c9331402f Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Sat, 17 Jul 2010 17:37:49 +0200 Subject: [PATCH] More attributes and options --- osdd.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 85 insertions(+), 12 deletions(-) diff --git a/osdd.c b/osdd.c index 800f6ab..4659493 100644 --- a/osdd.c +++ b/osdd.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -18,7 +19,11 @@ #include "util.h" static xosd *osd; -#define MAX_LINES 4 + +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"; typedef uint64_t timestamp_t; static timestamp_t now; @@ -35,12 +40,14 @@ static void display_msg(struct msg *msg) { msg->min_light = msg->max_light = now + 1000; + 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; @@ -59,13 +66,27 @@ display_msg(struct msg *msg) 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); line = nl; } @@ -77,7 +98,8 @@ display_msg(struct msg *msg) static void hide_msg(struct msg *msg) { - xosd_scroll(osd, MAX_LINES); + for (int i=0; i\n\n\ +Options:\n\ +-c, --color=\t\tDefault color (#rgb, #rrggbb or a name from rgb.txt)\n\ +-f, --font=\t\tFont to use for the OSD\n\ +-l, --lines=\t\tNumber of lines of the OSD\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 'f': + font_name = optarg; + break; + case 'l': + num_lines = atoi(optarg); + if (num_lines < 1) + usage(); + break; + case 'o': + default_outline_color = optarg; + break; + default: + usage(); + } + + if (optind < argc) + usage(); +} + /*** Main loop ***/ int -main(void) +main(int argc, char **argv) { + parse_opts(argc, argv); XInitThreads(); Display *dpy = XOpenDisplay(NULL); @@ -144,12 +221,11 @@ main(void) XDeleteProperty(dpy, win, pty); XFlush(dpy); - osd = xosd_create(4); + osd = xosd_create(num_lines); if (!osd) die("Cannot initialize OSD"); - xosd_set_font(osd, "-bitstream-bitstream vera sans-bold-r-normal-*-*-320-*-*-p-*-*"); + xosd_set_font(osd, font_name); xosd_set_outline_offset(osd, 2); - xosd_set_outline_colour(osd, "black"); xosd_set_pos(osd, XOSD_middle); xosd_set_align(osd, XOSD_center); @@ -204,10 +280,7 @@ main(void) unsigned char *pty_buf = NULL; XGetWindowProperty(dpy, win, pty, 0, 4096, True, XA_STRING, &pty_type, &pty_fmt, &pty_items, &pty_remains, &pty_buf); if (pty_type == XA_STRING && pty_fmt == 8 && pty_items) - { - DBG("Received: <%.*s>\n", (int) pty_items, pty_buf); - parse_input(pty_buf, pty_items); - } + parse_input(pty_buf, pty_items); if (pty_buf) XFree(pty_buf); } -- 2.39.2