changed default colors 9e8b3258
Anselm R. Garbe · 2006-07-13 11:43 8 file(s) · +71 −82
Makefile +2 −2
3 3
4 4
include config.mk
5 5
6 -
SRC = client.c dev.c draw.c event.c util.c wm.c
6 +
SRC = client.c dev.c draw.c event.c main.c util.c
7 7
OBJ = ${SRC:.c=.o}
8 8
MAN1 = dwm.1 
9 9
BIN = dwm
22 22
	@echo CC $<
23 23
	@${CC} -c ${CFLAGS} $<
24 24
25 -
${OBJ}: wm.h
25 +
${OBJ}: dwm.h
26 26
27 27
dwm: ${OBJ}
28 28
	@echo LD $@
client.c +8 −7
9 9
#include <X11/Xatom.h>
10 10
#include <X11/Xutil.h>
11 11
12 -
#include "wm.h"
12 +
#include "dwm.h"
13 13
14 14
static void floating(void);
15 15
static void tiling(void);
125 125
	c->tw = 0;
126 126
	for(i = 0; i < TLast; i++)
127 127
		if(c->tags[i])
128 -
			c->tw += textw(&dc.font, c->tags[i]) + dc.font.height;
129 -
	c->tw += textw(&dc.font, c->name) + dc.font.height;
128 +
			c->tw += textw(c->tags[i]) + dc.font.height;
129 +
	c->tw += textw(c->name) + dc.font.height;
130 130
	if(c->tw > c->w)
131 131
		c->tw = c->w + 2;
132 132
	c->tx = c->x + c->w - c->tw + 2;
226 226
	c->snext = stack;
227 227
	stack = c;
228 228
	if(old && old != c) {
229 +
		XSetWindowBorder(dpy, old->win, dc.bg);
229 230
		XMapWindow(dpy, old->title);
230 231
		draw_client(old);
231 232
	}
232 233
	XUnmapWindow(dpy, c->title);
234 +
	XSetWindowBorder(dpy, c->win, dc.fg);
233 235
	draw_client(c);
234 236
	XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
235 237
	XFlush(dpy);
250 252
	c->th = th;
251 253
	c->border = 1;
252 254
	update_size(c);
253 -
	XSetWindowBorderWidth(dpy, c->win, 1);
254 -
	XSetWindowBorder(dpy, c->win, dc.border);
255 255
	XSelectInput(dpy, c->win,
256 256
			StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
257 257
	XGetTransientForHint(dpy, c->win, &c->trans);
269 269
	for(l=&clients; *l; l=&(*l)->next);
270 270
	c->next = *l; /* *l == nil */
271 271
	*l = c;
272 +
	XSetWindowBorderWidth(dpy, c->win, 1);
272 273
	XMapRaised(dpy, c->win);
273 274
	XMapRaised(dpy, c->title);
274 275
	XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
435 436
	for(i = 0; i < TLast; i++) {
436 437
		if(c->tags[i]) {
437 438
			dc.x += dc.w;
438 -
			dc.w = textw(&dc.font, c->tags[i]) + dc.font.height;
439 +
			dc.w = textw(c->tags[i]) + dc.font.height;
439 440
			draw(True, c->tags[i]);
440 441
		}
441 442
	}
442 443
	dc.x += dc.w;
443 -
	dc.w = textw(&dc.font, c->name) + dc.font.height;
444 +
	dc.w = textw(c->name) + dc.font.height;
444 445
	draw(True, c->name);
445 446
	XCopyArea(dpy, dc.drawable, c->title, dc.gc,
446 447
			0, 0, c->tw, c->th, 0, 0);
dev.c +1 −1
3 3
 * See LICENSE file for license details.
4 4
 */
5 5
6 -
#include "wm.h"
6 +
#include "dwm.h"
7 7
8 8
#include <stdlib.h>
9 9
#include <string.h>
draw.c +38 −51
8 8
9 9
#include <X11/Xlocale.h>
10 10
11 -
#include "wm.h"
11 +
#include "dwm.h"
12 12
13 13
static void
14 14
drawborder(void)
59 59
	x = dc.x + (h / 2);
60 60
61 61
	/* shorten text if necessary */
62 -
	while(len && (w = textnw(&dc.font, buf, len)) > dc.w - h)
62 +
	while(len && (w = textnw(buf, len)) > dc.w - h)
63 63
		buf[--len] = 0;
64 64
65 65
	if(w > dc.w)
79 79
	}
