 *** dwm.c	2011-05-30 00:05:45.926195438 -0500
---- DWM.c	2011-05-30 00:13:14.580431536 -0500
-***************
-*** 298,312 ****
-  		for(i = 0; i < LENGTH(rules); i++) {
-  			r = &rules[i];
-  			if((!r->title || strstr(c->name, r->title))
+--- DWM.c	2011-05-30 00:30:28.284831477 -0500
+***************
+*** 38,67 ****
+  #include <X11/Xutil.h>
+  #ifdef XINERAMA
+  #include <X11/extensions/Xinerama.h>
+! #endif /* XINERAMA */
+  
+- /* macros */
+  #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
+! #define CLEANMASK(mask)         (mask & ~(numlockmask|LockMask))
+! #define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
+! #define ISVISIBLE(C)            ((C->tags & C->mon->tagset[C->mon->seltags]))
+  #define LENGTH(X)               (sizeof X / sizeof X[0])
+! #define MAX(A, B)               ((A) > (B) ? (A) : (B))
+! #define MIN(A, B)               ((A) < (B) ? (A) : (B))
+  #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
+! #define WIDTH(X)                ((X)->w + 2 * (X)->bw)
+! #define HEIGHT(X)               ((X)->h + 2 * (X)->bw)
+  #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
+! #define TEXTW(X)                (textnw(X, strlen(X)) + dc.font.height)
+  
+! /* enums */
+! enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
+! enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
+! enum { NetSupported, NetWMName, NetWMState,
+!        NetWMFullscreen, NetLast };                      /* EWMH atoms */
+! enum { WMProtocols, WMDelete, WMState, WMLast };        /* default atoms */
+! enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
+!        ClkClientWin, ClkRootWin, ClkLast };             /* clicks */
+  
+  typedef union {
+  	int i;
+--- 38,65 ----
+  #include <X11/Xutil.h>
+  #ifdef XINERAMA
+  #include <X11/extensions/Xinerama.h>
+! #endif
+  
+  #define BUTTONMASK              (ButtonPressMask|ButtonReleaseMask)
+! #define CLEANMASK(mask)         (mask&~(numlockmask|LockMask))
+! #define INRECT(X,Y,RX,RY,RW,RH) ((X)>=(RX)&&(X)<(RX)(RW)&&(Y)>=(RY)&&(Y)<(RY)(RH))
+! #define ISVISIBLE(C)            ((C->tags&C->mon->tagset[C->mon->seltags]))
+  #define LENGTH(X)               (sizeof X / sizeof X[0])
+! #define MAX(A,B)               ((A)>(B)?(A):(B))
+! #define MIN(A,B)               ((A)<(B)?(A):(B))
+  #define MOUSEMASK               (BUTTONMASK|PointerMotionMask)
+! #define WIDTH(X)                ((X)->w2*(X)->bw)
+! #define HEIGHT(X)               ((X)->h2*(X)->bw)
+  #define TAGMASK                 ((1 << LENGTH(tags)) - 1)
+! #define TEXTW(X)                (textnw(X,strlen(X))dc.font.height)
+  
+! enum { CurNormal,CurResize,CurMove,CurLast };
+! enum { ColBorder,ColFG,ColBG,ColLast };
+! enum { NetSupported,NetWMName,NetWMState,
+!        NetWMFullscreen,NetLast };
+! enum { WMProtocols,WMDelete,WMState,WMLast };
+! enum { ClkTagBar,ClkLtSymbol,ClkStatusText,ClkWinTitle,
+!        ClkClientWin,ClkRootWin,ClkLast };
+  
+  typedef union {
+  	int i;
+***************
+*** 82,94 ****
+  typedef struct Client Client;
+  struct Client {
+  	char name[256];
+! 	float mina, maxa;
+! 	int x, y, w, h;
+! 	int oldx, oldy, oldw, oldh;
+! 	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
+! 	int bw, oldbw;
+  	unsigned int tags;
+! 	Bool isfixed, isfloating, isurgent, oldstate;
+  	Client *next;
+  	Client *snext;
+  	Monitor *mon;
+--- 80,92 ----
+  typedef struct Client Client;
+  struct Client {
+  	char name[256];
+! 	float mina,maxa;
+! 	int x,y,w,h;
+! 	int oldx,oldy,oldw,oldh;
+! 	int basew,baseh,incw,inch,maxw,maxh,minw,minh;
+! 	int bw,oldbw;
+  	unsigned int tags;
+! 	Bool isfixed,isfloating,isurgent,oldstate;
+  	Client *next;
+  	Client *snext;
+  	Monitor *mon;
+***************
+*** 96,102 ****
+  };
+  
+  typedef struct {
+! 	int x, y, w, h;
+  	unsigned long norm[ColLast];
+  	unsigned long sel[ColLast];
+  	Drawable drawable;
+--- 94,100 ----
+  };
+  
+  typedef struct {
+! 	int x,y,w,h;
+  	unsigned long norm[ColLast];
+  	unsigned long sel[ColLast];
+  	Drawable drawable;
+***************
+*** 108,114 ****
+  		XFontSet set;
+  		XFontStruct *xfont;
+  	} font;
+! } DC; /* draw context */
+  
+  typedef struct {
+  	unsigned int mod;
+--- 106,112 ----
+  		XFontSet set;
+  		XFontStruct *xfont;
+  	} font;
+! } DC;
+  
+  typedef struct {
+  	unsigned int mod;
+***************
+*** 126,134 ****
+  	char ltsymbol[16];
+  	float mfact;
+  	int num;
+! 	int by;               /* bar geometry */
+! 	int mx, my, mw, mh;   /* screen size */
+! 	int wx, wy, ww, wh;   /* window area  */
+  	unsigned int seltags;
+  	unsigned int sellt;
+  	unsigned int tagset[2];
+--- 124,132 ----
+  	char ltsymbol[16];
+  	float mfact;
+  	int num;
+! 	int by;
+! 	int mx,my,mw,mh;
+! 	int wx,wy,ww,wh;
+  	unsigned int seltags;
+  	unsigned int sellt;
+  	unsigned int tagset[2];
+***************
+*** 151,159 ****
+  	int monitor;
+  } Rule;
+  
+- /* function declarations */
+  static void applyrules(Client *c);
+! static Bool applysizehints(Client *c, int *x, int *y, int *w, int *h, Bool interact);
+  static void arrange(Monitor *m);
+  static void arrangemon(Monitor *m);
+  static void attach(Client *c);
+--- 149,156 ----
+  	int monitor;
+  } Rule;
+  
+  static void applyrules(Client *c);
+! static Bool applysizehints(Client *c,int *x,int *y,int *w,int *h,Bool interact);
+  static void arrange(Monitor *m);
+  static void arrangemon(Monitor *m);
+  static void attach(Client *c);
+***************
+*** 171,182 ****
+  static void destroynotify(XEvent *e);
+  static void detach(Client *c);
+  static void detachstack(Client *c);
+! static void die(const char *errstr, ...);
+  static Monitor *dirtomon(int dir);
+  static void drawbar(Monitor *m);
+  static void drawbars(void);
+! static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
+! static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
+  static void enternotify(XEvent *e);
+  static void expose(XEvent *e);
+  static void focus(Client *c);
+--- 168,179 ----
+  static void destroynotify(XEvent *e);
+  static void detach(Client *c);
+  static void detachstack(Client *c);
+! static void die(const char *errstr,...);
+  static Monitor *dirtomon(int dir);
+  static void drawbar(Monitor *m);
+  static void drawbars(void);
+! static void drawsquare(Bool filled,Bool empty,Bool invert,unsigned long col[ColLast]);
+! static void drawtext(const char *text,unsigned long col[ColLast],Bool invert);
+  static void enternotify(XEvent *e);
+  static void expose(XEvent *e);
+  static void focus(Client *c);
+***************
+*** 184,215 ****
+  static void focusmon(const Arg *arg);
+  static void focusstack(const Arg *arg);
+  static unsigned long getcolor(const char *colstr);
+! static Bool getrootptr(int *x, int *y);
+  static long getstate(Window w);
+! static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
+! static void grabbuttons(Client *c, Bool focused);
+  static void grabkeys(void);
+  static void initfont(const char *fontstr);
+  static Bool isprotodel(Client *c);
+  static void keypress(XEvent *e);
+  static void killclient(const Arg *arg);
+! static void manage(Window w, XWindowAttributes *wa);
+  static void mappingnotify(XEvent *e);
+  static void maprequest(XEvent *e);
+  static void monocle(Monitor *m);
+  static void movemouse(const Arg *arg);
+  static Client *nexttiled(Client *c);
+! static Monitor *ptrtomon(int x, int y);
+  static void propertynotify(XEvent *e);
+  static void quit(const Arg *arg);
+! static void resize(Client *c, int x, int y, int w, int h, Bool interact);
+! static void resizeclient(Client *c, int x, int y, int w, int h);
+  static void resizemouse(const Arg *arg);
+  static void restack(Monitor *m);
+  static void run(void);
+  static void scan(void);
+! static void sendmon(Client *c, Monitor *m);
+! static void setclientstate(Client *c, long state);
+  static void setlayout(const Arg *arg);
+  static void setmfact(const Arg *arg);
+  static void setup(void);
+--- 181,212 ----
+  static void focusmon(const Arg *arg);
+  static void focusstack(const Arg *arg);
+  static unsigned long getcolor(const char *colstr);
+! static Bool getrootptr(int *x,int *y);
+  static long getstate(Window w);
+! static Bool gettextprop(Window w,Atom atom,char *text,unsigned int size);
+! static void grabbuttons(Client *c,Bool focused);
+  static void grabkeys(void);
+  static void initfont(const char *fontstr);
+  static Bool isprotodel(Client *c);
+  static void keypress(XEvent *e);
+  static void killclient(const Arg *arg);
+! static void manage(Window w,XWindowAttributes *wa);
+  static void mappingnotify(XEvent *e);
+  static void maprequest(XEvent *e);
+  static void monocle(Monitor *m);
+  static void movemouse(const Arg *arg);
+  static Client *nexttiled(Client *c);
+! static Monitor *ptrtomon(int x,int y);
+  static void propertynotify(XEvent *e);
+  static void quit(const Arg *arg);
+! static void resize(Client *c,int x,int y,int w,int h,Bool interact);
+! static void resizeclient(Client *c,int x,int y,int w,int h);
+  static void resizemouse(const Arg *arg);
+  static void restack(Monitor *m);
+  static void run(void);
+  static void scan(void);
+! static void sendmon(Client *c,Monitor *m);
+! static void setclientstate(Client *c,long state);
+  static void setlayout(const Arg *arg);
+  static void setmfact(const Arg *arg);
+  static void setup(void);
+***************
+*** 218,231 ****
+  static void spawn(const Arg *arg);
+  static void tag(const Arg *arg);
+  static void tagmon(const Arg *arg);
+! static int textnw(const char *text, unsigned int len);
+  static void tile(Monitor *);
+  static void togglebar(const Arg *arg);
+  static void togglefloating(const Arg *arg);
+  static void toggletag(const Arg *arg);
+  static void toggleview(const Arg *arg);
+! static void unfocus(Client *c, Bool setfocus);
+! static void unmanage(Client *c, Bool destroyed);
+  static void unmapnotify(XEvent *e);
+  static Bool updategeom(void);
+  static void updatebarpos(Monitor *m);
+--- 215,228 ----
+  static void spawn(const Arg *arg);
+  static void tag(const Arg *arg);
+  static void tagmon(const Arg *arg);
+! static int textnw(const char *text,unsigned int len);
+  static void tile(Monitor *);
+  static void togglebar(const Arg *arg);
+  static void togglefloating(const Arg *arg);
+  static void toggletag(const Arg *arg);
+  static void toggleview(const Arg *arg);
+! static void unfocus(Client *c,Bool setfocus);
+! static void unmanage(Client *c,Bool destroyed);
+  static void unmapnotify(XEvent *e);
+  static Bool updategeom(void);
+  static void updatebarpos(Monitor *m);
+***************
+*** 238,405 ****
+  static void view(const Arg *arg);
+  static Client *wintoclient(Window w);
+  static Monitor *wintomon(Window w);
+! static int xerror(Display *dpy, XErrorEvent *ee);
+! static int xerrordummy(Display *dpy, XErrorEvent *ee);
+! static int xerrorstart(Display *dpy, XErrorEvent *ee);
+  static void zoom(const Arg *arg);
+  
+! /* variables */
+! static const char broken[] = "broken";
+  static char stext[256];
+  static int screen;
+! static int sw, sh;           /* X display screen geometry width, height */
+! static int bh, blw = 0;      /* bar geometry */
+! static int (*xerrorxlib)(Display *, XErrorEvent *);
+! static unsigned int numlockmask = 0;
+! static void (*handler[LASTEvent]) (XEvent *) = {
+! 	[ButtonPress] = buttonpress,
+! 	[ClientMessage] = clientmessage,
+! 	[ConfigureRequest] = configurerequest,
+! 	[ConfigureNotify] = configurenotify,
+! 	[DestroyNotify] = destroynotify,
+! 	[EnterNotify] = enternotify,
+! 	[Expose] = expose,
+! 	[FocusIn] = focusin,
+! 	[KeyPress] = keypress,
+! 	[MappingNotify] = mappingnotify,
+! 	[MapRequest] = maprequest,
+! 	[PropertyNotify] = propertynotify,
+! 	[UnmapNotify] = unmapnotify
+  };
+! static Atom wmatom[WMLast], netatom[NetLast];
+  static Bool otherwm;
+! static Bool running = True;
+  static Cursor cursor[CurLast];
+  static Display *dpy;
+  static DC dc;
+! static Monitor *mons = NULL, *selmon = NULL;
+  static Window root;
+  
+- /* configuration, allows nested code to access above variables */
+  #include "config.h"
+  
+! /* compile-time check if all tags fit into an unsigned int bit array. */
+! struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
+  
+- /* function implementations */
+  void
+  applyrules(Client *c) {
+! 	const char *class, *instance;
+  	unsigned int i;
+  	const Rule *r;
+  	Monitor *m;
+! 	XClassHint ch = { 0 };
+  
+! 	/* rule matching */
+! 	c->isfloating = c->tags = 0;
+! 	if(XGetClassHint(dpy, c->win, &ch)) {
+! 		class = ch.res_class ? ch.res_class : broken;
+! 		instance = ch.res_name ? ch.res_name : broken;
+! 		for(i = 0; i < LENGTH(rules); i++) {
+! 			r = &rules[i];
+! 			if((!r->title || strstr(c->name, r->title))
 ! 			&& (!r->class || strstr(class, r->class))
 ! 			&& (!r->instance || strstr(instance, r->instance)))
 ! 			{

  		}
- 	}
  	if(dirty) {
  		selmon = mons;
  		selmon = wintomon(root);
--- 1844,1860 ----
  	}
  	else
  #endif /* XINERAMA */
! 		/* default monitor setup */
! 		{
! 			if(!mons)
! 				mons = createmon();
! 			if(mons->mw != sw || mons->mh != sh) {
! 				dirty = True;
! 				mons->mw = mons->ww = sw;
! 				mons->mh = mons->wh = sh;
! 				updatebarpos(mons);
! 			}
  		}
  	if(dirty) {
  		selmon = mons;
  		selmon = wintomon(root);
***************
*** 1924,1930 ****
  	else
  		c->maxa = c->mina = 0.0;
  	c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
! 	             && c->maxw == c->minw && c->maxh == c->minh);
  }
  
  void
--- 1924,1930 ----
  	else
  		c->maxa = c->mina = 0.0;
  	c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
! 								&& c->maxw == c->minw && c->maxh == c->minh);
  }
  
  void
