diff options
| -rw-r--r-- | dmenu.c | 30 | ||||
| -rw-r--r-- | draw.c | 7 | 
2 files changed, 13 insertions, 24 deletions
| @@ -36,9 +36,8 @@ static void paste(void); | |||
| 36 | static void readstdin(void); | 36 | static void readstdin(void); | 
| 37 | static void run(void); | 37 | static void run(void); | 
| 38 | static void setup(void); | 38 | static void setup(void); | 
| 39 | static void usage(void); | ||
| 40 | 39 | ||
| 41 | static char text[BUFSIZ]; | 40 | static char text[BUFSIZ] = ""; | 
| 42 | static int bh, mw, mh; | 41 | static int bh, mw, mh; | 
| 43 | static int inputw = 0; | 42 | static int inputw = 0; | 
| 44 | static int lines = 0; | 43 | static int lines = 0; | 
| @@ -79,7 +78,7 @@ main(int argc, char *argv[]) { | |||
| 79 | else if(!strcmp(argv[i], "-i")) | 78 | else if(!strcmp(argv[i], "-i")) | 
| 80 | fstrncmp = strncasecmp; | 79 | fstrncmp = strncasecmp; | 
| 81 | else if(i == argc-1) | 80 | else if(i == argc-1) | 
| 82 | usage(); | 81 | goto usage; | 
| 83 | /* double flags */ | 82 | /* double flags */ | 
| 84 | else if(!strcmp(argv[i], "-l")) | 83 | else if(!strcmp(argv[i], "-l")) | 
| 85 | lines = atoi(argv[++i]); | 84 | lines = atoi(argv[++i]); | 
| @@ -98,15 +97,19 @@ main(int argc, char *argv[]) { | |||
| 98 | else if(!strcmp(argv[i], "-sf")) | 97 | else if(!strcmp(argv[i], "-sf")) | 
| 99 | selfgcolor = argv[++i]; | 98 | selfgcolor = argv[++i]; | 
| 100 | else | 99 | else | 
| 101 | usage(); | 100 | goto usage; | 
| 102 | 101 | ||
| 103 | dc = initdc(); | 102 | dc = initdc(); | 
| 104 | initfont(dc, font); | 103 | initfont(dc, font); | 
| 105 | readstdin(); | 104 | readstdin(); | 
| 106 | setup(); | 105 | setup(); | 
| 107 | run(); | 106 | run(); | 
| 107 | return EXIT_FAILURE; | ||
| 108 | 108 | ||
| 109 | return EXIT_FAILURE; /* should not reach */ | 109 | usage: | 
| 110 | fputs("usage: dmenu [-b] [-i] [-l lines] [-m monitor] [-p prompt] [-fn font]\n" | ||
| 111 | " [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr); | ||
| 112 | return EXIT_FAILURE; | ||
| 110 | } | 113 | } | 
| 111 | 114 | ||
| 112 | void | 115 | void | 
| @@ -223,7 +226,7 @@ keypress(XKeyEvent *ev) { | |||
| 223 | 226 | ||
| 224 | len = strlen(text); | 227 | len = strlen(text); | 
| 225 | XLookupString(ev, buf, sizeof buf, &ksym, NULL); | 228 | XLookupString(ev, buf, sizeof buf, &ksym, NULL); | 
| 226 | if(ev->state & ControlMask) { | 229 | if(ev->state & ControlMask) | 
| 227 | switch(tolower(ksym)) { | 230 | switch(tolower(ksym)) { | 
| 228 | default: | 231 | default: | 
| 229 | return; | 232 | return; | 
| @@ -277,7 +280,6 @@ keypress(XKeyEvent *ev) { | |||
| 277 | XConvertSelection(dc->dpy, XA_PRIMARY, utf8, utf8, win, CurrentTime); | 280 | XConvertSelection(dc->dpy, XA_PRIMARY, utf8, utf8, win, CurrentTime); | 
| 278 | return; | 281 | return; | 
| 279 | } | 282 | } | 
| 280 | } | ||
| 281 | switch(ksym) { | 283 | switch(ksym) { | 
| 282 | default: | 284 | default: | 
| 283 | if(!iscntrl(*buf)) | 285 | if(!iscntrl(*buf)) | 
| @@ -341,7 +343,6 @@ keypress(XKeyEvent *ev) { | |||
| 341 | case XK_Return: | 343 | case XK_Return: | 
| 342 | case XK_KP_Enter: | 344 | case XK_KP_Enter: | 
| 343 | fputs((sel && !(ev->state & ShiftMask)) ? sel->text : text, stdout); | 345 | fputs((sel && !(ev->state & ShiftMask)) ? sel->text : text, stdout); | 
| 344 | fflush(stdout); | ||
| 345 | exit(EXIT_SUCCESS); | 346 | exit(EXIT_SUCCESS); | 
| 346 | case XK_Right: | 347 | case XK_Right: | 
| 347 | if(cursor < len) { | 348 | if(cursor < len) { | 
| @@ -403,7 +404,7 @@ match(void) { | |||
| 403 | else | 404 | else | 
| 404 | matches = lsubstr; | 405 | matches = lsubstr; | 
| 405 | } | 406 | } | 
| 406 | curr = prev = next = sel = matches; | 407 | curr = sel = matches; | 
| 407 | calcoffsets(); | 408 | calcoffsets(); | 
| 408 | } | 409 | } | 
| 409 | 410 | ||
| @@ -438,11 +439,10 @@ readstdin(void) { | |||
| 438 | for(end = &items; fgets(buf, sizeof buf, stdin); *end = item, end = &item->next) { | 439 | for(end = &items; fgets(buf, sizeof buf, stdin); *end = item, end = &item->next) { | 
| 439 | if((p = strchr(buf, '\n'))) | 440 | if((p = strchr(buf, '\n'))) | 
| 440 | *p = '\0'; | 441 | *p = '\0'; | 
| 441 | if(!(item = malloc(sizeof *item))) | 442 | if(!(item = calloc(1, sizeof *item))) | 
| 442 | eprintf("cannot malloc %u bytes\n", sizeof *item); | 443 | eprintf("cannot malloc %u bytes\n", sizeof *item); | 
| 443 | if(!(item->text = strdup(buf))) | 444 | if(!(item->text = strdup(buf))) | 
| 444 | eprintf("cannot strdup %u bytes\n", strlen(buf)+1); | 445 | eprintf("cannot strdup %u bytes\n", strlen(buf)+1); | 
| 445 | item->next = item->left = item->right = NULL; | ||
| 446 | inputw = MAX(inputw, textw(dc, item->text)); | 446 | inputw = MAX(inputw, textw(dc, item->text)); | 
| 447 | } | 447 | } | 
| 448 | } | 448 | } | 
| @@ -530,13 +530,5 @@ setup(void) { | |||
| 530 | inputw = MIN(inputw, mw/3); | 530 | inputw = MIN(inputw, mw/3); | 
| 531 | promptw = prompt ? textw(dc, prompt) : 0; | 531 | promptw = prompt ? textw(dc, prompt) : 0; | 
| 532 | XMapRaised(dc->dpy, win); | 532 | XMapRaised(dc->dpy, win); | 
| 533 | text[0] = '\0'; | ||
| 534 | match(); | 533 | match(); | 
| 535 | } | 534 | } | 
| 536 | |||
| 537 | void | ||
| 538 | usage(void) { | ||
| 539 | fputs("usage: dmenu [-b] [-i] [-l lines] [-m monitor] [-p prompt] [-fn font]\n" | ||
| 540 | " [-nb color] [-nf color] [-sb color] [-sf color] [-v]\n", stderr); | ||
| 541 | exit(EXIT_FAILURE); | ||
| 542 | } | ||
| @@ -100,16 +100,13 @@ initdc(void) { | |||
| 100 | 100 | ||
| 101 | if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) | 101 | if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) | 
| 102 | weprintf("no locale support\n"); | 102 | weprintf("no locale support\n"); | 
| 103 | if(!(dc = malloc(sizeof *dc))) | 103 | if(!(dc = calloc(1, sizeof *dc))) | 
| 104 | eprintf("cannot malloc %u bytes\n", sizeof *dc); | 104 | eprintf("cannot malloc %u bytes\n", sizeof *dc); | 
| 105 | if(!(dc->dpy = XOpenDisplay(NULL))) | 105 | if(!(dc->dpy = XOpenDisplay(NULL))) | 
| 106 | eprintf("cannot open display\n"); | 106 | eprintf("cannot open display\n"); | 
| 107 | 107 | ||
| 108 | dc->gc = XCreateGC(dc->dpy, DefaultRootWindow(dc->dpy), 0, NULL); | 108 | dc->gc = XCreateGC(dc->dpy, DefaultRootWindow(dc->dpy), 0, NULL); | 
| 109 | XSetLineAttributes(dc->dpy, dc->gc, 1, LineSolid, CapButt, JoinMiter); | 109 | XSetLineAttributes(dc->dpy, dc->gc, 1, LineSolid, CapButt, JoinMiter); | 
| 110 | dc->font.xfont = NULL; | ||
| 111 | dc->font.set = NULL; | ||
| 112 | dc->canvas = None; | ||
| 113 | return dc; | 110 | return dc; | 
| 114 | } | 111 | } | 
| 115 | 112 | ||
| @@ -187,7 +184,7 @@ void | |||
| 187 | weprintf(const char *fmt, ...) { | 184 | weprintf(const char *fmt, ...) { | 
| 188 | va_list ap; | 185 | va_list ap; | 
| 189 | 186 | ||
| 190 | fprintf(stderr, "%s: warning: ", progname); | 187 | fprintf(stderr, "%s: ", progname); | 
| 191 | va_start(ap, fmt); | 188 | va_start(ap, fmt); | 
| 192 | vfprintf(stderr, fmt, ap); | 189 | vfprintf(stderr, fmt, ap); | 
| 193 | va_end(ap); | 190 | va_end(ap); | 
