Compare commits

...

19 Commits
1.6 ... 1.8

Author SHA1 Message Date
bbfd5391ac fixed a typo in dmenu.1 2006-12-19 11:49:28 +01:00
0e96ae6f48 prepared dmenu-1.8, shortened command line options (-font is -fn, -selbg is -sb, -selfg is -sf, -normbg is -nb, -normfg is -nf now) 2006-12-19 11:39:07 +01:00
989649b5a5 added wmii reference to dmenu(1) 2006-12-18 13:46:44 +01:00
f8d2a29a20 agreed with Sander 2006-12-18 13:25:11 +01:00
3438af001a applied Stefan Tibus' sun patch, added -bottom option to dmenu which makes it appear in the bottom (for wmii compliance), slightly modified version than the patch proposed by Stefan Tibus 2006-12-18 12:52:58 +01:00
201b056e39 hotfix 2006-12-14 14:41:53 +01:00
3dcdbe2a57 added vi-like key-bindings for keyboards without cursor keys (they are undocumented features) 2006-12-14 14:40:58 +01:00
5336608a86 Added tag 1.7.1 for changeset 3696d77aaf02f5d15728dde3b9e35abcaf291496 2006-12-14 09:45:11 +01:00
d398a2e318 foo 2006-12-14 09:45:06 +01:00
2829009138 silent hotfix 2006-12-14 09:34:24 +01:00
cae2fbdf38 Added tag 1.7.1 for changeset 8e0b9b09bf83c429c73e60a23997f32877a645bf 2006-12-14 09:30:31 +01:00
225cd764c3 applied hotfix of sander 2006-12-14 09:30:23 +01:00
279966a16f Added tag 1.7 for changeset 58dbef4aef3d45c7a3da6945e53c9667c0f02d5b 2006-12-14 08:51:21 +01:00
9bd80b3968 changed text in dmenu manpage 2006-12-13 14:36:09 +01:00
65912f2a96 added prompt option (-p 'prompt text'), documented in man page as well 2006-12-13 14:14:41 +01:00
4bd3466215 ordered switch branches in kpress alphabetically, applied Sanders patch for PgUp/Dn and Home/End scrolling 2006-12-12 09:57:42 +01:00
e19e42adbb fixed diagnostic error message 2006-12-08 11:12:11 +01:00
796c4fb9e5 removed hardcoded 'fixed' fallback, useless and misleading 2006-12-08 10:41:16 +01:00
93c3f930c5 Added tag 1.6 for changeset dcc5427f99f51a978386a0dd770467cd911ac84b 2006-12-07 14:54:47 +01:00
5 changed files with 165 additions and 70 deletions

View File

@ -13,3 +13,6 @@ bee7fe6d1189174d0204ca3195b83cdc1bb4f82e 1.2
2eb9997be51cb1b11a8900728ccc0904f9371157 1.3 2eb9997be51cb1b11a8900728ccc0904f9371157 1.3
df3fbb050004c544d14e43c36f6a94cca6ed4a69 1.4 df3fbb050004c544d14e43c36f6a94cca6ed4a69 1.4
e071fb045bd9e8574947acff7196360bc0270e68 1.5 e071fb045bd9e8574947acff7196360bc0270e68 1.5
dcc5427f99f51a978386a0dd770467cd911ac84b 1.6
58dbef4aef3d45c7a3da6945e53c9667c0f02d5b 1.7
3696d77aaf02f5d15728dde3b9e35abcaf291496 1.7.1

View File

@ -1,5 +1,5 @@
# dmenu version # dmenu version
VERSION = 1.6 VERSION = 1.8
# Customize below to fit your system # Customize below to fit your system
@ -20,6 +20,11 @@ LDFLAGS = ${LIBS}
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" #CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
#LDFLAGS = -g ${LIBS} #LDFLAGS = -g ${LIBS}
# Solaris
#CFLAGS = -fast ${INCS} -DVERSION=\"${VERSION}\"
#LDFLAGS = ${LIBS}
#CFLAGS += -xtarget=ultra
# compiler and linker # compiler and linker
CC = cc CC = cc
LD = ${CC} LD = ${CC}

39
dmenu.1
View File