***************
*** 2001,2017 ****
  int
  xerror(Display *dpy, XErrorEvent *ee) {
  	if(ee->error_code == BadWindow
! 	|| (ee->request_code == X_SetInputFocus && ee->error_code == BadMatch)
! 	|| (ee->request_code == X_PolyText8 && ee->error_code == BadDrawable)
! 	|| (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)

! 	|| (ee->request_code == X_GrabKey && ee->error_code == BadAccess)
! 	|| (ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
  		return 0;
! 	fprintf(stderr, "dwm: fatal error: request code=%d, error code=%d\n",
! 			ee->request_code, ee->error_code);
! 	return xerrorxlib(dpy, ee); /* may call exit */
  }
  
  int
! xerrordummy(Display *dpy, XErrorEvent *ee) {
  	return 0;
  }
  
- /* Startup Error handler to check if another window manager
-  * is already running. */
  int
! xerrorstart(Display *dpy, XErrorEvent *ee) {
! 	otherwm = True;
  	return -1;
  }
  
  void
  zoom(const Arg *arg) {
! 	Client *c = selmon->sel;
  
  	if(!selmon->lt[selmon->sellt]->arrange
! 	|| selmon->lt[selmon->sellt]->arrange == monocle
! 	|| (selmon->sel && selmon->sel->isfloating))
  		return;
! 	if(c == nexttiled(selmon->clients))
! 		if(!c || !(c = nexttiled(c->next)))
  			return;
  	detach(c);
  	attach(c);
--- 1938,2004 ----
  	Client *c;
  	Monitor *m;
  
! 	for(m=mons;m;m=m->next)
! 		for(c=m->clients;c;c=c->next)
! 			if(c->win==w)
  				return c;
  	return NULL;
  }
  
  Monitor *
  wintomon(Window w) {
! 	int x,y;
  	Client *c;
  	Monitor *m;
  
! 	if(w==root&&getrootptr(&x,&y))
! 		return ptrtomon(x,y);
! 	for(m=mons;m;m=m->next)
! 		if(w==m->barwin)
  			return m;
! 	if((c=wintoclient(w)))
  		return c->mon;
  	return selmon;
  }
  
  int
! xerror(Display *dpy,XErrorEvent *ee) {
! 	if(ee->error_code==BadWindow
! 		 ||(ee->request_code==X_SetInputFocus&&ee->error_code==BadMatch)
! 		 ||(ee->request_code==X_PolyText8&&ee->error_code==BadDrawable)
! 		 ||(ee->request_code==X_PolyFillRectangle&&ee->error_code==BadDrawable)
! 		 ||(ee->request_code==X_PolySegment&&ee->error_code==BadDrawable)
! 		 ||(ee->request_code==X_ConfigureWindow&&ee->error_code==BadMatch)
! 		 ||(ee->request_code==X_GrabButton&&ee->error_code==BadAccess)
! 		 ||(ee->request_code==X_GrabKey&&ee->error_code==BadAccess)
! 		 ||(ee->request_code==X_CopyArea&&ee->error_code==BadDrawable))
  		return 0;
! 	fprintf(stderr,"dwm: fatal error: request code=%d,error code=%d\n",
! 					ee->request_code,ee->error_code);
! 	return xerrorxlib(dpy,ee);
  }
  
  int
! xerrordummy(Display *dpy,XErrorEvent *ee) {
  	return 0;
  }
  
  int
! xerrorstart(Display *dpy,XErrorEvent *ee) {
! 	otherwm=True;
  	return -1;
  }
  
  void
  zoom(const Arg *arg) {
! 	Client *c=selmon->sel;
  
  	if(!selmon->lt[selmon->sellt]->arrange
! 		 ||selmon->lt[selmon->sellt]->arrange==monocle
! 		 ||(selmon->sel&&selmon->sel->isfloating))
  		return;
! 	if(c==nexttiled(selmon->clients))
! 		if(!c||!(c=nexttiled(c->next)))
  			return;
  	detach(c);
  	attach(c);
***************
*** 2046,2059 ****
  }
  
  int
! main(int argc, char *argv[]) {
! 	if(argc == 2 && !strcmp("-v", argv[1]))
! 		die("dwm-"VERSION", © 2006-2010 dwm engineers, see LICENSE for details\n");
  	else if(argc != 1)
  		die("usage: dwm [-v]\n");
! 	if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
! 		fputs("warning: no locale support\n", stderr);
! 	if(!(dpy = XOpenDisplay(NULL)))
  		die("dwm: cannot open display\n");
  	checkotherwm();
  	setup();
--- 2007,2020 ----
  }
  
  int
! main(int argc,char *argv[]) {
! 	if(argc==2&&!strcmp("-v",argv[1]))
! 		die("dwm-"VERSION",© 2006-2010 dwm engineers,see LICENSE for details\n");
  	else if(argc != 1)
  		die("usage: dwm [-v]\n");
! 	if(!setlocale(LC_CTYPE,"")||!XSupportsLocale())
! 		fputs("warning: no locale support\n",stderr);
! 	if(!(dpy=XOpenDisplay(NULL)))
  		die("dwm: cannot open display\n");
  	checkotherwm();
  	setup();
