diff options
Diffstat (limited to 'dmenu.c')
| -rwxr-xr-x | dmenu.c | 49 |
1 files changed, 19 insertions, 30 deletions
@@ -25,7 +25,7 @@ #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad) /* enums */ -enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */ +enum { SchemeNorm, SchemeSel, SchemeOut, SchemePrompt, SchemeLast }; /* color schemes */ struct item { char *text; @@ -36,7 +36,7 @@ struct item { static char text[BUFSIZ] = ""; static char *embed; static int bh, mw, mh; -static int inputw = 0, promptw, passwd = 0; +static int inputw = 0, promptw; static int lrpad; /* sum of left and right padding */ static size_t cursor; static struct item *items = NULL; @@ -100,7 +100,7 @@ cleanup(void) { size_t i; - XUngrabKey(dpy, AnyKey, AnyModifier, root); + XUngrabKeyboard(dpy, CurrentTime); for (i = 0; i < SchemeLast; i++) free(scheme[i]); for (i = 0; items && items[i].text; ++i) @@ -148,31 +148,28 @@ drawmenu(void) unsigned int curpos; struct item *item; int x = 0, y = 0, w; - char *censort; drw_setscheme(drw, scheme[SchemeNorm]); drw_rect(drw, 0, 0, mw, mh, 1, 1); - if (prompt && *prompt) { - drw_setscheme(drw, scheme[SchemeSel]); - x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0); - } - /* draw input field */ w = (lines > 0 || !matches) ? mw - x : inputw; - drw_setscheme(drw, scheme[SchemeNorm]); - if (passwd) { - censort = ecalloc(1, sizeof(text)); - memset(censort, '.', strlen(text)); - drw_text(drw, x, 0, w, bh, lrpad / 2, censort, 0); - free(censort); - } else drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0); - - curpos = TEXTW(text) - TEXTW(&text[cursor]); - if ((curpos += lrpad / 2 - 1) < w) { + + if (text[0] == '\0' && prompt && *prompt) { + drw_setscheme(drw, scheme[SchemePrompt]); + /* If vertical list: use full width (w), else just promptw */ + drw_text(drw, x, 0, (lines > 0 ? w : promptw), bh, lrpad / 2, prompt, 0); + } else { drw_setscheme(drw, scheme[SchemeNorm]); - drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0); + drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0); } + if (text[0] != '\0') { + curpos = TEXTW(text) - TEXTW(&text[cursor]); + if ((curpos += lrpad / 2 - 1) < w) { + drw_setscheme(drw, scheme[SchemeNorm]); + drw_rect(drw, x + curpos, 1, 2, bh - 4, 1, 0); + } + } if (lines > 0) { /* draw vertical list */ for (item = curr; item != next; item = item->right) @@ -558,11 +555,6 @@ readstdin(void) size_t i, itemsiz = 0, linesiz = 0; ssize_t len; - if (passwd) { - inputw = lines = 0; - return; - } - /* read each line from stdin and add it to the item list */ for (i = 0; (len = getline(&line, &linesiz, stdin)) != -1; i++) { if (i + 1 >= itemsiz) { @@ -700,7 +692,6 @@ setup(void) CWOverrideRedirect | CWBackPixel | CWEventMask, &swa); XSetClassHint(dpy, win, &ch); - /* input methods */ if ((xim = XOpenIM(dpy, NULL, NULL, NULL)) == NULL) die("XOpenIM failed: could not open input device"); @@ -726,7 +717,7 @@ setup(void) static void usage(void) { - die("usage: dmenu [-bfivP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" + die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]"); } @@ -748,9 +739,7 @@ main(int argc, char *argv[]) else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ fstrncmp = strncasecmp; fstrstr = cistrstr; - } else if (!strcmp(argv[i], "-P")) /* is the input a password */ - passwd = 1; - else if (i + 1 == argc) + } else if (i + 1 == argc) usage(); /* these options take one argument */ else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */ |
