Commit Diff


commit - ec4e7034a943f389ff098aafbbe9f9de5908934b
commit + 125e80b814d7008855e62cbb081204803e8c7061
blob - 1f2ccc071a4c245fd66da8f3c13d65c5a6b9dc6e
blob + 70ee9a744336717ed4d5fce61072cfee6f81ac55
--- TODO
+++ TODO
@@ -6,9 +6,6 @@
 # Fix
 - dwm: XKeycodeToKeysum
 
-# Patch
-- dmenu: passwords
-
 # Refactor
 - split common code into a library (drw.c)
 - pinentry code is ugly AF, replace it with something better
blob - 037c667f2c65babef293b5cd3a5c119b21dd555e
blob + da01b4c1f2b579312f717f99393879f3a678592f
--- dmenu/config.h
+++ dmenu/config.h
@@ -25,3 +25,6 @@ static unsigned int lines = 0;
  * for example: " /?\"&[]"
  */
 static const char worddelimiters[] = " ";
+
+/* Character to be shown, when entering a password. */
+static char pwcensorchar = '*';
blob - 323f93cf88eee5bd4878cf78cf40d9677277916c
blob + 762f7071c23f0a2bc3b2c872695fdb9cdc5317fd
--- dmenu/dmenu.1
+++ dmenu/dmenu.1
@@ -3,7 +3,7 @@
 dmenu \- dynamic menu
 .SH SYNOPSIS
 .B dmenu
-.RB [ \-bfiv ]
+.RB [ \-bfivP ]
 .RB [ \-l
 .IR lines ]
 .RB [ \-m
@@ -47,6 +47,9 @@ is faster, but will lock up X until stdin reaches end\
 .B \-i
 dmenu matches menu items case insensitively.
 .TP
+.B \-P
+dmenu will not directly display the keyboard input, but instead replace it with dots. All data from stdin will be ignored.
+.TP
 .BI \-l " lines"
 dmenu lists items vertically, with the given number of lines.
 .TP
blob - c6dc01ea4ac34d82b4f6a04d0a43de79ad1b9c14
blob + fa3606efa7e0841ca21c9e66f16d168406ba2048
--- dmenu/dmenu.c
+++ dmenu/dmenu.c
@@ -42,7 +42,7 @@ static char numbers[NUMBERSBUFSIZE] = "";
 static char text[BUFSIZ] = "";
 static char *embed;
 static int bh, mw, mh;
-static int inputw = 0, promptw;
+static int inputw = 0, promptw, passwd = 0;
 static int lrpad; /* sum of left and right padding */
 static size_t cursor;
 static struct item *items = NULL;
@@ -209,6 +209,7 @@ 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);
@@ -220,7 +221,12 @@ drawmenu(void)
 	/* draw input field */
 	w = (lines > 0 || !matches) ? mw - x : inputw;
 	drw_setscheme(drw, scheme[SchemeNorm]);
-	drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0);
+	if (passwd) {
+	        censort = ecalloc(1, sizeof(text));
+		memset(censort, pwcensorchar, 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) {
@@ -702,6 +708,11 @@ readstdin(void)
 	size_t i, junk, size = 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, &junk, stdin)) != -1; i++, line = NULL) {
 		if (i + 1 >= size / sizeof *items)
@@ -859,7 +870,7 @@ setup(void)
 static void
 usage(void)
 {
-	die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+	die("usage: dmenu [-bfivP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
 	    "             [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]");
 }
 
@@ -883,7 +894,9 @@ main(int argc, char *argv[])
 		else if (!strcmp(argv[i], "-i")) { /* case-insensitive item matching */
 			fstrncmp = strncasecmp;
 			fstrstr = cistrstr;
-		} else if (i + 1 == argc)
+		} else if (!strcmp(argv[i], "-P"))   /* is the input a password */
+			passwd = 1;
+		else if (i + 1 == argc)
 			usage();
 		/* these options take one argument */
 		else if (!strcmp(argv[i], "-l"))   /* number of lines in vertical list */