dwm.c
changeset 1220 6603d83d133d
parent 1219 455e795c1c38
child 1222 6e2f71b72e51
equal deleted inserted replaced
1219:455e795c1c38 1220:6603d83d133d
    51 #define LENGTH(x)       (sizeof x / sizeof x[0])
    51 #define LENGTH(x)       (sizeof x / sizeof x[0])
    52 #define MAXTAGLEN       16
    52 #define MAXTAGLEN       16
    53 #define MOUSEMASK       (BUTTONMASK|PointerMotionMask)
    53 #define MOUSEMASK       (BUTTONMASK|PointerMotionMask)
    54 
    54 
    55 /* enums */
    55 /* enums */
    56 enum { BarTop, BarBot, BarOff, BarLast };               /* bar appearance */
       
    57 enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
    56 enum { CurNormal, CurResize, CurMove, CurLast };        /* cursor */
    58 enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
    57 enum { ColBorder, ColFG, ColBG, ColLast };              /* color */
    59 enum { NetSupported, NetWMName, NetLast };              /* EWMH atoms */
    58 enum { NetSupported, NetWMName, NetLast };              /* EWMH atoms */
    60 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
    59 enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
    61 
    60 
   163 void resizemouse(Client *c);
   162 void resizemouse(Client *c);
   164 void restack(void);
   163 void restack(void);
   165 void run(void);
   164 void run(void);
   166 void scan(void);
   165 void scan(void);
   167 void setclientstate(Client *c, long state);
   166 void setclientstate(Client *c, long state);
       
   167 void setmfact(const char *arg);
   168 void setup(void);
   168 void setup(void);
   169 void spawn(const char *arg);
   169 void spawn(const char *arg);
   170 void tag(const char *arg);
   170 void tag(const char *arg);
   171 unsigned int textnw(const char *text, unsigned int len);
   171 unsigned int textnw(const char *text, unsigned int len);
   172 unsigned int textw(const char *text);
   172 unsigned int textw(const char *text);
       
   173 void tile(void);
       
   174 void tileresize(Client *c, int x, int y, int w, int h);
   173 void togglebar(const char *arg);
   175 void togglebar(const char *arg);
   174 void togglefloating(const char *arg);
   176 void togglefloating(const char *arg);
   175 void togglelayout(const char *arg);
   177 void togglelayout(const char *arg);
   176 void toggletag(const char *arg);
   178 void toggletag(const char *arg);
   177 void toggleview(const char *arg);
   179 void toggleview(const char *arg);
   179 void unmanage(Client *c);
   181 void unmanage(Client *c);
   180 void unmapnotify(XEvent *e);
   182 void unmapnotify(XEvent *e);
   181 void updatebar(void);
   183 void updatebar(void);
   182 void updategeom(void);
   184 void updategeom(void);
   183 void updatesizehints(Client *c);
   185 void updatesizehints(Client *c);
       
   186 void updatetilegeom(void);
   184 void updatetitle(Client *c);
   187 void updatetitle(Client *c);
   185 void updatewmhints(Client *c);
   188 void updatewmhints(Client *c);
   186 void view(const char *arg);
   189 void view(const char *arg);
   187 void viewprevtag(const char *arg);
   190 void viewprevtag(const char *arg);
   188 int xerror(Display *dpy, XErrorEvent *ee);
   191 int xerror(Display *dpy, XErrorEvent *ee);
   192 
   195 
   193 /* variables */
   196 /* variables */
   194 char stext[256];
   197 char stext[256];
   195 int screen, sx, sy, sw, sh;
   198 int screen, sx, sy, sw, sh;
   196 int bx, by, bw, bh, blw, wx, wy, ww, wh;
   199 int bx, by, bw, bh, blw, wx, wy, ww, wh;
       
   200 int mx, my, mw, mh, tx, ty, tw, th;
   197 int seltags = 0;
   201 int seltags = 0;
   198 int (*xerrorxlib)(Display *, XErrorEvent *);
   202 int (*xerrorxlib)(Display *, XErrorEvent *);
   199 unsigned int numlockmask = 0;
   203 unsigned int numlockmask = 0;
   200 void (*handler[LASTEvent]) (XEvent *) = {
   204 void (*handler[LASTEvent]) (XEvent *) = {
   201 	[ButtonPress] = buttonpress,
   205 	[ButtonPress] = buttonpress,
  1331 	XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
  1335 	XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
  1332 			PropModeReplace, (unsigned char *)data, 2);
  1336 			PropModeReplace, (unsigned char *)data, 2);
  1333 }
  1337 }
  1334 
  1338 
  1335 void
  1339 void
       
  1340 setmfact(const char *arg) {
       
  1341 	double d;
       
  1342 
       
  1343 	if(!arg || lt->arrange != tile)
       
  1344 		return;
       
  1345 	else {
       
  1346 		d = strtod(arg, NULL);
       
  1347 		if(arg[0] == '-' || arg[0] == '+')
       
  1348 			d += mfact;
       
  1349 		if(d < 0.1 || d > 0.9)
       
  1350 			return;
       
  1351 		mfact = d;
       
  1352 	}
       
  1353 	updatetilegeom();
       
  1354 	arrange();
       
  1355 }
       
  1356 
       
  1357 void
  1336 setup(void) {
  1358 setup(void) {
  1337 	unsigned int i, w;
  1359 	unsigned int i, w;
  1338 	XSetWindowAttributes wa;
  1360 	XSetWindowAttributes wa;
  1339 
  1361 
  1340 	/* init screen */
  1362 	/* init screen */
  1462 }
  1484 }
  1463 
  1485 
  1464 unsigned int
  1486 unsigned int
  1465 textw(const char *text) {
  1487 textw(const char *text) {
  1466 	return textnw(text, strlen(text)) + dc.font.height;
  1488 	return textnw(text, strlen(text)) + dc.font.height;
       
  1489 }
       
  1490 
       
  1491 void
       
  1492 tile(void) {
       
  1493 	int x, y, h, w;
       
  1494 	unsigned int i, n;
       
  1495 	Client *c;
       
  1496 
       
  1497 	for(n = 0, c = nextunfloating(clients); c; c = nextunfloating(c->next), n++);
       
  1498 	if(n == 0)
       
  1499 		return;
       
  1500 
       
  1501 	/* master */
       
  1502 	c = nextunfloating(clients);
       
  1503 
       
  1504 	if(n == 1)
       
  1505 		tileresize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw);
       
  1506 	else
       
  1507 		tileresize(c, mx, my, mw - 2 * c->bw, mh - 2 * c->bw);
       
  1508 
       
  1509 	if(--n == 0)
       
  1510 		return;
       
  1511 
       
  1512 	/* tile stack */
       
  1513 	x = (tx > c->x + c->w) ? c->x + c->w + 2 * c->bw : tw;
       
  1514 	y = ty;
       
  1515 	w = (tx > c->x + c->w) ? wx + ww - x : tw;
       
  1516 	h = th / n;
       
  1517 	if(h < bh)
       
  1518 		h = th;
       
  1519 
       
  1520 	for(i = 0, c = nextunfloating(c->next); c; c = nextunfloating(c->next), i++) {
       
  1521 		if(i + 1 == n) /* remainder */
       
  1522 			tileresize(c, x, y, w - 2 * c->bw, (ty + th) - y - 2 * c->bw);
       
  1523 		else
       
  1524 			tileresize(c, x, y, w - 2 * c->bw, h - 2 * c->bw);
       
  1525 		if(h != th)
       
  1526 			y = c->y + c->h + 2 * c->bw;
       
  1527 	}
       
  1528 }
       
  1529 
       
  1530 void
       
  1531 tileresize(Client *c, int x, int y, int w, int h) {
       
  1532 	resize(c, x, y, w, h, resizehints);
       
  1533 	if(resizehints && ((c->h < bh) || (c->h > h) || (c->w < bh) || (c->w > w)))
       
  1534 		/* client doesn't accept size constraints */
       
  1535 		resize(c, x, y, w, h, False);
  1467 }
  1536 }
  1468 
  1537 
  1469 void
  1538 void
  1470 togglebar(const char *arg) {
  1539 togglebar(const char *arg) {
  1471 	showbar = !showbar;
  1540 	showbar = !showbar;
  1663 	}
  1732 	}
  1664 	else
  1733 	else
  1665 		c->minax = c->maxax = c->minay = c->maxay = 0;
  1734 		c->minax = c->maxax = c->minay = c->maxay = 0;
  1666 	c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
  1735 	c->isfixed = (c->maxw && c->minw && c->maxh && c->minh
  1667 			&& c->maxw == c->minw && c->maxh == c->minh);
  1736 			&& c->maxw == c->minw && c->maxh == c->minh);
       
  1737 }
       
  1738 
       
  1739 void
       
  1740 updatetilegeom(void) {
       
  1741 	/* master area geometry */
       
  1742 	mx = wx;
       
  1743 	my = wy;
       
  1744 	mw = mfact * ww;
       
  1745 	mh = wh;
       
  1746 
       
  1747 	/* tile area geometry */
       
  1748 	tx = mx + mw;
       
  1749 	ty = wy;
       
  1750 	tw = ww - mw;
       
  1751 	th = wh;
  1668 }
  1752 }
  1669 
  1753 
  1670 void
  1754 void
  1671 updatetitle(Client *c) {
  1755 updatetitle(Client *c) {
  1672 	if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
  1756 	if(!gettextprop(c->win, netatom[NetWMName], c->name, sizeof c->name))
  1731 xerrorstart(Display *dpy, XErrorEvent *ee) {
  1815 xerrorstart(Display *dpy, XErrorEvent *ee) {
  1732 	otherwm = True;
  1816 	otherwm = True;
  1733 	return -1;
  1817 	return -1;
  1734 }
  1818 }
  1735 
  1819 
       
  1820 void
       
  1821 zoom(const char *arg) {
       
  1822 	Client *c = sel;
       
  1823 
       
  1824 	if(c == nextunfloating(clients))
       
  1825 		if(!c || !(c = nextunfloating(c->next)))
       
  1826 			return;
       
  1827 	if(lt->arrange == tile && !sel->isfloating) {
       
  1828 		detach(c);
       
  1829 		attach(c);
       
  1830 		focus(c);
       
  1831 	}
       
  1832 	arrange();
       
  1833 }
       
  1834 
  1736 int
  1835 int
  1737 main(int argc, char *argv[]) {
  1836 main(int argc, char *argv[]) {
  1738 	if(argc == 2 && !strcmp("-v", argv[1]))
  1837 	if(argc == 2 && !strcmp("-v", argv[1]))
  1739 		eprint("dwm-"VERSION", © 2006-2008 dwm engineers, see LICENSE for details\n");
  1838 		eprint("dwm-"VERSION", © 2006-2008 dwm engineers, see LICENSE for details\n");
  1740 	else if(argc != 1)
  1839 	else if(argc != 1)