aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnselm R. Garbe <garbeam@gmail.com>2007-09-23 18:26:41 +0200
committerAnselm R. Garbe <garbeam@gmail.com>2007-09-23 18:26:41 +0200
commit724fe3cf7fc456db96bf10c2caeb7c307e529d73 (patch)
treea68e4faf704d0d06431ce7dab390f91c9c7d791f
parent70cb32b021848255907ac0a4e3341f81f1d2ae24 (diff)
applied Michał Janeczek dmenu patch, made dmenu match case-insensitive by default, added -i command line option to enable ido matching, added Michał to Copyright holders
-rw-r--r--LICENSE1
-rw-r--r--config.mk2
-rw-r--r--dmenu.14
-rw-r--r--dmenu.c79
4 files changed, 45 insertions, 41 deletions
diff --git a/LICENSE b/LICENSE
index 69214cb..85970bb 100644
--- a/LICENSE
+++ b/LICENSE
@@ -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
6Permission is hereby granted, free of charge, to any person obtaining a 7Permission is hereby granted, free of charge, to any person obtaining a
7copy of this software and associated documentation files (the "Software"), 8copy of this software and associated documentation files (the "Software"),
diff --git a/config.mk b/config.mk
index b4c3110..22a8adc 100644
--- a/config.mk
+++ b/config.mk
@@ -1,5 +1,5 @@
1# dmenu version 1# dmenu version
2VERSION = 3.3 2VERSION = 3.4
3 3
4# Customize below to fit your system 4# Customize below to fit your system
5 5
diff --git a/dmenu.1 b/dmenu.1
index 373d193..dc13f2b 100644
--- a/dmenu.1
+++ b/dmenu.1
@@ -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
23makes dmenu appear at the screen bottom (by default it appears at the screen top). 24makes dmenu appear at the screen bottom (by default it appears at the screen top).
24.TP 25.TP
26.B \-i
27makes dmenu match menu entries with ignoring intermediate characters.
28.TP
25.B \-fn <font> 29.B \-fn <font>
26defines the font. 30defines the font.
27.TP 31.TP
diff --git a/dmenu.c b/dmenu.c
index 5cb638b..3bb9351 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -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 */
44Item *appenditem(Item *i, Item *last);
43void calcoffsets(void); 45void calcoffsets(void);
44void cleanup(void); 46void cleanup(void);
45void drawmenu(void); 47void drawmenu(void);
@@ -55,7 +57,7 @@ void match(char *pattern);
55void readstdin(void); 57void readstdin(void);
56void run(void); 58void run(void);
57void setup(Bool bottom); 59void setup(Bool bottom);
58int strido(const char *text, const char *pattern); 60int strcaseido(const char *text, const char *pattern);
59unsigned int textnw(const char *text, unsigned int len); 61unsigned int textnw(const char *text, unsigned int len);
60unsigned int textw(const char *text); 62unsigned int textw(const char *text);
61 63
@@ -77,6 +79,7 @@ unsigned int mw, mh;
77unsigned int promptw = 0; 79unsigned int promptw = 0;
78unsigned int nitem = 0; 80unsigned int nitem = 0;
79unsigned int numlockmask = 0; 81unsigned int numlockmask = 0;
82Bool idomatch = False;
80Bool running = True; 83Bool running = True;
81Display *dpy; 84Display *dpy;
82DC dc = {0}; 85DC dc = {0};
@@ -88,6 +91,20 @@ Item *prev = NULL;
88Item *curr = NULL; 91Item *curr = NULL;
89Window root, win; 92Window root, win;
90 93
94Item *
95appenditem(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
91void 108void
92calcoffsets(void) { 109calcoffsets(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
631int 628int
632strido(const char *text, const char *pattern) { 629strcaseido(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);