applied multisel patch to mainline

This commit is contained in:
Anselm R Garbe 2013-04-17 20:56:54 +02:00
parent dec9a28863
commit 0d12a47415
2 changed files with 21 additions and 3 deletions

View File

@ -83,6 +83,9 @@ Copy the selected item to the input field.
Confirm selection. Prints the selected item to stdout and exits, returning Confirm selection. Prints the selected item to stdout and exits, returning
success. success.
.TP .TP
.B Ctrl-Return
Confirm selection. Prints the selected item to stdout and continues.
.TP
.B Shift\-Return .B Shift\-Return
Confirm input. Prints the input text to stdout and exits, returning success. Confirm input. Prints the input text to stdout and exits, returning success.
.TP .TP

21
dmenu.c
View File

@ -22,6 +22,7 @@ typedef struct Item Item;
struct Item { struct Item {
char *text; char *text;
Item *left, *right; Item *left, *right;
Bool out;
}; };
static void appenditem(Item *item, Item **list, Item **last); static void appenditem(Item *item, Item **list, Item **last);
@ -49,9 +50,12 @@ static const char *normbgcolor = "#222222";
static const char *normfgcolor = "#bbbbbb"; static const char *normfgcolor = "#bbbbbb";
static const char *selbgcolor = "#005577"; static const char *selbgcolor = "#005577";
static const char *selfgcolor = "#eeeeee"; static const char *selfgcolor = "#eeeeee";
static const char *outbgcolor = "#00ffff";
static const char *outfgcolor = "#000000";
static unsigned int lines = 0; static unsigned int lines = 0;
static unsigned long normcol[ColLast]; static unsigned long normcol[ColLast];
static unsigned long selcol[ColLast]; static unsigned long selcol[ColLast];
static unsigned long outcol[ColLast];
static Atom clip, utf8; static Atom clip, utf8;
static Bool topbar = True; static Bool topbar = True;
static DC *dc; static DC *dc;
@ -185,7 +189,8 @@ drawmenu(void) {
dc->w = mw - dc->x; dc->w = mw - dc->x;
for(item = curr; item != next; item = item->right) { for(item = curr; item != next; item = item->right) {
dc->y += dc->h; dc->y += dc->h;
drawtext(dc, item->text, (item == sel) ? selcol : normcol); drawtext(dc, item->text, (item == sel) ? selcol :
(item->out) ? outcol : normcol);
} }
} }
else if(matches) { else if(matches) {
@ -197,7 +202,8 @@ drawmenu(void) {
for(item = curr; item != next; item = item->right) { for(item = curr; item != next; item = item->right) {
dc->x += dc->w; dc->x += dc->w;
dc->w = MIN(textw(dc, item->text), mw - dc->x - textw(dc, ">")); dc->w = MIN(textw(dc, item->text), mw - dc->x - textw(dc, ">"));
drawtext(dc, item->text, (item == sel) ? selcol : normcol); drawtext(dc, item->text, (item == sel) ? selcol :
(item->out) ? outcol : normcol);
} }
dc->w = textw(dc, ">"); dc->w = textw(dc, ">");
dc->x = mw - dc->w; dc->x = mw - dc->w;
@ -278,6 +284,9 @@ keypress(XKeyEvent *ev) {
XConvertSelection(dc->dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, XConvertSelection(dc->dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
utf8, utf8, win, CurrentTime); utf8, utf8, win, CurrentTime);
return; return;
case XK_Return:
case XK_KP_Enter:
break;
default: default:
return; return;
} }
@ -362,7 +371,10 @@ keypress(XKeyEvent *ev) {
case XK_Return: case XK_Return:
case XK_KP_Enter: case XK_KP_Enter:
puts((sel && !(ev->state & ShiftMask)) ? sel->text : text); puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
exit(EXIT_SUCCESS); if(!(ev->state & ControlMask))
exit(EXIT_SUCCESS);
sel->out = True;
break;
case XK_Right: case XK_Right:
if(text[cursor] != '\0') { if(text[cursor] != '\0') {
cursor = nextrune(+1); cursor = nextrune(+1);
@ -480,6 +492,7 @@ readstdin(void) {
*p = '\0'; *p = '\0';
if(!(items[i].text = strdup(buf))) if(!(items[i].text = strdup(buf)))
eprintf("cannot strdup %u bytes:", strlen(buf)+1); eprintf("cannot strdup %u bytes:", strlen(buf)+1);
items[i].out = False;
if(strlen(items[i].text) > max) if(strlen(items[i].text) > max)
max = strlen(maxstr = items[i].text); max = strlen(maxstr = items[i].text);
} }
@ -531,6 +544,8 @@ setup(void) {
normcol[ColFG] = getcolor(dc, normfgcolor); normcol[ColFG] = getcolor(dc, normfgcolor);
selcol[ColBG] = getcolor(dc, selbgcolor); selcol[ColBG] = getcolor(dc, selbgcolor);
selcol[ColFG] = getcolor(dc, selfgcolor); selcol[ColFG] = getcolor(dc, selfgcolor);
outcol[ColBG] = getcolor(dc, outbgcolor);
outcol[ColFG] = getcolor(dc, outfgcolor);
clip = XInternAtom(dc->dpy, "CLIPBOARD", False); clip = XInternAtom(dc->dpy, "CLIPBOARD", False);
utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False); utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);