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

This commit is contained in:
Anselm R. Garbe 2007-09-23 18:26:41 +02:00
parent 70cb32b021
commit 724fe3cf7f
4 changed files with 45 additions and 41 deletions

View File

@ -2,6 +2,7 @@ MIT/X Consortium License
© 2006-2007 Anselm R. Garbe <garbeam at gmail dot com> © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
© 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com> © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
© 2006-2007 Michał Janeczek <janeczek at gmail dot com>
Permission is hereby granted, free of charge, to any person obtaining a Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"), copy of this software and associated documentation files (the "Software"),

View File

@ -1,5 +1,5 @@
# dmenu version # dmenu version
VERSION = 3.3 VERSION = 3.4
# Customize below to fit your system # Customize below to fit your system

View File

@ -4,6 +4,7 @@ dmenu \- dynamic menu
.SH SYNOPSIS .SH SYNOPSIS
.B dmenu .B dmenu
.RB [ \-b ] .RB [ \-b ]
.RB [ \-i ]
.RB [ \-fn " <font>"] .RB [ \-fn " <font>"]
.RB [ \-nb " <color>"] .RB [ \-nb " <color>"]
.RB [ \-nf " <color>"] .RB [ \-nf " <color>"]
@ -22,6 +23,9 @@ efficiently.
.B \-b .B \-b
makes dmenu appear at the screen bottom (by default it appears at the screen top). makes dmenu appear at the screen bottom (by default it appears at the screen top).
.TP .TP
.B \-i
makes dmenu match menu entries with ignoring intermediate characters.
.TP
.B \-fn <font> .B \-fn <font>
defines the font. defines the font.
.TP .TP

79
dmenu.c
View File

@ -37,9 +37,11 @@ struct Item {
Item *next; /* traverses all items */ Item *next; /* traverses all items */
Item *left, *right; /* traverses items matching current search pattern */ Item *left, *right; /* traverses items matching current search pattern */
char *text; char *text;
Bool matched;
}; };
/* forward declarations */ /* forward declarations */
Item *appenditem(Item *i, Item *last);
void calcoffsets(void); void calcoffsets(void);
void cleanup(void); void cleanup(void);
void drawmenu(void); void drawmenu(void);
@ -55,7 +57,7 @@ void match(char *pattern);
void readstdin(void); void readstdin(void);
void run(void); void run(void);
void setup(Bool bottom); void setup(Bool bottom);
int strido(const char *text, const char *pattern); int strcaseido(const char *text, const char *pattern);
unsigned int textnw(const char *text, unsigned int len); unsigned int textnw(const char *text, unsigned int len);
unsigned int textw(const char *text); unsigned int textw(const char *text);
@ -77,6 +79,7 @@ unsigned int mw, mh;
unsigned int promptw = 0; unsigned int promptw = 0;
unsigned int nitem = 0; unsigned int nitem = 0;
unsigned int numlockmask = 0; unsigned int numlockmask = 0;
Bool idomatch = False;
Bool running = True; Bool running = True;
Display *dpy; Display *dpy;
DC dc = {0}; DC dc = {0};
@ -88,6 +91,20 @@ Item *prev = NULL;
Item *curr = NULL; Item *curr = NULL;
Window root, win; Window root, win;
Item *
appenditem(Item *i, Item *last) {
if(!last)
item = i;
else
last->right = i;
i->matched = True;
i->left = last;
i->right = NULL;
last = i;
nitem++;
return last;
}
void void
calcoffsets(void) { calcoffsets(void) {
unsigned int tw, w; unsigned int tw, w;
@ -489,41 +506,21 @@ match(char *pattern) {
item = j = NULL; item = j = NULL;
nitem = 0; nitem = 0;
for(i = allitems; i; i=i->next) for(i = allitems; i; i=i->next)
if(!plen || !strncmp(pattern, i->text, plen)) { i->matched = False;
if(!j)
item = i; for(i = allitems; i; i = i->next)
else if(!i->matched && !strncasecmp(pattern, i->text, plen))
j->right = i; j = appenditem(i,j);
i->left = j;
i->right = NULL; for (i = allitems; i; i = i->next)
j = i; if(!i->matched && strcasestr(i->text, pattern))
nitem++; j = appenditem(i, j);
}
for(i = allitems; i; i=i->next) if(idomatch)
if(plen && strncmp(pattern, i->text, plen) for (i = allitems; i; i = i->next)
&& strstr(i->text, pattern)) { if(!i->matched && strcaseido(i->text, pattern))
if(!j) j = appenditem(i, j);
item = i;
else
j->right = i;
i->left = j;
i->right = NULL;
j = i;
nitem++;
}
for(i = allitems; i; i=i->next)
if(plen && strncmp(pattern, i->text, plen)
&& !strstr(i->text, pattern)
&& strido(i->text,pattern)) {
if(!j)
item = i;
else
j->right = i;
i->left = j;
i->right = NULL;
j = i;
nitem++;
}
curr = prev = next = sel = item; curr = prev = next = sel = item;
calcoffsets(); calcoffsets();
} }
@ -629,9 +626,9 @@ setup(Bool bottom) {
} }
int int
strido(const char *text, const char *pattern) { strcaseido(const char *text, const char *pattern) {
for(; *text && *pattern; text++) for(; *text && *pattern; text++)
if (*text == *pattern) if (tolower(*text) == tolower(*pattern))
pattern++; pattern++;
return !*pattern; return !*pattern;
} }
@ -662,6 +659,8 @@ main(int argc, char *argv[]) {
if(!strcmp(argv[i], "-b")) { if(!strcmp(argv[i], "-b")) {
bottom = True; bottom = True;
} }
else if(!strcmp(argv[i], "-i"))
idomatch = True;
else if(!strcmp(argv[i], "-fn")) { else if(!strcmp(argv[i], "-fn")) {
if(++i < argc) font = argv[i]; if(++i < argc) font = argv[i];
} }
@ -681,9 +680,9 @@ main(int argc, char *argv[]) {
if(++i < argc) selfg = argv[i]; if(++i < argc) selfg = argv[i];
} }
else if(!strcmp(argv[i], "-v")) else if(!strcmp(argv[i], "-v"))
eprint("dmenu-"VERSION", © 2006-2007 Anselm R. Garbe, Sander van Dijk\n"); eprint("dmenu-"VERSION", © 2006-2007 Anselm R. Garbe, Sander van Dijk, Michał Janeczek\n");
else else
eprint("usage: dmenu [-b] [-fn <font>] [-nb <color>] [-nf <color>]\n" eprint("usage: dmenu [-b] [-i] [-fn <font>] [-nb <color>] [-nf <color>]\n"
" [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n"); " [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
dpy = XOpenDisplay(0); dpy = XOpenDisplay(0);