updated dmenu to borderless drawing as well 13ef97e6
Anselm R. Garbe · 2006-08-25 14:45 5 file(s) · +32 −44
config.arg.h +4 −3
4 4
 */
5 5
6 6
#define FONT			"-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*"
7 -
#define BGCOLOR			"#666699"
8 -
#define FGCOLOR			"#eeeeee"
9 -
#define BORDERCOLOR		"#9999CC"
7 +
#define SELBGCOLOR		"#666699"
8 +
#define SELFGCOLOR		"#eeeeee"
9 +
#define NORMBGCOLOR		"#333366"
10 +
#define NORMFGCOLOR		"#cccccc"
config.default.h +4 −3
4 4
 */
5 5
6 6
#define FONT			"fixed"
7 -
#define BGCOLOR			"#666699"
8 -
#define FGCOLOR			"#eeeeee"
9 -
#define BORDERCOLOR		"#9999CC"
7 +
#define SELBGCOLOR		"#666699"
8 +
#define SELFGCOLOR		"#eeeeee"
9 +
#define NORMBGCOLOR		"#333366"
10 +
#define NORMFGCOLOR		"#cccccc"
dmenu.h +6 −4
9 9
10 10
#define SPACE		30 /* px */
11 11
12 +
/* color */
13 +
enum { ColFG, ColBG, ColLast };
14 +
12 15
typedef struct DC DC;
13 16
typedef struct Fnt Fnt;
14 17
22 25
23 26
struct DC { /* draw context */
24 27
	int x, y, w, h;
25 -
	unsigned long bg;
26 -
	unsigned long fg;
27 -
	unsigned long border;
28 +
	unsigned long norm[ColLast];
29 +
	unsigned long sel[ColLast];
28 30
	Drawable drawable;
29 31
	Fnt font;
30 32
	GC gc;
35 37
extern DC dc;
36 38
37 39
/* draw.c */
38 -
extern void drawtext(const char *text, Bool invert, Bool border);
40 +
extern void drawtext(const char *text, unsigned long col[ColLast]);
39 41
extern unsigned long getcolor(const char *colstr);
40 42
extern void setfont(const char *fontstr);
41 43
extern unsigned int textw(const char *text);
draw.c +8 −25
24 24
/* extern */
25 25
26 26
void
27 -
drawtext(const char *text, Bool invert, Bool border)
27 +
drawtext(const char *text, unsigned long col[ColLast])
28 28
{
29 29
	int x, y, w, h;
30 30
	static char buf[256];
31 31
	unsigned int len, olen;
32 32
	XGCValues gcv;
33 -
	XPoint points[5];
34 33
	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
35 34
36 -
	XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg);
35 +
	XSetForeground(dpy, dc.gc, col[ColBG]);
37 36
	XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
38 37
39 -
	w = 0;
40 -
	if(border) {
41 -
		points[0].x = dc.x;
42 -
		points[0].y = dc.y;
43 -
		points[1].x = dc.w - 1;
44 -
		points[1].y = 0;
45 -
		points[2].x = 0;
46 -
		points[2].y = dc.h - 1;
47 -
		points[3].x = -(dc.w - 1);
48 -
		points[3].y = 0;
49 -
		points[4].x = 0;
50 -
		points[4].y = -(dc.h - 1);
51 -
		XSetForeground(dpy, dc.gc, dc.border);
52 -
		XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
53 -
	}
54 -
55 38
	if(!text)
56 39
		return;
57 40
41 +
	w = 0;
58 42
	olen = len = strlen(text);
59 43
	if(len >= sizeof(buf))
60 44
		len = sizeof(buf) - 1;
80 64
	if(w > dc.w)
81 65
		return; /* too long */
82 66
83 -
	gcv.foreground = invert ? dc.bg : dc.fg;
84 -
	gcv.background = invert ? dc.fg : dc.bg;
67 +
	gcv.foreground = col[ColFG];
85 68
	if(dc.font.set) {
86 -
		XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
87 -
		XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc,
69 +
		XChangeGC(dpy, dc.gc, GCForeground, &gcv);
70 +
		XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc,
88 71
				x, y, buf, len);
89 72
	}
90 73
	else {
91 74
		gcv.font = dc.font.xfont->fid;
92 -
		XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv);
93 -
		XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len);
75 +
		XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
76 +
		XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
94 77
	}
95 78
}
96 79
main.c +10 −9
77 77
	dc.y = 0;
78 78
	dc.w = mw;
79 79
	dc.h = mh;
80 -
	drawtext(NULL, False, False);
80 +
	drawtext(NULL, dc.norm);
81 81
82 82
	/* print command */
83 83
	if(cmdw && item)
84 84
		dc.w = cmdw;
85 -
	drawtext(text[0] ? text : NULL, False, False);
85 +
	drawtext(text[0] ? text : NULL, dc.norm);
86 86
	dc.x += cmdw;
87 87
88 88
	if(curr) {
89 89
		dc.w = SPACE;
90 -
		drawtext((curr && curr->left) ? "<" : NULL, False, False);
90 +
		drawtext((curr && curr->left) ? "<" : NULL, dc.norm);
91 91
		dc.x += dc.w;
92 92
93 93
		/* determine maximum items */
95 95
			dc.w = textw(i->text);
96 96
			if(dc.w > mw / 3)
97 97
				dc.w = mw / 3;
98 -
			drawtext(i->text, sel == i, sel == i);
98 +
			drawtext(i->text, (sel == i) ? dc.sel : dc.norm);
99 99
			dc.x += dc.w;
100 100
		}
101 101
102 102
		dc.x = mw - SPACE;
103 103
		dc.w = SPACE;
104 -
		drawtext(next ? ">" : NULL, False, False);
104 +
		drawtext(next ? ">" : NULL, dc.norm);
105 105
	}
106 106
	XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
107 107
	XFlush(dpy);
315 315
		usleep(1000);
316 316
317 317
	/* style */
318 -
	dc.bg = getcolor(BGCOLOR);
319 -
	dc.fg = getcolor(FGCOLOR);
320 -
	dc.border = getcolor(BORDERCOLOR);
318 +
	dc.sel[ColBG] = getcolor(SELBGCOLOR);
319 +
	dc.sel[ColFG] = getcolor(SELFGCOLOR);
320 +
	dc.norm[ColBG] = getcolor(NORMBGCOLOR);
321 +
	dc.norm[ColFG] = getcolor(NORMFGCOLOR);
321 322
	setfont(FONT);
322 323
323 324
	wa.override_redirect = 1;
326 327
327 328
	mx = my = 0;
328 329
	mw = DisplayWidth(dpy, screen);
329 -
	mh = dc.font.height + 4;
330 +
	mh = dc.font.height + 2;
330 331
331 332
	win = XCreateWindow(dpy, root, mx, my, mw, mh, 0,
332 333
			DefaultDepth(dpy, screen), CopyFromParent,