Compare commits
13 Commits
Author | SHA1 | Date | |
---|---|---|---|
adc4ec02c0 | |||
8b2f132973 | |||
1c488e6dac | |||
03c546c6b3 | |||
fdc1dba7ce | |||
3439470a47 | |||
6674bac1d3 | |||
72a8eb412f | |||
975dfb4163 | |||
2e898a308f | |||
6514b07ad2 | |||
724fe3cf7f | |||
70cb32b021 |
1
.hgtags
1
.hgtags
@ -32,3 +32,4 @@ dd3d02b07cac44fbafc074a361c1002cebe7aae4 2.8
|
||||
59b3024854db49739c6d237fa9077f04a2da847a 3.0
|
||||
8f0f917ac988164e1b4446236e3a6ab6cfcb8c67 3.1
|
||||
e4c81a78ffbad6ba4d1ad119cc654da6eca63a4c 3.2
|
||||
709df5a4bad7015a346b2b44b1b3b573ea3088ff 3.3
|
||||
|
1
LICENSE
1
LICENSE
@ -2,6 +2,7 @@ MIT/X Consortium License
|
||||
|
||||
© 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 Michał Janeczek <janeczek at gmail dot com>
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a
|
||||
copy of this software and associated documentation files (the "Software"),
|
||||
|
10
config.h
10
config.h
@ -1,10 +1,10 @@
|
||||
/* See LICENSE file for copyright and license details. */
|
||||
|
||||
/* appearance */
|
||||
#define FONT "-*-terminus-medium-r-*-*-12-*-*-*-*-*-iso10646-*"
|
||||
#define NORMBGCOLOR "#000"
|
||||
#define NORMFGCOLOR "#ccc"
|
||||
#define SELBGCOLOR "#00f"
|
||||
#define SELFGCOLOR "#fff"
|
||||
#define FONT "-*-terminus-medium-*-*-*-*-*-*-*-*-*-*-*"
|
||||
#define NORMBGCOLOR "#cccccc"
|
||||
#define NORMFGCOLOR "#000000"
|
||||
#define SELBGCOLOR "#0066ff"
|
||||
#define SELFGCOLOR "#ffffff"
|
||||
/* next macro defines the space between menu items */
|
||||
#define SPACE 30 /* px */
|
||||
|
@ -1,5 +1,5 @@
|
||||
# dmenu version
|
||||
VERSION = 3.3
|
||||
VERSION = 3.4
|
||||
|
||||
# Customize below to fit your system
|
||||
|
||||
@ -17,7 +17,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
|
||||
# flags
|
||||
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
|
||||
LDFLAGS = -s ${LIBS}
|
||||
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
|
||||
#CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
|
||||
#LDFLAGS = -g ${LIBS}
|
||||
|
||||
# Solaris
|
||||
|
6
dmenu.1
6
dmenu.1
@ -1,9 +1,10 @@
|
||||
.TH DMENU 1 dmenu\-3.2
|
||||
.TH DMENU 1 dmenu\-VERSION
|
||||
.SH NAME
|
||||
dmenu \- dynamic menu
|
||||
.SH SYNOPSIS
|
||||
.B dmenu
|
||||
.RB [ \-b ]
|
||||
.RB [ \-i ]
|
||||
.RB [ \-fn " <font>"]
|
||||
.RB [ \-nb " <color>"]
|
||||
.RB [ \-nf " <color>"]
|
||||
@ -22,6 +23,9 @@ efficiently.
|
||||
.B \-b
|
||||
makes dmenu appear at the screen bottom (by default it appears at the screen top).
|
||||
.TP
|
||||
.B \-i
|
||||
makes dmenu match menu entries with ignoring intermediate characters.
|
||||
.TP
|
||||
.B \-fn <font>
|
||||
defines the font.
|
||||
.TP
|
||||
|
95
dmenu.c
95
dmenu.c
@ -37,9 +37,11 @@ struct Item {
|
||||
Item *next; /* traverses all items */
|
||||
Item *left, *right; /* traverses items matching current search pattern */
|
||||
char *text;
|
||||
Bool matched;
|
||||
};
|
||||
|
||||
/* forward declarations */
|
||||
Item *appenditem(Item *i, Item *last);
|
||||
void calcoffsets(void);
|
||||
void cleanup(void);
|
||||
void drawmenu(void);
|
||||
@ -55,7 +57,8 @@ void match(char *pattern);
|
||||
void readstdin(void);
|
||||
void run(void);
|
||||
void setup(Bool bottom);
|
||||
int strido(const char *text, const char *pattern);
|
||||
int strcaseido(const char *text, const char *pattern);
|
||||
char *cistrstr(const char *s, const char *sub);
|
||||
unsigned int textnw(const char *text, unsigned int len);
|
||||
unsigned int textw(const char *text);
|
||||
|
||||
@ -77,6 +80,7 @@ unsigned int mw, mh;
|
||||
unsigned int promptw = 0;
|
||||
unsigned int nitem = 0;
|
||||
unsigned int numlockmask = 0;
|
||||
Bool idomatch = False;
|
||||
Bool running = True;
|
||||
Display *dpy;
|
||||
DC dc = {0};
|
||||
@ -88,6 +92,20 @@ Item *prev = NULL;
|
||||
Item *curr = NULL;
|
||||
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
|
||||
calcoffsets(void) {
|
||||
unsigned int tw, w;
|
||||
@ -489,41 +507,17 @@ match(char *pattern) {
|
||||
item = j = NULL;
|
||||
nitem = 0;
|
||||
for(i = allitems; i; i=i->next)
|
||||
if(!plen || !strncmp(pattern, i->text, plen)) {
|
||||
if(!j)
|
||||
item = i;
|
||||
else
|
||||
j->right = i;
|
||||
i->left = j;
|
||||
i->right = NULL;
|
||||
j = i;
|
||||
nitem++;
|
||||
}
|
||||
i->matched = False;
|
||||
for(i = allitems; i; i = i->next)
|
||||
if(plen && strncmp(pattern, i->text, plen)
|
||||
&& strstr(i->text, pattern)) {
|
||||
if(!j)
|
||||
item = i;
|
||||
else
|
||||
j->right = i;
|
||||
i->left = j;
|
||||
i->right = NULL;
|
||||
j = i;
|
||||
nitem++;
|
||||
}
|
||||
if(!i->matched && !strncasecmp(pattern, i->text, plen))
|
||||
j = appenditem(i, j);
|
||||
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++;
|
||||
}
|
||||
if(!i->matched && cistrstr(i->text, pattern))
|
||||
j = appenditem(i, j);
|
||||
if(idomatch)
|
||||
for(i = allitems; i; i = i->next)
|
||||
if(!i->matched && strcaseido(i->text, pattern))
|
||||
j = appenditem(i, j);
|
||||
curr = prev = next = sel = item;
|
||||
calcoffsets();
|
||||
}
|
||||
@ -629,13 +623,36 @@ setup(Bool bottom) {
|
||||
}
|
||||
|
||||
int
|
||||
strido(const char *text, const char *pattern) {
|
||||
strcaseido(const char *text, const char *pattern) {
|
||||
for(; *text && *pattern; text++)
|
||||
if (*text == *pattern)
|
||||
if(tolower((int)*text) == tolower((int)*pattern))
|
||||
pattern++;
|
||||
return !*pattern;
|
||||
}
|
||||
|
||||
char *
|
||||
cistrstr(const char *s, const char *sub) {
|
||||
int c, csub;
|
||||
unsigned int len;
|
||||
|
||||
if(!sub)
|
||||
return (char *)s;
|
||||
if((c = *sub++) != 0) {
|
||||
c = tolower(c);
|
||||
len = strlen(sub);
|
||||
do {
|
||||
do {
|
||||
if((csub = *s++) == 0)
|
||||
return (NULL);
|
||||
}
|
||||
while(tolower(csub) != c);
|
||||
}
|
||||
while(strncasecmp(s, sub, len) != 0);
|
||||
s--;
|
||||
}
|
||||
return (char *)s;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
textnw(const char *text, unsigned int len) {
|
||||
XRectangle r;
|
||||
@ -662,6 +679,8 @@ main(int argc, char *argv[]) {
|
||||
if(!strcmp(argv[i], "-b")) {
|
||||
bottom = True;
|
||||
}
|
||||
else if(!strcmp(argv[i], "-i"))
|
||||
idomatch = True;
|
||||
else if(!strcmp(argv[i], "-fn")) {
|
||||
if(++i < argc) font = argv[i];
|
||||
}
|
||||
@ -681,9 +700,9 @@ main(int argc, char *argv[]) {
|
||||
if(++i < argc) selfg = argv[i];
|
||||
}
|
||||
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
|
||||
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");
|
||||
setlocale(LC_CTYPE, "");
|
||||
dpy = XOpenDisplay(0);
|
||||
|
Reference in New Issue
Block a user