X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=osdd.c;h=15836ea51b7d36377197c5a94fd307bdb16b64e1;hb=845e5d4b6ac0a561a0ee55f6a11bdb4380d4e014;hp=98a35a6d09d23285afed741cc992664e8b264b32;hpb=a883082ba08cf9e8acb0360056b240ebd77ab110;p=osdd.git diff --git a/osdd.c b/osdd.c index 98a35a6..15836ea 100644 --- a/osdd.c +++ b/osdd.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -15,7 +16,7 @@ #include #include -#define DEBUG +#undef DEBUG #include "util.h" static xosd *osd; @@ -31,17 +32,19 @@ static char *default_color = "green"; static char *default_outline_color = "black"; static int default_duration = 1000; static int default_min_duration = 1000; +static int debug_mode; -static const char short_opts[] = "c:d:f:l:m:o:"; +static const char short_opts[] = "c:d:Df:l:m:o:"; static const struct option long_opts[] = { { "color", required_argument, NULL, 'c' }, + { "debug", no_argument, NULL, 'D' }, { "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 }, + { NULL, 0, NULL, 0 }, }; static void NONRET @@ -50,6 +53,7 @@ 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, --debug\t\tDebugging mode (do not detach from the terminal)\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\ @@ -72,6 +76,9 @@ parse_opts(int argc, char **argv) case 'd': default_duration = atoi(optarg); break; + case 'D': + debug_mode = 1; + break; case 'f': font_name = optarg; break; @@ -157,7 +164,7 @@ display_msg(struct msg *msg) else if (!strcmp(key, "outline-color")) xosd_set_outline_colour(osd, val); else - DBG("\tPARSE ERROR\n"); + xosd_display(osd, (row < num_lines ? row++ : num_lines-1), XOSD_string, "PARSE ERROR"); line = nl; } @@ -235,6 +242,19 @@ main(int argc, char **argv) if (!pty) die("Cannot intern OSD_QUEUE atom"); + if (!debug_mode) + { + pid_t pid = fork(); + if (pid < 0) + { + fprintf(stderr, "batt: Cannot fork: %m\n"); + return 1; + } + if (pid > 0) + return 0; + setsid(); + } + XSelectInput(dpy, win, PropertyChangeMask); XDeleteProperty(dpy, win, pty); XFlush(dpy);