dwm.c
changeset 1148 d49ff154375f
parent 1147 def76530f636
child 1149 2fbda289c7af
equal deleted inserted replaced
1147:def76530f636 1148:d49ff154375f
   134 void focusin(XEvent *e);
   134 void focusin(XEvent *e);
   135 void focusnext(const char *arg);
   135 void focusnext(const char *arg);
   136 void focusprev(const char *arg);
   136 void focusprev(const char *arg);
   137 Client *getclient(Window w);
   137 Client *getclient(Window w);
   138 unsigned long getcolor(const char *colstr);
   138 unsigned long getcolor(const char *colstr);
       
   139 double getdouble(const char *s);
   139 long getstate(Window w);
   140 long getstate(Window w);
   140 Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   141 Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
   141 void grabbuttons(Client *c, Bool focused);
   142 void grabbuttons(Client *c, Bool focused);
   142 void grabkeys(void);
   143 void grabkeys(void);
   143 unsigned int idxoftag(const char *t);
   144 unsigned int idxoftag(const char *t);
   161 void resizemouse(Client *c);
   162 void resizemouse(Client *c);
   162 void restack(void);
   163 void restack(void);
   163 void run(void);
   164 void run(void);
   164 void scan(void);
   165 void scan(void);
   165 void setclientstate(Client *c, long state);
   166 void setclientstate(Client *c, long state);
   166 void setdefgeoms(void);
   167 void setgeom(const char *arg);
   167 void setlayout(const char *arg);
   168 void setlayout(const char *arg);
   168 void setup(void);
   169 void setup(void);
   169 void spawn(const char *arg);
   170 void spawn(const char *arg);
   170 void tag(const char *arg);
   171 void tag(const char *arg);
   171 unsigned int textnw(const char *text, unsigned int len);
   172 unsigned int textnw(const char *text, unsigned int len);
   408 void
   409 void
   409 configurenotify(XEvent *e) {
   410 configurenotify(XEvent *e) {
   410 	XConfigureEvent *ev = &e->xconfigure;
   411 	XConfigureEvent *ev = &e->xconfigure;
   411 
   412 
   412 	if(ev->window == root && (ev->width != sw || ev->height != sh)) {
   413 	if(ev->window == root && (ev->width != sw || ev->height != sh)) {
   413 		setgeoms();
   414 		setgeom(NULL);
   414 		updatebarpos();
   415 		updatebarpos();
   415 		arrange();
   416 		arrange();
   416 	}
   417 	}
   417 }
   418 }
   418 
   419 
  1388 
  1389 
  1389 	XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
  1390 	XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32,
  1390 			PropModeReplace, (unsigned char *)data, 2);
  1391 			PropModeReplace, (unsigned char *)data, 2);
  1391 }
  1392 }
  1392 
  1393 
  1393 void
  1394 /**
  1394 setdefgeoms(void) {
  1395  * Idea:
  1395 
  1396  *
  1396 	/* screen dimensions */
  1397  * having a geom syntax as follows, which is interpreted as integer.
  1397 	sx = 0;
  1398  *
  1398 	sy = 0;
  1399  * [-,+][<0..n>|<W,H,B>]
  1399 	sw = DisplayWidth(dpy, screen);
  1400  *
  1400 	sh = DisplayHeight(dpy, screen);
  1401  *
  1401 
  1402  * B = bar height, W = DisplayWidth(), H = DisplayHeight()
  1402 	/* bar position */
  1403  *
  1403 	bx = sx;
  1404  * -/+/* /: is relative to current
  1404 	by = sy;
  1405  *
  1405 	bw = sw;
  1406  * Then we would come down with <bx>,<by>,<bw>,<bh>,...
  1406 	bh = dc.font.height + 2;
  1407  *
  1407 
  1408  * "0 0 W B 0 0 W W N E B,W,B,
  1408 	/* window area */
  1409  *
  1409 	wx = sx;
  1410  *
  1410 	wy = sy + bh;
  1411  */
  1411 	ww = sw;
  1412 
  1412 	wh = sh - bh;
  1413 double
  1413 
  1414 getdouble(const char *s) {
  1414 	/* master area */
  1415 	char *endp;
  1415 	mx = wx;
  1416 	double result = 0;
  1416 	my = wy;
  1417 
  1417 	mw = ((float)sw) * 0.55;
  1418 	fprintf(stderr, "getdouble '%s'\n", s);
  1418 	mh = wh;
  1419 	switch(*s) {
  1419 
  1420 	default: 
  1420 	/* tile area */
  1421 		result = strtod(s, &endp);
  1421 	tx = mx + mw;
  1422 		if(s == endp || *endp != 0)
  1422 	ty = wy;
  1423 			result = strtol(s, &endp, 0);
  1423 	tw = ww - mw;
  1424 		break;
  1424 	th = wh;
  1425 	case 'B': result = dc.font.height + 2; break;
  1425 
  1426 	case 'W': result = sw; break;
  1426 	/* monocle area */
  1427 	case 'H': result = sh; break;
  1427 	mox = wx;
  1428 	}
  1428 	moy = wy;
  1429 	fprintf(stderr, "getdouble returns '%f'\n", result);
  1429 	mow = ww;
  1430 	return result;
  1430 	moh = wh;
  1431 }
       
  1432 
       
  1433 void
       
  1434 setgeom(const char *arg) {
       
  1435 	static const char *lastArg = NULL;
       
  1436 	char op, *s, *e, *p;
       
  1437 	double val;
       
  1438 	int i, *map[] = { &bx,  &by,  &bw,  &bh,
       
  1439 	                  &wx,  &wy,  &ww,  &wh,
       
  1440 	                  &mx,  &my,  &mw,  &mh,
       
  1441 	                  &tx,  &ty,  &tw,  &th,
       
  1442 	                  &mox, &moy, &mow, &moh };
       
  1443 
       
  1444 	if(!arg)
       
  1445 		arg = lastArg;
       
  1446 	else
       
  1447 		lastArg = arg;
       
  1448 	if(!lastArg)
       
  1449 		return;
       
  1450 	strncpy(buf, arg, sizeof buf);
       
  1451 	for(i = 0, e = s = buf; e && *e; e++)
       
  1452 		if(*e == ' ') {
       
  1453 			*e = 0;
       
  1454 			fprintf(stderr, "next geom arg='%s'\n", s);
       
  1455 			op = 0;
       
  1456 			/* check if there is an operator */
       
  1457 			for(p = s; *p && *p != '-' && *p != '+' && *p != '*' && *p != ':'; p++);
       
  1458 			if(*p) {
       
  1459 				op = *p;
       
  1460 				*p = 0;
       
  1461 			}
       
  1462 			val = getdouble(s);
       
  1463 			fprintf(stderr, "val1: %d\n", val);
       
  1464 			if(p > s) { /* intermediate operand, e.g. H-B */
       
  1465 				*(map[i]) = val;
       
  1466 				s = ++p;
       
  1467 				val = getdouble(s);
       
  1468 				fprintf(stderr, "val2: %d\n", val);
       
  1469 			}
       
  1470 			switch(op) {
       
  1471 			default: *(map[i])   = val; break;
       
  1472 			case '-': *(map[i]) -= val; break;
       
  1473 			case '+': *(map[i]) += val; break;
       
  1474 			case '*': *(map[i]) *= val; break;
       
  1475 			case ':': if(val != 0) *(map[i]) /= val; break;
       
  1476 			}
       
  1477 			fprintf(stderr, "map[i]='%d'\n", val);
       
  1478 			s = ++e;
       
  1479 			i++;
       
  1480 		}
       
  1481 	updatebarpos();
       
  1482 	arrange();
  1431 }
  1483 }
  1432 
  1484 
  1433 void
  1485 void
  1434 setlayout(const char *arg) {
  1486 setlayout(const char *arg) {
  1435 	static Layout *revert = 0;
  1487 	static Layout *revert = 0;
  1462 	/* init screen */
  1514 	/* init screen */
  1463 	screen = DefaultScreen(dpy);
  1515 	screen = DefaultScreen(dpy);
  1464 	root = RootWindow(dpy, screen);
  1516 	root = RootWindow(dpy, screen);
  1465 	initfont(FONT);
  1517 	initfont(FONT);
  1466 
  1518 
  1467 	/* apply default geometries */
  1519 	/* apply default dimensions */
  1468 	setgeoms();
  1520 	sx = 0;
       
  1521 	sy = 0;
       
  1522 	sw = DisplayWidth(dpy, screen);
       
  1523 	sh = DisplayHeight(dpy, screen);
       
  1524 	setgeom(GEOMETRY);
  1469 
  1525 
  1470 	/* init atoms */
  1526 	/* init atoms */
  1471 	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
  1527 	wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False);
  1472 	wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
  1528 	wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
  1473 	wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False);
  1529 	wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False);