]> git.armaanb.net Git - dmenu.git/blobdiff - dmenu.c
Switch to dark theme
[dmenu.git] / dmenu.c
diff --git a/dmenu.c b/dmenu.c
index 49b60ab577a86d165e5741ed012767c77876e916..1560b60466856fb86992f7f727bed73fd0dbb71e 100644 (file)
--- a/dmenu.c
+++ b/dmenu.c
@@ -29,8 +29,7 @@
 #define NUMBERSBUFSIZE        (NUMBERSMAXDIGITS * 2) + 1
 
 /* enums */
-enum { SchemeNorm, SchemeSel, SchemeNormHighlight, SchemeSelHighlight,
-       SchemeOut, SchemeLast }; /* color schemes */
+enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
 
 
 struct item {
@@ -44,7 +43,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;
@@ -130,9 +129,7 @@ drawhighlights(struct item *item, int x, int y, int maxw)
        if (!(strlen(item->text) && strlen(text)))
                return;
 
-       drw_setscheme(drw, scheme[item == sel
-                          ? SchemeSelHighlight
-                          : SchemeNormHighlight]);
+       drw_setscheme(drw, scheme[item == sel ? SchemeSel : SchemeNorm]);
        for (i = 0, highlight = item->text; *highlight && text[i];) {
                if (*highlight == text[i]) {
                        /* get indentation */
@@ -196,6 +193,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);
@@ -207,7 +205,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, '*', 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) {
@@ -506,8 +509,8 @@ keypress(XKeyEvent *ev)
                        while (cursor > 0 && !strchr(worddelimiters, text[nextrune(-1)]))
                                insert(NULL, nextrune(-1) - cursor);
                        break;
-               case XK_y: /* paste selection */
-               case XK_Y:
+               case XK_v: /* paste selection */
+               case XK_V:
                        XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
                                          utf8, utf8, win, CurrentTime);
                        return;
@@ -676,6 +679,11 @@ readstdin(void)
        char buf[sizeof text], *p;
        size_t i, imax = 0, size = 0;
        unsigned int tmpmax = 0;
+       if(passwd){
+       inputw = lines = 0;
+       return;
+       }
+
 
        /* read each line from stdin and add it to the item list */
        for (i = 0; fgets(buf, sizeof buf, stdin); i++) {
@@ -841,9 +849,9 @@ setup(void)
 static void
 usage(void)
 {
-       fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+       fputs("usage: dmenu [-bfivP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
              "             [-nb color] [-nf color] [-sb color] [-sf color]\n"
-             "             [-nhb color] [-nhf color] [-shb color] [-shf color] [-w windowid]\n", stderr);
+             "             [-w windowid]\n", stderr);
        exit(1);
 }
 
@@ -867,7 +875,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 */
@@ -886,14 +896,6 @@ main(int argc, char *argv[])
                        colors[SchemeSel][ColBg] = argv[++i];
                else if (!strcmp(argv[i], "-sf"))  /* selected foreground color */
                        colors[SchemeSel][ColFg] = argv[++i];
-               else if (!strcmp(argv[i], "-nhb")) /* normal hi background color */
-                       colors[SchemeNormHighlight][ColBg] = argv[++i];
-               else if (!strcmp(argv[i], "-nhf")) /* normal hi foreground color */
-                       colors[SchemeNormHighlight][ColFg] = argv[++i];
-               else if (!strcmp(argv[i], "-shb")) /* selected hi background color */
-                       colors[SchemeSelHighlight][ColBg] = argv[++i];
-               else if (!strcmp(argv[i], "-shf")) /* selected hi foreground color */
-                       colors[SchemeSelHighlight][ColFg] = argv[++i];
                else if (!strcmp(argv[i], "-w"))   /* embedding window id */
                        embed = argv[++i];
                else