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