dmenu-emoji-highlight-5.0.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
dmenu-emoji-highlight-5.0.diff (9148B)
---
1 diff --git a/config.def.h b/config.def.h
2 index 1edb647..ed3b175 100644
3 --- a/config.def.h
4 +++ b/config.def.h
5 @@ -4,18 +4,33 @@
6 static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */
7 /* -fn option overrides fonts[0]; default X11 font or font set */
8 static const char *fonts[] = {
9 - "monospace:size=10"
10 + "monospace:size=10",
11 + "FiraCode Nerd Font:size=12",
12 };
13 +
14 static const char *prompt = NULL; /* -p option; prompt to the left of input field */
15 -static const char *colors[SchemeLast][2] = {
16 - /* fg bg */
17 - [SchemeNorm] = { "#bbbbbb", "#222222" },
18 - [SchemeSel] = { "#eeeeee", "#005577" },
19 - [SchemeOut] = { "#000000", "#00ffff" },
20 +static const char *colors[SchemeLast][10] = {
21 + /* fg bg */
22 + [SchemeNorm] = { "#bbbbbb", "#222222", "#222222" },
23 + [SchemeSel] = { "#eeeeee", "#005577", "#005577" },
24 + [SchemeOut] = { "#000000", "#00ffff", "#00ffff" },
25 + [SchemeHighlight] = {"#f1fa8c", "#596377", "#3E485B"},
26 + [SchemeHover] = {"#ffffff", "#353D4B", "#3E485B"},
27 + [SchemeGreen] = {"#ffffff", "#52E067", "#41b252"},
28 + [SchemeRed] = {"#ffffff", "#e05252", "#c24343"},
29 + [SchemeYellow] = {"#ffffff", "#e0c452", "#bca33f"},
30 + [SchemeBlue] = {"#ffffff", "#5280e0", "#3a62b3"},
31 + [SchemePurple] = {"#ffffff", "#9952e0", "#7439b0"},
32 };
33 /* -l option; if nonzero, dmenu uses vertical list with given number of lines */
34 static unsigned int lines = 0;
35
36 +static unsigned int lineheight = 0; /* -h option; minimum height of a menu line */
37 +static unsigned int min_lineheight = 8;
38 +static int sely = 0;
39 +static int commented = 0;
40 +static int animated = 0;
41 +
42 /*
43 * Characters not considered part of a word while deleting words
44 * for example: " /?\"&[]"
45 diff --git a/dmenu.c b/dmenu.c
46 index 65f25ce..a558fcb 100644
47 --- a/dmenu.c
48 +++ b/dmenu.c
49 @@ -26,7 +26,20 @@
50 #define TEXTW(X) (drw_fontset_getwidth(drw, (X)) + lrpad)
51
52 /* enums */
53 -enum { SchemeNorm, SchemeSel, SchemeOut, SchemeLast }; /* color schemes */
54 +enum {
55 + SchemeNorm,
56 + SchemeFade,
57 + SchemeHighlight,
58 + SchemeHover,
59 + SchemeSel,
60 + SchemeOut,
61 + SchemeGreen,
62 + SchemeYellow,
63 + SchemeBlue,
64 + SchemePurple,
65 + SchemeRed,
66 + SchemeLast
67 +}; /* color schemes */
68
69 struct item {
70 char *text;
71 @@ -37,6 +50,9 @@ struct item {
72 static char text[BUFSIZ] = "";
73 static char *embed;
74 static int bh, mw, mh;
75 +static int dmx = 0; /* put dmenu at this x offset */
76 +static int dmy = 0; /* put dmenu at this y offset (measured from the bottom if topbar is 0) */
77 +static unsigned int dmw = 0; /* make dmenu this wide */
78 static int inputw = 0, promptw;
79 static int lrpad; /* sum of left and right padding */
80 static size_t cursor;
81 @@ -114,16 +130,117 @@ cistrstr(const char *s, const char *sub)
82 }
83
84 static int
85 -drawitem(struct item *item, int x, int y, int w)
86 -{
87 - if (item == sel)
88 - drw_setscheme(drw, scheme[SchemeSel]);
89 - else if (item->out)
90 - drw_setscheme(drw, scheme[SchemeOut]);
91 - else
92 - drw_setscheme(drw, scheme[SchemeNorm]);
93 -
94 - return drw_text(drw, x, y, w, bh, lrpad / 2, item->text, 0);
95 +drawitem(struct item *item, int x, int y, int w) {
96 + int iscomment = 0;
97 + if (item->text[0] == '>') {
98 + if (item->text[1] == '>') {
99 + iscomment = 3;
100 + switch (item->text[2]) {
101 + case 'r':
102 + drw_setscheme(drw, scheme[SchemeRed]);
103 + break;
104 + case 'g':
105 + drw_setscheme(drw, scheme[SchemeGreen]);
106 + break;
107 + case 'y':
108 + drw_setscheme(drw, scheme[SchemeYellow]);
109 + break;
110 + case 'b':
111 + drw_setscheme(drw, scheme[SchemeBlue]);
112 + break;
113 + case 'p':
114 + drw_setscheme(drw, scheme[SchemePurple]);
115 + break;
116 + case 'h':
117 + drw_setscheme(drw, scheme[SchemeHighlight]);
118 + break;
119 + case 's':
120 + drw_setscheme(drw, scheme[SchemeSel]);
121 + break;
122 + default:
123 + iscomment = 1;
124 + drw_setscheme(drw, scheme[SchemeNorm]);
125 + break;
126 + }
127 + } else {
128 + drw_setscheme(drw, scheme[SchemeNorm]);
129 + iscomment = 1;
130 + }
131 +
132 + } else if (item->text[0] == ':') {
133 + iscomment = 2;
134 + if (item == sel) {
135 + switch (item->text[1]) {
136 + case 'r':
137 + drw_setscheme(drw, scheme[SchemeRed]);
138 + break;
139 + case 'g':
140 + drw_setscheme(drw, scheme[SchemeGreen]);
141 + break;
142 + case 'y':
143 + drw_setscheme(drw, scheme[SchemeYellow]);
144 + break;
145 + case 'b':
146 + drw_setscheme(drw, scheme[SchemeBlue]);
147 + break;
148 + case 'p':
149 + drw_setscheme(drw, scheme[SchemePurple]);
150 + break;
151 + case 'h':
152 + drw_setscheme(drw, scheme[SchemeHighlight]);
153 + break;
154 + case 's':
155 + drw_setscheme(drw, scheme[SchemeSel]);
156 + break;
157 + default:
158 + drw_setscheme(drw, scheme[SchemeSel]);
159 + iscomment = 0;
160 + break;
161 + }
162 + } else {
163 + drw_setscheme(drw, scheme[SchemeNorm]);
164 + }
165 + } else {
166 + if (item == sel)
167 + drw_setscheme(drw, scheme[SchemeSel]);
168 + else if (item->out)
169 + drw_setscheme(drw, scheme[SchemeOut]);
170 + else
171 + drw_setscheme(drw, scheme[SchemeNorm]);
172 + }
173 +
174 + int temppadding;
175 + temppadding = 0;
176 + if (iscomment == 2) {
177 + if (item->text[2] == ' ') {
178 + temppadding = drw->fonts->h * 3;
179 + animated = 1;
180 + char dest[1000];
181 + strcpy(dest, item->text);
182 + dest[6] = '\0';
183 + drw_text(drw, x, y, temppadding, lineheight, temppadding / 2.6, dest + 3, 0);
184 + iscomment = 6;
185 + drw_setscheme(drw, sel == item ? scheme[SchemeHover] : scheme[SchemeNorm]);
186 + }
187 + }
188 +
189 + char *output;
190 + if (commented) {
191 + static char onestr[2];
192 + onestr[0] = item->text[0];
193 + onestr[1] = '\0';
194 + output = onestr;
195 + } else {
196 + output = item->text;
197 + }
198 +
199 + if (item == sel)
200 + sely = y;
201 + return drw_text(
202 + drw, x + ((iscomment == 6) ? temppadding : 0), y,
203 + commented ? bh : (w - ((iscomment == 6) ? temppadding : 0)), bh,
204 + commented ? (bh - drw_fontset_getwidth(drw, (output))) / 2 : lrpad / 2,
205 + output + iscomment, 0);
206 }
207
208 static void
209 @@ -131,7 +248,7 @@ drawmenu(void)
210 {
211 unsigned int curpos;
212 struct item *item;
213 - int x = 0, y = 0, w;
214 + int x = 0, y = 0, fh = drw->fonts->h, w;
215
216 drw_setscheme(drw, scheme[SchemeNorm]);
217 drw_rect(drw, 0, 0, mw, mh, 1, 1);
218 @@ -148,7 +265,7 @@ drawmenu(void)
219 curpos = TEXTW(text) - TEXTW(&text[cursor]);
220 if ((curpos += lrpad / 2 - 1) < w) {
221 drw_setscheme(drw, scheme[SchemeNorm]);
222 - drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0);
223 + drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0);
224 }
225
226 if (lines > 0) {
227 @@ -609,6 +726,7 @@ setup(void)
228
229 /* calculate menu geometry */
230 bh = drw->fonts->h + 2;
231 + bh = MAX(bh,lineheight); /* make a menu line AT LEAST 'lineheight' tall */
232 lines = MAX(lines, 0);
233 mh = (lines + 1) * bh;
234 #ifdef XINERAMA
235 @@ -637,9 +755,9 @@ setup(void)
236 if (INTERSECT(x, y, 1, 1, info[i]))
237 break;
238
239 - x = info[i].x_org;
240 - y = info[i].y_org + (topbar ? 0 : info[i].height - mh);
241 - mw = info[i].width;
242 + x = info[i].x_org + dmx;
243 + y = info[i].y_org + (topbar ? dmy : info[i].height - mh - dmy);
244 + mw = (dmw>0 ? dmw : info[i].width);
245 XFree(info);
246 } else
247 #endif
248 @@ -647,9 +765,9 @@ setup(void)
249 if (!XGetWindowAttributes(dpy, parentwin, &wa))
250 die("could not get embedding window attributes: 0x%lx",
251 parentwin);
252 - x = 0;
253 - y = topbar ? 0 : wa.height - mh;
254 - mw = wa.width;
255 + x = dmx;
256 + y = topbar ? dmy : wa.height - mh - dmy;
257 + mw = (dmw>0 ? dmw : wa.width);
258 }
259 promptw = (prompt && *prompt) ? TEXTW(prompt) - lrpad / 4 : 0;
260 inputw = MIN(inputw, mw/3);
261 @@ -689,7 +807,8 @@ setup(void)
262 static void
263 usage(void)
264 {
265 - fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
266 + fputs("usage: dmenu [-bfiv] [-l lines] [-h height] [-p prompt] [-fn font] [-m monitor]\n"
267 + " [-x xoffset] [-y yoffset] [-z width]\n"
268 " [-nb color] [-nf color] [-sb color] [-sf color] [-w windowid]\n", stderr);
269 exit(1);
270 }
271 @@ -717,6 +836,16 @@ main(int argc, char *argv[])
272 /* these options take one argument */
273 else if (!strcmp(argv[i], "-l")) /* number of lines in vertical list */
274 lines = atoi(argv[++i]);
275 + else if (!strcmp(argv[i], "-x")) /* window x offset */
276 + dmx = atoi(argv[++i]);
277 + else if (!strcmp(argv[i], "-y")) /* window y offset (from bottom up if -b) */
278 + dmy = atoi(argv[++i]);
279 + else if (!strcmp(argv[i], "-z")) /* make dmenu this wide */
280 + dmw = atoi(argv[++i]);
281 + else if (!strcmp(argv[i], "-h")) { /* minimum height of one menu line */
282 + lineheight = atoi(argv[++i]);
283 + lineheight = MAX(lineheight, min_lineheight);
284 + }
285 else if (!strcmp(argv[i], "-m"))
286 mon = atoi(argv[++i]);
287 else if (!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
288 @@ -752,6 +881,9 @@ main(int argc, char *argv[])
289 die("no fonts could be loaded.");
290 lrpad = drw->fonts->h;
291
292 + if (lineheight == -1)
293 + lineheight = drw->fonts->h * 2.5;
294 +
295 #ifdef __OpenBSD__
296 if (pledge("stdio rpath", NULL) == -1)
297 die("pledge");