Compare commits

...

45 Commits
2.1 ... 3.1

Author SHA1 Message Date
5a3dfb1c40 removed strip, added -s to LDFLAGs 2007-05-15 13:44:41 +02:00
4042a11e51 applied anydot's dmenu_path caching patch, thank you! 2007-05-14 11:56:41 +02:00
aa2f73fc88 fixed a small bug in dmenu when an empty font is supplied 2007-05-02 15:25:52 +02:00
f189781bbd Added tag 3.0 for changeset 59b3024854db 2007-04-19 09:27:08 +02:00
0e19146d5f making copyright notice more compact 2007-04-13 11:36:44 +02:00
85a151c6a4 next version is 2.9 2007-03-28 08:17:57 +02:00
1fa4fa386a allowing numpad keys as inpyt 2007-03-27 16:52:50 +02:00
e1515a2fdc Added tag 2.8 for changeset dd3d02b07cac 2007-03-07 13:30:57 +01:00
f555908cef attempt to grab the keyboard only 1000 times, not forever. 2007-03-07 11:01:14 +01:00
73120414e2 reverting keyboard grab to root window - invoking several dmenu's now works again... 2007-03-07 10:54:21 +01:00
9911455f5b Wait for an Expose and draw the menu immediately after mapping the window. 2007-03-06 03:24:40 -05:00
2772c51e79 Added tag 2.7 for changeset fbd9e9d63f20 2007-03-05 11:25:18 +01:00
d57c873f10 keyboard grab works on the dmenu window now (not on the root window) - thx for Kris for this hint 2007-03-02 21:48:48 +01:00
724f72142f also, don't set the font all the time 2007-03-02 15:16:36 +01:00
5b8dce15d3 Added tag 2.6 for changeset 775f761a5647 2007-03-01 15:47:54 +01:00
063c3d26e9 useless var declaration prev_nitem 2007-02-27 14:44:21 +01:00
03c2b05bb2 changed Backspace/C-w behavior (now it only removes a single character) 2007-02-26 14:07:19 +01:00
8a066fabd9 if isatty() first read from stdin and then grab the keyboard, otherwise first grab the keyboard and then read from stdin 2007-02-26 11:44:41 +01:00
6c0e05eb0d next is 2.6, but not yet ;) 2007-02-26 10:47:52 +01:00
900d34347b Escape -s in dmenu.1 2007-02-25 16:41:05 -05:00
4d0cc17794 Added tag 2.5 for changeset 041143e9fc54 2007-02-24 15:38:26 +01:00
28b6ea0f67 I also dislike sort -u, I support that each Unix tool does one job and does it right ;) 2007-02-24 15:38:10 +01:00
598d72fba9 removed superfluous externs as well 2007-02-24 14:07:40 +01:00
007be12f2b using the old-style fashion we uses earlier 2007-02-23 15:28:25 +01:00
6b5b580aff fixed a bug when dmenu is run with -v 2007-02-23 14:39:54 +01:00
d8b48d64e1 Added tag 2.4.2 for changeset 1ca5d430524e 2007-02-23 13:51:23 +01:00
a71424ac0e ok 2.4.2 2007-02-23 13:51:06 +01:00
f1ab687c62 Added tag 2.4.1 for changeset 03e83e2788c8 2007-02-23 13:28:43 +01:00
68a24f5535 hotfix 2007-02-23 13:28:38 +01:00
47b37834c4 Added tag 2.4 for changeset 9e9036cbfb4b 2007-02-23 10:42:00 +01:00
5f436fdcb7 added dmenu_path convenience script 2007-02-23 10:16:43 +01:00
de34639883 made Fnt an anonymous struct 2007-02-22 18:16:35 +01:00
18592825d2 Added tag 2.3 for changeset b6e09682c8adcb6569656bee73c311f9ab457715 2007-02-21 11:05:19 +01:00
3bc1f99e3c applied the fix inspired by a recent wmii commit 2007-02-21 10:59:36 +01:00
8a10b35c64 renamed getcolor to initcolor 2007-02-20 13:57:05 +01:00
e4fc905317 s/setfont/initfont/ 2007-02-20 13:54:37 +01:00
a1913a6af7 readded draw.c again (except getcolor and setfont) 2007-02-20 13:54:00 +01:00
66b2e8379f removed -t, now using isatty() instead of select() to prevent execution from an interactive shell 2007-02-19 21:18:36 +01:00
665488a6ee removed draw.c, implemented C-w handling (backward word deletion) 2007-02-19 15:49:50 +01:00
1e01ca0317 Added tag 2.2 for changeset 90f0e34e7f11 2007-02-14 09:42:02 +01:00
f3c12a7bff fixed Copyright notice in Makefile 2007-02-08 14:10:17 +01:00
3ba8b71aba nah nah nah, I can't get used to the bottom bar, pushing the conditional dmenu again 2007-02-08 11:17:11 +01:00
2bac5599b3 letting dmenu appear at the bottom by default 2007-02-08 11:10:29 +01:00
dbccf6fbff got rid of LD, inspired by JGs patch to wmii 2007-02-05 11:10:41 +01:00
aea9bfec5e Added tag 2.1 for changeset 7656557298c9 2007-01-17 11:10:31 +01:00
10 changed files with 224 additions and 188 deletions

