Compare commits
28 Commits
Author | SHA1 | Date | |
---|---|---|---|
5a3dfb1c40 | |||
4042a11e51 | |||
aa2f73fc88 | |||
f189781bbd | |||
0e19146d5f | |||
85a151c6a4 | |||
1fa4fa386a | |||
e1515a2fdc | |||
f555908cef | |||
73120414e2 | |||
9911455f5b | |||
2772c51e79 | |||
d57c873f10 | |||
724f72142f | |||
5b8dce15d3 | |||
063c3d26e9 | |||
03c2b05bb2 | |||
8a066fabd9 | |||
6c0e05eb0d | |||
900d34347b | |||
4d0cc17794 | |||
28b6ea0f67 | |||
598d72fba9 | |||
007be12f2b | |||
6b5b580aff | |||
d8b48d64e1 | |||
a71424ac0e | |||
f1ab687c62 |
7
.hgtags
7
.hgtags
@ -23,3 +23,10 @@ c7f5f4d543170f03d70468e98a3a0ec8d2c4161b 1.9
|
|||||||
90f0e34e7f118c9ad3227a1606211ee825942b1c 2.2
|
90f0e34e7f118c9ad3227a1606211ee825942b1c 2.2
|
||||||
b6e09682c8adcb6569656bee73c311f9ab457715 2.3
|
b6e09682c8adcb6569656bee73c311f9ab457715 2.3
|
||||||
9e9036cbfb4b7306c6fb366249e81dc0e65bdfde 2.4
|
9e9036cbfb4b7306c6fb366249e81dc0e65bdfde 2.4
|
||||||
|
03e83e2788c83ddd63b45a667939d7ec783c98cb 2.4.1
|
||||||
|
1ca5d430524e838c52ede912533cb90108c5cd66 2.4.2
|
||||||
|
041143e9fc544c62edc58af52cae9ac5237e5945 2.5
|
||||||
|
775f761a5647a05038e091d1c99fc35d3034cd68 2.6
|
||||||
|
fbd9e9d63f202afe6834ccfdf890904f1897ec0b 2.7
|
||||||
|
dd3d02b07cac44fbafc074a361c1002cebe7aae4 2.8
|
||||||
|
59b3024854db49739c6d237fa9077f04a2da847a 3.0
|
||||||
|
4
LICENSE
4
LICENSE
@ -1,7 +1,7 @@
|
|||||||
MIT/X Consortium License
|
MIT/X Consortium License
|
||||||
|
|
||||||
(C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
|
© 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
(C)opyright MMVI-MMVII 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>
|
||||||
|
|
||||||
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"),
|
||||||
|
3
Makefile
3
Makefile
@ -1,5 +1,5 @@
|
|||||||
# dmenu - dynamic menu
|
# dmenu - dynamic menu
|
||||||
# (C)opyright MMVI-MMVII Anselm R. Garbe
|
# © 2006-2007 Anselm R. Garbe, Sander van Dijk
|
||||||
|
|
||||||
include config.mk
|
include config.mk
|
||||||
|
|
||||||
@ -23,7 +23,6 @@ ${OBJ}: dmenu.h config.mk
|
|||||||
dmenu: ${OBJ}
|
dmenu: ${OBJ}
|
||||||
@echo CC -o $@
|
@echo CC -o $@
|
||||||
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||||
@strip $@
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo cleaning
|
@echo cleaning
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# dmenu version
|
# dmenu version
|
||||||
VERSION = 2.4.1
|
VERSION = 3.1
|
||||||
|
|
||||||
# Customize below to fit your system
|
# Customize below to fit your system
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
|
|||||||
|
|
||||||
# flags
|
# flags
|
||||||
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
|
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
|
||||||
LDFLAGS = ${LIBS}
|
LDFLAGS = -s ${LIBS}
|
||||||
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
|
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
|
||||||
#LDFLAGS = -g ${LIBS}
|
#LDFLAGS = -g ${LIBS}
|
||||||
|
|
||||||
|
24
dmenu.1
24
dmenu.1
@ -1,4 +1,4 @@
|
|||||||
.TH DMENU 1 dmenu-VERSION
|
.TH DMENU 1 dmenu\-VERSION
|
||||||
.SH NAME
|
.SH NAME
|
||||||
dmenu \- dynamic menu
|
dmenu \- dynamic menu
|
||||||
.SH SYNOPSIS
|
.SH SYNOPSIS
|
||||||
@ -53,41 +53,41 @@ dmenu is completely controlled by the keyboard. The following keys are recognize
|
|||||||
Appends the character to the text in the input field. This works as a filter:
|
Appends the character to the text in the input field. This works as a filter:
|
||||||
only items containing this text will be displayed.
|
only items containing this text will be displayed.
|
||||||
.TP
|
.TP
|
||||||
.B Left/Right (Mod1-h/Mod1-l)
|
.B Left/Right (Mod1\-h/Mod1\-l)
|
||||||
Select the previous/next item.
|
Select the previous/next item.
|
||||||
.TP
|
.TP
|
||||||
.B PageUp/PageDown (Mod1-k/Mod1-j)
|
.B PageUp/PageDown (Mod1\-k/Mod1\-j)
|
||||||
Select the first item of the previous/next 'page' of items.
|
Select the first item of the previous/next 'page' of items.
|
||||||
.TP
|
.TP
|
||||||
.B Home/End (Mod1-g/Mod1-G)
|
.B Home/End (Mod1\-g/Mod1\-G)
|
||||||
Select the first/last item.
|
Select the first/last item.
|
||||||
.TP
|
.TP
|
||||||
.B Tab (Control-i)
|
.B Tab (Control\-i)
|
||||||
Copy the selected item to the input field.
|
Copy the selected item to the input field.
|
||||||
.TP
|
.TP
|
||||||
.B Return (Control-j)
|
.B Return (Control\-j)
|
||||||
Confirm selection and quit (print the selected item to standard output). Returns
|
Confirm selection and quit (print the selected item to standard output). Returns
|
||||||
.B 0
|
.B 0
|
||||||
on termination.
|
on termination.
|
||||||
.TP
|
.TP
|
||||||
.B Shift-Return (Control-Shift-j)
|
.B Shift\-Return (Control\-Shift\-j)
|
||||||
Confirm selection and quit (print the text in the input field to standard output).
|
Confirm selection and quit (print the text in the input field to standard output).
|
||||||
Returns
|
Returns
|
||||||
.B 0
|
.B 0
|
||||||
on termination.
|
on termination.
|
||||||
.TP
|
.TP
|
||||||
.B Escape (Control-bracketleft)
|
.B Escape (Control\-bracketleft)
|
||||||
Quit without selecting an item. Returns
|
Quit without selecting an item. Returns
|
||||||
.B 1
|
.B 1
|
||||||
on termination.
|
on termination.
|
||||||
.TP
|
.TP
|
||||||
.B Backspace (Control-h)
|
.B Backspace (Control\-h)
|
||||||
Remove enough characters from the input field to change its filtering effect.
|
Remove a character from the input field.
|
||||||
.TP
|
.TP
|
||||||
.B Control-u
|
.B Control\-u
|
||||||
Remove all characters from the input field.
|
Remove all characters from the input field.
|
||||||
.TP
|
.TP
|
||||||
.B Control-w
|
.B Control\-w
|
||||||
Remove all characters of current word from the input field.
|
Remove all characters of current word from the input field.
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
.BR dwm (1),
|
.BR dwm (1),
|
||||||
|
25
dmenu.h
25
dmenu.h
@ -1,7 +1,6 @@
|
|||||||
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
|
/* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
* See LICENSE file for license details.
|
* © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
||||||
*/
|
* See LICENSE file for license details. */
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
#define FONT "-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*"
|
#define FONT "-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*"
|
||||||
@ -29,16 +28,16 @@ typedef struct {
|
|||||||
} font;
|
} font;
|
||||||
} DC; /* draw context */
|
} DC; /* draw context */
|
||||||
|
|
||||||
extern int screen;
|
int screen;
|
||||||
extern Display *dpy;
|
Display *dpy;
|
||||||
extern DC dc; /* global drawing context */
|
DC dc; /* global drawing context */
|
||||||
|
|
||||||
/* draw.c */
|
/* draw.c */
|
||||||
extern void drawtext(const char *text, unsigned long col[ColLast]);
|
void drawtext(const char *text, unsigned long col[ColLast]);
|
||||||
extern unsigned int textw(const char *text);
|
unsigned int textw(const char *text);
|
||||||
extern unsigned int textnw(const char *text, unsigned int len);
|
unsigned int textnw(const char *text, unsigned int len);
|
||||||
|
|
||||||
/* util.c */
|
/* util.c */
|
||||||
extern void *emalloc(unsigned int size); /* allocates memory, exits on error */
|
void *emalloc(unsigned int size); /* allocates memory, exits on error */
|
||||||
extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */
|
void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */
|
||||||
extern char *estrdup(const char *str); /* duplicates str, exits on allocation error */
|
char *estrdup(const char *str); /* duplicates str, exits on allocation error */
|
||||||
|
30
dmenu_path
30
dmenu_path
@ -1,2 +1,30 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
/bin/ls -lL `echo $PATH | tr : ' '` 2> /dev/null | awk '$1 ~ /^[^d].*x/ { print $NF }' | sort | uniq
|
CACHE=$HOME/.dmenu_cache
|
||||||
|
UPTODATE=1
|
||||||
|
IFS=:
|
||||||
|
|
||||||
|
if test ! -f $CACHE
|
||||||
|
then
|
||||||
|
unset UPTODATE
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test $UPTODATE
|
||||||
|
then
|
||||||
|
for dir in $PATH
|
||||||
|
do
|
||||||
|
test $dir -nt $CACHE && unset UPTODATE
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test ! $UPTODATE
|
||||||
|
then
|
||||||
|
for dir in $PATH
|
||||||
|
do
|
||||||
|
for file in "$dir"/*
|
||||||
|
do
|
||||||
|
test -x "$file" && echo "${file##*/}"
|
||||||
|
done
|
||||||
|
done | sort | uniq > $CACHE
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat $CACHE
|
||||||
|
22
draw.c
22
draw.c
@ -1,7 +1,6 @@
|
|||||||
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
|
/* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
* (C)opyright MMVI-MMVII 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>
|
||||||
* See LICENSE file for license details.
|
* See LICENSE file for license details. */
|
||||||
*/
|
|
||||||
#include "dmenu.h"
|
#include "dmenu.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -12,7 +11,6 @@ drawtext(const char *text, unsigned long col[ColLast]) {
|
|||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
static char buf[256];
|
static char buf[256];
|
||||||
unsigned int len, olen;
|
unsigned int len, olen;
|
||||||
XGCValues gcv;
|
|
||||||
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
|
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
|
||||||
|
|
||||||
XSetForeground(dpy, dc.gc, col[ColBG]);
|
XSetForeground(dpy, dc.gc, col[ColBG]);
|
||||||
@ -41,17 +39,11 @@ drawtext(const char *text, unsigned long col[ColLast]) {
|
|||||||
}
|
}
|
||||||
if(w > dc.w)
|
if(w > dc.w)
|
||||||
return; /* too long */
|
return; /* too long */
|
||||||
gcv.foreground = col[ColFG];
|
XSetForeground(dpy, dc.gc, col[ColFG]);
|
||||||
if(dc.font.set) {
|
if(dc.font.set)
|
||||||
XChangeGC(dpy, dc.gc, GCForeground, &gcv);
|
XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
|
||||||
XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc,
|
else
|
||||||
x, y, buf, len);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
gcv.font = dc.font.xfont->fid;
|
|
||||||
XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
|
|
||||||
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
|
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
|
59
main.c
59
main.c
@ -1,7 +1,6 @@
|
|||||||
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
|
/* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
* (C)opyright MMVI-MMVII 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>
|
||||||
* See LICENSE file for license details.
|
* See LICENSE file for license details. */
|
||||||
*/
|
|
||||||
#include "dmenu.h"
|
#include "dmenu.h"
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
@ -108,6 +107,19 @@ drawmenu(void) {
|
|||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Bool
|
||||||
|
grabkeyboard(void) {
|
||||||
|
unsigned int len;
|
||||||
|
|
||||||
|
for(len = 1000; len; len--) {
|
||||||
|
if(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime)
|
||||||
|
== GrabSuccess)
|
||||||
|
break;
|
||||||
|
usleep(1000);
|
||||||
|
}
|
||||||
|
return len > 0;
|
||||||
|
}
|
||||||
|
|
||||||
static unsigned long
|
static unsigned long
|
||||||
initcolor(const char *colstr) {
|
initcolor(const char *colstr) {
|
||||||
Colormap cmap = DefaultColormap(dpy, screen);
|
Colormap cmap = DefaultColormap(dpy, screen);
|
||||||
@ -123,6 +135,8 @@ initfont(const char *fontstr) {
|
|||||||
char *def, **missing;
|
char *def, **missing;
|
||||||
int i, n;
|
int i, n;
|
||||||
|
|
||||||
|
if(!fontstr || fontstr[0] == '\0')
|
||||||
|
eprint("error, cannot load font: '%s'\n", fontstr);
|
||||||
missing = NULL;
|
missing = NULL;
|
||||||
if(dc.font.set)
|
if(dc.font.set)
|
||||||
XFreeFontSet(dpy, dc.font.set);
|
XFreeFontSet(dpy, dc.font.set);
|
||||||
@ -196,13 +210,20 @@ match(char *pattern) {
|
|||||||
static void
|
static void
|
||||||
kpress(XKeyEvent * e) {
|
kpress(XKeyEvent * e) {
|
||||||
char buf[32];
|
char buf[32];
|
||||||
int i, num, prev_nitem;
|
int i, num;
|
||||||
unsigned int len;
|
unsigned int len;
|
||||||
KeySym ksym;
|
KeySym ksym;
|
||||||
|
|
||||||
len = strlen(text);
|
len = strlen(text);
|
||||||
buf[0] = 0;
|
buf[0] = 0;
|
||||||
num = XLookupString(e, buf, sizeof buf, &ksym, 0);
|
num = XLookupString(e, buf, sizeof buf, &ksym, 0);
|
||||||
|
if(IsKeypadKey(ksym)) {
|
||||||
|
if(ksym == XK_KP_Enter) {
|
||||||
|
ksym = XK_Return;
|
||||||
|
} else if(ksym >= XK_KP_0 && ksym <= XK_KP_9) {
|
||||||
|
ksym = (ksym - XK_KP_0) + XK_0;
|
||||||
|
}
|
||||||
|
}
|
||||||
if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
|
if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
|
||||||
|| IsMiscFunctionKey(ksym) || IsPFKey(ksym)
|
|| IsMiscFunctionKey(ksym) || IsPFKey(ksym)
|
||||||
|| IsPrivateKeypadKey(ksym))
|
|| IsPrivateKeypadKey(ksym))
|
||||||
@ -282,12 +303,8 @@ kpress(XKeyEvent * e) {
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case XK_BackSpace:
|
case XK_BackSpace:
|
||||||
if((i = len)) {
|
if(len) {
|
||||||
prev_nitem = nitem;
|
text[--len] = 0;
|
||||||
do {
|
|
||||||
text[--i] = 0;
|
|
||||||
match(text);
|
|
||||||
} while(i && nitem && prev_nitem == nitem);
|
|
||||||
match(text);
|
match(text);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -418,10 +435,6 @@ main(int argc, char *argv[]) {
|
|||||||
XModifierKeymap *modmap;
|
XModifierKeymap *modmap;
|
||||||
XSetWindowAttributes wa;
|
XSetWindowAttributes wa;
|
||||||
|
|
||||||
if(isatty(STDIN_FILENO)) {
|
|
||||||
fputs("error: dmenu can't run in an interactive shell\n", stdout);
|
|
||||||
usage();
|
|
||||||
}
|
|
||||||
/* command line args */
|
/* command line args */
|
||||||
for(i = 1; i < argc; i++)
|
for(i = 1; i < argc; i++)
|
||||||
if(!strncmp(argv[i], "-b", 3)) {
|
if(!strncmp(argv[i], "-b", 3)) {
|
||||||
@ -446,7 +459,7 @@ main(int argc, char *argv[]) {
|
|||||||
if(++i < argc) selfg = argv[i];
|
if(++i < argc) selfg = argv[i];
|
||||||
}
|
}
|
||||||
else if(!strncmp(argv[i], "-v", 3))
|
else if(!strncmp(argv[i], "-v", 3))
|
||||||
eprint("dmenu-"VERSION", (C)opyright MMVI-MMVII Anselm R. Garbe\n");
|
eprint("dmenu-"VERSION", © 2006-2007 Anselm R. Garbe, Sander van Dijk\n");
|
||||||
else
|
else
|
||||||
usage();
|
usage();
|
||||||
setlocale(LC_CTYPE, "");
|
setlocale(LC_CTYPE, "");
|
||||||
@ -455,10 +468,14 @@ main(int argc, char *argv[]) {
|
|||||||
eprint("dmenu: cannot open display\n");
|
eprint("dmenu: cannot open display\n");
|
||||||
screen = DefaultScreen(dpy);
|
screen = DefaultScreen(dpy);
|
||||||
root = RootWindow(dpy, screen);
|
root = RootWindow(dpy, screen);
|
||||||
while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
|
if(isatty(STDIN_FILENO)) {
|
||||||
GrabModeAsync, CurrentTime) != GrabSuccess)
|
maxname = readstdin();
|
||||||
usleep(1000);
|
running = grabkeyboard();
|
||||||
maxname = readstdin();
|
}
|
||||||
|
else { /* prevent keypress loss */
|
||||||
|
running = grabkeyboard();
|
||||||
|
maxname = readstdin();
|
||||||
|
}
|
||||||
/* init modifier map */
|
/* init modifier map */
|
||||||
modmap = XGetModifierMapping(dpy);
|
modmap = XGetModifierMapping(dpy);
|
||||||
for (i = 0; i < 8; i++) {
|
for (i = 0; i < 8; i++) {
|
||||||
@ -490,6 +507,8 @@ main(int argc, char *argv[]) {
|
|||||||
dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen));
|
dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen));
|
||||||
dc.gc = XCreateGC(dpy, root, 0, 0);
|
dc.gc = XCreateGC(dpy, root, 0, 0);
|
||||||
XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
|
XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
|
||||||
|
if(!dc.font.set)
|
||||||
|
XSetFont(dpy, dc.gc, dc.font.xfont->fid);
|
||||||
if(maxname)
|
if(maxname)
|
||||||
cmdw = textw(maxname);
|
cmdw = textw(maxname);
|
||||||
if(cmdw > mw / 3)
|
if(cmdw > mw / 3)
|
||||||
|
6
util.c
6
util.c
@ -1,6 +1,6 @@
|
|||||||
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
|
/* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
|
||||||
* See LICENSE file for license details.
|
* © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
|
||||||
*/
|
* See LICENSE file for license details. */
|
||||||
#include "dmenu.h"
|
#include "dmenu.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
Reference in New Issue
Block a user