new color stuff/new rendering stuff b55bd709
Anselm R. Garbe · 2006-08-25 12:59 6 file(s) · +70 −58
config.arg.h +24 −15
4 4
 */
5 5
6 6
#define TAGS \
7 -
const char *tags[] = { "work", "net", "fnord", NULL };
7 +
const char *tags[] = { "1", "2", "3", "4", "5", NULL };
8 8
9 9
#define DEFMODE			dotile /* dofloat */
10 -
#define FONT			"-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*"
11 -
#define BGCOLOR			"#666699"
12 -
#define FGCOLOR			"#eeeeee"
13 -
#define BORDERCOLOR		"#9999CC"
10 +
11 +
#define FONT			"fixed"
12 +
#define SELBGCOLOR		"#666699"
13 +
#define SELFGCOLOR		"#eeeeee"
14 +
#define NORMBGCOLOR		"#333366"
15 +
#define NORMFGCOLOR		"#cccccc"
16 +
#define STATUSBGCOLOR		"#dddddd"
17 +
#define STATUSFGCOLOR		"#222222"
18 +
14 19
#define MODKEY			Mod1Mask
15 20
#define MASTERW			60 /* percent */
16 21
17 22
#define KEYS \
18 23
static Key key[] = { \
19 24
	/* modifier			key		function	arguments */ \
20 -
	{ MODKEY|ShiftMask,		XK_Return,	spawn, \
21 -
		{ .cmd = "exec uxterm -bg '#e0e0e0' -fg '#000000' -cr '#000000' +sb -fn '"FONT"'" } }, \
22 -
	{ MODKEY,			XK_p,		spawn, \
23 -
		{ .cmd = "exec `ls -lL /usr/bin /usr/X11R6/bin /usr/local/bin 2>/dev/null | " \
24 -
			"awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort -u | dmenu`" } }, \
25 -
	{ MODKEY,			XK_j,		focusnext,	{ 0 } }, \
26 -
	{ MODKEY,			XK_k,		focusprev,	{ 0 } }, \
25 +
	{ MODKEY|ShiftMask,		XK_Return,	spawn,		{ .cmd = "exec xterm" } }, \
26 +
	{ MODKEY,			XK_Tab,		focusnext,	{ 0 } }, \
27 +
	{ MODKEY|ShiftMask,		XK_Tab,		focusprev,	{ 0 } }, \
27 28
	{ MODKEY,			XK_Return,	zoom,		{ 0 } }, \
28 29
	{ MODKEY,			XK_m,		togglemax,	{ 0 } }, \
29 30
	{ MODKEY|ShiftMask,		XK_1,		tag,		{ .i = 0 } }, \
30 31
	{ MODKEY|ShiftMask,		XK_2,		tag,		{ .i = 1 } }, \
31 32
	{ MODKEY|ShiftMask,		XK_3,		tag,		{ .i = 2 } }, \
33 +
	{ MODKEY|ShiftMask,		XK_4,		tag,		{ .i = 3 } }, \
34 +
	{ MODKEY|ShiftMask,		XK_5,		tag,		{ .i = 4 } }, \
32 35
	{ MODKEY|ControlMask|ShiftMask,	XK_1,		toggletag,	{ .i = 0 } }, \
33 36
	{ MODKEY|ControlMask|ShiftMask,	XK_2,		toggletag,	{ .i = 1 } }, \
34 37
	{ MODKEY|ControlMask|ShiftMask,	XK_3,		toggletag,	{ .i = 2 } }, \
38 +
	{ MODKEY|ControlMask|ShiftMask,	XK_4,		toggletag,	{ .i = 3 } }, \
39 +
	{ MODKEY|ControlMask|ShiftMask,	XK_5,		toggletag,	{ .i = 4 } }, \
35 40
	{ MODKEY|ShiftMask,		XK_c,		killclient,	{ 0 } }, \
36 41
	{ MODKEY,			XK_space,	togglemode,	{ 0 } }, \
37 42
	{ MODKEY,			XK_1,		view,		{ .i = 0 } }, \
38 43
	{ MODKEY,			XK_2,		view,		{ .i = 1 } }, \
39 44
	{ MODKEY,			XK_3,		view,		{ .i = 2 } }, \
45 +
	{ MODKEY,			XK_4,		view,		{ .i = 3 } }, \
46 +
	{ MODKEY,			XK_5,		view,		{ .i = 4 } }, \
40 47
	{ MODKEY|ControlMask,		XK_1,		toggleview,	{ .i = 0 } }, \
41 48
	{ MODKEY|ControlMask,		XK_2,		toggleview,	{ .i = 1 } }, \
42 49
	{ MODKEY|ControlMask,		XK_3,		toggleview,	{ .i = 2 } }, \
50 +
	{ MODKEY|ControlMask,		XK_4,		toggleview,	{ .i = 3 } }, \
51 +
	{ MODKEY|ControlMask,		XK_5,		toggleview,	{ .i = 4 } }, \
43 52
	{ MODKEY|ShiftMask,		XK_q,		quit,		{ 0 } }, \
44 53
};
45 54
55 +
/* Query class:instance:title for regex matching info with following command:
56 +
 * xprop | awk -F '"' '/^WM_CLASS/ { printf("%s:%s:",$4,$2) }; /^WM_NAME/{ printf("%s\n",$2) }' */
