X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dmenu.c;h=94c70deb749db4710067ff4b1c98904d36d2b3ed;hb=13a529ce63364544bdc851dfd5d3aa2ef8740914;hp=c25dc82373f623757393c593eff6bf6292a76151;hpb=ec64f273fb7660d3746eb765dc02e40726a54294;p=dmenu.git diff --git a/dmenu.c b/dmenu.c index c25dc82..94c70de 100644 --- a/dmenu.c +++ b/dmenu.c @@ -44,26 +44,19 @@ static char text[BUFSIZ] = ""; 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 const char *outbgcolor = "#00ffff"; -static const char *outfgcolor = "#000000"; -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; @@ -76,7 +69,7 @@ main(int argc, char *argv[]) { for(i = 1; i < argc; i++) /* these options take no arguments */ if(!strcmp(argv[i], "-v")) { /* prints version information */ - puts("dmenu-"VERSION", © 2006-2012 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 */ @@ -92,6 +85,8 @@ main(int argc, char *argv[]) { /* 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 */ @@ -261,9 +256,9 @@ keypress(XKeyEvent *ev) { case XK_h: ksym = XK_BackSpace; break; case XK_i: ksym = XK_Tab; break; case XK_j: /* fallthrough */ - case XK_J: ksym = XK_Return; break; + case XK_J: /* fallthrough */ case XK_m: /* fallthrough */ - case XK_M: ksym = XK_Return; break; + case XK_M: ksym = XK_Return; ev->state &= ~ControlMask; break; case XK_n: ksym = XK_Down; break; case XK_p: ksym = XK_Up; break; @@ -287,6 +282,8 @@ keypress(XKeyEvent *ev) { case XK_Return: case XK_KP_Enter: break; + case XK_bracketleft: + exit(EXIT_FAILURE); default: return; } @@ -373,7 +370,8 @@ keypress(XKeyEvent *ev) { puts((sel && !(ev->state & ShiftMask)) ? sel->text : text); if(!(ev->state & ControlMask)) exit(EXIT_SUCCESS); - sel->out = True; + if(sel) + sel->out = True; break; case XK_Right: if(text[cursor] != '\0') { @@ -563,7 +561,9 @@ setup(void) { 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) @@ -578,7 +578,7 @@ setup(void) { } } /* 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; @@ -620,7 +620,7 @@ setup(void) { 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); }