diff options
Diffstat (limited to 'dmenu.c')
-rw-r--r-- | dmenu.c | 21 |
1 files changed, 18 insertions, 3 deletions
@@ -22,6 +22,7 @@ typedef struct Item Item; | |||
22 | struct Item { | 22 | struct Item { |
23 | char *text; | 23 | char *text; |
24 | Item *left, *right; | 24 | Item *left, *right; |
25 | Bool out; | ||
25 | }; | 26 | }; |
26 | 27 | ||
27 | static void appenditem(Item *item, Item **list, Item **last); | 28 | static void appenditem(Item *item, Item **list, Item **last); |
@@ -49,9 +50,12 @@ static const char *normbgcolor = "#222222"; | |||
49 | static const char *normfgcolor = "#bbbbbb"; | 50 | static const char *normfgcolor = "#bbbbbb"; |
50 | static const char *selbgcolor = "#005577"; | 51 | static const char *selbgcolor = "#005577"; |
51 | static const char *selfgcolor = "#eeeeee"; | 52 | static const char *selfgcolor = "#eeeeee"; |
53 | static const char *outbgcolor = "#00ffff"; | ||
54 | static const char *outfgcolor = "#000000"; | ||
52 | static unsigned int lines = 0; | 55 | static unsigned int lines = 0; |
53 | static unsigned long normcol[ColLast]; | 56 | static unsigned long normcol[ColLast]; |
54 | static unsigned long selcol[ColLast]; | 57 | static unsigned long selcol[ColLast]; |
58 | static unsigned long outcol[ColLast]; | ||
55 | static Atom clip, utf8; | 59 | static Atom clip, utf8; |
56 | static Bool topbar = True; | 60 | static Bool topbar = True; |
57 | static DC *dc; | 61 | static DC *dc; |
@@ -185,7 +189,8 @@ drawmenu(void) { | |||
185 | dc->w = mw - dc->x; | 189 | dc->w = mw - dc->x; |
186 | for(item = curr; item != next; item = item->right) { | 190 | for(item = curr; item != next; item = item->right) { |
187 | dc->y += dc->h; | 191 | dc->y += dc->h; |
188 | drawtext(dc, item->text, (item == sel) ? selcol : normcol); | 192 | drawtext(dc, item->text, (item == sel) ? selcol : |
193 | (item->out) ? outcol : normcol); | ||
189 | } | 194 | } |
190 | } | 195 | } |
191 | else if(matches) { | 196 | else if(matches) { |
@@ -197,7 +202,8 @@ drawmenu(void) { | |||
197 | for(item = curr; item != next; item = item->right) { | 202 | for(item = curr; item != next; item = item->right) { |
198 | dc->x += dc->w; | 203 | dc->x += dc->w; |
199 | dc->w = MIN(textw(dc, item->text), mw - dc->x - textw(dc, ">")); | 204 | dc->w = MIN(textw(dc, item->text), mw - dc->x - textw(dc, ">")); |
200 | drawtext(dc, item->text, (item == sel) ? selcol : normcol); | 205 | drawtext(dc, item->text, (item == sel) ? selcol : |
206 | (item->out) ? outcol : normcol); | ||
201 | } | 207 | } |
202 | dc->w = textw(dc, ">"); | 208 | dc->w = textw(dc, ">"); |
203 | dc->x = mw - dc->w; | 209 | dc->x = mw - dc->w; |
@@ -278,6 +284,9 @@ keypress(XKeyEvent *ev) { | |||
278 | XConvertSelection(dc->dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, | 284 | XConvertSelection(dc->dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, |
279 | utf8, utf8, win, CurrentTime); | 285 | utf8, utf8, win, CurrentTime); |
280 | return; | 286 | return; |
287 | case XK_Return: | ||
288 | case XK_KP_Enter: | ||
289 | break; | ||
281 | default: | 290 | default: |
282 | return; | 291 | return; |
283 | } | 292 | } |
@@ -362,7 +371,10 @@ keypress(XKeyEvent *ev) { | |||
362 | case XK_Return: | 371 | case XK_Return: |
363 | case XK_KP_Enter: | 372 | case XK_KP_Enter: |
364 | puts((sel && !(ev->state & ShiftMask)) ? sel->text : text); | 373 | puts((sel && !(ev->state & ShiftMask)) ? sel->text : text); |
365 | exit(EXIT_SUCCESS); | 374 | if(!(ev->state & ControlMask)) |
375 | exit(EXIT_SUCCESS); | ||
376 | sel->out = True; | ||
377 | break; | ||
366 | case XK_Right: | 378 | case XK_Right: |
367 | if(text[cursor] != '\0') { | 379 | if(text[cursor] != '\0') { |
368 | cursor = nextrune(+1); | 380 | cursor = nextrune(+1); |
@@ -480,6 +492,7 @@ readstdin(void) { | |||
480 | *p = '\0'; | 492 | *p = '\0'; |
481 | if(!(items[i].text = strdup(buf))) | 493 | if(!(items[i].text = strdup(buf))) |
482 | eprintf("cannot strdup %u bytes:", strlen(buf)+1); | 494 | eprintf("cannot strdup %u bytes:", strlen(buf)+1); |
495 | items[i].out = False; | ||
483 | if(strlen(items[i].text) > max) | 496 | if(strlen(items[i].text) > max) |
484 | max = strlen(maxstr = items[i].text); | 497 | max = strlen(maxstr = items[i].text); |
485 | } | 498 | } |
@@ -531,6 +544,8 @@ setup(void) { | |||
531 | normcol[ColFG] = getcolor(dc, normfgcolor); | 544 | normcol[ColFG] = getcolor(dc, normfgcolor); |
532 | selcol[ColBG] = getcolor(dc, selbgcolor); | 545 | selcol[ColBG] = getcolor(dc, selbgcolor); |
533 | selcol[ColFG] = getcolor(dc, selfgcolor); | 546 | selcol[ColFG] = getcolor(dc, selfgcolor); |
547 | outcol[ColBG] = getcolor(dc, outbgcolor); | ||
548 | outcol[ColFG] = getcolor(dc, outfgcolor); | ||
534 | 549 | ||
535 | clip = XInternAtom(dc->dpy, "CLIPBOARD", False); | 550 | clip = XInternAtom(dc->dpy, "CLIPBOARD", False); |
536 | utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False); | 551 | utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False); |