46 57
#define RULES \
47 58
static Rule rule[] = { \
48 59
	/* class:instance:title regex	tags regex	isfloat */ \
49 -
	{ "Firefox.*",			"net",		False }, \
60 +
	{ "Firefox.*",			"2",		False }, \
50 61
	{ "Gimp.*",			NULL,		True}, \
51 -
	{ "MPlayer.*",			NULL,		True}, \
52 -
	{ "Acroread.*",			NULL,		True}, \
53 62
};
config.default.h +8 −3
7 7
const char *tags[] = { "1", "2", "3", "4", "5", NULL };
8 8
9 9
#define DEFMODE			dotile /* dofloat */
10 +
10 11
#define FONT			"fixed"
11 -
#define BGCOLOR			"#666699"
12 -
#define FGCOLOR			"#eeeeee"
13 -
#define BORDERCOLOR		"#9999CC"
12 +
#define SELBGCOLOR		"#666699"
13 +
#define SELFGCOLOR		"#eeeeee"
14 +
#define NORMBGCOLOR		"#333366"
15 +
#define NORMFGCOLOR		"#cccccc"
16 +
#define STATUSBGCOLOR		"#dddddd"
17 +
#define STATUSFGCOLOR		"#222222"
18 +
14 19
#define MODKEY			Mod1Mask
15 20
#define MASTERW			60 /* percent */
16 21
draw.c +19 −30
22 22
}
23 23
24 24
static void
25 -
drawtext(const char *text, Bool invert, Bool highlight)
25 +
drawtext(const char *text, unsigned long col[ColLast], Bool highlight)
26 26
{
27 27
	int x, y, w, h;
28 28
	static char buf[256];
29 29
	unsigned int len, olen;
30 30
	XGCValues gcv;
31 -
	XPoint points[5];
32 31
	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
33 32
34 -
	XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg);
33 +
	XSetForeground(dpy, dc.gc, col[ColBG]);
35 34
	XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
36 -
	points[0].x = dc.x;
37 -
	points[0].y = dc.y;
38 -
	points[1].x = dc.w - 1;
39 -
	points[1].y = 0;
40 -
	points[2].x = 0;
41 -
	points[2].y = dc.h - 1;
42 -
	points[3].x = -(dc.w - 1);
43 -
	points[3].y = 0;
44 -
	points[4].x = 0;
45 -
	points[4].y = -(dc.h - 1);
46 -
	XSetForeground(dpy, dc.gc, dc.border);
47 -
	XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
48 35
49 36
	if(!text)
50 37
		return;
74 61
75 62
	if(w > dc.w)
76 63
		return; /* too long */
77 -
	gcv.foreground = invert ? dc.bg : dc.fg;
78 -
	gcv.background = invert ? dc.fg : dc.bg;
64 +
	gcv.foreground = col[ColFG];
79 65
	if(dc.font.set) {
80 -
		XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
66 +
		XChangeGC(dpy, dc.gc, GCForeground, &gcv);
81 67
		XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
82 68
	}
83 69
	else {
84 70
		gcv.font = dc.font.xfont->fid;
85 -
		XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv);
71 +
		XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
86 72
		XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
87 73
	}
88 74
	if(highlight) {
108 94
void
109 95
drawstatus()
110 96
{
97 +
	static const char *mode[] = { "~", "=" };
111 98
	int i, x;
112 -
	Bool istile = arrange == dotile;
113 99
114 100
	dc.x = dc.y = 0;
115 101
	dc.w = bw;
116 -
	drawtext(NULL, !istile, False);
102 +
103 +
	if(!modew)
104 +
		modew = textw(mode[0]) > textw(mode[1]) ? textw(mode[0]) : textw(mode[1]);
105 +
	drawtext(mode[arrange == dotile ? 1 : 0], dc.status, False);
117 106
118 107
	dc.w = 0;
108 +
	dc.x = modew;
119 109
	for(i = 0; i < ntags; i++) {
120 110
		dc.x += dc.w;
121 111
		dc.w = textw(tags[i]);
122 -
		if(istile)
123 -
			drawtext(tags[i], seltag[i], sel && sel->tags[i]);
112 +
		if(seltag[i])
113 +
			drawtext(tags[i], dc.sel, sel && sel->tags[i]);
124 114
		else
125 -
			drawtext(tags[i], !seltag[i], sel && sel->tags[i]);
115 +
			drawtext(tags[i], dc.norm, sel && sel->tags[i]);
126 116
	}
127 117
	x = dc.x + dc.w;
128 118
	dc.w = textw(stext);
131 121
		dc.x = x;
132 122
		dc.w = bw - x;
133 123
	}
134 -
	drawtext(stext, !istile, False);
124 +
	drawtext(stext, dc.status, False);
135 125
136 126
	if(sel && ((dc.w = dc.x - x) > bh)) {
137 127
		dc.x = x;
138 -
		drawtext(sel->name, istile, False);
128 +
		drawtext(sel->name, dc.sel, False);
139 129
	}
140 130
	XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0, bw, bh, 0, 0);
