diff options
author | Anselm R. Garbe <arg@10kloc.org> | 2006-08-24 11:47:08 +0200 |
---|---|---|
committer | Anselm R. Garbe <arg@10kloc.org> | 2006-08-24 11:47:08 +0200 |
commit | e980c7ff1814b533f674eec535af6c5658b1bc62 (patch) | |
tree | 178d0389a8d9e203cac609373fe6f7bf360e4530 | |
parent | 7848b53dc3c8c05bd2cf1f10d59db2310456acf7 (diff) |
migrated dmenu to use 4 instead of 3 colors
-rw-r--r-- | config.arg.h | 7 | ||||
-rw-r--r-- | config.default.h | 7 | ||||
-rw-r--r-- | config.mk | 2 | ||||
-rw-r--r-- | dmenu.h | 7 | ||||
-rw-r--r-- | draw.c | 19 | ||||
-rw-r--r-- | main.c | 17 |
6 files changed, 28 insertions, 31 deletions
diff --git a/config.arg.h b/config.arg.h index 066c1a4..5dbbb7c 100644 --- a/config.arg.h +++ b/config.arg.h | |||
@@ -4,6 +4,7 @@ | |||
4 | */ | 4 | */ |
5 | 5 | ||
6 | #define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*" | 6 | #define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*" |
7 | #define BGCOLOR "#666699" | 7 | #define NORMBGCOLOR "#666699" |
8 | #define FGCOLOR "#eeeeee" | 8 | #define NORMFGCOLOR "#eeeeee" |
9 | #define BORDERCOLOR "#9999CC" | 9 | #define SELBGCOLOR "#eeeeee" |
10 | #define SELFGCOLOR "#666699" | ||
diff --git a/config.default.h b/config.default.h index cf1baea..6949cea 100644 --- a/config.default.h +++ b/config.default.h | |||
@@ -4,6 +4,7 @@ | |||
4 | */ | 4 | */ |
5 | 5 | ||
6 | #define FONT "fixed" | 6 | #define FONT "fixed" |
7 | #define BGCOLOR "#666699" | 7 | #define NORMBGCOLOR "#666699" |
8 | #define FGCOLOR "#eeeeee" | 8 | #define NORMFGCOLOR "#eeeeee" |
9 | #define BORDERCOLOR "#9999CC" | 9 | #define SELBGCOLOR "#eeeeee" |
10 | #define SELBFCOLOR "#666699" | ||
@@ -1,5 +1,5 @@ | |||
1 | # dmenu version | 1 | # dmenu version |
2 | VERSION = 0.5 | 2 | VERSION = 0.6 |
3 | 3 | ||
4 | # Customize below to fit your system | 4 | # Customize below to fit your system |
5 | 5 | ||
@@ -22,9 +22,8 @@ struct Fnt { | |||
22 | 22 | ||
23 | struct DC { /* draw context */ | 23 | struct DC { /* draw context */ |
24 | int x, y, w, h; | 24 | int x, y, w, h; |
25 | unsigned long bg; | 25 | unsigned long bg[2]; |
26 | unsigned long fg; | 26 | unsigned long fg[2]; |
27 | unsigned long border; | ||
28 | Drawable drawable; | 27 | Drawable drawable; |
29 | Fnt font; | 28 | Fnt font; |
30 | GC gc; | 29 | GC gc; |
@@ -35,7 +34,7 @@ extern Display *dpy; | |||
35 | extern DC dc; | 34 | extern DC dc; |
36 | 35 | ||
37 | /* draw.c */ | 36 | /* draw.c */ |
38 | extern void drawtext(const char *text, Bool invert, Bool border); | 37 | extern void drawtext(const char *text, unsigned int colidx, Bool border); |
39 | extern unsigned long getcolor(const char *colstr); | 38 | extern unsigned long getcolor(const char *colstr); |
40 | extern void setfont(const char *fontstr); | 39 | extern void setfont(const char *fontstr); |
41 | extern unsigned int textw(const char *text); | 40 | extern unsigned int textw(const char *text); |
@@ -24,7 +24,7 @@ textnw(const char *text, unsigned int len) | |||
24 | /* extern */ | 24 | /* extern */ |
25 | 25 | ||
26 | void | 26 | void |
27 | drawtext(const char *text, Bool invert, Bool border) | 27 | drawtext(const char *text, unsigned int colidx, Bool border) |
28 | { | 28 | { |
29 | int x, y, w, h; | 29 | int x, y, w, h; |
30 | static char buf[256]; | 30 | static char buf[256]; |
@@ -33,10 +33,11 @@ drawtext(const char *text, Bool invert, Bool border) | |||
33 | XPoint points[5]; | 33 | XPoint points[5]; |
34 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; | 34 | XRectangle r = { dc.x, dc.y, dc.w, dc.h }; |
35 | 35 | ||
36 | XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg); | 36 | XSetForeground(dpy, dc.gc, dc.bg[colidx]); |
37 | XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); | 37 | XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); |
38 | 38 | ||
39 | w = 0; | 39 | w = 0; |
40 | XSetForeground(dpy, dc.gc, dc.fg[colidx]); | ||
40 | if(border) { | 41 | if(border) { |
41 | points[0].x = dc.x; | 42 | points[0].x = dc.x; |
42 | points[0].y = dc.y; | 43 | points[0].y = dc.y; |
@@ -48,7 +49,6 @@ drawtext(const char *text, Bool invert, Bool border) | |||
48 | points[3].y = 0; | 49 | points[3].y = 0; |
49 | points[4].x = 0; | 50 | points[4].x = 0; |
50 | points[4].y = -(dc.h - 1); | 51 | points[4].y = -(dc.h - 1); |
51 | XSetForeground(dpy, dc.gc, dc.border); | ||
52 | XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious); | 52 | XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious); |
53 | } | 53 | } |
54 | 54 | ||
@@ -80,17 +80,12 @@ drawtext(const char *text, Bool invert, Bool border) | |||
80 | if(w > dc.w) | 80 | if(w > dc.w) |
81 | return; /* too long */ | 81 | return; /* too long */ |
82 | 82 | ||
83 | gcv.foreground = invert ? dc.bg : dc.fg; | 83 | if(dc.font.set) |
84 | gcv.background = invert ? dc.fg : dc.bg; | 84 | XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len); |
85 | if(dc.font.set) { | ||
86 | XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv); | ||
87 | XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc, | ||
88 | x, y, buf, len); | ||
89 | } | ||
90 | else { | 85 | else { |
91 | gcv.font = dc.font.xfont->fid; | 86 | gcv.font = dc.font.xfont->fid; |
92 | XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv); | 87 | XChangeGC(dpy, dc.gc, GCFont, &gcv); |
93 | XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len); | 88 | XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len); |
94 | } | 89 | } |
95 | } | 90 | } |
96 | 91 | ||
@@ -77,17 +77,17 @@ drawmenu() | |||
77 | dc.y = 0; | 77 | dc.y = 0; |
78 | dc.w = mw; | 78 | dc.w = mw; |
79 | dc.h = mh; | 79 | dc.h = mh; |
80 | drawtext(NULL, False, False); | 80 | drawtext(NULL, 0, False); |
81 | 81 | ||
82 | /* print command */ | 82 | /* print command */ |
83 | if(cmdw && item) | 83 | if(cmdw && item) |
84 | dc.w = cmdw; | 84 | dc.w = cmdw; |
85 | drawtext(text[0] ? text : NULL, False, False); | 85 | drawtext(text[0] ? text : NULL, 0, False); |
86 | dc.x += cmdw; | 86 | dc.x += cmdw; |
87 | 87 | ||
88 | if(curr) { | 88 | if(curr) { |
89 | dc.w = SPACE; | 89 | dc.w = SPACE; |
90 | drawtext((curr && curr->left) ? "<" : NULL, False, False); | 90 | drawtext((curr && curr->left) ? "<" : NULL, 0, False); |
91 | dc.x += dc.w; | 91 | dc.x += dc.w; |
92 | 92 | ||
93 | /* determine maximum items */ | 93 | /* determine maximum items */ |
@@ -95,13 +95,13 @@ drawmenu() | |||
95 | dc.w = textw(i->text); | 95 | dc.w = textw(i->text); |
96 | if(dc.w > mw / 3) | 96 | if(dc.w > mw / 3) |
97 | dc.w = mw / 3; | 97 | dc.w = mw / 3; |
98 | drawtext(i->text, sel == i, sel == i); | 98 | drawtext(i->text, sel == i ? 1 : 0, sel == i); |
99 | dc.x += dc.w; | 99 | dc.x += dc.w; |
100 | } | 100 | } |
101 | 101 | ||
102 | dc.x = mw - SPACE; | 102 | dc.x = mw - SPACE; |
103 | dc.w = SPACE; | 103 | dc.w = SPACE; |
104 | drawtext(next ? ">" : NULL, False, False); | 104 | drawtext(next ? ">" : NULL, 0, False); |
105 | } | 105 | } |
106 | XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); | 106 | XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); |
107 | XFlush(dpy); | 107 | XFlush(dpy); |
@@ -315,9 +315,10 @@ main(int argc, char *argv[]) | |||
315 | usleep(1000); | 315 | usleep(1000); |
316 | 316 | ||
317 | /* style */ | 317 | /* style */ |
318 | dc.bg = getcolor(BGCOLOR); | 318 | dc.bg[0] = getcolor(NORMBGCOLOR); |
319 | dc.fg = getcolor(FGCOLOR); | 319 | dc.fg[0] = getcolor(NORMFGCOLOR); |
320 | dc.border = getcolor(BORDERCOLOR); | 320 | dc.bg[1] = getcolor(SELBGCOLOR); |
321 | dc.fg[1] = getcolor(SELFGCOLOR); | ||
321 | setfont(FONT); | 322 | setfont(FONT); |
322 | 323 | ||
323 | wa.override_redirect = 1; | 324 | wa.override_redirect = 1; |