dmenu-tmenu-5.2.diff - sites - public wiki contents of suckless.org | |
git clone git://git.suckless.org/sites | |
Log | |
Files | |
Refs | |
--- | |
dmenu-tmenu-5.2.diff (3079B) | |
--- | |
1 diff --git a/config.def.h b/config.def.h | |
2 index 1edb647..805d8c4 100644 | |
3 --- a/config.def.h | |
4 +++ b/config.def.h | |
5 @@ -21,3 +21,6 @@ static unsigned int lines = 0; | |
6 * for example: " /?\"&[]" | |
7 */ | |
8 static const char worddelimiters[] = " "; | |
9 + | |
10 +/* delimiter for tmenu */ | |
11 +static char valuedelimiter = '\t'; | |
12 diff --git a/dmenu.1 b/dmenu.1 | |
13 index 323f93c..fb22ed3 100644 | |
14 --- a/dmenu.1 | |
15 +++ b/dmenu.1 | |
16 @@ -47,6 +47,9 @@ is faster, but will lock up X until stdin reaches end\… | |
17 .B \-i | |
18 dmenu matches menu items case insensitively. | |
19 .TP | |
20 +.BI \-d " tmenu delimiter" | |
21 +when used in a line, the value after the delimiter will be displayed. W… | |
22 +.TP | |
23 .BI \-l " lines" | |
24 dmenu lists items vertically, with the given number of lines. | |
25 .TP | |
26 diff --git a/dmenu.c b/dmenu.c | |
27 index 27b7a30..b586a40 100644 | |
28 --- a/dmenu.c | |
29 +++ b/dmenu.c | |
30 @@ -29,7 +29,7 @@ | |
31 enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes… | |
32 | |
33 struct item { | |
34 - char *text; | |
35 + char *text, *value; | |
36 struct item *left, *right; | |
37 int out; | |
38 }; | |
39 @@ -104,8 +104,8 @@ cleanup(void) | |
40 XUngrabKey(dpy, AnyKey, AnyModifier, root); | |
41 for (i = 0; i < SchemeLast; i++) | |
42 free(scheme[i]); | |
43 - for (i = 0; items && items[i].text; ++i) | |
44 - free(items[i].text); | |
45 + for (i = 0; items && items[i].value; ++i) | |
46 + free(items[i].value); | |
47 free(items); | |
48 drw_free(drw); | |
49 XSync(dpy, False); | |
50 @@ -490,7 +490,7 @@ insert: | |
51 break; | |
52 case XK_Return: | |
53 case XK_KP_Enter: | |
54 - puts((sel && !(ev->state & ShiftMask)) ? sel->text : te… | |
55 + puts((sel && !(ev->state & ShiftMask)) ? sel->value : t… | |
56 if (!(ev->state & ControlMask)) { | |
57 cleanup(); | |
58 exit(0); | |
59 @@ -549,7 +549,7 @@ paste(void) | |
60 static void | |
61 readstdin(void) | |
62 { | |
63 - char *line = NULL; | |
64 + char *line = NULL, *text; | |
65 size_t i, junk, itemsiz = 0; | |
66 ssize_t len; | |
67 | |
68 @@ -562,13 +562,22 @@ readstdin(void) | |
69 } | |
70 if (line[len - 1] == '\n') | |
71 line[len - 1] = '\0'; | |
72 - items[i].text = line; | |
73 + | |
74 + if ((text = strchr(line, valuedelimiter)) != NULL) { | |
75 + items[i].text = text + 1; | |
76 + text[0] = '\0'; | |
77 + } else { | |
78 + items[i].text = line; | |
79 + } | |
80 + items[i].value = line; | |
81 items[i].out = 0; | |
82 line = NULL; /* next call of getline() allocates a new … | |
83 } | |
84 free(line); | |
85 - if (items) | |
86 + if (items) { | |
87 items[i].text = NULL; | |
88 + items[i].value = NULL; | |
89 + } | |
90 lines = MIN(lines, i); | |
91 } | |
92 | |
93 @@ -714,7 +723,7 @@ setup(void) | |
94 static void | |
95 usage(void) | |
96 { | |
97 - die("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m… | |
98 + die("usage: dmenu [-bfiv] [-d tmenu-delim] [-l lines] [-p promp… | |
99 " [-nb color] [-nf color] [-sb color] [-sf colo… | |
100 } | |
101 | |
102 @@ -739,6 +748,8 @@ main(int argc, char *argv[]) | |
103 } else if (i + 1 == argc) | |
104 usage(); | |
105 /* these options take one argument */ | |
106 + else if (!strcmp(argv[i], "-d")) /* delimiter for tme… | |
107 + valuedelimiter = argv[++i][0]; | |
108 else if (!strcmp(argv[i], "-l")) /* number of lines i… | |
109 lines = atoi(argv[++i]); | |
110 else if (!strcmp(argv[i], "-m")) |