aboutsummaryrefslogtreecommitdiff
path: root/dmenu.c
diff options
context:
space:
mode:
Diffstat (limited to 'dmenu.c')
-rw-r--r--dmenu.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/dmenu.c b/dmenu.c
index 3962801..efc1e54 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -22,6 +22,7 @@ typedef struct Item Item;
22struct Item { 22struct Item {
23 char *text; 23 char *text;
24 Item *left, *right; 24 Item *left, *right;
25 Bool out;
25}; 26};
26 27
27static void appenditem(Item *item, Item **list, Item **last); 28static void appenditem(Item *item, Item **list, Item **last);
@@ -49,9 +50,12 @@ static const char *normbgcolor = "#222222";
49static const char *normfgcolor = "#bbbbbb"; 50static const char *normfgcolor = "#bbbbbb";
50static const char *selbgcolor = "#005577"; 51static const char *selbgcolor = "#005577";
51static const char *selfgcolor = "#eeeeee"; 52static const char *selfgcolor = "#eeeeee";
53static const char *outbgcolor = "#00ffff";
54static const char *outfgcolor = "#000000";
52static unsigned int lines = 0; 55static unsigned int lines = 0;
53static unsigned long normcol[ColLast]; 56static unsigned long normcol[ColLast];
54static unsigned long selcol[ColLast]; 57static unsigned long selcol[ColLast];
58static unsigned long outcol[ColLast];
55static Atom clip, utf8; 59static Atom clip, utf8;
56static Bool topbar = True; 60static Bool topbar = True;
57static DC *dc; 61static 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);