summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.def.h1
-rwxr-xr-xdmenubin43560 -> 43704 bytes
-rw-r--r--dmenu.c65
-rw-r--r--dmenu.c.orig21
-rw-r--r--dmenu.c.rej27
-rw-r--r--dmenu.obin36080 -> 37744 bytes
6 files changed, 104 insertions, 10 deletions
diff --git a/config.def.h b/config.def.h
index 1edb647..65e03fb 100644
--- a/config.def.h
+++ b/config.def.h
@@ -12,6 +12,7 @@ static const char *colors[SchemeLast][2] = {
[SchemeNorm] = { "#bbbbbb", "#222222" },
[SchemeSel] = { "#eeeeee", "#005577" },
[SchemeOut] = { "#000000", "#00ffff" },
+ [SchemeHp] = { "#bbbbbb", "#333333" }
};
/* -l option; if nonzero, dmenu uses vertical list with given number of lines */
static unsigned int lines = 0;
diff --git a/dmenu b/dmenu
index 8dfd948..fc63cb9 100755
--- a/dmenu
+++ b/dmenu
Binary files differ
diff --git a/dmenu.c b/dmenu.c
index d07e55d..9a9cc5f 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -27,14 +27,16 @@
#define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
/* enums */
-enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
+enum { SchemeNorm, SchemeSel, SchemeHp, SchemeOut, SchemeLast }; /* color schemes */
struct item {
char *text;
struct item *left, *right;
- int out;
+ int out, hp;
};
+static char **hpitems = NULL;
+static int hplength = 0;
static char text[BUFSIZ] = "";
static char *embed;
static int bh, mw, mh;
@@ -63,6 +65,36 @@ static char *tempfonts;
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
static char *(*fstrstr)(const char *, const char *) = strstr;
+static char**
+tokenize(char *source, const char *delim, int *llen) {
+ int listlength = 0;
+ char **list = malloc(1 * sizeof(char*));
+ char *token = strtok(source, delim);
+
+ while (token) {
+ if (!(list = realloc(list, sizeof(char*) * (listlength + 1))))
+ die("Unable to realloc %d bytes\n", sizeof(char*) * (listlength + 1));
+ if (!(list[listlength] = strdup(token)))
+ die("Unable to strdup %d bytes\n", strlen(token) + 1);
+ token = strtok(NULL, delim);
+ listlength++;
+ }
+
+ *llen = listlength;
+ return list;
+}
+
+static int
+arrayhas(char **list, int length, char *item) {
+ for (int i = 0; i < length; i++) {
+ int len1 = strlen(list[i]);
+ int len2 = strlen(item);
+ if (fstrncmp(list[i], item, len1 > len2 ? len2 : len1) == 0)
+ return 1;
+ }
+ return 0;
+}
+
static void
appenditem(struct item *item, struct item **list, struct item **last)
{
@@ -130,6 +162,8 @@ drawitem(struct item *item, int x, int y, int w)
{
if (item == sel)
drw_setscheme(drw, scheme[SchemeSel]);
+ else if (item->hp)
+ drw_setscheme(drw, scheme[SchemeHp]);
else if (item->out)
drw_setscheme(drw, scheme[SchemeOut]);
else
@@ -237,7 +271,7 @@ match(void)
char buf[sizeof text], *s;
int i, tokc = 0;
size_t len, textsize;
- struct item *item, *lprefix, *lsubstr, *prefixend, *substrend;
+ struct item *item, *lhpprefix, *lprefix, *lsubstr, *hpprefixend, *prefixend, *substrend;
strcpy(buf, text);
/* separate input text into tokens to be matched individually */
@@ -246,7 +280,7 @@ match(void)
die("cannot realloc %u bytes:", tokn * sizeof *tokv);
len = tokc ? strlen(tokv[0]) : 0;
- matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL;
+ matches = lhpprefix = lprefix = lsubstr = matchend = hpprefixend = prefixend = substrend = NULL;
textsize = strlen(text) + 1;
for (item = items; item && item->text; item++) {
for (i = 0; i < tokc; i++)
@@ -254,14 +288,24 @@ match(void)
break;
if (i != tokc) /* not all tokens match */
continue;
- /* exact matches go first, then prefixes, then substrings */
+ /* exact matches go first, then prefixes with high priority, then prefixes, then substrings */
if (!tokc || !fstrncmp(text, item->text, textsize))
appenditem(item, &matches, &matchend);
+ else if (item->hp && !fstrncmp(tokv[0], item->text, len))
+ appenditem(item, &lhpprefix, &hpprefixend);
else if (!fstrncmp(tokv[0], item->text, len))
appenditem(item, &lprefix, &prefixend);
else
appenditem(item, &lsubstr, &substrend);
}
+ if (lhpprefix) {
+ if (matches) {
+ matchend->right = lhpprefix;
+ lhpprefix->left = matchend;
+ } else
+ matches = lhpprefix;
+ matchend = hpprefixend;
+ }
if (lprefix) {
if (matches) {
matchend->right = lprefix;
@@ -569,6 +613,7 @@ readstdin(void)
if (!(items[i].text = strdup(buf)))
die("cannot strdup %u bytes:", strlen(buf) + 1);
items[i].out = 0;
+ items[i].hp = arrayhas(hpitems, hplength, items[i].text);
drw_font_getexts(drw->fonts, buf, strlen(buf), &tmpmax, NULL);
if (tmpmax > inputw) {
inputw = tmpmax;
@@ -729,7 +774,9 @@ static void
usage(void)
{
fputs("usage: dmenu [-bfivP] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
+ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n"
+ " [-hb color] [-hf color] [-hp items]\n", stderr);
+
exit(1);
}
@@ -807,8 +854,14 @@ main(int argc, char *argv[])
colortemp[2] = argv[++i];
else if (!strcmp(argv[i], "-sf")) /* selected foreground color */
colortemp[3] = argv[++i];
+ else if (!strcmp(argv[i], "-hb")) /* high priority background color */
+ colors[SchemeHp][ColBg] = argv[++i];
+ else if (!strcmp(argv[i], "-hf")) /* low priority background color */
+ colors[SchemeHp][ColFg] = argv[++i];
else if (!strcmp(argv[i], "-w")) /* embedding window id */
embed = argv[++i];
+ else if (!strcmp(argv[i], "-hp"))
+ hpitems = tokenize(argv[++i], ",", &hplength);
else
usage();
diff --git a/dmenu.c.orig b/dmenu.c.orig
index 3a7c4d4..d07e55d 100644
--- a/dmenu.c.orig
+++ b/dmenu.c.orig
@@ -38,7 +38,7 @@ struct item {
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;
@@ -144,6 +144,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);
@@ -155,7 +156,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) {
@@ -547,6 +553,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++) {
@@ -717,7 +728,7 @@ 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] [-w windowid]\n", stderr);
exit(1);
}
@@ -775,7 +786,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 */
diff --git a/dmenu.c.rej b/dmenu.c.rej
new file mode 100644
index 0000000..e747a27
--- /dev/null
+++ b/dmenu.c.rej
@@ -0,0 +1,27 @@
+--- dmenu.c
++++ dmenu.c
+@@ -728,7 +773,8 @@ static void
+ usage(void)
+ {
+ fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
+- " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
++ " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n"
++ " [-hb color] [-hf color] [-hp items]\n", stderr);
+ exit(1);
+ }
+
+@@ -769,8 +815,14 @@ 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], "-hb")) /* high priority background color */
++ colors[SchemeHp][ColBg] = argv[++i];
++ else if (!strcmp(argv[i], "-hf")) /* low priority background color */
++ colors[SchemeHp][ColFg] = argv[++i];
+ else if (!strcmp(argv[i], "-w")) /* embedding window id */
+ embed = argv[++i];
++ else if (!strcmp(argv[i], "-hp"))
++ hpitems = tokenize(argv[++i], ",", &hplength);
+ else
+ usage();
+
diff --git a/dmenu.o b/dmenu.o
index f5b4e80..5781ab9 100644
--- a/dmenu.o
+++ b/dmenu.o
Binary files differ