dwm.c
changeset 1400 a5312d498a58
parent 1399 0decadd79fd5
child 1401 8cee6e329111
equal deleted inserted replaced
1399:0decadd79fd5 1400:a5312d498a58
   114 	const Arg arg;
   114 	const Arg arg;
   115 } Key;
   115 } Key;
   116 
   116 
   117 typedef struct {
   117 typedef struct {
   118 	char symbol[4];
   118 	char symbol[4];
       
   119 	float mfact;
   119 	int by, btx;          /* bar geometry */
   120 	int by, btx;          /* bar geometry */
   120 	int wx, wy, ww, wh;   /* window area  */
   121 	int wx, wy, ww, wh;   /* window area  */
   121 	unsigned int seltags;
   122 	unsigned int seltags;
   122 	unsigned int sellt;
   123 	unsigned int sellt;
   123 	Bool showbar;
   124 	Bool showbar;
   249 static Cursor cursor[CurLast];
   250 static Cursor cursor[CurLast];
   250 static Display *dpy;
   251 static Display *dpy;
   251 static DC dc;
   252 static DC dc;
   252 static Layout *lt[] = { NULL, NULL };
   253 static Layout *lt[] = { NULL, NULL };
   253 static Monitor *mon = NULL, *selmon = NULL;
   254 static Monitor *mon = NULL, *selmon = NULL;
   254 static unsigned int nmons;
   255 static unsigned int nmons = 0;
   255 static Window root;
   256 static Window root;
   256 /* configuration, allows nested code to access above variables */
   257 /* configuration, allows nested code to access above variables */
   257 #include "config.h"
   258 #include "config.h"
   258 
   259 
   259 /* compile-time check if all tags fit into an unsigned int bit array. */
   260 /* compile-time check if all tags fit into an unsigned int bit array. */
  1320 setmfact(const Arg *arg) {
  1321 setmfact(const Arg *arg) {
  1321 	float f;
  1322 	float f;
  1322 
  1323 
  1323 	if(!arg || !lt[selmon->sellt]->arrange)
  1324 	if(!arg || !lt[selmon->sellt]->arrange)
  1324 		return;
  1325 		return;
  1325 	f = arg->f < 1.0 ? arg->f + mfact : arg->f - 1.0;
  1326 	f = arg->f < 1.0 ? arg->f + selmon->mfact : arg->f - 1.0;
  1326 	if(f < 0.1 || f > 0.9)
  1327 	if(f < 0.1 || f > 0.9)
  1327 		return;
  1328 		return;
  1328 	mfact = f;
  1329 	selmon->mfact = f;
  1329 	arrange();
  1330 	arrange();
  1330 }
  1331 }
  1331 
  1332 
  1332 void
  1333 void
  1333 setup(void) {
  1334 setup(void) {
  1481 	if(n == 0)
  1482 	if(n == 0)
  1482 		return;
  1483 		return;
  1483 
  1484 
  1484 	/* master */
  1485 	/* master */
  1485 	c = nexttiled(m, clients);
  1486 	c = nexttiled(m, clients);
  1486 	mw = mfact * m->ww;
  1487 	mw = m->mfact * m->ww;
  1487 	resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw);
  1488 	resize(c, m->wx, m->wy, (n == 1 ? m->ww : mw) - 2 * c->bw, m->wh - 2 * c->bw);
  1488 
  1489 
  1489 	if(--n == 0)
  1490 	if(--n == 0)
  1490 		return;
  1491 		return;
  1491 
  1492 
  1579 }
  1580 }
  1580 
  1581 
  1581 void
  1582 void
  1582 updategeom(void) {
  1583 updategeom(void) {
  1583 #ifdef XINERAMA
  1584 #ifdef XINERAMA
  1584 	int di, x, y, n;
  1585 	int n;
  1585 	unsigned int dui, i = 0;
  1586 	unsigned int i = 0;
  1586 	Bool pquery;
       
  1587 	Client *c;
  1587 	Client *c;
  1588 	Window dummy;
       
  1589 	XineramaScreenInfo *info = NULL;
  1588 	XineramaScreenInfo *info = NULL;
  1590 
  1589 
  1591 	/* window area geometry */
  1590 	/* window area geometry */
  1592 	if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
  1591 	if(XineramaIsActive(dpy) && (info = XineramaQueryScreens(dpy, &n))) {
  1593 		nmons = (unsigned int)n;
  1592 		if(n != nmons) {
  1594 		for(c = clients; c; c = c->next)
  1593 			for(c = clients; c; c = c->next)
  1595 			if(c->mon >= nmons)
  1594 				if(c->mon >= n)
  1596 				c->mon = nmons - 1;
  1595 					c->mon = n - 1;
  1597 		if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor) * nmons)))
  1596 			if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor) * n)))
  1598 			die("fatal: could not realloc() %u bytes\n", sizeof(Monitor) * nmons);
  1597 				die("fatal: could not realloc() %u bytes\n", sizeof(Monitor) * nmons);
  1599 		pquery = XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui);
  1598 		}
  1600 		for(i = 0; i < nmons; i++) {
  1599 		for(i = 0; i < n ; i++) {
  1601 			/* TODO: consider re-using XineramaScreenInfo */
  1600 			/* TODO: consider re-using XineramaScreenInfo */
  1602 			mon[i].symbol[0] = '[';
  1601 			mon[i].symbol[0] = '[';
  1603 			mon[i].symbol[1] = '0' + info[i].screen_number;
  1602 			mon[i].symbol[1] = '0' + info[i].screen_number;
  1604 			mon[i].symbol[2] = ']';
  1603 			mon[i].symbol[2] = ']';
  1605 			mon[i].symbol[3] = 0;
  1604 			mon[i].symbol[3] = 0;
  1606 			mon[i].showbar = showbar;
  1605 			if(!selmon) { /* not initialised yet */
  1607 			mon[i].topbar = topbar;
  1606 				mon[i].mfact = mfact;
       
  1607 				mon[i].showbar = showbar;
       
  1608 				mon[i].topbar = topbar;
       
  1609 			}
  1608 			mon[i].wx = info[i].x_org;
  1610 			mon[i].wx = info[i].x_org;
  1609 			mon[i].wy = mon[i].showbar && mon[i].topbar ? info[i].y_org + bh : info[i].y_org;
  1611 			mon[i].wy = mon[i].showbar && mon[i].topbar ? info[i].y_org + bh : info[i].y_org;
  1610 			mon[i].ww = info[i].width;
  1612 			mon[i].ww = info[i].width;
  1611 			mon[i].wh = mon[i].showbar ? info[i].height - bh : info[i].height;
  1613 			mon[i].wh = mon[i].showbar ? info[i].height - bh : info[i].height;
  1612 			mon[i].seltags = 0;
  1614 			mon[i].seltags = 0;
  1613 			mon[i].sellt = 0;
  1615 			mon[i].sellt = 0;
  1614 			if(mon[i].showbar)
  1616 			if(mon[i].showbar)
  1615 				mon[i].by = mon[i].topbar ? info[i].y_org : mon[i].wy + mon[i].wh;
  1617 				mon[i].by = mon[i].topbar ? info[i].y_org : mon[i].wy + mon[i].wh;
  1616 			else
  1618 			else
  1617 				mon[i].by = -bh;
  1619 				mon[i].by = -bh;
  1618 			if(pquery && INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height))
  1620 		}
  1619 				selmon = &mon[i];
  1621 		nmons = (unsigned int)n;
       
  1622 		if(!selmon) {
       
  1623 			selmon = &mon[0];
       
  1624 			int di, x, y;
       
  1625 			unsigned int dui;
       
  1626 			Window dummy;
       
  1627 			if(XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui)) 
       
  1628 				for(i = 0; i < nmons; i++)
       
  1629 					if(INRECT(x, y, info[i].x_org, info[i].y_org, info[i].width, info[i].height)) {
       
  1630 						selmon = &mon[i];
       
  1631 						break;
       
  1632 					}
  1620 		}
  1633 		}
  1621 		XFree(info);
  1634 		XFree(info);
  1622 	}
  1635 	}
  1623 	else
  1636 	else
  1624 #endif /* XINERAMA */
  1637 #endif /* XINERAMA */
  1625 	{
  1638 	{
  1626 		nmons = 1;
  1639 		if(!mon) {
  1627 		if(!(mon = (Monitor *)realloc(mon, sizeof(Monitor))))
  1640 			nmons = 1;
  1628 			die("fatal: could not realloc() %u bytes\n", sizeof(Monitor));
  1641 			if(!(mon = (Monitor *)malloc(sizeof(Monitor))))
  1629 		selmon = &mon[0];
  1642 				die("fatal: could not malloc() %u bytes\n", sizeof(Monitor));
  1630 		mon[0].symbol[0] = '[';
  1643 		}
  1631 		mon[0].symbol[1] = '0';
  1644 		if(!selmon) {
  1632 		mon[0].symbol[2] = ']';
  1645 			mon[0].symbol[0] = '[';
  1633 		mon[0].symbol[3] = 0;
  1646 			mon[0].symbol[1] = '0';
  1634 		mon[0].showbar = showbar;
  1647 			mon[0].symbol[2] = ']';
  1635 		mon[0].topbar = topbar;
  1648 			mon[0].symbol[3] = 0;
       
  1649 			mon[0].mfact = mfact;
       
  1650 			mon[0].showbar = showbar;
       
  1651 			mon[0].topbar = topbar;
       
  1652 		}
  1636 		mon[0].wx = sx;
  1653 		mon[0].wx = sx;
  1637 		mon[0].wy = mon[0].showbar && mon[0].topbar ? sy + bh : sy;
  1654 		mon[0].wy = mon[0].showbar && mon[0].topbar ? sy + bh : sy;
  1638 		mon[0].ww = sw;
  1655 		mon[0].ww = sw;
  1639 		mon[0].wh = mon[0].showbar ? sh - bh : sh;
  1656 		mon[0].wh = mon[0].showbar ? sh - bh : sh;
  1640 		mon[0].seltags = 0;
  1657 		mon[0].seltags = 0;
  1641 		mon[0].sellt = 0;
  1658 		mon[0].sellt = 0;
  1642 		if(mon[0].showbar)
  1659 		if(mon[0].showbar)
  1643 			mon[0].by = mon[0].topbar ? sy : mon[0].wy + mon[0].wh;
  1660 			mon[0].by = mon[0].topbar ? sy : mon[0].wy + mon[0].wh;
  1644 		else
  1661 		else
  1645 			mon[0].by = -bh;
  1662 			mon[0].by = -bh;
       
  1663 		selmon = &mon[0];
  1646 	}
  1664 	}
  1647 }
  1665 }
  1648 
  1666 
  1649 void
  1667 void
  1650 updatenumlockmask(void) {
  1668 updatenumlockmask(void) {