diff --git a/dmenubar/config.def.h b/dmenubar/config.def.h index 7dcc375..b38faac 100644 --- a/dmenubar/config.def.h +++ b/dmenubar/config.def.h @@ -1,13 +1,22 @@ /* See LICENSE file for copyright and license details. */ /* Default settings; some can be overriden by command line. */ +/* if this is true, dmenubar will exit 0 when it receives EOF from + * standard input. otherwise it'll just keep reading until you pkill + * it. */ +#define BREAK_ON_EOF 0 + static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ + /* -fn option overrides fonts[0]; default X11 font or font set */ static const char *fonts[] = { "monospace:size=10" }; -static const int text_s = 1024; /* chars to be allocated for the text displayed in the bar */ + +/* chars to be allocated for the text displayed in the bar */ +static const int text_s = 1024; + static const char *colors[SchemeLast][2] = { /* fg, bg */ - [Scheme] = { "#eeeeee", "#005577" }, + [Scheme] = { "#eeeeee", "#005577" } }; diff --git a/dmenubar/dmenubar.c b/dmenubar/dmenubar.c index ee1cd35..d9c0673 100644 --- a/dmenubar/dmenubar.c +++ b/dmenubar/dmenubar.c @@ -26,6 +26,8 @@ #include "drw.h" #include "util.h" +#define BREAK_ON_EOF 0 + /* macros */ #define INTERSECT(x,y,w,h,r) (MAX(0, MIN((x)+(w),(r).x_org+(r).width) - MAX((x),(r).x_org)) \ * MAX(0, MIN((y)+(h),(r).y_org+(r).height) - MAX((y),(r).y_org))) @@ -64,7 +66,6 @@ cleanup(void) { size_t i; - XUngrabKey(dpy, AnyKey, AnyModifier, root); for (i = 0; i < SchemeLast; i++) free(scheme[i]); drw_free(drw); @@ -102,7 +103,7 @@ setup(void) XIM xim; Window w, dw, *dws; XWindowAttributes wa; - XClassHint ch = {"dmenu", "dmenu"}; + XClassHint ch = {"dmenubar", "dmenubar"}; #ifdef XINERAMA XineramaScreenInfo *info; Window pw; @@ -192,8 +193,8 @@ setup(void) static void usage(void) { - fputs("usage: dmenu [-bfiv] [-fn font] [-m monitor]\n" - " [-bc color] [-fc color] [-w windowid]\n", stderr); + fputs("usage: dmenubar [-bv] [-fn font] [-m monitor]\n" + " [-cb color] [-cf color] [-w windowid]\n", stderr); exit(1); } @@ -203,13 +204,13 @@ main(int argc, char *argv[]) XWindowAttributes wa; int i; char text[text_s]; - for(i = 0; i < text_s; ++i) + for(i = 0; i < text_s; ++i) /* initialize text[] */ text[i] = '\0'; for (i = 1; i < argc; i++) /* these options take no arguments */ if (!strcmp(argv[i], "-v")) { /* prints version information */ - puts("dmenu-"VERSION); + puts("dmenuBAR-"VERSION); exit(0); } else if (!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */ topbar = 0; @@ -220,9 +221,9 @@ main(int argc, char *argv[]) mon = atoi(argv[++i]); else if (!strcmp(argv[i], "-fn")) /* font or font set */ fonts[0] = argv[++i]; - else if (!strcmp(argv[i], "-bc")) /* bg color */ + else if (!strcmp(argv[i], "-cb")) /* bg color */ colors[Scheme][ColBg] = argv[++i]; - else if (!strcmp(argv[i], "-fc")) /* fg color */ + else if (!strcmp(argv[i], "-cf")) /* fg color */ colors[Scheme][ColFg] = argv[++i]; else if (!strcmp(argv[i], "-w")) /* embedding window id */ embed = argv[++i]; @@ -253,17 +254,13 @@ main(int argc, char *argv[]) setup(); - /* might seem elementary but i made this mistake: - * you can't just let it exit 0 when you hit EOF because then - * stuff like `printf "hello\n" | dmenubar` won't have time to - * be shown. */ - for(;;){ - fgets(text, text_s, stdin); + do { /* fgets adds a newline which will be printable in some fonts */ - if(strlen(text) > 0) + if (strlen(text) > 0) text[strlen(text)-1] = '\0'; drawmenu(text); - } + } while (fgets(text, text_s, stdin) != NULL || !BREAK_ON_EOF); - return 1; /* unreachable */ + cleanup(); + return 0; }