dmenu-password-4.7.diff (2273B)
1 diff -wup a/dmenu.c b/dmenu.c 2 --- a/dmenu.c 2017-06-12 00:35:39.814716857 +0200 3 +++ b/dmenu.c 2017-06-11 23:59:18.794768196 +0200 4 @@ -36,7 +36,7 @@ struct item { 5 static char text[BUFSIZ] = ""; 6 static char *embed; 7 static int bh, mw, mh; 8 -static int inputw = 0, promptw; 9 +static int inputw = 0, promptw, passwd = 0; 10 static int lrpad; /* sum of left and right padding */ 11 static size_t cursor; 12 static struct item *items = NULL; 13 @@ -131,6 +131,7 @@ drawmenu(void) 14 unsigned int curpos; 15 struct item *item; 16 int x = 0, y = 0, w; 17 + char *censort; 18 19 drw_setscheme(drw, scheme[SchemeNorm]); 20 drw_rect(drw, 0, 0, mw, mh, 1, 1); 21 @@ -142,7 +143,12 @@ drawmenu(void) 22 /* draw input field */ 23 w = (lines > 0 || !matches) ? mw - x : inputw; 24 drw_setscheme(drw, scheme[SchemeNorm]); 25 - drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0); 26 + if (passwd) { 27 + censort = ecalloc(1, sizeof(text)); 28 + memset(censort, '.', strlen(text)); 29 + drw_text(drw, x, 0, w, bh, lrpad / 2, censort, 0); 30 + free(censort); 31 + } else drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0); 32 33 drw_font_getexts(drw->fonts, text, cursor, &curpos, NULL); 34 if ((curpos += lrpad / 2 - 1) < w) { 35 @@ -481,6 +487,11 @@ readstdin(void) 36 size_t i, imax = 0, size = 0; 37 unsigned int tmpmax = 0; 38 39 + if (passwd) { 40 + inputw = lines = 0; 41 + return; 42 + } 43 + 44 /* read each line from stdin and add it to the item list */ 45 for (i = 0; fgets(buf, sizeof buf, stdin); i++) { 46 if (i + 1 >= size / sizeof *items) 47 @@ -636,7 +647,7 @@ setup(void) 48 static void 49 usage(void) 50 { 51 - fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" 52 + fputs("usage: dmenu [-bfiPv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" 53 " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr); 54 exit(1); 55 } 56 @@ -659,7 +670,9 @@ main(int argc, char *argv[]) 57 else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */ 58 fstrncmp = strncasecmp; 59 fstrstr = cistrstr; 60 - } else if (i + 1 == argc) 61 + } else if (!strcmp(argv[i], "-P")) /* is the input a password */ 62 + passwd = 1; 63 + else if (i + 1 == argc) 64 usage(); 65 /* these options take one argument */ 66 else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */