cleaned up
b27ffbd7
1 file(s) · +21 −31
| 93 | 93 | static Item *prev = NULL; |
|
| 94 | 94 | static Item *curr = NULL; |
|
| 95 | 95 | static Window parent, win; |
|
| 96 | - | static int (*fstrncmp)(const char *, const char *, size_t n) = strncmp; |
|
| 96 | + | static int (*fstrncmp)(const char *, const char *, size_t) = strncmp; |
|
| 97 | 97 | static char *(*fstrstr)(const char *, const char *) = strstr; |
|
| 98 | 98 | static unsigned int lines = 0; |
|
| 99 | 99 | static void (*calcoffsets)(void) = calcoffsetsh; |
|
| 144 | 144 | ||
| 145 | 145 | if(!sub) |
|
| 146 | 146 | return (char *)s; |
|
| 147 | - | if((c = *sub++) != '\0') { |
|
| 148 | - | c = tolower(c); |
|
| 147 | + | if((c = tolower(*sub++)) != '\0') { |
|
| 149 | 148 | len = strlen(sub); |
|
| 150 | 149 | do { |
|
| 151 | 150 | do { |
|
| 199 | 198 | /* print command */ |
|
| 200 | 199 | if(cmdw && item && lines == 0) |
|
| 201 | 200 | dc.w = cmdw; |
|
| 202 | - | drawtext(text[0] ? text : NULL, dc.norm); |
|
| 201 | + | drawtext(*text ? text : NULL, dc.norm); |
|
| 203 | 202 | drawcursor(); |
|
| 204 | 203 | if(curr) { |
|
| 205 | 204 | if(lines > 0) |
|
| 345 | 344 | ||
| 346 | 345 | len = strlen(text); |
|
| 347 | 346 | num = XLookupString(e, buf, sizeof buf, &ksym, NULL); |
|
| 348 | - | if(IsKeypadKey(ksym)) { |
|
| 349 | - | if(ksym == XK_KP_Enter) |
|
| 350 | - | ksym = XK_Return; |
|
| 351 | - | else if(ksym >= XK_KP_0 && ksym <= XK_KP_9) |
|
| 352 | - | ksym = (ksym - XK_KP_0) + XK_0; |
|
| 353 | - | } |
|
| 354 | - | if(IsFunctionKey(ksym) || IsKeypadKey(ksym) |
|
| 355 | - | || IsMiscFunctionKey(ksym) || IsPFKey(ksym) |
|
| 356 | - | || IsPrivateKeypadKey(ksym)) |
|
| 347 | + | if(ksym == XK_KP_Enter) |
|
| 348 | + | ksym = XK_Return; |
|
| 349 | + | else if(ksym >= XK_KP_0 && ksym <= XK_KP_9) |
|
| 350 | + | ksym = (ksym - XK_KP_0) + XK_0; |
|
| 351 | + | else if(IsFunctionKey(ksym) || IsKeypadKey(ksym) |
|
| 352 | + | || IsMiscFunctionKey(ksym) || IsPFKey(ksym) |
|
| 353 | + | || IsPrivateKeypadKey(ksym)) |
|
| 357 | 354 | return; |
|
| 358 | 355 | /* first check if a control mask is omitted */ |
|
| 359 | 356 | if(e->state & ControlMask) { |
|
| 405 | 402 | } |
|
| 406 | 403 | if(CLEANMASK(e->state) & Mod1Mask) { |
|
| 407 | 404 | switch(ksym) { |
|
| 408 | - | default: return; |
|
| 405 | + | default: |
|
| 406 | + | return; |
|
| 409 | 407 | case XK_h: |
|
| 410 | 408 | ksym = XK_Left; |
|
| 411 | 409 | break; |
|
| 491 | 489 | case XK_Left: |
|
| 492 | 490 | case XK_Up: |
|
| 493 | 491 | if(sel && sel->left){ |
|
| 494 | - | sel=sel->left; |
|
| 492 | + | sel = sel->left; |
|
| 495 | 493 | if(sel->right == curr) { |
|
| 496 | 494 | curr = prev; |
|
| 497 | 495 | calcoffsets(); |
|
| 498 | 496 | } |
|
| 499 | 497 | } |
|
| 500 | - | else if(cursor > 0) { |
|
| 501 | - | do { |
|
| 502 | - | cursor--; |
|
| 503 | - | } while(cursor > 0 && !IS_UTF8_1ST_CHAR(text[cursor])); |
|
| 504 | - | } else |
|
| 498 | + | else if(cursor > 0) |
|
| 499 | + | while(cursor-- > 0 && !IS_UTF8_1ST_CHAR(text[cursor])); |
|
| 500 | + | else |
|
| 505 | 501 | return; |
|
| 506 | 502 | break; |
|
| 507 | 503 | case XK_Next: |
|
| 526 | 522 | break; |
|
| 527 | 523 | case XK_Right: |
|
| 528 | 524 | case XK_Down: |
|
| 529 | - | if(cursor < len) { |
|
| 530 | - | do { |
|
| 531 | - | cursor++; |
|
| 532 | - | } while(cursor < len && !IS_UTF8_1ST_CHAR(text[cursor])); |
|
| 533 | - | } else if(sel && sel->right) { |
|
| 534 | - | sel=sel->right; |
|
| 525 | + | if(cursor < len) |
|
| 526 | + | while(cursor++ < len && !IS_UTF8_1ST_CHAR(text[cursor])); |
|
| 527 | + | else if(sel && sel->right) { |
|
| 528 | + | sel = sel->right; |
|
| 535 | 529 | if(sel == next) { |
|
| 536 | 530 | curr = next; |
|
| 537 | 531 | calcoffsets(); |
|
| 605 | 599 | buf[--len] = '\0'; |
|
| 606 | 600 | if(!(p = strdup(buf))) |
|
| 607 | 601 | eprint("dmenu: cannot strdup %u bytes\n", len); |
|
| 608 | - | if(max < len || !maxname) { |
|
| 602 | + | if((max = MAX(max, len)) == len) |
|
| 609 | 603 | maxname = p; |
|
| 610 | - | max = len; |
|
| 611 | - | } |
|
| 612 | 604 | if(!(new = malloc(sizeof *new))) |
|
| 613 | 605 | eprint("dmenu: cannot malloc %u bytes\n", sizeof *new); |
|
| 614 | 606 | new->next = new->left = new->right = NULL; |
|
| 628 | 620 | /* main event loop */ |
|
| 629 | 621 | while(running && !XNextEvent(dpy, &ev)) |
|
| 630 | 622 | switch (ev.type) { |
|
| 631 | - | default: /* ignore all crap */ |
|
| 632 | - | break; |
|
| 633 | 623 | case KeyPress: |
|
| 634 | 624 | kpress(&ev.xkey); |
|
| 635 | 625 | break; |
|