struct Item {
char *text;
Item *left, *right;
+ Bool out;
};
static void appenditem(Item *item, Item **list, Item **last);
static int bh, mw, mh;
static int inputw, promptw;
static size_t cursor = 0;
-static const char *font = NULL;
-static const char *prompt = NULL;
-static const char *normbgcolor = "#222222";
-static const char *normfgcolor = "#bbbbbb";
-static const char *selbgcolor = "#005577";
-static const char *selfgcolor = "#eeeeee";
-static unsigned int lines = 0;
static unsigned long normcol[ColLast];
static unsigned long selcol[ColLast];
+static unsigned long outcol[ColLast];
static Atom clip, utf8;
-static Bool topbar = True;
static DC *dc;
static Item *items = NULL;
static Item *matches, *matchend;
static Item *prev, *curr, *next, *sel;
static Window win;
static XIC xic;
+static int mon = -1;
+
+#include "config.h"
static int (*fstrncmp)(const char *, const char *, size_t) = strncmp;
static char *(*fstrstr)(const char *, const char *) = strstr;
for(i = 1; i < argc; i++)
/* these options take no arguments */
if(!strcmp(argv[i], "-v")) { /* prints version information */
- puts("dmenu-"VERSION", © 2006-2011 dmenu engineers, see LICENSE for details");
+ puts("dmenu-"VERSION", © 2006-2014 dmenu engineers, see LICENSE for details");
exit(EXIT_SUCCESS);
}
else if(!strcmp(argv[i], "-b")) /* appears at the bottom of the screen */
/* these options take one argument */
else if(!strcmp(argv[i], "-l")) /* number of lines in vertical list */
lines = atoi(argv[++i]);
+ else if(!strcmp(argv[i], "-m"))
+ mon = atoi(argv[++i]);
else if(!strcmp(argv[i], "-p")) /* adds prompt to left of input field */
prompt = argv[++i];
else if(!strcmp(argv[i], "-fn")) /* font or font set */
setup();
run();
- return EXIT_FAILURE; /* unreachable */
+ return 1; /* unreachable */
}
void
dc->h = bh;
drawrect(dc, 0, 0, mw, mh, True, BG(dc, normcol));
- if(prompt) {
+ if(prompt && *prompt) {
dc->w = promptw;
drawtext(dc, prompt, selcol);
dc->x = dc->w;
dc->w = mw - dc->x;
for(item = curr; item != next; item = item->right) {
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) {
for(item = curr; item != next; item = item->right) {
dc->x += dc->w;
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->x = mw - dc->w;
len = XmbLookupString(xic, ev, buf, sizeof buf, &ksym, &status);
if(status == XBufferOverflow)
return;
- if(ev->state & ControlMask) {
- KeySym lower, upper;
-
- XConvertCase(ksym, &lower, &upper);
- switch(lower) {
+ if(ev->state & ControlMask)
+ switch(ksym) {
case XK_a: ksym = XK_Home; break;
case XK_b: ksym = XK_Left; break;
case XK_c: ksym = XK_Escape; break;
case XK_d: ksym = XK_Delete; break;
case XK_e: ksym = XK_End; break;
case XK_f: ksym = XK_Right; break;
+ case XK_g: ksym = XK_Escape; break;
case XK_h: ksym = XK_BackSpace; break;
case XK_i: ksym = XK_Tab; break;
- case XK_j: ksym = XK_Return; break;
- case XK_m: ksym = XK_Return; break;
+ case XK_j: /* fallthrough */
+ case XK_J: ksym = XK_Return; break;
+ case XK_m: /* fallthrough */
+ case XK_M: ksym = XK_Return; break;
case XK_n: ksym = XK_Down; break;
case XK_p: ksym = XK_Up; break;
XConvertSelection(dc->dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
utf8, utf8, win, CurrentTime);
return;
+ case XK_Return:
+ case XK_KP_Enter:
+ break;
+ case XK_bracketleft:
+ exit(EXIT_FAILURE);
+ default:
+ return;
+ }
+ else if(ev->state & Mod1Mask)
+ switch(ksym) {
+ case XK_g: ksym = XK_Home; break;
+ case XK_G: ksym = XK_End; break;
+ case XK_h: ksym = XK_Up; break;
+ case XK_j: ksym = XK_Next; break;
+ case XK_k: ksym = XK_Prior; break;
+ case XK_l: ksym = XK_Down; break;
default:
return;
}
- }
switch(ksym) {
default:
if(!iscntrl(*buf))
cursor = nextrune(-1);
break;
}
+ if(lines > 0)
+ return;
/* fallthrough */
case XK_Up:
if(sel && sel->left && (sel = sel->left)->right == curr) {
case XK_Return:
case XK_KP_Enter:
puts((sel && !(ev->state & ShiftMask)) ? sel->text : text);
- exit(EXIT_SUCCESS);
+ if(!(ev->state & ControlMask))
+ exit(EXIT_SUCCESS);
+ if(sel)
+ sel->out = True;
+ break;
case XK_Right:
if(text[cursor] != '\0') {
cursor = nextrune(+1);
break;
}
+ if(lines > 0)
+ return;
/* fallthrough */
case XK_Down:
if(sel && sel->right && (sel = sel->right) == next) {
case XK_Tab:
if(!sel)
return;
- strncpy(text, sel->text, sizeof text);
+ strncpy(text, sel->text, sizeof text - 1);
+ text[sizeof text - 1] = '\0';
cursor = strlen(text);
match();
break;
*p = '\0';
if(!(items[i].text = strdup(buf)))
eprintf("cannot strdup %u bytes:", strlen(buf)+1);
+ items[i].out = False;
if(strlen(items[i].text) > max)
max = strlen(maxstr = items[i].text);
}
normcol[ColFG] = getcolor(dc, normfgcolor);
selcol[ColBG] = getcolor(dc, selbgcolor);
selcol[ColFG] = getcolor(dc, selfgcolor);
+ outcol[ColBG] = getcolor(dc, outbgcolor);
+ outcol[ColFG] = getcolor(dc, outfgcolor);
clip = XInternAtom(dc->dpy, "CLIPBOARD", False);
utf8 = XInternAtom(dc->dpy, "UTF8_STRING", False);
XWindowAttributes wa;
XGetInputFocus(dc->dpy, &w, &di);
- if(w != root && w != PointerRoot && w != None) {
+ if(mon != -1 && mon < n)
+ i = mon;
+ if(!i && w != root && w != PointerRoot && w != None) {
/* find top-level window containing current input focus */
do {
if(XQueryTree(dc->dpy, (pw = w), &dw, &w, &dws, &du) && dws)
}
}
/* no focused window is on screen, so use pointer location instead */
- if(!area && XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
+ if(mon == -1 && !area && XQueryPointer(dc->dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
for(i = 0; i < n; i++)
if(INTERSECT(x, y, 1, 1, info[i]))
break;
y = topbar ? 0 : DisplayHeight(dc->dpy, screen) - mh;
mw = DisplayWidth(dc->dpy, screen);
}
- promptw = prompt ? textw(dc, prompt) : 0;
+ promptw = (prompt && *prompt) ? textw(dc, prompt) : 0;
inputw = MIN(inputw, mw/3);
match();
/* create menu window */
swa.override_redirect = True;
- swa.background_pixmap = ParentRelative;
+ swa.background_pixel = normcol[ColBG];
swa.event_mask = ExposureMask | KeyPressMask | VisibilityChangeMask;
win = XCreateWindow(dc->dpy, root, x, y, mw, mh, 0,
DefaultDepth(dc->dpy, screen), CopyFromParent,
DefaultVisual(dc->dpy, screen),
- CWOverrideRedirect | CWBackPixmap | CWEventMask, &swa);
+ CWOverrideRedirect | CWBackPixel | CWEventMask, &swa);
/* open input methods */
xim = XOpenIM(dc->dpy, NULL, NULL, NULL);
void
usage(void) {
- fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font]\n"
+ fputs("usage: dmenu [-b] [-f] [-i] [-l lines] [-p prompt] [-fn font] [-m monitor]\n"
" [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr);
exit(EXIT_FAILURE);
}