@ -3,11 +3,13 @@
dmenu \- dynamic menu dmenu \- dynamic menu
.SH SYNOPSIS .SH SYNOPSIS
.B dmenu .B dmenu
.RB [ \-font " <name>"] .RB [ \-b ]
.RB [ \-normbg " <color>"] .RB [ \-fn " <font>"]
.RB [ \-normfg " <color>"] .RB [ \-nb " <color>"]
.RB [ \-selbg " <color>"] .RB [ \-nf " <color>"]
.RB [ \-selfg " <color>"] .RB [ \-p " <prompt>"]
.RB [ \-sb " <color>"]
.RB [ \-sf " <color>"]
.RB [ \-t " <seconds>"] .RB [ \-t " <seconds>"]
.RB [ \-v ] .RB [ \-v ]
.SH DESCRIPTION .SH DESCRIPTION
@ -18,19 +20,25 @@ It manages huge amounts (up to 10.000 and more) of user defined menu items
efficiently. efficiently.
.SS Options .SS Options
.TP .TP
.B \-font <name> .B \-b
makes dmenu appear at the screen bottom (by default it appears at the screen top).
.TP
.B \-fn <font>
defines the font. defines the font.
.TP .TP
.B \-normbg <color> .B \-nb <color>
defines the normal background color (#RGB, #RRGGBB, and color names are supported). defines the normal background color (#RGB, #RRGGBB, and color names are supported).
.TP .TP
.B \-normfg <color> .B \-nf <color>
defines the normal foreground color (#RGB, #RRGGBB, and color names are supported). defines the normal foreground color (#RGB, #RRGGBB, and color names are supported).
.TP .TP
.B \-selbg <color> .B \-p <prompt>
defines a prompt to be displayed before the input area.
.TP
.B \-sb <color>
defines the selected background color (#RGB, #RRGGBB, and color names are supported). defines the selected background color (#RGB, #RRGGBB, and color names are supported).
.TP .TP
.B \-selfg <color> .B \-sf <color>
defines the selected foreground color (#RGB, #RRGGBB, and color names are supported). defines the selected foreground color (#RGB, #RRGGBB, and color names are supported).
.TP .TP
.B \-t <seconds> .B \-t <seconds>
@ -40,7 +48,7 @@ defines the seconds to wait for standard input, before exiting (default is 3).
prints version information to standard output, then exits. prints version information to standard output, then exits.
.SH USAGE .SH USAGE
dmenu reads a list of newline-separated items from standard input and creates a dmenu reads a list of newline-separated items from standard input and creates a
menu. When the user selects an item or enters any text and presses Return, his menu. When the user selects an item or enters any text and presses Return, his/her
choice is printed to standard output and dmenu terminates. choice is printed to standard output and dmenu terminates.
.P .P
dmenu is completely controlled by the keyboard. The following keys are recognized: dmenu is completely controlled by the keyboard. The following keys are recognized:
@ -52,6 +60,12 @@ only items containing this text will be displayed.
.B Left/Right .B Left/Right
Select the previous/next item. Select the previous/next item.
.TP .TP
.B PageUp/PageDown
Select the first item of the previous/next 'page' of items.
.TP
.B Home/End
Select the first/last item.
.TP
.B Tab .B Tab
Copy the selected item to the input field. Copy the selected item to the input field.
.TP .TP
@ -77,4 +91,5 @@ Remove enough characters from the input field to change its filtering effect.
.B Control-u .B Control-u
Remove all characters from the input field. Remove all characters from the input field.
.SH SEE ALSO .SH SEE ALSO
.BR dwm (1) .BR dwm (1),
.BR wmii (1) .

7
draw.c
View File

@ -107,11 +107,8 @@ setfont(const char *fontstr) {
if(dc.font.xfont) if(dc.font.xfont)
XFreeFont(dpy, dc.font.xfont); XFreeFont(dpy, dc.font.xfont);
dc.font.xfont = NULL; dc.font.xfont = NULL;
dc.font.xfont = XLoadQueryFont(dpy, fontstr); if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)))
if (!dc.font.xfont) eprint("error, cannot load font: '%s'\n", fontstr);
dc.font.xfont = XLoadQueryFont(dpy, "fixed");
if (!dc.font.xfont)
eprint("error, cannot init 'fixed' font\n");
dc.font.ascent = dc.font.xfont->ascent; dc.font.ascent = dc.font.xfont->ascent;
dc.font.descent = dc.font.xfont->descent; dc.font.descent = dc.font.xfont->descent;
} }

175
main.c
View File