11
.hgtags
View File

@ -19,3 +19,14 @@ dcc5427f99f51a978386a0dd770467cd911ac84b 1.6
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

View File

@ -1,7 +1,7 @@
MIT/X Consortium License
(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>
© 2006-2007 Anselm R. Garbe <garbeam 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
copy of this software and associated documentation files (the "Software"),

View File

@ -1,5 +1,5 @@
# dmenu - dynamic menu
# (C)opyright MMVII Anselm R. Garbe
# © 2006-2007 Anselm R. Garbe, Sander van Dijk
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,9 +21,8 @@ options:
${OBJ}: dmenu.h config.mk
dmenu: ${OBJ}
@echo LD $@
@${LD} -o $@ ${OBJ} ${LDFLAGS}
@strip $@
@echo CC -o $@
@${CC} -o $@ ${OBJ} ${LDFLAGS}
clean:
@echo cleaning
@ -33,7 +31,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 +39,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

View File

@ -1,5 +1,5 @@
# dmenu version
VERSION = 2.1
VERSION = 3.1
# Customize below to fit your system
@ -16,7 +16,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11
# flags
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
LDFLAGS = ${LIBS}
LDFLAGS = -s ${LIBS}
#CFLAGS = -g -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\"
#LDFLAGS = -g ${LIBS}
@ -27,4 +27,3 @@ LDFLAGS = ${LIBS}
# compiler and linker
CC = cc
LD = ${CC}

29
dmenu.1
View File

@ -1,4 +1,4 @@
.TH DMENU 1 dmenu-VERSION
.TH DMENU 1 dmenu\-VERSION
.SH NAME
dmenu \- dynamic menu
.SH SYNOPSIS
@ -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
@ -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:
only items containing this text will be displayed.
.TP
.B Left/Right (Mod1-h/Mod1-l)
.B Left/Right (Mod1\-h/Mod1\-l)
Select the previous/next item.
.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.
.TP
.B Home/End (Mod1-g/Mod1-G)
.B Home/End (Mod1\-g/Mod1\-G)
Select the first/last item.
.TP
.B Tab (Control-i)
.B Tab (Control\-i)
Copy the selected item to the input field.
.TP
.B Return (Control-j)
.B Return (Control\-j)
Confirm selection and quit (print the selected item to standard output). Returns
.B 0
on termination.
.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).
Returns
.B 0
on termination.
.TP
.B Escape (Control-bracketleft)
.B Escape (Control\-bracketleft)
Quit without selecting an item. Returns
.B 1
on termination.
.TP
.B Backspace (Control-h)
Remove enough characters from the input field to change its filtering effect.
.B Backspace (Control\-h)
Remove a character from the input field.
.TP
.B Control-u
.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) .

50
dmenu.h
View File

