Compare commits

...

14 Commits
0.5 ... 0.7

8 changed files with 42 additions and 52 deletions

View File

@ -2,3 +2,5 @@ fcc8a282cb52c6a9343b461026b386825590cd31 0.1
656be0f47df545dfdd2e1e0663663b8b1b26f031 0.2 656be0f47df545dfdd2e1e0663663b8b1b26f031 0.2
d352e9dc112ee96aa5cad961a0ed880ae9ce7276 0.3 d352e9dc112ee96aa5cad961a0ed880ae9ce7276 0.3
7acf0dde1120542917bae12e0e42293f9d2cc899 0.4 7acf0dde1120542917bae12e0e42293f9d2cc899 0.4
4a0ecd881c4fc15de4a0bebd79308b064be020ef 0.5
25f679fb19686140a907684ffcb423b9e9d44b53 0.6

View File

@ -4,6 +4,7 @@
*/ */
#define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*" #define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*"
#define BGCOLOR "#666699" #define SELBGCOLOR "#333366"
#define FGCOLOR "#eeeeee" #define SELFGCOLOR "#eeeeee"
#define BORDERCOLOR "#9999CC" #define NORMBGCOLOR "#333333"
#define NORMFGCOLOR "#dddddd"

View File

@ -4,6 +4,7 @@
*/ */
#define FONT "fixed" #define FONT "fixed"
#define BGCOLOR "#666699" #define SELBGCOLOR "#666699"
#define FGCOLOR "#eeeeee" #define SELFGCOLOR "#eeeeee"
#define BORDERCOLOR "#9999CC" #define NORMBGCOLOR "#333366"
#define NORMFGCOLOR "#cccccc"

View File

@ -1,5 +1,5 @@
# dmenu version # dmenu version
VERSION = 0.5 VERSION = 0.7
# Customize below to fit your system # Customize below to fit your system

10
dmenu.1
View File

@ -14,12 +14,12 @@ It supports arbitrary, user defined menu contents.
.SS Options .SS Options
.TP .TP
.B \-v .B \-v
prints version information to stdout, then exits. prints version information to standard output, then exits.
.SH USAGE .SH USAGE
.B dmenu .B dmenu
reads a list of newline-separated items from stdin and creates a menu. 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 choice When the user selects an item or enters any text and presses Return, his choice
is printed to stdout and is printed to standard output and
.B dmenu .B dmenu
terminates. terminates.
.B dmenu .B dmenu
@ -36,10 +36,10 @@ Tab
Copy the selected item to the input field. Copy the selected item to the input field.
.TP .TP
Return Return
Confirm selection and quit (print the selected item to stdout). Confirm selection and quit (print the selected item to standard output).
.TP .TP
Shift-Return Shift-Return
Confirm selection and quit (print the text in the input field to stdout). Confirm selection and quit (print the text in the input field to standard output).
.TP .TP
Escape Escape
Quit without selecting an item. Quit without selecting an item.

10
dmenu.h
View File

@ -9,6 +9,9 @@
#define SPACE 30 /* px */ #define SPACE 30 /* px */
/* color */
enum { ColFG, ColBG, ColLast };
typedef struct DC DC; typedef struct DC DC;
typedef struct Fnt Fnt; typedef struct Fnt Fnt;
@ -22,9 +25,8 @@ struct Fnt {
struct DC { /* draw context */ struct DC { /* draw context */
int x, y, w, h; int x, y, w, h;
unsigned long bg; unsigned long norm[ColLast];
unsigned long fg; unsigned long sel[ColLast];
unsigned long border;
Drawable drawable; Drawable drawable;
Fnt font; Fnt font;
GC gc; GC gc;
@ -35,7 +37,7 @@ extern Display *dpy;
extern DC dc; extern DC dc;
/* draw.c */ /* draw.c */
extern void drawtext(const char *text, Bool invert, Bool border); extern void drawtext(const char *text, unsigned long col[ColLast]);
extern unsigned long getcolor(const char *colstr); extern unsigned long getcolor(const char *colstr);
extern void setfont(const char *fontstr); extern void setfont(const char *fontstr);
extern unsigned int textw(const char *text); extern unsigned int textw(const char *text);

33
draw.c
View File

@ -24,37 +24,21 @@ textnw(const char *text, unsigned int len)
/* extern */ /* extern */
void void
drawtext(const char *text, Bool invert, Bool border) 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; XGCValues gcv;
XPoint points[5];
XRectangle r = { dc.x, dc.y, dc.w, dc.h }; XRectangle r = { dc.x, dc.y, dc.w, dc.h };
XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg); XSetForeground(dpy, dc.gc, col[ColBG]);
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
w = 0;
if(border) {
points[0].x = dc.x;
points[0].y = dc.y;
points[1].x = dc.w - 1;
points[1].y = 0;
points[2].x = 0;
points[2].y = dc.h - 1;
points[3].x = -(dc.w - 1);
points[3].y = 0;
points[4].x = 0;
points[4].y = -(dc.h - 1);
XSetForeground(dpy, dc.gc, dc.border);
XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
}
if(!text) if(!text)
return; return;
w = 0;
olen = len = strlen(text); olen = len = strlen(text);
if(len >= sizeof(buf)) if(len >= sizeof(buf))
len = sizeof(buf) - 1; len = sizeof(buf) - 1;
@ -80,17 +64,16 @@ drawtext(const char *text, Bool invert, Bool border)
if(w > dc.w) if(w > dc.w)
return; /* too long */ return; /* too long */
gcv.foreground = invert ? dc.bg : dc.fg; gcv.foreground = col[ColFG];
gcv.background = invert ? dc.fg : dc.bg;
if(dc.font.set) { if(dc.font.set) {
XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv); XChangeGC(dpy, dc.gc, GCForeground, &gcv);
XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc, XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc,
x, y, buf, len); x, y, buf, len);
} }
else { else {
gcv.font = dc.font.xfont->fid; gcv.font = dc.font.xfont->fid;
XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv); XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len); XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
} }
} }

