dwm-meillo

changeset 123:61490330e90a

cleaned up code
author arg@10ksloc.org
date Thu, 20 Jul 2006 12:18:06 +0200
parents f20cea484900
children 75576e44c1d8
files client.c config.mk draw.c dwm.1 event.c main.c tag.c util.c
diffstat 8 files changed, 78 insertions(+), 85 deletions(-) [+]
line diff
     1.1 --- a/client.c	Thu Jul 20 10:48:22 2006 +0200
     1.2 +++ b/client.c	Thu Jul 20 12:18:06 2006 +0200
     1.3 @@ -97,6 +97,7 @@
     1.4  getclient(Window w)
     1.5  {
     1.6  	Client *c;
     1.7 +
     1.8  	for(c = clients; c; c = c->next)
     1.9  		if(c->win == w)
    1.10  			return c;
    1.11 @@ -107,6 +108,7 @@
    1.12  getctitle(Window w)
    1.13  {
    1.14  	Client *c;
    1.15 +
    1.16  	for(c = clients; c; c = c->next)
    1.17  		if(c->title == w)
    1.18  			return c;
    1.19 @@ -198,8 +200,8 @@
    1.20  {
    1.21  	int diff;
    1.22  	Client *c;
    1.23 +	Window trans;
    1.24  	XSetWindowAttributes twa;
    1.25 -	Window trans;
    1.26  
    1.27  	c = emallocz(sizeof(Client));
    1.28  	c->win = w;
    1.29 @@ -278,6 +280,7 @@
    1.30  pop(Client *c)
    1.31  {
    1.32  	Client **l;
    1.33 +
    1.34  	for(l = &clients; *l && *l != c; l = &(*l)->next);
    1.35  	*l = c->next;
    1.36  
    1.37 @@ -289,9 +292,9 @@
    1.38  void
    1.39  resize(Client *c, Bool inc, Corner sticky)
    1.40  {
    1.41 +	int bottom = c->y + c->h;
    1.42 +	int right = c->x + c->w;
    1.43  	XConfigureEvent e;
    1.44 -	int right = c->x + c->w;
    1.45 -	int bottom = c->y + c->h;
    1.46  
    1.47  	if(inc) {
    1.48  		if(c->incw)
    1.49 @@ -337,8 +340,9 @@
    1.50  void
    1.51  setsize(Client *c)
    1.52  {
    1.53 +	long msize;
    1.54  	XSizeHints size;
    1.55 -	long msize;
    1.56 +
    1.57  	if(!XGetWMNormalHints(dpy, c->win, &size, &msize) || !size.flags)
    1.58  		size.flags = PSize;
    1.59  	c->flags = size.flags;
    1.60 @@ -375,9 +379,9 @@
    1.61  void
    1.62  settitle(Client *c)
    1.63  {
    1.64 +	char **list = NULL;
    1.65 +	int n;
    1.66  	XTextProperty name;
    1.67 -	int n;
    1.68 -	char **list = NULL;
    1.69  
    1.70  	name.nitems = 0;
    1.71  	c->name[0] = 0;
     2.1 --- a/config.mk	Thu Jul 20 10:48:22 2006 +0200
     2.2 +++ b/config.mk	Thu Jul 20 12:18:06 2006 +0200
     2.3 @@ -7,7 +7,7 @@
     2.4  X11INC = /usr/X11R6/include
     2.5  X11LIB = /usr/X11R6/lib
     2.6  
     2.7 -VERSION = 0.4
     2.8 +VERSION = 0.5
     2.9  
    2.10  # includes and libs
    2.11  LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11
     3.1 --- a/draw.c	Thu Jul 20 10:48:22 2006 +0200
     3.2 +++ b/draw.c	Thu Jul 20 12:18:06 2006 +0200
     3.3 @@ -14,6 +14,7 @@
     3.4  drawborder(void)
     3.5  {
     3.6  	XPoint points[5];
     3.7 +
     3.8  	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
     3.9  	XSetForeground(dpy, dc.gc, dc.border);
    3.10  	points[0].x = dc.x;
    3.11 @@ -33,6 +34,7 @@
    3.12  textnw(char *text, unsigned int len)
    3.13  {
    3.14  	XRectangle r;
    3.15 +
    3.16  	if(dc.font.set) {
    3.17  		XmbTextExtents(dc.font.set, text, len, NULL, &r);
    3.18  		return r.width;
    3.19 @@ -44,8 +46,8 @@
    3.20  drawtext(const char *text, Bool invert, Bool border)
    3.21  {
    3.22  	int x, y, w, h;
    3.23 +	static char buf[256];
    3.24  	unsigned int len;
    3.25 -	static char buf[256];
    3.26  	XGCValues gcv;
    3.27  	XRectangle r = { dc.x, dc.y, dc.w, dc.h };
    3.28  
    3.29 @@ -170,8 +172,8 @@
    3.30  unsigned long
    3.31  getcolor(const char *colstr)
    3.32  {
    3.33 +	Colormap cmap = DefaultColormap(dpy, screen);
    3.34  	XColor color;
    3.35 -	Colormap cmap = DefaultColormap(dpy, screen);
    3.36  
    3.37  	XAllocNamedColor(dpy, cmap, colstr, &color, &color);
    3.38  	return color.pixel;
     4.1 --- a/dwm.1	Thu Jul 20 10:48:22 2006 +0200
     4.2 +++ b/dwm.1	Thu Jul 20 12:18:06 2006 +0200
     4.3 @@ -1,4 +1,4 @@
     4.4 -.TH DWM 1 dwm-0.4
     4.5 +.TH DWM 1 dwm-0.5
     4.6  .SH NAME
     4.7  dwm \- dynamic window manager
     4.8  .SH SYNOPSIS
     5.1 --- a/event.c	Thu Jul 20 10:48:22 2006 +0200
     5.2 +++ b/event.c	Thu Jul 20 12:18:06 2006 +0200
     5.3 @@ -20,50 +20,44 @@
     5.4  	Arg arg;
     5.5  } Key;
     5.6  
     5.7 -/*
     5.8  const char *browse[] = { "firefox", NULL };
     5.9  const char *gimp[] = { "gimp", NULL };
    5.10 -*/
    5.11 -const char *term[] = { "xterm", NULL };
    5.12 -/*
    5.13 +const char *term[] = { 
    5.14  	"urxvtc", "-tr", "+sb", "-bg", "black", "-fg", "white", "-cr", "white",
    5.15  	"-fn", "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", NULL
    5.16  };
    5.17 -coonst char *xlock[] = { "xlock", NULL };
    5.18 -*/
    5.19 +const char *xlock[] = { "xlock", NULL };
    5.20  
    5.21  static Key key[] = {
    5.22 -	/* modifier				key			function	arguments */
    5.23 -	{ ControlMask,			XK_0,		appendtag,	{ .i = Tscratch } }, 
    5.24 -	{ ControlMask,			XK_1,		appendtag,	{ .i = Tdev } }, 
    5.25 -	{ ControlMask,			XK_2,		appendtag,	{ .i = Twww } }, 
    5.26 -	{ ControlMask,			XK_3,		appendtag,	{ .i = Twork } }, 
    5.27 -	{ MODKEY,				XK_0,		view,		{ .i = Tscratch } }, 
    5.28 -	{ MODKEY,				XK_1,		view,		{ .i = Tdev } }, 
    5.29 -	{ MODKEY,				XK_2,		view,		{ .i = Twww } }, 
    5.30 -	{ MODKEY,				XK_3,		view,		{ .i = Twork } }, 
    5.31 -	{ MODKEY,				XK_j,		focusnext,		{ 0 } }, 
    5.32 -	{ MODKEY,				XK_k,		focusprev,		{ 0 } },
    5.33 -	{ MODKEY,				XK_m,		maximize,		{ 0 } }, 
    5.34 -	{ MODKEY,				XK_space,	dotile,		{ 0 } }, 
    5.35 -	{ MODKEY,				XK_Return,	zoom,		{ 0 } },
    5.36 +	/* modifier		key		function	arguments */
    5.37 +	{ ControlMask,		XK_0,		appendtag,	{ .i = Tscratch } }, 
    5.38 +	{ ControlMask,		XK_1,		appendtag,	{ .i = Tdev } }, 
    5.39 +	{ ControlMask,		XK_2,		appendtag,	{ .i = Twww } }, 
    5.40 +	{ ControlMask,		XK_3,		appendtag,	{ .i = Twork } }, 
    5.41 +	{ MODKEY,		XK_0,		view,		{ .i = Tscratch } }, 
    5.42 +	{ MODKEY,		XK_1,		view,		{ .i = Tdev } }, 
    5.43 +	{ MODKEY,		XK_2,		view,		{ .i = Twww } }, 
    5.44 +	{ MODKEY,		XK_3,		view,		{ .i = Twork } }, 
    5.45 +	{ MODKEY,		XK_j,		focusnext,	{ 0 } }, 
    5.46 +	{ MODKEY,		XK_k,		focusprev,	{ 0 } },
    5.47 +	{ MODKEY,		XK_m,		maximize,	{ 0 } }, 
    5.48 +	{ MODKEY,		XK_space,	dotile,		{ 0 } }, 
    5.49 +	{ MODKEY,		XK_Return,	zoom,		{ 0 } },
    5.50  	{ ControlMask|ShiftMask,XK_0,		heretag,	{ .i = Tscratch } }, 
    5.51  	{ ControlMask|ShiftMask,XK_1,		heretag,	{ .i = Tdev } }, 
    5.52  	{ ControlMask|ShiftMask,XK_2,		heretag,	{ .i = Twww } }, 
    5.53  	{ ControlMask|ShiftMask,XK_3,		heretag,	{ .i = Twork } }, 
    5.54 -	{ MODKEY|ShiftMask,		XK_0,		replacetag,		{ .i = Tscratch } }, 
    5.55 -	{ MODKEY|ShiftMask,		XK_1,		replacetag,		{ .i = Tdev } }, 
    5.56 -	{ MODKEY|ShiftMask,		XK_2,		replacetag,		{ .i = Twww } }, 
    5.57 -	{ MODKEY|ShiftMask,		XK_3,		replacetag,		{ .i = Twork } }, 
    5.58 -	{ MODKEY|ShiftMask,		XK_c,		killclient,		{ 0 } }, 
    5.59 -	/*
    5.60 -	{ MODKEY|ShiftMask,		XK_g,		spawn,		{ .argv = gimp } },
    5.61 -	{ MODKEY|ShiftMask,		XK_l,		spawn,		{ .argv = xlock } },
    5.62 -	*/
    5.63 -	{ MODKEY|ShiftMask,		XK_q,		quit,		{ 0 } },
    5.64 -	{ MODKEY|ShiftMask,		XK_space,	dofloat,	{ 0 } }, 
    5.65 -	/*{ MODKEY|ShiftMask,		XK_w,		spawn,		{ .argv = browse } },*/
    5.66 -	{ MODKEY|ShiftMask,		XK_Return,	spawn,		{ .argv = term } },
    5.67 +	{ MODKEY|ShiftMask,	XK_0,		replacetag,	{ .i = Tscratch } }, 
    5.68 +	{ MODKEY|ShiftMask,	XK_1,		replacetag,	{ .i = Tdev } }, 
    5.69 +	{ MODKEY|ShiftMask,	XK_2,		replacetag,	{ .i = Twww } }, 
    5.70 +	{ MODKEY|ShiftMask,	XK_3,		replacetag,	{ .i = Twork } }, 
    5.71 +	{ MODKEY|ShiftMask,	XK_c,		killclient,	{ 0 } }, 
    5.72 +	{ MODKEY|ShiftMask,	XK_g,		spawn,		{ .argv = gimp } },
    5.73 +	{ MODKEY|ShiftMask,	XK_l,		spawn,		{ .argv = xlock } },
    5.74 +	{ MODKEY|ShiftMask,	XK_q,		quit,		{ 0 } },
    5.75 +	{ MODKEY|ShiftMask,	XK_space,	dofloat,	{ 0 } }, 
    5.76 +	{ MODKEY|ShiftMask,	XK_w,		spawn,		{ .argv = browse } },
    5.77 +	{ MODKEY|ShiftMask,	XK_Return,	spawn,		{ .argv = term } },
    5.78  };
    5.79  
    5.80  /* static */
    5.81 @@ -71,15 +65,15 @@
    5.82  static void
    5.83  movemouse(Client *c)
    5.84  {
    5.85 -	XEvent ev;
    5.86  	int x1, y1, ocx, ocy, di;
    5.87  	unsigned int dui;
    5.88  	Window dummy;
    5.89 +	XEvent ev;
    5.90  
    5.91  	ocx = c->x;
    5.92  	ocy = c->y;
    5.93  	if(XGrabPointer(dpy, root, False, MouseMask, GrabModeAsync, GrabModeAsync,
    5.94 -				None, cursor[CurMove], CurrentTime) != GrabSuccess)
    5.95 +			None, cursor[CurMove], CurrentTime) != GrabSuccess)
    5.96  		return;
    5.97  	XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
    5.98  	for(;;) {
    5.99 @@ -105,9 +99,9 @@
   5.100  static void
   5.101  resizemouse(Client *c)
   5.102  {
   5.103 -	XEvent ev;
   5.104  	int ocx, ocy;
   5.105  	Corner sticky;
   5.106 +	XEvent ev;
   5.107  
   5.108  	ocx = c->x;
   5.109  	ocy = c->y;
   5.110 @@ -146,8 +140,8 @@
   5.111  {
   5.112  	int x;
   5.113  	Arg a;
   5.114 +	Client *c;
   5.115  	XButtonPressedEvent *ev = &e->xbutton;
   5.116 -	Client *c;
   5.117  
   5.118  	if(barwin == ev->window) {
   5.119  		switch(ev->button) {
   5.120 @@ -201,9 +195,9 @@
   5.121  static void
   5.122  configurerequest(XEvent *e)
   5.123  {
   5.124 +	Client *c;
   5.125  	XConfigureRequestEvent *ev = &e->xconfigurerequest;
   5.126  	XWindowChanges wc;
   5.127 -	Client *c;
   5.128  
   5.129  	ev->value_mask &= ~CWSibling;
   5.130  	if((c = getclient(ev->window))) {
   5.131 @@ -248,8 +242,8 @@
   5.132  static void
   5.133  enternotify(XEvent *e)
   5.134  {
   5.135 +	Client *c;
   5.136  	XCrossingEvent *ev = &e->xcrossing;
   5.137 -	Client *c;
   5.138  
   5.139  	if(ev->mode != NotifyNormal || ev->detail == NotifyInferior)
   5.140  		return;
   5.141 @@ -263,8 +257,8 @@
   5.142  static void
   5.143  expose(XEvent *e)
   5.144  {
   5.145 +	Client *c;
   5.146  	XExposeEvent *ev = &e->xexpose;
   5.147 -	Client *c;
   5.148  
   5.149  	if(ev->count == 0) {
   5.150  		if(barwin == ev->window)
   5.151 @@ -277,10 +271,10 @@
   5.152  static void
   5.153  keypress(XEvent *e)
   5.154  {
   5.155 -	XKeyEvent *ev = &e->xkey;
   5.156  	static unsigned int len = key ? sizeof(key) / sizeof(key[0]) : 0;
   5.157  	unsigned int i;
   5.158  	KeySym keysym;
   5.159 +	XKeyEvent *ev = &e->xkey;
   5.160  
   5.161  	keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
   5.162  	for(i = 0; i < len; i++)
   5.163 @@ -303,8 +297,8 @@
   5.164  static void
   5.165  maprequest(XEvent *e)
   5.166  {
   5.167 +	static XWindowAttributes wa;
   5.168  	XMapRequestEvent *ev = &e->xmaprequest;
   5.169 -	static XWindowAttributes wa;
   5.170  
   5.171  	if(!XGetWindowAttributes(dpy, ev->window, &wa))
   5.172  		return;
   5.173 @@ -322,9 +316,9 @@
   5.174  static void
   5.175  propertynotify(XEvent *e)
   5.176  {
   5.177 +	Client *c;
   5.178 +	Window trans;
   5.179  	XPropertyEvent *ev = &e->xproperty;
   5.180 -	Window trans;
   5.181 -	Client *c;
   5.182  
   5.183  	if(ev->state == PropertyDelete)
   5.184  		return; /* ignore */
     6.1 --- a/main.c	Thu Jul 20 10:48:22 2006 +0200
     6.2 +++ b/main.c	Thu Jul 20 12:18:06 2006 +0200
     6.3 @@ -17,8 +17,8 @@
     6.4  
     6.5  /* static */
     6.6  
     6.7 +static int (*xerrorxlib)(Display *, XErrorEvent *);
     6.8  static Bool otherwm;
     6.9 -static int (*xerrorxlib)(Display *, XErrorEvent *);
    6.10  
    6.11  static void
    6.12  cleanup()
    6.13 @@ -34,9 +34,8 @@
    6.14  scan()
    6.15  {
    6.16  	unsigned int i, num;
    6.17 -	Window *wins;
    6.18 +	Window *wins, d1, d2;
    6.19  	XWindowAttributes wa;
    6.20 -	Window d1, d2;
    6.21  
    6.22  	if(XQueryTree(dpy, root, &d1, &d2, &wins, &num)) {
    6.23  		for(i = 0; i < num; i++) {
    6.24 @@ -55,10 +54,9 @@
    6.25  static int
    6.26  win_property(Window w, Atom a, Atom t, long l, unsigned char **prop)
    6.27  {
    6.28 +	int status, format;
    6.29 +	unsigned long res, extra;
    6.30  	Atom real;
    6.31 -	int format;
    6.32 -	unsigned long res, extra;
    6.33 -	int status;
    6.34  
    6.35  	status = XGetWindowProperty(dpy, w, a, 0L, l, False, t, &real, &format,
    6.36  			&res, &extra, prop);
    6.37 @@ -101,10 +99,10 @@
    6.38  int
    6.39  getproto(Window w)
    6.40  {
    6.41 -	unsigned char *protocols;
    6.42 -	long res;
    6.43  	int protos = 0;
    6.44  	int i;
    6.45 +	long res;
    6.46 +	unsigned char *protocols;
    6.47  
    6.48  	res = win_property(w, wmatom[WMProtocols], XA_ATOM, 20L, &protocols);
    6.49  	if(res <= 0) {
    6.50 @@ -148,21 +146,15 @@
    6.51  xerror(Display *dpy, XErrorEvent *ee)
    6.52  {
    6.53  	if(ee->error_code == BadWindow
    6.54 -			|| (ee->request_code == X_SetInputFocus
    6.55 -				&& ee->error_code == BadMatch)
    6.56 -			|| (ee->request_code == X_PolyText8
    6.57 -				&& ee->error_code == BadDrawable)
    6.58 -			|| (ee->request_code == X_PolyFillRectangle
    6.59 -				&& ee->error_code == BadDrawable)
    6.60 -			|| (ee->request_code == X_PolySegment
    6.61 -				&& ee->error_code == BadDrawable)
    6.62 -			|| (ee->request_code == X_ConfigureWindow
    6.63 -				&& ee->error_code == BadMatch)
    6.64 -			|| (ee->request_code == X_GrabKey
    6.65 -				&& ee->error_code == BadAccess))
    6.66 +	|| (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
    6.67 +	|| (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
    6.68 +	|| (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)
    6.69 +	|| (ee->request_code == X_PolySegment && ee->error_code == BadDrawable)
    6.70 +	|| (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
    6.71 +	|| (ee->request_code == X_GrabKey && ee->error_code == BadAccess))
    6.72  		return 0;
    6.73  	fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
    6.74 -			ee->request_code, ee->error_code);
    6.75 +		ee->request_code, ee->error_code);
    6.76  	return xerrorxlib(dpy, ee); /* may call exit() */
    6.77  }
    6.78  
    6.79 @@ -170,12 +162,12 @@
    6.80  main(int argc, char *argv[])
    6.81  {
    6.82  	int i, n;
    6.83 +	unsigned int mask;
    6.84  	fd_set rd;
    6.85 -	XSetWindowAttributes wa;
    6.86 -	unsigned int mask;
    6.87  	Bool readstdin = True;
    6.88  	Window w;
    6.89  	XEvent ev;
    6.90 +	XSetWindowAttributes wa;
    6.91  
    6.92  	for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
    6.93  		switch (argv[i][1]) {
    6.94 @@ -254,14 +246,11 @@
    6.95  
    6.96  	issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
    6.97  
    6.98 -	wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
    6.99 -					| LeaveWindowMask;
   6.100 +	wa.event_mask = SubstructureRedirectMask | EnterWindowMask | LeaveWindowMask;
   6.101  	wa.cursor = cursor[CurNormal];
   6.102 -
   6.103  	XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
   6.104  
   6.105  	strcpy(stext, "dwm-"VERSION);
   6.106 -
   6.107  	scan();
   6.108  
   6.109  	/* main event loop, reads status text from stdin as well */
     7.1 --- a/tag.c	Thu Jul 20 10:48:22 2006 +0200
     7.2 +++ b/tag.c	Thu Jul 20 12:18:06 2006 +0200
     7.3 @@ -20,9 +20,9 @@
     7.4  
     7.5  /* CUSTOMIZE */ 
     7.6  static Rule rule[] = {
     7.7 -	/* class			instance	tags		isfloat */
     7.8 -	{ "Firefox.*",	{ [Twww] = "www" },			False },
     7.9 -	{ "Gimp.*",		{ 0 },						True},
    7.10 +	/* class:instance	tags				isfloat */
    7.11 +	{ "Firefox.*",		{ [Twww] = "www" },		False },
    7.12 +	{ "Gimp.*",		{ 0 },				True},
    7.13  };
    7.14  
    7.15  /* extern */
    7.16 @@ -71,8 +71,8 @@
    7.17  void
    7.18  dotile(Arg *arg)
    7.19  {
    7.20 +	int n, i, w, h;
    7.21  	Client *c;
    7.22 -	int n, i, w, h;
    7.23  
    7.24  	w = sw - mw;
    7.25  	arrange = dotile;
    7.26 @@ -161,6 +161,7 @@
    7.27  replacetag(Arg *arg)
    7.28  {
    7.29  	int i;
    7.30 +
    7.31  	if(!sel)
    7.32  		return;
    7.33  
     8.1 --- a/util.c	Thu Jul 20 10:48:22 2006 +0200
     8.2 +++ b/util.c	Thu Jul 20 12:18:06 2006 +0200
     8.3 @@ -26,6 +26,7 @@
     8.4  emallocz(unsigned int size)
     8.5  {
     8.6  	void *res = calloc(1, size);
     8.7 +
     8.8  	if(!res)
     8.9  		bad_malloc(size);
    8.10  	return res;
    8.11 @@ -34,6 +35,7 @@
    8.12  void
    8.13  eprint(const char *errstr, ...) {
    8.14  	va_list ap;
    8.15 +
    8.16  	va_start(ap, errstr);
    8.17  	vfprintf(stderr, errstr, ap);
    8.18  	va_end(ap);
    8.19 @@ -44,6 +46,7 @@
    8.20  spawn(Arg *arg)
    8.21  {
    8.22  	char **argv = (char **)arg->argv;
    8.23 +
    8.24  	if(!argv || !argv[0])
    8.25  		return;
    8.26  	if(fork() == 0) {