@ -1,7 +1,6 @@
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
/* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
* © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
* See LICENSE file for license details. */
#include <X11/Xlib.h>
#define FONT "-*-fixed-medium-r-normal-*-13-*-*-*-*-*-*-*"
@ -14,38 +13,31 @@
/* 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 */
int screen;
Display *dpy;
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 */
void drawtext(const char *text, unsigned long col[ColLast]);
unsigned int textw(const char *text);
unsigned int textnw(const char *text, unsigned int len);
/* util.c */
extern void *emalloc(unsigned int size); /* allocates memory, exits on error */
extern void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */
extern char *estrdup(const char *str); /* duplicates str, exits on allocation error */
void *emalloc(unsigned int size); /* allocates memory, exits on error */
void eprint(const char *errstr, ...); /* prints errstr and exits with 1 */
char *estrdup(const char *str); /* duplicates str, exits on allocation error */

30
dmenu_path Executable file
View File

@ -0,0 +1,30 @@
#!/bin/sh
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

94
draw.c
View File

@ -1,23 +1,9 @@
/* (C)opyright MMIV-MMVII Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
/* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
* © 2006-2007 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
@ -25,7 +11,6 @@ drawtext(const char *text, unsigned long col[ColLast]) {
int x, y, w, h;
static char buf[256];
unsigned int len, olen;
XGCValues gcv;
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
XSetForeground(dpy, dc.gc, col[ColBG]);
@ -54,68 +39,25 @@ drawtext(const char *text, unsigned long col[ColLast]) {
}
if(w > dc.w)
return; /* too long */
gcv.foreground = 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;
XSetForeground(dpy, dc.gc, col[ColFG]);
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;
XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
else
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
}
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);
}

164
main.c
View File

@ -1,17 +1,13 @@
/* (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.
*/
/* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
* © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
* 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 +107,69 @@ drawmenu(void) {
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
match(char *pattern) {
unsigned int plen;
@ -151,13 +210,20 @@ match(char *pattern) {
static void
kpress(XKeyEvent * e) {
char buf[32];
int num, prev_nitem;
unsigned int i, len;
int i, num;
unsigned int len;
KeySym ksym;
len = strlen(text);
buf[0] = 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)
|| IsMiscFunctionKey(ksym) || IsPFKey(ksym)
|| IsPrivateKeypadKey(ksym))
@ -188,6 +254,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) {
@ -225,12 +303,8 @@ kpress(XKeyEvent * e) {
}
break;
case XK_BackSpace:
if((i = len)) {
prev_nitem = nitem;
do {
text[--i] = 0;
match(text);
} while(i && nitem && prev_nitem == nitem);
if(len) {
text[--len] = 0;
match(text);
}
break;
@ -334,6 +408,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 +429,12 @@ main(int argc, char *argv[]) {
char *normfg = NORMFGCOLOR;
char *selbg = SELBGCOLOR;
char *selfg = SELFGCOLOR;
fd_set rd;
int i, j;
struct timeval timeout;
Item *itm;
XEvent ev;
XModifierKeymap *modmap;
XSetWindowAttributes wa;
timeout.tv_usec = 0;
timeout.tv_sec = 3;
/* command line args */
for(i = 1; i < argc; i++)
if(!strncmp(argv[i], "-b", 3)) {
@ -382,51 +458,40 @@ 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", © 2006-2007 Anselm R. Garbe, Sander van Dijk\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();
if(isatty(STDIN_FILENO)) {
maxname = readstdin();
running = grabkeyboard();
}
else { /* prevent keypress loss */
running = grabkeyboard();
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;
@ -442,6 +507,8 @@ main(int argc, char *argv[]) {
dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen));
dc.gc = XCreateGC(dpy, root, 0, 0);
XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
if(!dc.font.set)
XSetFont(dpy, dc.gc, dc.font.xfont->fid);
if(maxname)
cmdw = textw(maxname);
if(cmdw > mw / 3)
@ -484,7 +551,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;

8
util.c
View File

@ -1,13 +1,11 @@
/* (C)opyright MMVI-MMVII Anselm R. Garbe <garbeam at gmail dot com>
* See LICENSE file for license details.
*/
/* © 2006-2007 Anselm R. Garbe <garbeam at gmail dot com>
* © 2006-2007 Sander van Dijk <a dot h dot vandijk at gmail dot com>
* See LICENSE file for license details. */
#include "dmenu.h"
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/wait.h>
#include <unistd.h>
void *
emalloc(unsigned int size) {