23
main.c
View File

@ -77,17 +77,17 @@ drawmenu()
dc.y = 0; dc.y = 0;
dc.w = mw; dc.w = mw;
dc.h = mh; dc.h = mh;
drawtext(NULL, False, False); drawtext(NULL, dc.norm);
/* print command */ /* print command */
if(cmdw && item) if(cmdw && item)
dc.w = cmdw; dc.w = cmdw;
drawtext(text[0] ? text : NULL, False, False); drawtext(text[0] ? text : NULL, dc.norm);
dc.x += cmdw; dc.x += cmdw;
if(curr) { if(curr) {
dc.w = SPACE; dc.w = SPACE;
drawtext((curr && curr->left) ? "<" : NULL, False, False); drawtext((curr && curr->left) ? "<" : NULL, dc.norm);
dc.x += dc.w; dc.x += dc.w;
/* determine maximum items */ /* determine maximum items */
@ -95,13 +95,13 @@ drawmenu()
dc.w = textw(i->text); dc.w = textw(i->text);
if(dc.w > mw / 3) if(dc.w > mw / 3)
dc.w = mw / 3; dc.w = mw / 3;
drawtext(i->text, sel == i, sel == i); drawtext(i->text, (sel == i) ? dc.sel : dc.norm);
dc.x += dc.w; dc.x += dc.w;
} }
dc.x = mw - SPACE; dc.x = mw - SPACE;
dc.w = SPACE; dc.w = SPACE;
drawtext(next ? ">" : NULL, False, False); drawtext(next ? ">" : NULL, dc.norm);
} }
XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
XFlush(dpy); XFlush(dpy);
@ -315,9 +315,10 @@ main(int argc, char *argv[])
usleep(1000); usleep(1000);
/* style */ /* style */
dc.bg = getcolor(BGCOLOR); dc.sel[ColBG] = getcolor(SELBGCOLOR);
dc.fg = getcolor(FGCOLOR); dc.sel[ColFG] = getcolor(SELFGCOLOR);
dc.border = getcolor(BORDERCOLOR); dc.norm[ColBG] = getcolor(NORMBGCOLOR);
dc.norm[ColFG] = getcolor(NORMFGCOLOR);
setfont(FONT); setfont(FONT);
wa.override_redirect = 1; wa.override_redirect = 1;
@ -326,7 +327,7 @@ main(int argc, char *argv[])
mx = my = 0; mx = my = 0;
mw = DisplayWidth(dpy, screen); mw = DisplayWidth(dpy, screen);
mh = dc.font.height + 4; mh = dc.font.height + 2;
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,
@ -353,6 +354,8 @@ main(int argc, char *argv[])
/* main event loop */ /* main event loop */
while(running && !XNextEvent(dpy, &ev)) { while(running && !XNextEvent(dpy, &ev)) {
switch (ev.type) { switch (ev.type) {
default: /* ignore all crap */
break;
case KeyPress: case KeyPress:
kpress(&ev.xkey); kpress(&ev.xkey);
break; break;
@ -360,8 +363,6 @@ main(int argc, char *argv[])
if(ev.xexpose.count == 0) if(ev.xexpose.count == 0)
drawmenu(); drawmenu();
break; break;
default:
break;
} }
} }