141 131
	XSync(dpy, False);
145 135
drawtitle(Client *c)
146 136
{
147 137
	int i;
148 -
	Bool istile = arrange == dotile;
149 138
150 139
	if(c == sel && issel) {
151 140
		drawstatus();
152 141
		XUnmapWindow(dpy, c->twin);
153 -
		XSetWindowBorder(dpy, c->win, dc.fg);
142 +
		XSetWindowBorder(dpy, c->win, dc.sel[ColBG]);
154 143
		return;
155 144
	}
156 145
157 -
	XSetWindowBorder(dpy, c->win, dc.bg);
146 +
	XSetWindowBorder(dpy, c->win, dc.norm[ColBG]);
158 147
	XMapWindow(dpy, c->twin);
159 148
	dc.x = dc.y = 0;
160 149
	dc.w = c->tw;
161 -
	drawtext(c->name, !istile, False);
150 +
	drawtext(c->name, dc.norm, False);
162 151
	XCopyArea(dpy, dc.drawable, c->twin, dc.gc, 0, 0, c->tw, c->th, 0, 0);
163 152
	XSync(dpy, False);
164 153
}
dwm.h +7 −4
23 23
/* cursor */
24 24
enum { CurNormal, CurResize, CurMove, CurLast };
25 25
26 +
/* color */
27 +
enum { ColFG, ColBG, ColLast };
28 +
26 29
/* window corners */
27 30
typedef enum { TopLeft, TopRight, BotLeft, BotRight } Corner;
28 31
36 39
37 40
typedef struct { /* draw context */
38 41
	int x, y, w, h;
39 -
	unsigned long bg;
40 -
	unsigned long fg;
41 -
	unsigned long border;
42 +
	unsigned long norm[ColLast];
43 +
	unsigned long sel[ColLast];
44 +
	unsigned long status[ColLast];
42 45
	Drawable drawable;
43 46
	Fnt font;
44 47
	GC gc;
66 69
extern const char *tags[];
67 70
extern char stext[1024];
68 71
extern int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
69 -
extern unsigned int ntags, numlockmask;
72 +
extern unsigned int ntags, numlockmask, modew;
70 73
extern void (*handler[LASTEvent])(XEvent *);
71 74
extern void (*arrange)(Arg *);
72 75
extern Atom wmatom[WMLast], netatom[NetLast];
event.c +3 −1
105 105
	XButtonPressedEvent *ev = &e->xbutton;
106 106
107 107
	if(barwin == ev->window) {
108 -
		x = 0;
108 +
		if(ev->x < modew)
109 +
			return;
110 +
		x = modew;
109 111
		for(a.i = 0; a.i < ntags; a.i++) {
110 112
			x += textw(tags[a.i]);
111 113
			if(ev->x < x) {
main.c +9 −5
20 20
char stext[1024];
21 21
Bool *seltag;
22 22
int screen, sx, sy, sw, sh, bx, by, bw, bh, mw;
23 -
unsigned int ntags, numlockmask;
23 +
unsigned int ntags, numlockmask, modew;
24 24
Atom wmatom[WMLast], netatom[NetLast];
25 25
Bool running = True;
26 26
Bool issel = True;
121 121
	seltag[0] = True;
122 122
123 123
	/* style */
124 -
	dc.bg = getcolor(BGCOLOR);
125 -
	dc.fg = getcolor(FGCOLOR);
126 -
	dc.border = getcolor(BORDERCOLOR);
124 +
	dc.norm[ColBG] = getcolor(NORMBGCOLOR);
125 +
	dc.norm[ColFG] = getcolor(NORMFGCOLOR);
126 +
	dc.sel[ColBG] = getcolor(SELBGCOLOR);
127 +
	dc.sel[ColFG] = getcolor(SELFGCOLOR);
128 +
	dc.status[ColBG] = getcolor(STATUSBGCOLOR);
129 +
	dc.status[ColFG] = getcolor(STATUSFGCOLOR);
127 130
	setfont(FONT);
128 131
132 +
	modew = 0;
129 133
	sx = sy = 0;
130 134
	sw = DisplayWidth(dpy, screen);
131 135
	sh = DisplayHeight(dpy, screen);
133 137
134 138
	bx = by = 0;
135 139
	bw = sw;
136 -
	dc.h = bh = dc.font.height + 4;
140 +
	dc.h = bh = dc.font.height + 2;
137 141
	wa.override_redirect = 1;
138 142
	wa.background_pixmap = ParentRelative;
139 143
	wa.event_mask = ButtonPressMask | ExposureMask;