Compare commits
18 Commits
Author | SHA1 | Date | |
---|---|---|---|
5f436fdcb7 | |||
de34639883 | |||
18592825d2 | |||
3bc1f99e3c | |||
8a10b35c64 | |||
e4fc905317 | |||
a1913a6af7 | |||
66b2e8379f | |||
665488a6ee | |||
1e01ca0317 | |||
f3c12a7bff | |||
3ba8b71aba | |||
2bac5599b3 | |||
dbccf6fbff | |||
aea9bfec5e | |||
6175a39e8e | |||
2c7ff85f24 | |||
447046f7ae |
4
.hgtags
4
.hgtags
@ -18,3 +18,7 @@ dcc5427f99f51a978386a0dd770467cd911ac84b 1.6
|
||||
3696d77aaf02f5d15728dde3b9e35abcaf291496 1.7.1
|
||||
d3e6fa22ae45b38b1bdb0d813390365e5930360b 1.8
|
||||
c7f5f4d543170f03d70468e98a3a0ec8d2c4161b 1.9
|
||||
1fce5c464fcd870b9f024aa1853d5cf3a3eb371b 2.0
|
||||
7656557298c954469a6a9564e6649b1fb5db663e 2.1
|
||||
90f0e34e7f118c9ad3227a1606211ee825942b1c 2.2
|
||||
b6e09682c8adcb6569656bee73c311f9ab457715 2.3
|
||||
|
16
Makefile
16
Makefile
@ -1,5 +1,5 @@
|
||||
# dmenu - dynamic menu
|
||||
# (C)opyright MMVII Anselm R. Garbe
|
||||
# (C)opyright MMVI-MMVII Anselm R. Garbe
|
||||
|
||||
include config.mk
|
||||
|
||||
@ -13,7 +13,6 @@ options:
|
||||
@echo "CFLAGS = ${CFLAGS}"
|
||||
@echo "LDFLAGS = ${LDFLAGS}"
|
||||
@echo "CC = ${CC}"
|
||||
@echo "LD = ${LD}"
|
||||
|
||||
.c.o:
|
||||
@echo CC $<
|
||||
@ -22,8 +21,8 @@ options:
|
||||
${OBJ}: dmenu.h config.mk
|
||||
|
||||
dmenu: ${OBJ}
|
||||
@echo LD $@
|
||||
@${LD} -o $@ ${OBJ} ${LDFLAGS}
|
||||
@echo CC -o $@
|
||||
@${CC} -o $@ ${OBJ} ${LDFLAGS}
|
||||
@strip $@
|
||||
|
||||
clean:
|
||||
@ -33,7 +32,7 @@ clean:
|
||||
dist: clean
|
||||
@echo creating dist tarball
|
||||
@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}
|
||||
@gzip dmenu-${VERSION}.tar
|
||||
@rm -rf dmenu-${VERSION}
|
||||
@ -41,16 +40,17 @@ dist: clean
|
||||
install: all
|
||||
@echo installing executable file to ${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_path
|
||||
@echo installing manual page to ${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
|
||||
|
||||
uninstall:
|
||||
@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
|
||||
@rm -f ${DESTDIR}${MANPREFIX}/man1/dmenu.1
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
# dmenu version
|
||||
VERSION = 2.0
|
||||
VERSION = 2.4
|
||||
|
||||
# Customize below to fit your system
|
||||
|
||||
@ -27,4 +27,3 @@ LDFLAGS = ${LIBS}
|
||||
|
||||
# compiler and linker
|
||||
CC = cc
|
||||
LD = ${CC}
|
||||
|
7
dmenu.1
7
dmenu.1
@ -10,7 +10,6 @@ dmenu \- dynamic menu
|
||||
.RB [ \-p " <prompt>"]
|
||||
.RB [ \-sb " <color>"]
|
||||
.RB [ \-sf " <color>"]
|
||||
.RB [ \-t " <seconds>"]
|
||||
.RB [ \-v ]
|
||||
.SH DESCRIPTION
|
||||
.SS Overview
|
||||
@ -41,9 +40,6 @@ defines the selected background color (#RGB, #RRGGBB, and color names are suppor
|
||||
.B \-sf <color>
|
||||
defines the selected foreground color (#RGB, #RRGGBB, and color names are supported).
|
||||
.TP
|
||||
.B \-t <seconds>
|
||||
defines the seconds to wait for standard input, before exiting (default is 3).
|
||||
.TP
|
||||
.B \-v
|
||||
prints version information to standard output, then exits.
|
||||
.SH USAGE
|
||||
@ -90,6 +86,9 @@ Remove enough characters from the input field to change its filtering effect.
|
||||
.TP
|
||||
.B Control-u
|
||||
Remove all characters from the input field.
|
||||
.TP
|
||||
.B Control-w
|
||||
Remove all characters of current word from the input field.
|
||||
.SH SEE ALSO
|
||||
.BR dwm (1),
|
||||
.BR wmii (1) .
|
||||
|
31
dmenu.h
31
dmenu.h
@ -14,36 +14,29 @@
|
||||
/* color */
|
||||
enum { ColFG, ColBG, ColLast };
|
||||
|
||||
typedef struct DC DC;
|
||||
typedef struct Fnt Fnt;
|
||||
|
||||
struct Fnt {
|
||||
XFontStruct *xfont;
|
||||
XFontSet set;
|
||||
int ascent;
|
||||
int descent;
|
||||
int height;
|
||||
};
|
||||
|
||||
struct DC {
|
||||
typedef struct {
|
||||
int x, y, w, h;
|
||||
unsigned long norm[ColLast];
|
||||
unsigned long sel[ColLast];
|
||||
Drawable drawable;
|
||||
Fnt font;
|
||||
GC gc;
|
||||
}; /* draw context */
|
||||
struct {
|
||||
XFontStruct *xfont;
|
||||
XFontSet set;
|
||||
int ascent;
|
||||
int descent;
|
||||
int height;
|
||||
} font;
|
||||
} DC; /* draw context */
|
||||
|
||||
extern int screen;
|
||||
extern Display *dpy;
|
||||
extern DC dc; /* global drawing context */
|
||||
|
||||
/* draw.c */
|
||||
extern void drawtext(const char *text,
|
||||
unsigned long col[ColLast]); /* draws text with the defined color tuple */
|
||||
extern unsigned long getcolor(const char *colstr); /* returns color of colstr */
|
||||
extern void setfont(const char *fontstr); /* sets global font */
|
||||
extern unsigned int textw(const char *text); /* returns width of text in px */
|
||||
extern void drawtext(const char *text, unsigned long col[ColLast]);
|
||||
extern unsigned int textw(const char *text);
|
||||
extern unsigned int textnw(const char *text, unsigned int len);
|
||||
|
||||
/* util.c */
|
||||
extern void *emalloc(unsigned int size); /* allocates memory, exits on error */
|
||||
|
2
dmenu_path
Executable file
2
dmenu_path
Executable file
@ -0,0 +1,2 @@
|
||||
#!/bin/sh
|
||||
/bin/ls -lL `echo $PATH | tr : ' '` 2> /dev/null | awk '$1 ~ /^[^d].*x/ { print $NF }' | /usr/bin/sort -u
|
76
draw.c
76
draw.c
@ -1,23 +1,10 @@
|
||||
/* (C)opyright MMIV-MMVII Anselm R. Garbe <garbeam at gmail dot com>
|
||||
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
|
||||
* (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 <stdio.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 */
|
||||
|
||||
void
|
||||
@ -67,55 +54,18 @@ drawtext(const char *text, unsigned long col[ColLast]) {
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
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;
|
||||
}
|
||||
|
||||
unsigned int
|
||||
textw(const char *text) {
|
||||
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);
|
||||
}
|
||||
|
125
main.c
125
main.c
@ -3,15 +3,12 @@
|
||||
* See LICENSE file for license details.
|
||||
*/
|
||||
#include "dmenu.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <locale.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/time.h>
|
||||
#include <X11/Xutil.h>
|
||||
#include <X11/keysym.h>
|
||||
|
||||
@ -111,6 +108,54 @@ drawmenu(void) {
|
||||
XFlush(dpy);
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
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
|
||||
match(char *pattern) {
|
||||
unsigned int plen;
|
||||
@ -151,8 +196,8 @@ match(char *pattern) {
|
||||
static void
|
||||
kpress(XKeyEvent * e) {
|
||||
char buf[32];
|
||||
int num, prev_nitem;
|
||||
unsigned int i, len;
|
||||
int i, num, prev_nitem;
|
||||
unsigned int len;
|
||||
KeySym ksym;
|
||||
|
||||
len = strlen(text);
|
||||
@ -188,6 +233,18 @@ kpress(XKeyEvent * e) {
|
||||
match(text);
|
||||
drawmenu();
|
||||
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) {
|
||||
@ -334,6 +391,12 @@ readstdin(void) {
|
||||
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 */
|
||||
|
||||
int screen;
|
||||
@ -349,16 +412,16 @@ main(int argc, char *argv[]) {
|
||||
char *normfg = NORMFGCOLOR;
|
||||
char *selbg = SELBGCOLOR;
|
||||
char *selfg = SELFGCOLOR;
|
||||
fd_set rd;
|
||||
int i, j, my;
|
||||
struct timeval timeout;
|
||||
int i, j;
|
||||
Item *itm;
|
||||
XEvent ev;
|
||||
XModifierKeymap *modmap;
|
||||
XSetWindowAttributes wa;
|
||||
|
||||
timeout.tv_usec = 0;
|
||||
timeout.tv_sec = 3;
|
||||
if(isatty(STDIN_FILENO)) {
|
||||
fputs("error: dmenu can't run in an interactive shell\n", stdout);
|
||||
usage();
|
||||
}
|
||||
/* command line args */
|
||||
for(i = 1; i < argc; i++)
|
||||
if(!strncmp(argv[i], "-b", 3)) {
|
||||
@ -382,61 +445,44 @@ main(int argc, char *argv[]) {
|
||||
else if(!strncmp(argv[i], "-sf", 4)) {
|
||||
if(++i < argc) selfg = argv[i];
|
||||
}
|
||||
else if(!strncmp(argv[i], "-t", 3)) {
|
||||
if(++i < argc) timeout.tv_sec = atoi(argv[i]);
|
||||
}
|
||||
else if(!strncmp(argv[i], "-v", 3)) {
|
||||
fputs("dmenu-"VERSION", (C)opyright MMVI-MMVII Anselm R. Garbe\n", stdout);
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
else if(!strncmp(argv[i], "-v", 3))
|
||||
eprint("dmenu-"VERSION", (C)opyright MMVI-MMVII Anselm R. Garbe\n");
|
||||
else
|
||||
eprint("usage: dmenu [-b] [-fn <font>] [-nb <color>] [-nf <color>] [-p <prompt>]\n"
|
||||
" [-sb <color>] [-sf <color>] [-t <seconds>] [-v]\n", stdout);
|
||||
usage();
|
||||
setlocale(LC_CTYPE, "");
|
||||
dpy = XOpenDisplay(0);
|
||||
if(!dpy)
|
||||
eprint("dmenu: cannot open display\n");
|
||||
screen = DefaultScreen(dpy);
|
||||
root = RootWindow(dpy, screen);
|
||||
|
||||
/* Note, the select() construction allows to grab all keypresses as
|
||||
* early as possible, to not loose them. But if there is no standard
|
||||
* input supplied, we will make sure to exit after MAX_WAIT_STDIN
|
||||
* seconds. This is convenience behavior for rapid typers.
|
||||
*/
|
||||
while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
|
||||
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 */
|
||||
modmap = XGetModifierMapping(dpy);
|
||||
for (i = 0; i < 8; i++) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
XFreeModifiermap(modmap);
|
||||
/* style */
|
||||
dc.norm[ColBG] = getcolor(normbg);
|
||||
dc.norm[ColFG] = getcolor(normfg);
|
||||
dc.sel[ColBG] = getcolor(selbg);
|
||||
dc.sel[ColFG] = getcolor(selfg);
|
||||
setfont(font);
|
||||
dc.norm[ColBG] = initcolor(normbg);
|
||||
dc.norm[ColFG] = initcolor(normfg);
|
||||
dc.sel[ColBG] = initcolor(selbg);
|
||||
dc.sel[ColFG] = initcolor(selfg);
|
||||
initfont(font);
|
||||
/* menu window */
|
||||
wa.override_redirect = 1;
|
||||
wa.background_pixmap = ParentRelative;
|
||||
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
|
||||
my = 0;
|
||||
mw = DisplayWidth(dpy, screen);
|
||||
mh = dc.font.height + 2;
|
||||
if(bottom)
|
||||
my += DisplayHeight(dpy, screen) - mh;
|
||||
win = XCreateWindow(dpy, root, 0, 0, mw, mh, 0,
|
||||
win = XCreateWindow(dpy, root, 0,
|
||||
bottom ? DisplayHeight(dpy, screen) - mh : 0, mw, mh, 0,
|
||||
DefaultDepth(dpy, screen), CopyFromParent,
|
||||
DefaultVisual(dpy, screen),
|
||||
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
|
||||
@ -486,7 +532,6 @@ main(int argc, char *argv[]) {
|
||||
XFreePixmap(dpy, dc.drawable);
|
||||
XFreeGC(dpy, dc.gc);
|
||||
XDestroyWindow(dpy, win);
|
||||
UninitializedEnd:
|
||||
XUngrabKeyboard(dpy, CurrentTime);
|
||||
XCloseDisplay(dpy);
|
||||
return ret;
|
||||
|
Reference in New Issue
Block a user