dwm.c
changeset 1491 4754e7889841
parent 1489 9f79d36bd5e0
child 1492 62a601261c8b
equal deleted inserted replaced
1490:e3492f42fc39 1491:4754e7889841
   119 	const char *symbol;
   119 	const char *symbol;
   120 	void (*arrange)(Monitor *);
   120 	void (*arrange)(Monitor *);
   121 } Layout;
   121 } Layout;
   122 
   122 
   123 struct Monitor {
   123 struct Monitor {
       
   124 	const char *ltsymbol;
   124 	float mfact;
   125 	float mfact;
   125 	int num;
   126 	int num;
   126 	int by;               /* bar geometry */
   127 	int by;               /* bar geometry */
   127 	int mx, my, mw, mh;   /* screen size */
   128 	int mx, my, mw, mh;   /* screen size */
   128 	int wx, wy, ww, wh;   /* window area  */
   129 	int wx, wy, ww, wh;   /* window area  */
   236 static int xerrorstart(Display *dpy, XErrorEvent *ee);
   237 static int xerrorstart(Display *dpy, XErrorEvent *ee);
   237 static void zoom(const Arg *arg);
   238 static void zoom(const Arg *arg);
   238 
   239 
   239 /* variables */
   240 /* variables */
   240 static const char broken[] = "broken";
   241 static const char broken[] = "broken";
   241 static char stext[256], ntext[8];
   242 static char stext[256];
   242 static int screen;
   243 static int screen;
   243 static int sw, sh;           /* X display screen geometry width, height */
   244 static int sw, sh;           /* X display screen geometry width, height */
   244 static int bh, blw = 0;      /* bar geometry */
   245 static int bh, blw = 0;      /* bar geometry */
   245 static int (*xerrorxlib)(Display *, XErrorEvent *);
   246 static int (*xerrorxlib)(Display *, XErrorEvent *);
   246 static unsigned int numlockmask = 0;
   247 static unsigned int numlockmask = 0;
   382 
   383 
   383 	for(m = mons; m; m = m->next)
   384 	for(m = mons; m; m = m->next)
   384 		showhide(m->stack);
   385 		showhide(m->stack);
   385 	focus(NULL);
   386 	focus(NULL);
   386 	for(m = mons; m; m = m->next) {
   387 	for(m = mons; m; m = m->next) {
       
   388 		m->ltsymbol = m->lt[m->sellt]->symbol;
   387 		if(m->lt[m->sellt]->arrange)
   389 		if(m->lt[m->sellt]->arrange)
   388 			m->lt[m->sellt]->arrange(m);
   390 			m->lt[m->sellt]->arrange(m);
   389 		restack(m);
   391 		restack(m);
   390 	}
   392 	}
   391 }
   393 }
   647 }
   649 }
   648 
   650 
   649 void
   651 void
   650 drawbar(Monitor *m) {
   652 drawbar(Monitor *m) {
   651 	int x;
   653 	int x;
   652 	unsigned int i, n = 0, occ = 0, urg = 0;
   654 	unsigned int i, occ = 0, urg = 0;
   653 	unsigned long *col;
   655 	unsigned long *col;
   654 	Client *c;
   656 	Client *c;
   655 
   657 
   656 	for(c = m->clients; c; c = c->next) {
   658 	for(c = m->clients; c; c = c->next) {
   657 		if(ISVISIBLE(c))
       
   658 			n++;
       
   659 		occ |= c->tags;
   659 		occ |= c->tags;
   660 		if(c->isurgent)
   660 		if(c->isurgent)
   661 			urg |= c->tags;
   661 			urg |= c->tags;
   662 	}
   662 	}
   663 	dc.x = 0;
   663 	dc.x = 0;
   667 		drawtext(tags[i], col, urg & 1 << i);
   667 		drawtext(tags[i], col, urg & 1 << i);
   668 		drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
   668 		drawsquare(m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
   669 		           occ & 1 << i, urg & 1 << i, col);
   669 		           occ & 1 << i, urg & 1 << i, col);
   670 		dc.x += dc.w;
   670 		dc.x += dc.w;
   671 	}
   671 	}
   672 	if(blw > 0) {
   672 	dc.w = blw = TEXTW(m->ltsymbol);
   673 		dc.w = blw;
   673 	drawtext(m->ltsymbol, dc.norm, False);
   674 		drawtext(m->lt[m->sellt]->symbol, dc.norm, False);
   674 	dc.x += dc.w;
   675 		dc.x += dc.w;
   675 	x = dc.x;
   676 	}
       
   677 	snprintf(ntext, sizeof ntext, "%u", n);
       
   678 	dc.w = TEXTW(ntext);
       
   679 	drawtext(ntext, dc.norm, False);
       
   680 	x = (dc.x += dc.w);
       
   681 	if(m == selmon) { /* status is only drawn on selected monitor */
   676 	if(m == selmon) { /* status is only drawn on selected monitor */
   682 		dc.w = TEXTW(stext);
   677 		dc.w = TEXTW(stext);
   683 		dc.x = m->ww - dc.w;
   678 		dc.x = m->ww - dc.w;
   684 		if(dc.x < x) {
   679 		if(dc.x < x) {
   685 			dc.x = x;
   680 			dc.x = x;
  1135 		manage(ev->window, &wa);
  1130 		manage(ev->window, &wa);
  1136 }
  1131 }
  1137 
  1132 
  1138 void
  1133 void
  1139 monocle(Monitor *m) {
  1134 monocle(Monitor *m) {
       
  1135 	static char ntext[8];
       
  1136 	unsigned int n = 0;
  1140 	Client *c;
  1137 	Client *c;
  1141 
  1138 
       
  1139 	for(c = m->clients; c; c = c->next)
       
  1140 		if(ISVISIBLE(c))
       
  1141 			n++;
       
  1142 	if(n > 0) { /* override layout symbol */
       
  1143 		snprintf(ntext, sizeof ntext, "[%d]", n);
       
  1144 		m->ltsymbol = ntext;
       
  1145 	}
  1142 	for(c = nexttiled(m->clients); c; c = nexttiled(c->next))
  1146 	for(c = nexttiled(m->clients); c; c = nexttiled(c->next))
  1143 		resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, False);
  1147 		resize(c, m->wx, m->wy, m->ww - 2 * c->bw, m->wh - 2 * c->bw, False);
  1144 }
  1148 }
  1145 
  1149 
  1146 void
  1150 void
  1429 	arrange();
  1433 	arrange();
  1430 }
  1434 }
  1431 
  1435 
  1432 void
  1436 void
  1433 setup(void) {
  1437 setup(void) {
  1434 	unsigned int i;
       
  1435 	int w;
       
  1436 	XSetWindowAttributes wa;
  1438 	XSetWindowAttributes wa;
  1437 
  1439 
  1438 	/* clean up any zombies immediately */
  1440 	/* clean up any zombies immediately */
  1439 	sigchld(0);
  1441 	sigchld(0);
  1440 
  1442 
  1467 	dc.gc = XCreateGC(dpy, root, 0, NULL);
  1469 	dc.gc = XCreateGC(dpy, root, 0, NULL);
  1468 	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
  1470 	XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
  1469 	if(!dc.font.set)
  1471 	if(!dc.font.set)
  1470 		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
  1472 		XSetFont(dpy, dc.gc, dc.font.xfont->fid);
  1471 	/* init bars */
  1473 	/* init bars */
  1472 	for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
       
  1473 		w = TEXTW(layouts[i].symbol);
       
  1474 		blw = MAX(blw, w);
       
  1475 	}
       
  1476 	updatebars();
  1474 	updatebars();
  1477 	updatestatus();
  1475 	updatestatus();
  1478 	/* EWMH support per view */
  1476 	/* EWMH support per view */
  1479 	XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
  1477 	XChangeProperty(dpy, root, netatom[NetSupported], XA_ATOM, 32,
  1480 			PropModeReplace, (unsigned char *) netatom, NetLast);
  1478 			PropModeReplace, (unsigned char *) netatom, NetLast);
  1750 		m->mfact = mfact;
  1748 		m->mfact = mfact;
  1751 		m->showbar = showbar;
  1749 		m->showbar = showbar;
  1752 		m->topbar = topbar;
  1750 		m->topbar = topbar;
  1753 		m->lt[0] = &layouts[0];
  1751 		m->lt[0] = &layouts[0];
  1754 		m->lt[1] = &layouts[1 % LENGTH(layouts)];
  1752 		m->lt[1] = &layouts[1 % LENGTH(layouts)];
       
  1753 		m->ltsymbol = layouts[0].symbol;
  1755 		updatebarpos(m);
  1754 		updatebarpos(m);
  1756 	}
  1755 	}
  1757 	/* reassign left over clients of disappeared monitors */
  1756 	/* reassign left over clients of disappeared monitors */
  1758 	for(tm = mons; tm; tm = tm->next)
  1757 	for(tm = mons; tm; tm = tm->next)
  1759 		while(tm->clients) {
  1758 		while(tm->clients) {