@ -25,10 +25,12 @@ struct Item {
/* static */ /* static */
static char text[4096]; static char text[4096];
static char *prompt = NULL;
static int mx, my, mw, mh; static int mx, my, mw, mh;
static int ret = 0; static int ret = 0;
static int nitem = 0; static int nitem = 0;
static unsigned int cmdw = 0; static unsigned int cmdw = 0;
static unsigned int promptw = 0;
static Bool running = True; static Bool running = True;
static Item *allitems = NULL; /* first of all items */ static Item *allitems = NULL; /* first of all items */
static Item *item = NULL; /* first of pattern matching items */ static Item *item = NULL; /* first of pattern matching items */
@ -45,7 +47,7 @@ calcoffsets(void) {
if(!curr) if(!curr)
return; return;
w = cmdw + 2 * SPACE; w = promptw + cmdw + 2 * SPACE;
for(next = curr; next; next=next->right) { for(next = curr; next; next=next->right) {
tw = textw(next->text); tw = textw(next->text);
if(tw > mw / 3) if(tw > mw / 3)
@ -54,7 +56,7 @@ calcoffsets(void) {
if(w > mw) if(w > mw)
break; break;
} }
w = cmdw + 2 * SPACE; w = promptw + cmdw + 2 * SPACE;
for(prev = curr; prev && prev->left; prev=prev->left) { for(prev = curr; prev && prev->left; prev=prev->left) {
tw = textw(prev->left->text); tw = textw(prev->left->text);
if(tw > mw / 3) if(tw > mw / 3)
@ -74,6 +76,13 @@ drawmenu(void) {
dc.w = mw; dc.w = mw;
dc.h = mh; dc.h = mh;
drawtext(NULL, dc.norm); drawtext(NULL, dc.norm);
/* print prompt? */
if(promptw) {
dc.w = promptw;
drawtext(prompt, dc.sel);
}
dc.x += promptw;
dc.w = mw - promptw;
/* print command */ /* print command */
if(cmdw && item) if(cmdw && item)
dc.w = cmdw; dc.w = cmdw;
@ -169,45 +178,40 @@ kpress(XKeyEvent * e) {
break; break;
} }
} }
if(e->state & Mod1Mask) {
switch(ksym) { switch(ksym) {
case XK_Left: default: return;
if(!(sel && sel->left)) case XK_h:
return; ksym = XK_Left;
sel=sel->left;
if(sel->right == curr) {
curr = prev;
calcoffsets();
}
break; break;
case XK_Tab: case XK_l:
if(!sel) ksym = XK_Right;
return; break;
strncpy(text, sel->text, sizeof text); case XK_j:
ksym = XK_Next;
break;
case XK_k:
ksym = XK_Prior;
break;
case XK_g:
ksym = XK_Home;
break;
case XK_G:
ksym = XK_End;
break;
}
}
switch(ksym) {
default:
if(num && !iscntrl((int) buf[0])) {
buf[num] = 0;
if(len > 0)
strncat(text, buf, sizeof text);
else
strncpy(text, buf, sizeof text);
match(text); match(text);
break;
case XK_Right:
if(!(sel && sel->right))
return;
sel=sel->right;
if(sel == next) {
curr = next;
calcoffsets();
} }
break; break;
case XK_Return:
if((e->state & ShiftMask) && text)
fprintf(stdout, "%s", text);
else if(sel)
fprintf(stdout, "%s", sel->text);
else if(text)
fprintf(stdout, "%s", text);
fflush(stdout);
running = False;
break;
case XK_Escape:
ret = 1;
running = False;
break;
case XK_BackSpace: case XK_BackSpace:
if((i = len)) { if((i = len)) {
prev_nitem = nitem; prev_nitem = nitem;
@ -218,15 +222,72 @@ kpress(XKeyEvent * e) {
match(text); match(text);
} }
break; break;
default: case XK_End:
if(num && !iscntrl((int) buf[0])) { if(!item)
buf[num] = 0; return;
if(len > 0) while(next) {
strncat(text, buf, sizeof text); sel = curr = next;
else calcoffsets();
strncpy(text, buf, sizeof text);
match(text);
} }
while(sel && sel->right)
sel = sel->right;
break;
case XK_Escape:
ret = 1;
running = False;
break;
case XK_Home:
if(!item)
return;
sel = curr = item;
calcoffsets();
break;
case XK_Left:
if(!(sel && sel->left))
return;
sel=sel->left;
if(sel->right == curr) {
curr = prev;
calcoffsets();
}
break;
case XK_Next:
if(!next)
return;
sel = curr = next;
calcoffsets();
break;
case XK_Prior:
if(!prev)
return;
sel = curr = prev;
calcoffsets();
break;
case XK_Return:
if((e->state & ShiftMask) && text)
fprintf(stdout, "%s", text);
else if(sel)
fprintf(stdout, "%s", sel->text);
else if(text)
fprintf(stdout, "%s", text);
fflush(stdout);
running = False;
break;
case XK_Right:
if(!(sel && sel->right))
return;
sel=sel->right;
if(sel == next) {
curr = next;
calcoffsets();
}
break;
case XK_Tab:
if(!sel)
return;
strncpy(text, sel->text, sizeof text);
match(text);
break;
} }
drawmenu(); drawmenu();
} }
@ -269,6 +330,7 @@ DC dc = {0};
int int
main(int argc, char *argv[]) { main(int argc, char *argv[]) {
Bool bottom = False;
char *font = FONT; char *font = FONT;
char *maxname; char *maxname;
char *normbg = NORMBGCOLOR; char *normbg = NORMBGCOLOR;
@ -286,19 +348,25 @@ main(int argc, char *argv[]) {
timeout.tv_sec = 3; timeout.tv_sec = 3;
/* command line args */ /* command line args */
for(i = 1; i < argc; i++) for(i = 1; i < argc; i++)
if(!strncmp(argv[i], "-font", 6)) { if(!strncmp(argv[i], "-b", 3)) {
bottom = True;
}
else if(!strncmp(argv[i], "-fn", 4)) {
if(++i < argc) font = argv[i]; if(++i < argc) font = argv[i];
} }
else if(!strncmp(argv[i], "-normbg", 8)) { else if(!strncmp(argv[i], "-nb", 4)) {
if(++i < argc) normbg = argv[i]; if(++i < argc) normbg = argv[i];
} }
else if(!strncmp(argv[i], "-normfg", 8)) { else if(!strncmp(argv[i], "-nf", 4)) {
if(++i < argc) normfg = argv[i]; if(++i < argc) normfg = argv[i];
} }
else if(!strncmp(argv[i], "-selbg", 7)) { else if(!strncmp(argv[i], "-p", 3)) {
if(++i < argc) prompt = argv[i];
}
else if(!strncmp(argv[i], "-sb", 4)) {
if(++i < argc) selbg = argv[i]; if(++i < argc) selbg = argv[i];
} }
else if(!strncmp(argv[i], "-selfg", 7)) { else if(!strncmp(argv[i], "-sf", 4)) {
if(++i < argc) selfg = argv[i]; if(++i < argc) selfg = argv[i];
} }
else if(!strncmp(argv[i], "-t", 3)) { else if(!strncmp(argv[i], "-t", 3)) {
@ -309,7 +377,8 @@ main(int argc, char *argv[]) {
exit(EXIT_SUCCESS); exit(EXIT_SUCCESS);
} }
else else
eprint("usage: dmenu [-font <name>] [-{norm,sel}{bg,fg} <color>] [-t <seconds>] [-v]\n", stdout); eprint("usage: dmenu [-b] [-fn <font>] [-nb <color>] [-nf <color>] [-p <prompt>]\n"
" [-sb <color>] [-sf <color>] [-t <seconds>] [-v]\n", stdout);
setlocale(LC_CTYPE, ""); setlocale(LC_CTYPE, "");
dpy = XOpenDisplay(0); dpy = XOpenDisplay(0);
if(!dpy) if(!dpy)
@ -343,6 +412,8 @@ main(int argc, char *argv[]) {
mx = my = 0; mx = my = 0;
mw = DisplayWidth(dpy, screen); mw = DisplayWidth(dpy, screen);
mh = dc.font.height + 2; mh = dc.font.height + 2;
if(bottom)
my += DisplayHeight(dpy, screen) - mh;
win = XCreateWindow(dpy, root, mx, my, mw, mh, 0, win = XCreateWindow(dpy, root, mx, my, mw, mh, 0,
DefaultDepth(dpy, screen), CopyFromParent, DefaultDepth(dpy, screen), CopyFromParent,
DefaultVisual(dpy, screen), DefaultVisual(dpy, screen),
@ -355,6 +426,10 @@ main(int argc, char *argv[]) {
cmdw = textw(maxname); cmdw = textw(maxname);
if(cmdw > mw / 3) if(cmdw > mw / 3)
cmdw = mw / 3; cmdw = mw / 3;
if(prompt)
promptw = textw(prompt);
if(promptw > mw / 5)
promptw = mw / 5;
text[0] = 0; text[0] = 0;
match(text); match(text);
XMapRaised(dpy, win); XMapRaised(dpy, win);