80 80
}
81 81
82 -
static unsigned long
83 -
xinitcolors(Colormap cmap, const char *colstr)
82 +
unsigned long
83 +
initcolor(const char *colstr)
84 84
{
85 85
	XColor color;
86 +
	Colormap cmap = DefaultColormap(dpy, screen);
87 +
86 88
	XAllocNamedColor(dpy, cmap, colstr, &color, &color);
87 89
	return color.pixel;
88 90
}
89 91
90 -
void
91 -
initcolors(const char *bg, const char *fg, const char *border)
92 -
{
93 -
	Colormap cmap = DefaultColormap(dpy, screen);
94 -
	dc.bg = xinitcolors(cmap, bg);
95 -
	dc.fg = xinitcolors(cmap, fg);
96 -
	dc.border = xinitcolors(cmap, border);
97 -
}
98 -
99 92
unsigned int
100 -
textnw(Fnt *font, char *text, unsigned int len)
93 +
textnw(char *text, unsigned int len)
101 94
{
102 95
	XRectangle r;
103 -
	if(font->set) {
104 -
		XmbTextExtents(font->set, text, len, NULL, &r);
96 +
	if(dc.font.set) {
97 +
		XmbTextExtents(dc.font.set, text, len, NULL, &r);
105 98
		return r.width;
106 99
	}
107 -
	return XTextWidth(font->xfont, text, len);
100 +
	return XTextWidth(dc.font.xfont, text, len);
108 101
}
109 102
110 103
unsigned int
111 -
textw(Fnt *font, char *text)
112 -
{
113 -
	return textnw(font, text, strlen(text));
114 -
}
115 -
116 -
unsigned int
117 -
texth(Fnt *font)
104 +
textw(char *text)
118 105
{
119 -
	return font->height + 4;
106 +
	return textnw(text, strlen(text));
120 107
}
121 108
122 109
void
123 -
initfont(Fnt *font, const char *fontstr)
110 +
initfont(const char *fontstr)
124 111
{
125 112
	char **missing, *def;
126 113
	int i, n;
127 114
128 115
	missing = NULL;
129 116
	setlocale(LC_ALL, "");
130 -
	if(font->set)
131 -
		XFreeFontSet(dpy, font->set);
132 -
	font->set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
117 +
	if(dc.font.set)
118 +
		XFreeFontSet(dpy, dc.font.set);
119 +
	dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
133 120
	if(missing) {
134 121
		while(n--)
135 122
			fprintf(stderr, "missing fontset: %s\n", missing[n]);
136 123
		XFreeStringList(missing);
137 -
		if(font->set) {
138 -
			XFreeFontSet(dpy, font->set);
139 -
			font->set = NULL;
124 +
		if(dc.font.set) {
125 +
			XFreeFontSet(dpy, dc.font.set);
126 +
			dc.font.set = NULL;
140 127
		}
141 128
	}
142 -
	if(font->set) {
129 +
	if(dc.font.set) {
143 130
		XFontSetExtents *font_extents;
144 131
		XFontStruct **xfonts;
145 132
		char **font_names;
146 133
147 -
		font->ascent = font->descent = 0;
148 -
		font_extents = XExtentsOfFontSet(font->set);
149 -
		n = XFontsOfFontSet(font->set, &xfonts, &font_names);
150 -
		for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
151 -
			if(font->ascent < (*xfonts)->ascent)
152 -
				font->ascent = (*xfonts)->ascent;
153 -
			if(font->descent < (*xfonts)->descent)
154 -
				font->descent = (*xfonts)->descent;
134 +
		dc.font.ascent = dc.font.descent = 0;
135 +
		font_extents = XExtentsOfFontSet(dc.font.set);
136 +
		n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
137 +
		for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
138 +
			if(dc.font.ascent < (*xfonts)->ascent)
139 +
				dc.font.ascent = (*xfonts)->ascent;
140 +
			if(dc.font.descent < (*xfonts)->descent)
141 +
				dc.font.descent = (*xfonts)->descent;
155 142
			xfonts++;
156 143
		}
157 144
	}
158 145
	else {
159 -
		if(font->xfont)
160 -
			XFreeFont(dpy, font->xfont);
161 -
		font->xfont = NULL;
162 -
		font->xfont = XLoadQueryFont(dpy, fontstr);
163 -
		if (!font->xfont)
164 -
			font->xfont = XLoadQueryFont(dpy, "fixed");
165 -
		if (!font->xfont)
146 +
		if(dc.font.xfont)
147 +
			XFreeFont(dpy, dc.font.xfont);
148 +
		dc.font.xfont = NULL;
149 +
		dc.font.xfont = XLoadQueryFont(dpy, fontstr);
150 +
		if (!dc.font.xfont)
151 +
			dc.font.xfont = XLoadQueryFont(dpy, "fixed");
152 +
		if (!dc.font.xfont)
166 153
			error("error, cannot init 'fixed' font\n");
167 -
		font->ascent = font->xfont->ascent;
168 -
		font->descent = font->xfont->descent;
154 +
		dc.font.ascent = dc.font.xfont->ascent;
155 +
		dc.font.descent = dc.font.xfont->descent;
169 156
	}
170 -
	font->height = font->ascent + font->descent;
157 +
	dc.font.height = dc.font.ascent + dc.font.descent;
171 158
}
event.c +1 −1
9 9
#include <X11/keysym.h>
10 10
#include <X11/Xatom.h>
11 11
12 -
#include "wm.h"
12 +
#include "dwm.h"
13 13
14 14
/* local functions */
15 15
static void buttonpress(XEvent *e);
util.c +1 −1
11 11
#include <sys/wait.h>
12 12
#include <unistd.h>
13 13
14 -
#include "wm.h"
14 +
#include "dwm.h"
15 15
16 16
void
17 17
error(const char *errstr, ...) {
wm.c → main.c +6 −4
11 11
#include <X11/Xatom.h>
12 12
#include <X11/Xproto.h>
13 13
14 -
#include "wm.h"
14 +
#include "dwm.h"
15 15
16 16
/********** CUSTOMIZE **********/
17 17
244 244
	update_keys();
245 245
246 246
	/* style */
247 -
	initcolors(BGCOLOR, FGCOLOR, BORDERCOLOR);
248 -
	initfont(&dc.font, FONT);
247 +
	dc.bg = initcolor(BGCOLOR);
248 +
	dc.fg = initcolor(FGCOLOR);
249 +
	dc.border = initcolor(BORDERCOLOR);
250 +
	initfont(FONT);
249 251
250 -
	th = texth(&dc.font);
252 +
	th = dc.font.height + 4;
251 253
252 254
	dc.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen));
253 255
	dc.gc = XCreateGC(dpy, root, 0, 0);
wm.h → dwm.h +14 −15
8 8
/********** CUSTOMIZE **********/
9 9
10 10
#define FONT		"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
11 -
#define BGCOLOR		"#666699"
12 -
#define FGCOLOR		"#ffffff"
13 -
#define BORDERCOLOR	"#9999CC"
14 -
#define STATUSDELAY	10 /* seconds */
11 +
#define BGCOLOR		"DarkSlateGrey"
12 +
#define FGCOLOR		"LightSteelBlue"
13 +
#define BORDERCOLOR	"SlateGray"
15 14
#define WM_PROTOCOL_DELWIN 1
16 15
17 16
/* tags */
106 105
107 106
/* draw.c */
108 107
extern void draw(Bool border, const char *text);
109 -
extern void initcolors(const char *bg, const char *fg, const char *bo);
110 -
extern void initfont(Fnt *font, const char *fontstr);
111 -
extern unsigned int textnw(Fnt *font, char *text, unsigned int len);
112 -
extern unsigned int textw(Fnt *font, char *text);
113 -
extern unsigned int texth(Fnt *font);
108 +
extern unsigned long initcolor(const char *colstr);
109 +
extern void initfont(const char *fontstr);
110 +
extern unsigned int textnw(char *text, unsigned int len);
111 +
extern unsigned int textw(char *text);
112 +
extern unsigned int texth(void);
114 113
115 114
/* event.c */
116 115
extern void discard_events(long even_mask);
121 120
extern void mresize(Client *c);
122 121
extern void mmove(Client *c);
123 122
123 +
/* main.c */
124 +
extern int error_handler(Display *dsply, XErrorEvent *e);
125 +
extern void send_message(Window w, Atom a, long value);
126 +
extern int win_proto(Window w);
127 +
extern void quit(void *aux);
128 +
124 129
/* util.c */
125 130
extern void error(const char *errstr, ...);
126 131
extern void *emallocz(unsigned int size);
129 134
extern char *estrdup(const char *str);
130 135
extern void spawn(char *argv[]);
131 136
extern void swap(void **p1, void **p2);
132 -
133 -
/* wm.c */
134 -
extern int error_handler(Display *dsply, XErrorEvent *e);
135 -
extern void send_message(Window w, Atom a, long value);
136 -
extern int win_proto(Window w);
137 -
extern void quit(void *aux);