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