dwm.c
changeset 1026 bc0929d03388
parent 1025 107746bd83f0
child 1027 0735e86bbd49
equal deleted inserted replaced
1025:107746bd83f0 1026:bc0929d03388
    55 enum { NetSupported, NetWMName, NetLast };		/* EWMH atoms */
    55 enum { NetSupported, NetWMName, NetLast };		/* EWMH atoms */
    56 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
    56 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
    57 
    57 
    58 /* typedefs */
    58 /* typedefs */
    59 typedef struct Client Client;
    59 typedef struct Client Client;
    60 struct Client {
       
    61 	char name[256];
       
    62 	int x, y, w, h;
       
    63 	int rx, ry, rw, rh; /* revert geometry */
       
    64 	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
       
    65 	int minax, maxax, minay, maxay;
       
    66 	long flags;
       
    67 	unsigned int border, oldborder;
       
    68 	Bool isbanned, isfixed, ismax, isfloating, wasfloating;
       
    69 	Bool *tags;
       
    70 	Client *next;
       
    71 	Client *prev;
       
    72 	Client *snext;
       
    73 	Window win;
       
    74 };
       
    75 
    60 
    76 typedef struct {
    61 typedef struct {
    77 	int x, y, w, h;
    62 	int x, y, w, h;
    78 	unsigned long norm[ColLast];
    63 	unsigned long norm[ColLast];
    79 	unsigned long sel[ColLast];
    64 	unsigned long sel[ColLast];
   193 /* variables */
   178 /* variables */
   194 char stext[256];
   179 char stext[256];
   195 double mwfact;
   180 double mwfact;
   196 int screen, sx, sy, sw, sh, wax, way, waw, wah;
   181 int screen, sx, sy, sw, sh, wax, way, waw, wah;
   197 int (*xerrorxlib)(Display *, XErrorEvent *);
   182 int (*xerrorxlib)(Display *, XErrorEvent *);
   198 unsigned int bh, bpos, ntags;
   183 unsigned int bh, bpos;
   199 unsigned int blw = 0;
   184 unsigned int blw = 0;
   200 unsigned int ltidx = 0; /* default */
   185 unsigned int ltidx = 0; /* default */
   201 unsigned int nlayouts = 0;
   186 unsigned int nlayouts = 0;
   202 unsigned int nrules = 0;
   187 unsigned int nrules = 0;
   203 unsigned int numlockmask = 0;
   188 unsigned int numlockmask = 0;
   216 	[UnmapNotify] = unmapnotify
   201 	[UnmapNotify] = unmapnotify
   217 };
   202 };
   218 Atom wmatom[WMLast], netatom[NetLast];
   203 Atom wmatom[WMLast], netatom[NetLast];
   219 Bool otherwm, readin;
   204 Bool otherwm, readin;
   220 Bool running = True;
   205 Bool running = True;
   221 Bool *seltags;
       
   222 Bool selscreen = True;
   206 Bool selscreen = True;
   223 Client *clients = NULL;
   207 Client *clients = NULL;
   224 Client *sel = NULL;
   208 Client *sel = NULL;
   225 Client *stack = NULL;
   209 Client *stack = NULL;
   226 Cursor cursor[CurLast];
   210 Cursor cursor[CurLast];
   229 Window barwin, root;
   213 Window barwin, root;
   230 Regs *regs = NULL;
   214 Regs *regs = NULL;
   231 
   215 
   232 /* configuration, allows nested code to access above variables */
   216 /* configuration, allows nested code to access above variables */
   233 #include "config.h"
   217 #include "config.h"
       
   218 
       
   219 /* Statically define the number of tags. */
       
   220 unsigned int ntags = sizeof tags / sizeof tags[0];
       
   221 Bool seltags[sizeof tags / sizeof tags[0]] = {[0] = True};
       
   222 
       
   223 struct Client {
       
   224 	char name[256];
       
   225 	int x, y, w, h;
       
   226 	int rx, ry, rw, rh; /* revert geometry */
       
   227 	int basew, baseh, incw, inch, maxw, maxh, minw, minh;
       
   228 	int minax, maxax, minay, maxay;
       
   229 	long flags;
       
   230 	unsigned int border, oldborder;
       
   231 	Bool isbanned, isfixed, ismax, isfloating, wasfloating;
       
   232 	Bool tags[sizeof tags / sizeof tags[0]];
       
   233 	Client *next;
       
   234 	Client *prev;
       
   235 	Client *snext;
       
   236 	Window win;
       
   237 };
   234 
   238 
   235 /* functions*/
   239 /* functions*/
   236 void
   240 void
   237 applyrules(Client *c) {
   241 applyrules(Client *c) {
   238 	static char buf[512];
   242 	static char buf[512];
   391 	XFreeCursor(dpy, cursor[CurNormal]);
   395 	XFreeCursor(dpy, cursor[CurNormal]);
   392 	XFreeCursor(dpy, cursor[CurResize]);
   396 	XFreeCursor(dpy, cursor[CurResize]);
   393 	XFreeCursor(dpy, cursor[CurMove]);
   397 	XFreeCursor(dpy, cursor[CurMove]);
   394 	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
   398 	XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
   395 	XSync(dpy, False);
   399 	XSync(dpy, False);
   396 	free(seltags);
       
   397 }
   400 }
   398 
   401 
   399 void
   402 void
   400 compileregs(void) {
   403 compileregs(void) {
   401 	unsigned int i;
   404 	unsigned int i;
  1004 	Window trans;
  1007 	Window trans;
  1005 	Status rettrans;
  1008 	Status rettrans;
  1006 	XWindowChanges wc;
  1009 	XWindowChanges wc;
  1007 
  1010 
  1008 	c = emallocz(sizeof(Client));
  1011 	c = emallocz(sizeof(Client));
  1009 	c->tags = emallocz(ntags * sizeof(Bool));
       
  1010 	c->win = w;
  1012 	c->win = w;
  1011 	c->x = wa->x;
  1013 	c->x = wa->x;
  1012 	c->y = wa->y;
  1014 	c->y = wa->y;
  1013 	c->w = wa->width;
  1015 	c->w = wa->width;
  1014 	c->h = wa->height;
  1016 	c->h = wa->height;
  1465 	/* grab keys */
  1467 	/* grab keys */
  1466 	keypress(NULL);
  1468 	keypress(NULL);
  1467 
  1469 
  1468 	/* init tags */
  1470 	/* init tags */
  1469 	compileregs();
  1471 	compileregs();
  1470 	ntags = sizeof tags / sizeof tags[0];
       
  1471 	seltags = emallocz(sizeof(Bool) * ntags);
       
  1472 	seltags[0] = True;
       
  1473 
  1472 
  1474 	/* init appearance */
  1473 	/* init appearance */
  1475 	dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR);
  1474 	dc.norm[ColBorder] = getcolor(NORMBORDERCOLOR);
  1476 	dc.norm[ColBG] = getcolor(NORMBGCOLOR);
  1475 	dc.norm[ColBG] = getcolor(NORMBGCOLOR);
  1477 	dc.norm[ColFG] = getcolor(NORMFGCOLOR);
  1476 	dc.norm[ColFG] = getcolor(NORMFGCOLOR);
  1701 	detachstack(c);
  1700 	detachstack(c);
  1702 	if(sel == c)
  1701 	if(sel == c)
  1703 		focus(NULL);
  1702 		focus(NULL);
  1704 	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
  1703 	XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
  1705 	setclientstate(c, WithdrawnState);
  1704 	setclientstate(c, WithdrawnState);
  1706 	free(c->tags);
       
  1707 	free(c);
  1705 	free(c);
  1708 	XSync(dpy, False);
  1706 	XSync(dpy, False);
  1709 	XSetErrorHandler(xerror);
  1707 	XSetErrorHandler(xerror);
  1710 	XUngrabServer(dpy);
  1708 	XUngrabServer(dpy);
  1711 	arrange();
  1709 	arrange();