diff options
| -rw-r--r-- | LICENSE | 1 | ||||
| -rw-r--r-- | config.mk | 2 | ||||
| -rw-r--r-- | dmenu.1 | 4 | ||||
| -rw-r--r-- | dmenu.c | 79 |
4 files changed, 45 insertions, 41 deletions
| @@ -2,6 +2,7 @@ MIT/X Consortium License | |||
| 2 | 2 | ||
| 3 | © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com> | 3 | © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com> |
| 4 | © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com> | 4 | © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com> |
| 5 | © 2006-2007 Michał Janeczek <janeczek at gmail dot com> | ||
| 5 | 6 | ||
| 6 | Permission is hereby granted, free of charge, to any person obtaining a | 7 | Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | copy of this software and associated documentation files (the "Software"), | 8 | copy of this software and associated documentation files (the "Software"), |
| @@ -1,5 +1,5 @@ | |||
| 1 | # dmenu version | 1 | # dmenu version |
| 2 | VERSION = 3.3 | 2 | VERSION = 3.4 |
| 3 | 3 | ||
| 4 | # Customize below to fit your system | 4 | # Customize below to fit your system |
| 5 | 5 | ||
| @@ -4,6 +4,7 @@ dmenu \- dynamic menu | |||
| 4 | .SH SYNOPSIS | 4 | .SH SYNOPSIS |
| 5 | .B dmenu | 5 | .B dmenu |
| 6 | .RB [ \-b ] | 6 | .RB [ \-b ] |
| 7 | .RB [ \-i ] | ||
| 7 | .RB [ \-fn " <font>"] | 8 | .RB [ \-fn " <font>"] |
| 8 | .RB [ \-nb " <color>"] | 9 | .RB [ \-nb " <color>"] |
| 9 | .RB [ \-nf " <color>"] | 10 | .RB [ \-nf " <color>"] |
| @@ -22,6 +23,9 @@ efficiently. | |||
| 22 | .B \-b | 23 | .B \-b |
| 23 | makes dmenu appear at the screen bottom (by default it appears at the screen top). | 24 | makes dmenu appear at the screen bottom (by default it appears at the screen top). |
| 24 | .TP | 25 | .TP |
| 26 | .B \-i | ||
| 27 | makes dmenu match menu entries with ignoring intermediate characters. | ||
| 28 | .TP | ||
| 25 | .B \-fn <font> | 29 | .B \-fn <font> |
| 26 | defines the font. | 30 | defines the font. |
| 27 | .TP | 31 | .TP |
| @@ -37,9 +37,11 @@ struct Item { | |||
| 37 | Item *next; /* traverses all items */ | 37 | Item *next; /* traverses all items */ |
| 38 | Item *left, *right; /* traverses items matching current search pattern */ | 38 | Item *left, *right; /* traverses items matching current search pattern */ |
| 39 | char *text; | 39 | char *text; |
| 40 | Bool matched; | ||
| 40 | }; | 41 | }; |
| 41 | 42 | ||
| 42 | /* forward declarations */ | 43 | /* forward declarations */ |
| 44 | Item *appenditem(Item *i, Item *last); | ||
| 43 | void calcoffsets(void); | 45 | void calcoffsets(void); |
| 44 | void cleanup(void); | 46 | void cleanup(void); |
| 45 | void drawmenu(void); | 47 | void drawmenu(void); |
| @@ -55,7 +57,7 @@ void match(char *pattern); | |||
| 55 | void readstdin(void); | 57 | void readstdin(void); |
| 56 | void run(void); | 58 | void run(void); |
| 57 | void setup(Bool bottom); | 59 | void setup(Bool bottom); |
| 58 | int strido(const char *text, const char *pattern); | 60 | int strcaseido(const char *text, const char *pattern); |
| 59 | unsigned int textnw(const char *text, unsigned int len); | 61 | unsigned int textnw(const char *text, unsigned int len); |
| 60 | unsigned int textw(const char *text); | 62 | unsigned int textw(const char *text); |
| 61 | 63 | ||
| @@ -77,6 +79,7 @@ unsigned int mw, mh; | |||
| 77 | unsigned int promptw = 0; | 79 | unsigned int promptw = 0; |
| 78 | unsigned int nitem = 0; | 80 | unsigned int nitem = 0; |
| 79 | unsigned int numlockmask = 0; | 81 | unsigned int numlockmask = 0; |
| 82 | Bool idomatch = False; | ||
| 80 | Bool running = True; | 83 | Bool running = True; |
| 81 | Display *dpy; | 84 | Display *dpy; |
| 82 | DC dc = {0}; | 85 | DC dc = {0}; |
| @@ -88,6 +91,20 @@ Item *prev = NULL; | |||
| 88 | Item *curr = NULL; | 91 | Item *curr = NULL; |
| 89 | Window root, win; | 92 | Window root, win; |
| 90 | 93 | ||
| 94 | Item * | ||
| 95 | appenditem(Item *i, Item *last) { | ||
| 96 | if(!last) | ||
| 97 | item = i; | ||
| 98 | else | ||
| 99 | last->right = i; | ||
| 100 | i->matched = True; | ||
| 101 | i->left = last; | ||
| 102 | i->right = NULL; | ||
| 103 | last = i; | ||
| 104 | nitem++; | ||
| 105 | return last; | ||
| 106 | } | ||
| 107 | |||
| 91 | void | 108 | void |
| 92 | calcoffsets(void) { | 109 | calcoffsets(void) { |
| 93 | unsigned int tw, w; | 110 | unsigned int tw, w; |
| @@ -489,41 +506,21 @@ match(char *pattern) { | |||
| 489 | item = j = NULL; | 506 | item = j = NULL; |
| 490 | nitem = 0; | 507 | nitem = 0; |
| 491 | for(i = allitems; i; i=i->next) | 508 | for(i = allitems; i; i=i->next) |
| 492 | if(!plen || !strncmp(pattern, i->text, plen)) { | 509 | i->matched = False; |
| 493 | if(!j) | 510 | |
| 494 | item = i; | 511 | for(i = allitems; i; i = i->next) |
| 495 | else | 512 | if(!i->matched && !strncasecmp(pattern, i->text, plen)) |
| 496 | j->right = i; | 513 | j = appenditem(i,j); |
| 497 | i->left = j; | 514 | |
| 498 | i->right = NULL; | 515 | for (i = allitems; i; i = i->next) |
| 499 | j = i; | 516 | if(!i->matched && strcasestr(i->text, pattern)) |
| 500 | nitem++; | 517 | j = appenditem(i, j); |
| 501 | } | 518 | |
| 502 | for(i = allitems; i; i=i->next) | 519 | if(idomatch) |
| 503 | if(plen && strncmp(pattern, i->text, plen) | 520 | for (i = allitems; i; i = i->next) |
| 504 | && strstr(i->text, pattern)) { | 521 | if(!i->matched && strcaseido(i->text, pattern)) |
| 505 | if(!j) | 522 | j = appenditem(i, j); |
| 506 | item = i; | 523 | |
| 507 | else | ||
| 508 | j->right = i; | ||
| 509 | i->left = j; | ||
| 510 | i->right = NULL; | ||
| 511 | j = i; | ||
| 512 | nitem++; | ||
| 513 | } | ||
| 514 | for(i = allitems; i; i=i->next) | ||
| 515 | if(plen && strncmp(pattern, i->text, plen) | ||
| 516 | && !strstr(i->text, pattern) | ||
| 517 | && strido(i->text,pattern)) { | ||
| 518 | if(!j) | ||
| 519 | item = i; | ||
| 520 | else | ||
| 521 | j->right = i; | ||
| 522 | i->left = j; | ||
| 523 | i->right = NULL; | ||
| 524 | j = i; | ||
| 525 | nitem++; | ||
| 526 | } | ||
| 527 | curr = prev = next = sel = item; | 524 | curr = prev = next = sel = item; |
| 528 | calcoffsets(); | 525 | calcoffsets(); |
| 529 | } | 526 | } |
| @@ -629,9 +626,9 @@ setup(Bool bottom) { | |||
| 629 | } | 626 | } |
| 630 | 627 | ||
| 631 | int | 628 | int |
| 632 | strido(const char *text, const char *pattern) { | 629 | strcaseido(const char *text, const char *pattern) { |
| 633 | for(; *text && *pattern; text++) | 630 | for(; *text && *pattern; text++) |
| 634 | if (*text == *pattern) | 631 | if (tolower(*text) == tolower(*pattern)) |
| 635 | pattern++; | 632 | pattern++; |
| 636 | return !*pattern; | 633 | return !*pattern; |
| 637 | } | 634 | } |
| @@ -662,6 +659,8 @@ main(int argc, char *argv[]) { | |||
| 662 | if(!strcmp(argv[i], "-b")) { | 659 | if(!strcmp(argv[i], "-b")) { |
| 663 | bottom = True; | 660 | bottom = True; |
| 664 | } | 661 | } |
| 662 | else if(!strcmp(argv[i], "-i")) | ||
| 663 | idomatch = True; | ||
| 665 | else if(!strcmp(argv[i], "-fn")) { | 664 | else if(!strcmp(argv[i], "-fn")) { |
| 666 | if(++i < argc) font = argv[i]; | 665 | if(++i < argc) font = argv[i]; |
| 667 | } | 666 | } |
| @@ -681,9 +680,9 @@ main(int argc, char *argv[]) { | |||
| 681 | if(++i < argc) selfg = argv[i]; | 680 | if(++i < argc) selfg = argv[i]; |
| 682 | } | 681 | } |
| 683 | else if(!strcmp(argv[i], "-v")) | 682 | else if(!strcmp(argv[i], "-v")) |
| 684 | eprint("dmenu-"VERSION", © 2006-2007 Anselm R. Garbe, Sander van Dijk\n"); | 683 | eprint("dmenu-"VERSION", © 2006-2007 Anselm R. Garbe, Sander van Dijk, Michał Janeczek\n"); |
| 685 | else | 684 | else |
| 686 | eprint("usage: dmenu [-b] [-fn <font>] [-nb <color>] [-nf <color>]\n" | 685 | eprint("usage: dmenu [-b] [-i] [-fn <font>] [-nb <color>] [-nf <color>]\n" |
| 687 | " [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n"); | 686 | " [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n"); |
| 688 | setlocale(LC_CTYPE, ""); | 687 | setlocale(LC_CTYPE, ""); |
| 689 | dpy = XOpenDisplay(0); | 688 | dpy = XOpenDisplay(0); |
