cleaned up code

This commit is contained in:
arg@10ksloc.org 2006-07-20 12:18:06 +02:00
parent fe3756c8e1
commit dc5d967ee6
8 changed files with 78 additions and 85 deletions

View File

@ -97,6 +97,7 @@ Client *
getclient(Window w) getclient(Window w)
{ {
Client *c; Client *c;
for(c = clients; c; c = c->next) for(c = clients; c; c = c->next)
if(c->win == w) if(c->win == w)
return c; return c;
@ -107,6 +108,7 @@ Client *
getctitle(Window w) getctitle(Window w)
{ {
Client *c; Client *c;
for(c = clients; c; c = c->next) for(c = clients; c; c = c->next)
if(c->title == w) if(c->title == w)
return c; return c;
@ -198,8 +200,8 @@ manage(Window w, XWindowAttributes *wa)
{ {
int diff; int diff;
Client *c; Client *c;
XSetWindowAttributes twa;
Window trans; Window trans;
XSetWindowAttributes twa;
c = emallocz(sizeof(Client)); c = emallocz(sizeof(Client));
c->win = w; c->win = w;
@ -278,6 +280,7 @@ void
pop(Client *c) pop(Client *c)
{ {
Client **l; Client **l;
for(l = &clients; *l && *l != c; l = &(*l)->next); for(l = &clients; *l && *l != c; l = &(*l)->next);
*l = c->next; *l = c->next;
@ -289,9 +292,9 @@ pop(Client *c)
void void
resize(Client *c, Bool inc, Corner sticky) resize(Client *c, Bool inc, Corner sticky)
{ {
XConfigureEvent e;
int right = c->x + c->w;
int bottom = c->y + c->h; int bottom = c->y + c->h;
int right = c->x + c->w;
XConfigureEvent e;
if(inc) { if(inc) {
if(c->incw) if(c->incw)
@ -337,8 +340,9 @@ resize(Client *c, Bool inc, Corner sticky)
void void
setsize(Client *c) setsize(Client *c)
{ {
XSizeHints size;
long msize; long msize;
XSizeHints size;
if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags) if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
size.flags = PSize; size.flags = PSize;
c->flags = size.flags; c->flags = size.flags;
@ -375,9 +379,9 @@ setsize(Client *c)
void void
settitle(Client *c) settitle(Client *c)
{ {
XTextProperty name;
int n;
char **list = NULL; char **list = NULL;
int n;
XTextProperty name;
name.nitems = 0; name.nitems = 0;
c->name[0] = 0; c->name[0] = 0;

View File

@ -7,7 +7,7 @@ MANPREFIX = ${PREFIX}/share/man
X11INC = /usr/X11R6/include X11INC = /usr/X11R6/include
X11LIB = /usr/X11R6/lib X11LIB = /usr/X11R6/lib
VERSION = 0.4 VERSION = 0.5
# includes and libs # includes and libs
LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11 LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11

6
draw.c
View File

@ -14,6 +14,7 @@ static void
drawborder(void) drawborder(void)
{ {
XPoint points[5]; XPoint points[5];
XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
XSetForeground(dpy, dc.gc, dc.border); XSetForeground(dpy, dc.gc, dc.border);
points[0].x = dc.x; points[0].x = dc.x;
@ -33,6 +34,7 @@ static unsigned int
textnw(char *text, unsigned int len) textnw(char *text, unsigned int len)
{ {
XRectangle r; XRectangle r;
if(dc.font.set) { if(dc.font.set) {
XmbTextExtents(dc.font.set, text, len, NULL, &r); XmbTextExtents(dc.font.set, text, len, NULL, &r);
return r.width; return r.width;
@ -44,8 +46,8 @@ static void
drawtext(const char *text, Bool invert, Bool border) drawtext(const char *text, Bool invert, Bool border)
{ {
int x, y, w, h; int x, y, w, h;
unsigned int len;
static char buf[256]; static char buf[256];
unsigned int len;
XGCValues gcv; XGCValues gcv;
XRectangle r = { dc.x, dc.y, dc.w, dc.h }; XRectangle r = { dc.x, dc.y, dc.w, dc.h };
@ -170,8 +172,8 @@ drawtitle(Client *c)
unsigned long unsigned long
getcolor(const char *colstr) getcolor(const char *colstr)
{ {
XColor color;
Colormap cmap = DefaultColormap(dpy, screen); Colormap cmap = DefaultColormap(dpy, screen);
XColor color;
XAllocNamedColor(dpy, cmap, colstr, &color, &color); XAllocNamedColor(dpy, cmap, colstr, &color, &color);
return color.pixel; return color.pixel;

2
dwm.1
View File

@ -1,4 +1,4 @@
.TH DWM 1 dwm-0.4 .TH DWM 1 dwm-0.5
.SH NAME .SH NAME
dwm \- dynamic window manager dwm \- dynamic window manager
.SH SYNOPSIS .SH SYNOPSIS

32
event.c
View File

@ -20,17 +20,13 @@ typedef struct {
Arg arg; Arg arg;
} Key; } Key;
/*
const char *browse[] = { "firefox", NULL }; const char *browse[] = { "firefox", NULL };
const char *gimp[] = { "gimp", NULL }; const char *gimp[] = { "gimp", NULL };
*/ const char *term[] = {
const char *term[] = { "xterm", NULL };
/*
"urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-cr", "white", "urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-cr", "white",
"-fn", "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", NULL "-fn", "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", NULL
}; };
coonst char *xlock[] = { "xlock", NULL }; const char *xlock[] = { "xlock", NULL };
*/
static Key key[] = { static Key key[] = {
/* modifier key function arguments */ /* modifier key function arguments */
@ -56,13 +52,11 @@ static Key key[] = {
{ MODKEY|ShiftMask, XK_2, replacetag, { .i = Twww } }, { MODKEY|ShiftMask, XK_2, replacetag, { .i = Twww } },
{ MODKEY|ShiftMask, XK_3, replacetag, { .i = Twork } }, { MODKEY|ShiftMask, XK_3, replacetag, { .i = Twork } },
{ MODKEY|ShiftMask, XK_c, killclient, { 0 } }, { MODKEY|ShiftMask, XK_c, killclient, { 0 } },
/*
{ MODKEY|ShiftMask, XK_g, spawn, { .argv = gimp } }, { MODKEY|ShiftMask, XK_g, spawn, { .argv = gimp } },
{ MODKEY|ShiftMask, XK_l, spawn, { .argv = xlock } }, { MODKEY|ShiftMask, XK_l, spawn, { .argv = xlock } },
*/
{ MODKEY|ShiftMask, XK_q, quit, { 0 } }, { MODKEY|ShiftMask, XK_q, quit, { 0 } },
{ MODKEY|ShiftMask, XK_space, dofloat, { 0 } }, { MODKEY|ShiftMask, XK_space, dofloat, { 0 } },
/*{ MODKEY|ShiftMask, XK_w, spawn, { .argv = browse } },*/ { MODKEY|ShiftMask, XK_w, spawn, { .argv = browse } },
{ MODKEY|ShiftMask, XK_Return, spawn, { .argv = term } }, { MODKEY|ShiftMask, XK_Return, spawn, { .argv = term } },
}; };
@ -71,10 +65,10 @@ static Key key[] = {
static void static void
movemouse(Client *c) movemouse(Client *c)
{ {
XEvent ev;
int x1, y1, ocx, ocy, di; int x1, y1, ocx, ocy, di;
unsigned int dui; unsigned int dui;
Window dummy; Window dummy;
XEvent ev;
ocx = c->x; ocx = c->x;
ocy = c->y; ocy = c->y;
@ -105,9 +99,9 @@ movemouse(Client *c)
static void static void
resizemouse(Client *c) resizemouse(Client *c)
{ {
XEvent ev;
int ocx, ocy; int ocx, ocy;
Corner sticky; Corner sticky;
XEvent ev;
ocx = c->x; ocx = c->x;
ocy = c->y; ocy = c->y;
@ -146,8 +140,8 @@ buttonpress(XEvent *e)
{ {
int x; int x;
Arg a; Arg a;
XButtonPressedEvent *ev = &e->xbutton;
Client *c; Client *c;
XButtonPressedEvent *ev = &e->xbutton;
if(barwin == ev->window) { if(barwin == ev->window) {
switch(ev->button) { switch(ev->button) {
@ -201,9 +195,9 @@ buttonpress(XEvent *e)
static void static void
configurerequest(XEvent *e) configurerequest(XEvent *e)
{ {
Client *c;
XConfigureRequestEvent *ev = &e->xconfigurerequest; XConfigureRequestEvent *ev = &e->xconfigurerequest;
XWindowChanges wc; XWindowChanges wc;
Client *c;
ev->value_mask &= ~CWSibling; ev->value_mask &= ~CWSibling;
if((c = getclient(ev->window))) { if((c = getclient(ev->window))) {
@ -248,8 +242,8 @@ destroynotify(XEvent *e)
static void static void
enternotify(XEvent *e) enternotify(XEvent *e)
{ {
XCrossingEvent *ev = &e->xcrossing;
Client *c; Client *c;
XCrossingEvent *ev = &e->xcrossing;
if(ev->mode != NotifyNormal || ev->detail == NotifyInferior) if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
return; return;
@ -263,8 +257,8 @@ enternotify(XEvent *e)
static void static void
expose(XEvent *e) expose(XEvent *e)
{ {
XExposeEvent *ev = &e->xexpose;
Client *c; Client *c;
XExposeEvent *ev = &e->xexpose;
if(ev->count == 0) { if(ev->count == 0) {
if(barwin == ev->window) if(barwin == ev->window)
@ -277,10 +271,10 @@ expose(XEvent *e)
static void static void
keypress(XEvent *e) keypress(XEvent *e)
{ {
XKeyEvent *ev = &e->xkey;
static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0; static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
unsigned int i; unsigned int i;
KeySym keysym; KeySym keysym;
XKeyEvent *ev = &e->xkey;
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0); keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
for(i = 0; i < len; i++) for(i = 0; i < len; i++)
@ -303,8 +297,8 @@ leavenotify(XEvent *e)
static void static void
maprequest(XEvent *e) maprequest(XEvent *e)
{ {
XMapRequestEvent *ev = &e->xmaprequest;
static XWindowAttributes wa; static XWindowAttributes wa;
XMapRequestEvent *ev = &e->xmaprequest;
if(!XGetWindowAttributes(dpy, ev->window, &wa)) if(!XGetWindowAttributes(dpy, ev->window, &wa))
return; return;
@ -322,9 +316,9 @@ maprequest(XEvent *e)
static void static void
propertynotify(XEvent *e) propertynotify(XEvent *e)
{ {
XPropertyEvent *ev = &e->xproperty;
Window trans;
Client *c; Client *c;
Window trans;
XPropertyEvent *ev = &e->xproperty;
if(ev->state == PropertyDelete) if(ev->state == PropertyDelete)
return; /* ignore */ return; /* ignore */

41
main.c
View File

@ -17,8 +17,8 @@
/* static */ /* static */
static Bool otherwm;
static int (*xerrorxlib)(Display *, XErrorEvent *); static int (*xerrorxlib)(Display *, XErrorEvent *);
static Bool otherwm;
static void static void
cleanup() cleanup()
@ -34,9 +34,8 @@ static void
scan() scan()
{ {
unsigned int i, num; unsigned int i, num;
Window *wins; Window *wins, d1, d2;
XWindowAttributes wa; XWindowAttributes wa;
Window d1, d2;
if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) { if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
for(i = 0; i < num; i++) { for(i = 0; i < num; i++) {
@ -55,10 +54,9 @@ scan()
static int static int
win_property(Window w, Atom a, Atom t, long l, unsigned char **prop) win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
{ {
Atom real; int status, format;
int format;
unsigned long res, extra; unsigned long res, extra;
int status; Atom real;
status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format, status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
&res, &extra, prop); &res, &extra, prop);
@ -101,10 +99,10 @@ Window root, barwin;
int int
getproto(Window w) getproto(Window w)
{ {
unsigned char *protocols;
long res;
int protos = 0; int protos = 0;
int i; int i;
long res;
unsigned char *protocols;
res = win_property(w, wmatom[WMProtocols], XA_ATOM, 20L, &protocols); res = win_property(w, wmatom[WMProtocols], XA_ATOM, 20L, &protocols);
if(res <= 0) { if(res <= 0) {
@ -148,18 +146,12 @@ int
xerror(Display *dpy, XErrorEvent *ee) xerror(Display *dpy, XErrorEvent *ee)
{ {
if(ee->error_code == BadWindow if(ee->error_code == BadWindow
|| (ee->request_code == X_SetInputFocus || (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
&& ee->error_code == BadMatch) || (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
|| (ee->request_code == X_PolyText8 || (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)
&& ee->error_code == BadDrawable) || (ee->request_code == X_PolySegment && ee->error_code == BadDrawable)
|| (ee->request_code == X_PolyFillRectangle || (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
&& ee->error_code == BadDrawable) || (ee->request_code == X_GrabKey && ee->error_code == BadAccess))
|| (ee->request_code == X_PolySegment
&& ee->error_code == BadDrawable)
|| (ee->request_code == X_ConfigureWindow
&& ee->error_code == BadMatch)
|| (ee->request_code == X_GrabKey
&& ee->error_code == BadAccess))
return 0; return 0;
fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n", fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
ee->request_code, ee->error_code); ee->request_code, ee->error_code);
@ -170,12 +162,12 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
int i, n; int i, n;
fd_set rd;
XSetWindowAttributes wa;
unsigned int mask; unsigned int mask;
fd_set rd;
Bool readstdin = True; Bool readstdin = True;
Window w; Window w;
XEvent ev; XEvent ev;
XSetWindowAttributes wa;
for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) { for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
switch (argv[i][1]) { switch (argv[i][1]) {
@ -254,14 +246,11 @@ main(int argc, char *argv[])
issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask;
| LeaveWindowMask;
wa.cursor = cursor[CurNormal]; wa.cursor = cursor[CurNormal];
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
strcpy(stext, "dwm-"VERSION); strcpy(stext, "dwm-"VERSION);
scan(); scan();
/* main event loop, reads status text from stdin as well */ /* main event loop, reads status text from stdin as well */

5
tag.c
View File

@ -20,7 +20,7 @@ typedef struct {
/* CUSTOMIZE */ /* CUSTOMIZE */
static Rule rule[] = { static Rule rule[] = {
/* class instance tags isfloat */ /* class:instance tags isfloat */
{ "Firefox.*", { [Twww] = "www" }, False }, { "Firefox.*", { [Twww] = "www" }, False },
{ "Gimp.*", { 0 }, True}, { "Gimp.*", { 0 }, True},
}; };
@ -71,8 +71,8 @@ dofloat(Arg *arg)
void void
dotile(Arg *arg) dotile(Arg *arg)
{ {
Client *c;
int n, i, w, h; int n, i, w, h;
Client *c;
w = sw - mw; w = sw - mw;
arrange = dotile; arrange = dotile;
@ -161,6 +161,7 @@ void
replacetag(Arg *arg) replacetag(Arg *arg)
{ {
int i; int i;
if(!sel) if(!sel)
return; return;

3
util.c
View File

@ -26,6 +26,7 @@ void *
emallocz(unsigned int size) emallocz(unsigned int size)
{ {
void *res = calloc(1, size); void *res = calloc(1, size);
if(!res) if(!res)
bad_malloc(size); bad_malloc(size);
return res; return res;
@ -34,6 +35,7 @@ emallocz(unsigned int size)
void void
eprint(const char *errstr, ...) { eprint(const char *errstr, ...) {
va_list ap; va_list ap;
va_start(ap, errstr); va_start(ap, errstr);
vfprintf(stderr, errstr, ap); vfprintf(stderr, errstr, ap);
va_end(ap); va_end(ap);
@ -44,6 +46,7 @@ void
spawn(Arg *arg) spawn(Arg *arg)
{ {
char **argv = (char **)arg->argv; char **argv = (char **)arg->argv;
if(!argv || !argv[0]) if(!argv || !argv[0])
return; return;
if(fork() == 0) { if(fork() == 0) {