X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=dmenu.c;h=ff7436936315e4cc6c00942fc74179b5e797254b;hb=a97f550aa7b81d2add1d2a99e594c038da01fc19;hp=b19148632adb7f63b4706822f623d616f3f19e10;hpb=a4053bc4e403ae57343f43b7e363a0911bba5a3a;p=dmenu.git diff --git a/dmenu.c b/dmenu.c index b191486..ff74369 100644 --- a/dmenu.c +++ b/dmenu.c @@ -130,7 +130,7 @@ drawmenu(void) { unsigned int curpos; struct item *item; - int x = 0, y = 0, w, inputscheme; + int x = 0, y = 0, w; drw_setscheme(drw, scheme[SchemeNorm]); drw_rect(drw, 0, 0, mw, mh, 1, 1); @@ -138,27 +138,18 @@ drawmenu(void) if (prompt && *prompt) { drw_setscheme(drw, scheme[SchemeSel]); x = drw_text(drw, x, 0, promptw, bh, lrpad / 2, prompt, 0); - x += 2; } /* draw input field */ w = (lines > 0 || !matches) ? mw - x : inputw; - if (matches && !strcmp(text, curr->text)) - inputscheme = SchemeSel; - else - inputscheme = SchemeNorm; - drw_setscheme(drw, scheme[inputscheme]); - + drw_setscheme(drw, scheme[SchemeNorm]); drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0); drw_font_getexts(drw->fonts, text, cursor, &curpos, NULL); if ((curpos += lrpad / 2 - 1) < w) { - drw_setscheme(drw, scheme[inputscheme]); + drw_setscheme(drw, scheme[SchemeNorm]); drw_rect(drw, x + curpos, 2, 2, bh - 4, 1, 0); } - if (inputscheme == SchemeSel) - goto drawmap; - if (lines > 0) { /* draw vertical list */ for (item = curr; item != next; item = item->right) @@ -180,7 +171,6 @@ drawmenu(void) drw_text(drw, mw - w, 0, w, bh, lrpad / 2, ">", 0); } } -drawmap: drw_map(drw, win, 0, 0, mw, mh); } @@ -197,7 +187,7 @@ grabkeyboard(void) return; nanosleep(&ts, NULL); } - die("cannot grab keyboard\n"); + die("cannot grab keyboard"); } static void @@ -215,7 +205,7 @@ match(void) /* separate input text into tokens to be matched individually */ for (s = strtok(buf, " "); s; tokv[tokc - 1] = s, s = strtok(NULL, " ")) if (++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv))) - die("cannot realloc %u bytes\n", tokn * sizeof *tokv); + die("cannot realloc %u bytes:", tokn * sizeof *tokv); len = tokc ? strlen(tokv[0]) : 0; matches = lprefix = lsubstr = matchend = prefixend = substrend = NULL; @@ -551,7 +541,7 @@ setup(void) #ifdef XINERAMA if ((info = XineramaQueryScreens(dpy, &n))) { XGetInputFocus(dpy, &w, &di); - if (mon != -1 && mon < n) + if (mon >= 0 && mon < n) i = mon; else if (w != root && w != PointerRoot && w != None) { /* find top-level window containing current input focus */ @@ -568,7 +558,7 @@ setup(void) } } /* no focused window is on screen, so use pointer location instead */ - if (mon == -1 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du)) + if (mon < 0 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du)) for (i = 0; i < n; i++) if (INTERSECT(x, y, 1, 1, info[i])) break; @@ -610,8 +600,8 @@ setup(void) static void usage(void) { - 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); + fputs("usage: dmenu [-bfiv] [-l lines] [-p prompt] [-fn font] [-m monitor]\n" + " [-nb color] [-nf color] [-sb color] [-sf color]\n", stderr); exit(1); } @@ -657,14 +647,14 @@ main(int argc, char *argv[]) if (!setlocale(LC_CTYPE, "") || !XSupportsLocale()) fputs("warning: no locale support\n", stderr); if (!(dpy = XOpenDisplay(NULL))) - die("cannot open display\n"); + die("cannot open display"); screen = DefaultScreen(dpy); root = RootWindow(dpy, screen); sw = DisplayWidth(dpy, screen); sh = DisplayHeight(dpy, screen); drw = drw_create(dpy, screen, root, sw, sh); if (!drw_fontset_create(drw, fonts, LENGTH(fonts))) - die("no fonts could be loaded.\n"); + die("no fonts could be loaded."); lrpad = drw->fonts->h; if (fast) {