X-Git-Url: https://git.xinqibao.xyz/dmenu.git/blobdiff_plain/2535072fd81839326621851b9052375d11d11de5..170b977288fdf06db87089b5e0d6df5a17ab58d5:/main.c diff --git a/main.c b/main.c index 32b08b9..561f88f 100644 --- a/main.c +++ b/main.c @@ -24,13 +24,11 @@ struct Item { /* static */ -static char *title, text[4096]; +static char text[4096]; static int mx, my, mw, mh; static int ret = 0; static int nitem = 0; static unsigned int cmdw = 0; -static unsigned int tw = 0; -static unsigned int cw = 0; static Bool done = False; static Item *allitems = NULL; /* first of all items */ static Item *item = NULL; /* first of pattern matching items */ @@ -82,18 +80,10 @@ drawmenu() drawtext(NULL, False, False); /* print command */ - if(!title || text[0]) { - cmdw = cw; - if(cmdw && item) - dc.w = cmdw; - drawtext(text, False, False); - } - else { - cmdw = tw; + if(cmdw && item) dc.w = cmdw; - drawtext(title, False, False); - } - dc.x += dc.w; + drawtext(text[0] ? text : NULL, False, False); + dc.x += cmdw; if(curr) { dc.w = SPACE; @@ -102,7 +92,6 @@ drawmenu() /* determine maximum items */ for(i = curr; i != next; i=i->right) { - dc.border = False; dc.w = textw(i->text); if(dc.w > mw / 3) dc.w = mw / 3; @@ -119,7 +108,7 @@ drawmenu() } static void -input(char *pattern) +match(char *pattern) { unsigned int plen; Item *i, *j; @@ -127,11 +116,6 @@ input(char *pattern) if(!pattern) return; - if(!title || *pattern) - cmdw = cw; - else - cmdw = tw; - plen = strlen(pattern); item = j = NULL; nitem = 0; @@ -193,7 +177,7 @@ kpress(XKeyEvent * e) case XK_U: case XK_u: text[0] = 0; - input(text); + match(text); drawmenu(); return; break; @@ -216,7 +200,7 @@ kpress(XKeyEvent * e) if(!sel) return; strncpy(text, sel->text, sizeof(text)); - input(text); + match(text); break; case XK_Right: if(!(sel && sel->right)) @@ -248,9 +232,9 @@ kpress(XKeyEvent * e) prev_nitem = nitem; do { text[--i] = 0; - input(text); + match(text); } while(i && nitem && prev_nitem == nitem); - input(text); + match(text); } break; default: @@ -260,14 +244,14 @@ kpress(XKeyEvent * e) strncat(text, buf, sizeof(text)); else strncpy(text, buf, sizeof(text)); - input(text); + match(text); } } drawmenu(); } static char * -readinput() +readstdin() { static char *maxname = NULL; char *p, buf[1024]; @@ -308,30 +292,15 @@ int main(int argc, char *argv[]) { char *maxname; - int i; XEvent ev; XSetWindowAttributes wa; - /* command line args */ - for(i = 1; i < argc; i++) { - if (argv[i][0] == '-') - switch (argv[i][1]) { - case 'v': - fputs("dmenu-"VERSION", (C)opyright MMVI Anselm R. Garbe\n", stdout); - exit(EXIT_SUCCESS); - break; - case 't': - if(++i < argc) { - title = argv[i]; - break; - } - default: - eprint("usage: dmenu [-v] [-t