Compare commits
64 Commits
Author | SHA1 | Date | |
---|---|---|---|
d27e3c1092 | |||
3a9f3a51ce | |||
53e92b5c17 | |||
d50ff5ca11 | |||
383e40dc21 | |||
8369e1736b | |||
c04b688cc0 | |||
4ebd7c4a21 | |||
dfe95cb546 | |||
8b633bf17d | |||
64697cdd0c | |||
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 | |||
68a24f5535 | |||
47b37834c4 | |||
5f436fdcb7 | |||
de34639883 | |||
18592825d2 | |||
3bc1f99e3c | |||
8a10b35c64 | |||
e4fc905317 | |||
a1913a6af7 | |||
66b2e8379f | |||
665488a6ee | |||
1e01ca0317 | |||
f3c12a7bff | |||
3ba8b71aba | |||
2bac5599b3 | |||
dbccf6fbff | |||
aea9bfec5e | |||
6175a39e8e | |||
2c7ff85f24 | |||
447046f7ae | |||
b76632b9e3 | |||
f8f5b27036 | |||
d6bf35caad | |||
507c030b5b | |||
0245394e4d |
14
.hgtags
14
.hgtags
@ -17,3 +17,17 @@ dcc5427f99f51a978386a0dd770467cd911ac84b 1.6
|
|||||||
58dbef4aef3d45c7a3da6945e53c9667c0f02d5b 1.7
|
58dbef4aef3d45c7a3da6945e53c9667c0f02d5b 1.7
|
||||||
3696d77aaf02f5d15728dde3b9e35abcaf291496 1.7.1
|
3696d77aaf02f5d15728dde3b9e35abcaf291496 1.7.1
|
||||||
d3e6fa22ae45b38b1bdb0d813390365e5930360b 1.8
|
d3e6fa22ae45b38b1bdb0d813390365e5930360b 1.8
|
||||||
|
c7f5f4d543170f03d70468e98a3a0ec8d2c4161b 1.9
|
||||||
|
1fce5c464fcd870b9f024aa1853d5cf3a3eb371b 2.0
|
||||||
|
7656557298c954469a6a9564e6649b1fb5db663e 2.1
|
||||||
|
90f0e34e7f118c9ad3227a1606211ee825942b1c 2.2
|
||||||
|
b6e09682c8adcb6569656bee73c311f9ab457715 2.3
|
||||||
|
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
|
||||||
|
8f0f917ac988164e1b4446236e3a6ab6cfcb8c67 3.1
|
||||||
|
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"),
|
||||||
|
17
Makefile
17
Makefile
@ -1,5 +1,5 @@
|
|||||||
# dmenu - dynamic menu
|
# dmenu - dynamic menu
|
||||||
# (C)opyright MMVII Anselm R. Garbe
|
# © 2006-2007 Anselm R. Garbe, Sander van Dijk
|
||||||
|
|
||||||
include config.mk
|
include config.mk
|
||||||
|
|
||||||
@ -13,7 +13,6 @@ options:
|
|||||||
@echo "CFLAGS = ${CFLAGS}"
|
@echo "CFLAGS = ${CFLAGS}"
|
||||||
@echo "LDFLAGS = ${LDFLAGS}"
|
@echo "LDFLAGS = ${LDFLAGS}"
|
||||||
@echo "CC = ${CC}"
|
@echo "CC = ${CC}"
|
||||||
@echo "LD = ${LD}"
|
|
||||||
|
|
||||||
.c.o:
|
.c.o:
|
||||||
@echo CC $<
|
@echo CC $<
|
||||||
@ -22,9 +21,8 @@ options:
|
|||||||
${OBJ}: dmenu.h config.mk
|
${OBJ}: dmenu.h config.mk
|
||||||
|
|
||||||
dmenu: ${OBJ}
|
dmenu: ${OBJ}
|
||||||
@echo LD $@
|
@echo CC -o $@
|
||||||
@${LD} -o $@ ${OBJ} ${LDFLAGS}
|
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||||
@strip $@
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
@echo cleaning
|
@echo cleaning
|
||||||
@ -33,7 +31,7 @@ clean:
|
|||||||
dist: clean
|
dist: clean
|
||||||
@echo creating dist tarball
|
@echo creating dist tarball
|
||||||
@mkdir -p dmenu-${VERSION}
|
@mkdir -p dmenu-${VERSION}
|
||||||
@cp -R LICENSE Makefile README config.mk dmenu.1 dmenu.h ${SRC} dmenu-${VERSION}
|
@cp -R LICENSE Makefile README config.mk dmenu.1 dmenu.h dmenu_path ${SRC} dmenu-${VERSION}
|
||||||
@tar -cf dmenu-${VERSION}.tar dmenu-${VERSION}
|
@tar -cf dmenu-${VERSION}.tar dmenu-${VERSION}
|
||||||
@gzip dmenu-${VERSION}.tar
|
@gzip dmenu-${VERSION}.tar
|
||||||
@rm -rf dmenu-${VERSION}
|
@rm -rf dmenu-${VERSION}
|
||||||
@ -41,16 +39,17 @@ dist: clean
|
|||||||
install: all
|
install: all
|
||||||
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
|
@echo installing executable file to ${DESTDIR}${PREFIX}/bin
|
||||||
@mkdir -p ${DESTDIR}${PREFIX}/bin
|
@mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||||
@cp -f dmenu ${DESTDIR}${PREFIX}/bin
|
@cp -f dmenu dmenu_path ${DESTDIR}${PREFIX}/bin
|
||||||
@chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu
|
@chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu
|
||||||
|
@chmod 755 ${DESTDIR}${PREFIX}/bin/dmenu_path
|
||||||
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
|
@echo installing manual page to ${DESTDIR}${MANPREFIX}/man1
|
||||||
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
@mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
||||||
@sed 's/VERSION/${VERSION}/g' < dmenu.1 > ${DESTDIR}${MANPREFIX}/man1/dmenu.1
|
@sed "s/VERSION/${VERSION}/g" < dmenu.1 > ${DESTDIR}${MANPREFIX}/man1/dmenu.1
|
||||||
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/dmenu.1
|
@chmod 644 ${DESTDIR}${MANPREFIX}/man1/dmenu.1
|
||||||
|
|
||||||
uninstall:
|
uninstall:
|
||||||
@echo removing executable file from ${DESTDIR}${PREFIX}/bin
|
@echo removing executable file from ${DESTDIR}${PREFIX}/bin
|
||||||
@rm -f ${DESTDIR}${PREFIX}/bin/dmenu
|
@rm -f ${DESTDIR}${PREFIX}/bin/dmenu ${DESTDIR}${PREFIX}/bin/dmenu_path
|
||||||
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
|
@echo removing manual page from ${DESTDIR}${MANPREFIX}/man1
|
||||||
@rm -f ${DESTDIR}${MANPREFIX}/man1/dmenu.1
|
@rm -f ${DESTDIR}${MANPREFIX}/man1/dmenu.1
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# dmenu version
|
# dmenu version
|
||||||
VERSION = 1.9
|
VERSION = 3.2
|
||||||
|
|
||||||
# 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}
|
||||||
|
|
||||||
@ -27,4 +27,3 @@ LDFLAGS = ${LIBS}
|
|||||||
|
|
||||||
# compiler and linker
|
# compiler and linker
|
||||||
CC = cc
|
CC = cc
|
||||||
LD = ${CC}
|
|
||||||
|
29
dmenu.1
29
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
|
||||||
@ -10,7 +10,6 @@ dmenu \- dynamic menu
|
|||||||
.RB [ \-p " <prompt>"]
|
.RB [ \-p " <prompt>"]
|
||||||
.RB [ \-sb " <color>"]
|
.RB [ \-sb " <color>"]
|
||||||
.RB [ \-sf " <color>"]
|
.RB [ \-sf " <color>"]
|
||||||
.RB [ \-t " <seconds>"]
|
|
||||||
.RB [ \-v ]
|
.RB [ \-v ]
|
||||||
.SH DESCRIPTION
|
.SH DESCRIPTION
|
||||||
.SS Overview
|
.SS Overview
|
||||||
@ -41,9 +40,6 @@ defines the selected background color (#RGB, #RRGGBB, and color names are suppor
|
|||||||
.B \-sf <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>
|
|
||||||
defines the seconds to wait for standard input, before exiting (default is 3).
|
|
||||||
.TP
|
|
||||||
.B \-v
|
.B \-v
|
||||||
prints version information to standard output, then exits.
|
prints version information to standard output, then exits.
|
||||||
.SH USAGE
|
.SH USAGE
|
||||||
@ -57,39 +53,42 @@ 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
|
.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-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
|
||||||
|
.B Control\-w
|
||||||
|
Remove all characters of current word from the input field.
|
||||||
.SH SEE ALSO
|
.SH SEE ALSO
|
||||||
.BR dwm (1),
|
.BR dwm (1),
|
||||||
.BR wmii (1) .
|
.BR wmii (1) .
|
||||||
|
56
dmenu.h
56
dmenu.h
@ -1,51 +1,41 @@
|
|||||||
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
|
/* See LICENSE file for copyright and license details. */
|
||||||
* 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-*-*-*-*-*-*-*"
|
||||||
#define NORMBGCOLOR "#333366"
|
#define NORMBGCOLOR "#eeeeee"
|
||||||
#define NORMFGCOLOR "#cccccc"
|
#define NORMFGCOLOR "#222222"
|
||||||
#define SELBGCOLOR "#666699"
|
#define SELBGCOLOR "#006699"
|
||||||
#define SELFGCOLOR "#eeeeee"
|
#define SELFGCOLOR "#ffffff"
|
||||||
#define SPACE 30 /* px */
|
#define SPACE 30 /* px */
|
||||||
|
|
||||||
/* color */
|
/* color */
|
||||||
enum { ColFG, ColBG, ColLast };
|
enum { ColFG, ColBG, ColLast };
|
||||||
|
|
||||||
typedef struct DC DC;
|
typedef struct {
|
||||||
typedef struct Fnt Fnt;
|
|
||||||
|
|
||||||
struct Fnt {
|
|
||||||
XFontStruct *xfont;
|
|
||||||
XFontSet set;
|
|
||||||
int ascent;
|
|
||||||
int descent;
|
|
||||||
int height;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct DC {
|
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
unsigned long norm[ColLast];
|
unsigned long norm[ColLast];
|
||||||
unsigned long sel[ColLast];
|
unsigned long sel[ColLast];
|
||||||
Drawable drawable;
|
Drawable drawable;
|
||||||
Fnt font;
|
|
||||||
GC gc;
|
GC gc;
|
||||||
}; /* draw context */
|
struct {
|
||||||
|
XFontStruct *xfont;
|
||||||
|
XFontSet set;
|
||||||
|
int ascent;
|
||||||
|
int descent;
|
||||||
|
int height;
|
||||||
|
} font;
|
||||||
|
} 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,
|
void drawtext(const char *text, unsigned long col[ColLast]);
|
||||||
unsigned long col[ColLast]); /* draws text with the defined color tuple */
|
unsigned int textw(const char *text);
|
||||||
extern unsigned long getcolor(const char *colstr); /* returns color of colstr */
|
unsigned int textnw(const char *text, unsigned int len);
|
||||||
extern void setfont(const char *fontstr); /* sets global font */
|
|
||||||
extern unsigned int textw(const char *text); /* returns width of text in px */
|
|
||||||
|
|
||||||
/* 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 */
|
||||||
|
26
dmenu_path
Executable file
26
dmenu_path
Executable file
@ -0,0 +1,26 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
CACHE=$HOME/.dmenu_cache
|
||||||
|
IFS=:
|
||||||
|
|
||||||
|
uptodate() {
|
||||||
|
test ! -f $CACHE && return 1
|
||||||
|
for dir in $PATH
|
||||||
|
do
|
||||||
|
test $dir -nt $CACHE && return 1
|
||||||
|
done
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! uptodate
|
||||||
|
then
|
||||||
|
for dir in $PATH
|
||||||
|
do
|
||||||
|
for file in "$dir"/*
|
||||||
|
do
|
||||||
|
test -x "$file" && echo "${file##*/}"
|
||||||
|
done
|
||||||
|
done | sort | uniq > $CACHE.$$
|
||||||
|
mv $CACHE.$$ $CACHE
|
||||||
|
fi
|
||||||
|
|
||||||
|
cat $CACHE
|
92
draw.c
92
draw.c
@ -1,23 +1,7 @@
|
|||||||
/* (C)opyright MMIV-MMVII Anselm R. Garbe <garbeam at gmail dot com>
|
/* See LICENSE file for copyright and license details. */
|
||||||
* See LICENSE file for license details.
|
|
||||||
*/
|
|
||||||
#include "dmenu.h"
|
#include "dmenu.h"
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
/* static */
|
|
||||||
|
|
||||||
static unsigned int
|
|
||||||
textnw(const char *text, unsigned int len) {
|
|
||||||
XRectangle r;
|
|
||||||
|
|
||||||
if(dc.font.set) {
|
|
||||||
XmbTextExtents(dc.font.set, text, len, NULL, &r);
|
|
||||||
return r.width;
|
|
||||||
}
|
|
||||||
return XTextWidth(dc.font.xfont, text, len);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* extern */
|
/* extern */
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -25,7 +9,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]);
|
||||||
@ -54,68 +37,25 @@ 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) {
|
|
||||||
XChangeGC(dpy, dc.gc, GCForeground, &gcv);
|
|
||||||
XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc,
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long
|
|
||||||
getcolor(const char *colstr) {
|
|
||||||
Colormap cmap = DefaultColormap(dpy, screen);
|
|
||||||
XColor color;
|
|
||||||
|
|
||||||
if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
|
|
||||||
eprint("error, cannot allocate color '%s'\n", colstr);
|
|
||||||
return color.pixel;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
setfont(const char *fontstr) {
|
|
||||||
char *def, **missing;
|
|
||||||
int i, n;
|
|
||||||
|
|
||||||
missing = NULL;
|
|
||||||
if(dc.font.set)
|
if(dc.font.set)
|
||||||
XFreeFontSet(dpy, dc.font.set);
|
XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
|
||||||
dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
|
else
|
||||||
if(missing)
|
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
|
||||||
XFreeStringList(missing);
|
|
||||||
if(dc.font.set) {
|
|
||||||
XFontSetExtents *font_extents;
|
|
||||||
XFontStruct **xfonts;
|
|
||||||
char **font_names;
|
|
||||||
dc.font.ascent = dc.font.descent = 0;
|
|
||||||
font_extents = XExtentsOfFontSet(dc.font.set);
|
|
||||||
n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
|
|
||||||
for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
|
|
||||||
if(dc.font.ascent < (*xfonts)->ascent)
|
|
||||||
dc.font.ascent = (*xfonts)->ascent;
|
|
||||||
if(dc.font.descent < (*xfonts)->descent)
|
|
||||||
dc.font.descent = (*xfonts)->descent;
|
|
||||||
xfonts++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if(dc.font.xfont)
|
|
||||||
XFreeFont(dpy, dc.font.xfont);
|
|
||||||
dc.font.xfont = NULL;
|
|
||||||
if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)))
|
|
||||||
eprint("error, cannot load font: '%s'\n", fontstr);
|
|
||||||
dc.font.ascent = dc.font.xfont->ascent;
|
|
||||||
dc.font.descent = dc.font.xfont->descent;
|
|
||||||
}
|
|
||||||
dc.font.height = dc.font.ascent + dc.font.descent;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
textw(const char *text) {
|
textw(const char *text) {
|
||||||
return textnw(text, strlen(text)) + dc.font.height;
|
return textnw(text, strlen(text)) + dc.font.height;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unsigned int
|
||||||
|
textnw(const char *text, unsigned int len) {
|
||||||
|
XRectangle r;
|
||||||
|
|
||||||
|
if(dc.font.set) {
|
||||||
|
XmbTextExtents(dc.font.set, text, len, NULL, &r);
|
||||||
|
return r.width;
|
||||||
|
}
|
||||||
|
return XTextWidth(dc.font.xfont, text, len);
|
||||||
|
}
|
||||||
|
184
main.c
184
main.c
@ -1,17 +1,11 @@
|
|||||||
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
|
/* See LICENSE file for copyright and license details. */
|
||||||
* (C)opyright MMVI-MMVII 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 <ctype.h>
|
#include <ctype.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <sys/select.h>
|
|
||||||
#include <sys/time.h>
|
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
#include <X11/keysym.h>
|
#include <X11/keysym.h>
|
||||||
|
|
||||||
@ -28,7 +22,7 @@ struct Item {
|
|||||||
|
|
||||||
static char text[4096];
|
static char text[4096];
|
||||||
static char *prompt = NULL;
|
static char *prompt = NULL;
|
||||||
static int mx, my, mw, mh;
|
static int 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;
|
||||||
@ -111,6 +105,69 @@ 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
|
||||||
|
initcolor(const char *colstr) {
|
||||||
|
Colormap cmap = DefaultColormap(dpy, screen);
|
||||||
|
XColor color;
|
||||||
|
|
||||||
|
if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
|
||||||
|
eprint("error, cannot allocate color '%s'\n", colstr);
|
||||||
|
return color.pixel;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
initfont(const char *fontstr) {
|
||||||
|
char *def, **missing;
|
||||||
|
int i, n;
|
||||||
|
|
||||||
|
if(!fontstr || fontstr[0] == '\0')
|
||||||
|
eprint("error, cannot load font: '%s'\n", fontstr);
|
||||||
|
missing = NULL;
|
||||||
|
if(dc.font.set)
|
||||||
|
XFreeFontSet(dpy, dc.font.set);
|
||||||
|
dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
|
||||||
|
if(missing)
|
||||||
|
XFreeStringList(missing);
|
||||||
|
if(dc.font.set) {
|
||||||
|
XFontSetExtents *font_extents;
|
||||||
|
XFontStruct **xfonts;
|
||||||
|
char **font_names;
|
||||||
|
dc.font.ascent = dc.font.descent = 0;
|
||||||
|
font_extents = XExtentsOfFontSet(dc.font.set);
|
||||||
|
n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
|
||||||
|
for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
|
||||||
|
if(dc.font.ascent < (*xfonts)->ascent)
|
||||||
|
dc.font.ascent = (*xfonts)->ascent;
|
||||||
|
if(dc.font.descent < (*xfonts)->descent)
|
||||||
|
dc.font.descent = (*xfonts)->descent;
|
||||||
|
xfonts++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if(dc.font.xfont)
|
||||||
|
XFreeFont(dpy, dc.font.xfont);
|
||||||
|
dc.font.xfont = NULL;
|
||||||
|
if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)))
|
||||||
|
eprint("error, cannot load font: '%s'\n", fontstr);
|
||||||
|
dc.font.ascent = dc.font.xfont->ascent;
|
||||||
|
dc.font.descent = dc.font.xfont->descent;
|
||||||
|
}
|
||||||
|
dc.font.height = dc.font.ascent + dc.font.descent;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
match(char *pattern) {
|
match(char *pattern) {
|
||||||
unsigned int plen;
|
unsigned int plen;
|
||||||
@ -151,13 +208,20 @@ match(char *pattern) {
|
|||||||
static void
|
static void
|
||||||
kpress(XKeyEvent * e) {
|
kpress(XKeyEvent * e) {
|
||||||
char buf[32];
|
char buf[32];
|
||||||
int num, prev_nitem;
|
int i, num;
|
||||||
unsigned int i, 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))
|
||||||
@ -188,6 +252,18 @@ kpress(XKeyEvent * e) {
|
|||||||
match(text);
|
match(text);
|
||||||
drawmenu();
|
drawmenu();
|
||||||
return;
|
return;
|
||||||
|
case XK_w:
|
||||||
|
case XK_W:
|
||||||
|
if(len) {
|
||||||
|
i = len - 1;
|
||||||
|
while(i >= 0 && text[i] == ' ')
|
||||||
|
text[i--] = 0;
|
||||||
|
while(i >= 0 && text[i] != ' ')
|
||||||
|
text[i--] = 0;
|
||||||
|
match(text);
|
||||||
|
drawmenu();
|
||||||
|
}
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(CLEANMASK(e->state) & Mod1Mask) {
|
if(CLEANMASK(e->state) & Mod1Mask) {
|
||||||
@ -225,12 +301,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;
|
||||||
@ -334,6 +406,12 @@ readstdin(void) {
|
|||||||
return maxname;
|
return maxname;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
usage(void) {
|
||||||
|
eprint("usage: dmenu [-b] [-fn <font>] [-nb <color>] [-nf <color>]\n"
|
||||||
|
" [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
|
||||||
|
}
|
||||||
|
|
||||||
/* extern */
|
/* extern */
|
||||||
|
|
||||||
int screen;
|
int screen;
|
||||||
@ -349,94 +427,77 @@ main(int argc, char *argv[]) {
|
|||||||
char *normfg = NORMFGCOLOR;
|
char *normfg = NORMFGCOLOR;
|
||||||
char *selbg = SELBGCOLOR;
|
char *selbg = SELBGCOLOR;
|
||||||
char *selfg = SELFGCOLOR;
|
char *selfg = SELFGCOLOR;
|
||||||
fd_set rd;
|
|
||||||
int i, j;
|
int i, j;
|
||||||
struct timeval timeout;
|
|
||||||
Item *itm;
|
Item *itm;
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
XModifierKeymap *modmap;
|
XModifierKeymap *modmap;
|
||||||
XSetWindowAttributes wa;
|
XSetWindowAttributes wa;
|
||||||
|
|
||||||
timeout.tv_usec = 0;
|
|
||||||
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], "-b", 3)) {
|
if(!strcmp(argv[i], "-b")) {
|
||||||
bottom = True;
|
bottom = True;
|
||||||
}
|
}
|
||||||
else if(!strncmp(argv[i], "-fn", 4)) {
|
else if(!strcmp(argv[i], "-fn")) {
|
||||||
if(++i < argc) font = argv[i];
|
if(++i < argc) font = argv[i];
|
||||||
}
|
}
|
||||||
else if(!strncmp(argv[i], "-nb", 4)) {
|
else if(!strcmp(argv[i], "-nb")) {
|
||||||
if(++i < argc) normbg = argv[i];
|
if(++i < argc) normbg = argv[i];
|
||||||
}
|
}
|
||||||
else if(!strncmp(argv[i], "-nf", 4)) {
|
else if(!strcmp(argv[i], "-nf")) {
|
||||||
if(++i < argc) normfg = argv[i];
|
if(++i < argc) normfg = argv[i];
|
||||||
}
|
}
|
||||||
else if(!strncmp(argv[i], "-p", 3)) {
|
else if(!strcmp(argv[i], "-p")) {
|
||||||
if(++i < argc) prompt = argv[i];
|
if(++i < argc) prompt = argv[i];
|
||||||
}
|
}
|
||||||
else if(!strncmp(argv[i], "-sb", 4)) {
|
else if(!strcmp(argv[i], "-sb")) {
|
||||||
if(++i < argc) selbg = argv[i];
|
if(++i < argc) selbg = argv[i];
|
||||||
}
|
}
|
||||||
else if(!strncmp(argv[i], "-sf", 4)) {
|
else if(!strcmp(argv[i], "-sf")) {
|
||||||
if(++i < argc) selfg = argv[i];
|
if(++i < argc) selfg = argv[i];
|
||||||
}
|
}
|
||||||
else if(!strncmp(argv[i], "-t", 3)) {
|
else if(!strcmp(argv[i], "-v"))
|
||||||
if(++i < argc) timeout.tv_sec = atoi(argv[i]);
|
eprint("dmenu-"VERSION", © 2006-2007 Anselm R. Garbe, Sander van Dijk\n");
|
||||||
}
|
|
||||||
else if(!strncmp(argv[i], "-v", 3)) {
|
|
||||||
fputs("dmenu-"VERSION", (C)opyright MMVI-MMVII Anselm R. Garbe\n", stdout);
|
|
||||||
exit(EXIT_SUCCESS);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
eprint("usage: dmenu [-b] [-fn <font>] [-nb <color>] [-nf <color>] [-p <prompt>]\n"
|
usage();
|
||||||
" [-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)
|
||||||
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);
|
||||||
|
if(isatty(STDIN_FILENO)) {
|
||||||
/* Note, the select() construction allows to grab all keypresses as
|
maxname = readstdin();
|
||||||
* early as possible, to not loose them. But if there is no standard
|
running = grabkeyboard();
|
||||||
* input supplied, we will make sure to exit after MAX_WAIT_STDIN
|
}
|
||||||
* seconds. This is convenience behavior for rapid typers.
|
else { /* prevent keypress loss */
|
||||||
*/
|
running = grabkeyboard();
|
||||||
while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
|
maxname = readstdin();
|
||||||
GrabModeAsync, CurrentTime) != GrabSuccess)
|
}
|
||||||
usleep(1000);
|
|
||||||
FD_ZERO(&rd);
|
|
||||||
FD_SET(STDIN_FILENO, &rd);
|
|
||||||
if(select(ConnectionNumber(dpy) + 1, &rd, NULL, NULL, &timeout) < 1)
|
|
||||||
goto UninitializedEnd;
|
|
||||||
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++) {
|
||||||
for (j = 0; j < modmap->max_keypermod; j++) {
|
for (j = 0; j < modmap->max_keypermod; j++) {
|
||||||
if(modmap->modifiermap[i * modmap->max_keypermod + j] == XKeysymToKeycode(dpy, XK_Num_Lock))
|
if(modmap->modifiermap[i * modmap->max_keypermod + j]
|
||||||
|
== XKeysymToKeycode(dpy, XK_Num_Lock))
|
||||||
numlockmask = (1 << i);
|
numlockmask = (1 << i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
XFreeModifiermap(modmap);
|
XFreeModifiermap(modmap);
|
||||||
/* style */
|
/* style */
|
||||||
dc.norm[ColBG] = getcolor(normbg);
|
dc.norm[ColBG] = initcolor(normbg);
|
||||||
dc.norm[ColFG] = getcolor(normfg);
|
dc.norm[ColFG] = initcolor(normfg);
|
||||||
dc.sel[ColBG] = getcolor(selbg);
|
dc.sel[ColBG] = initcolor(selbg);
|
||||||
dc.sel[ColFG] = getcolor(selfg);
|
dc.sel[ColFG] = initcolor(selfg);
|
||||||
setfont(font);
|
initfont(font);
|
||||||
/* menu window */
|
/* menu window */
|
||||||
wa.override_redirect = 1;
|
wa.override_redirect = 1;
|
||||||
wa.background_pixmap = ParentRelative;
|
wa.background_pixmap = ParentRelative;
|
||||||
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
|
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
|
||||||
mx = my = 0;
|
|
||||||
mw = DisplayWidth(dpy, screen);
|
mw = DisplayWidth(dpy, screen);
|
||||||
mh = dc.font.height + 2;
|
mh = dc.font.height + 2;
|
||||||
if(bottom)
|
win = XCreateWindow(dpy, root, 0,
|
||||||
my += DisplayHeight(dpy, screen) - mh;
|
bottom ? DisplayHeight(dpy, screen) - mh : 0, 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),
|
||||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
||||||
@ -444,6 +505,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)
|
||||||
@ -486,7 +549,6 @@ main(int argc, char *argv[]) {
|
|||||||
XFreePixmap(dpy, dc.drawable);
|
XFreePixmap(dpy, dc.drawable);
|
||||||
XFreeGC(dpy, dc.gc);
|
XFreeGC(dpy, dc.gc);
|
||||||
XDestroyWindow(dpy, win);
|
XDestroyWindow(dpy, win);
|
||||||
UninitializedEnd:
|
|
||||||
XUngrabKeyboard(dpy, CurrentTime);
|
XUngrabKeyboard(dpy, CurrentTime);
|
||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
return ret;
|
return ret;
|
||||||
|
6
util.c
6
util.c
@ -1,13 +1,9 @@
|
|||||||
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
|
/* See LICENSE file for copyright and license details. */
|
||||||
* See LICENSE file for license details.
|
|
||||||
*/
|
|
||||||
#include "dmenu.h"
|
#include "dmenu.h"
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/wait.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
void *
|
void *
|
||||||
emalloc(unsigned int size) {
|
emalloc(unsigned int size) {
|
||||||
|
Reference in New Issue
Block a user