234 static Bool tmp[LENGTH(tags)]; |
235 static Bool tmp[LENGTH(tags)]; |
235 |
236 |
236 /* function implementations */ |
237 /* function implementations */ |
237 |
238 |
238 void |
239 void |
|
240 applygeometry(const char *arg) { |
|
241 static const char *lastArg = NULL; |
|
242 char delim, op, *s, *e, *p; |
|
243 double val; |
|
244 int i, *map[] = { &bx, &by, &bw, &bh, |
|
245 &wx, &wy, &ww, &wh, |
|
246 &mx, &my, &mw, &mh, |
|
247 &tx, &ty, &tw, &th, |
|
248 &mox, &moy, &mow, &moh }; |
|
249 |
|
250 if(!arg) |
|
251 arg = lastArg; |
|
252 else |
|
253 lastArg = arg; |
|
254 if(!lastArg) |
|
255 return; |
|
256 strncpy(buf, arg, sizeof buf); |
|
257 for(i = 0, e = s = buf; i < LENGTH(map) && e; e++) |
|
258 if(*e == ' ' || *e == 0) { |
|
259 delim = *e; |
|
260 *e = 0; |
|
261 op = 0; |
|
262 /* check if there is an operator */ |
|
263 for(p = s; p < e && *p != '-' && *p != '+' && *p != '*'; p++); |
|
264 if(*p) { |
|
265 op = *p; |
|
266 *p = 0; |
|
267 } |
|
268 val = getdouble(s); |
|
269 if(op && p > s) { /* intermediate operand, e.g. H-B */ |
|
270 *(map[i]) = (int)val; |
|
271 s = ++p; |
|
272 val = getdouble(s); |
|
273 } |
|
274 switch(op) { |
|
275 default: *(map[i]) = (int)val; break; |
|
276 case '-': *(map[i]) -= (int)val; break; |
|
277 case '+': *(map[i]) += (int)val; break; |
|
278 case '*': *(map[i]) = (int)(((double)*(map[i])) * val); break; |
|
279 } |
|
280 if(delim == 0) |
|
281 e = NULL; |
|
282 else |
|
283 s = ++e; |
|
284 i++; |
|
285 } |
|
286 } |
|
287 |
|
288 void |
239 applyrules(Client *c) { |
289 applyrules(Client *c) { |
240 unsigned int i; |
290 unsigned int i; |
241 Bool matched = False; |
291 Bool matched = False; |
242 Rule *r; |
292 Rule *r; |
243 XClassHint ch = { 0 }; |
293 XClassHint ch = { 0 }; |
1389 |
1436 |
1390 XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32, |
1437 XChangeProperty(dpy, c->win, wmatom[WMState], wmatom[WMState], 32, |
1391 PropModeReplace, (unsigned char *)data, 2); |
1438 PropModeReplace, (unsigned char *)data, 2); |
1392 } |
1439 } |
1393 |
1440 |
1394 /** |
|
1395 * Idea: |
|
1396 * |
|
1397 * having a geom syntax as follows, which is interpreted as integer. |
|
1398 * |
|
1399 * [-,+][<0..n>|<W,H,B>] |
|
1400 * |
|
1401 * |
|
1402 * B = bar height, W = DisplayWidth(), H = DisplayHeight() |
|
1403 * |
|
1404 * -/+/* /: is relative to current |
|
1405 * |
|
1406 * Then we would come down with <bx>,<by>,<bw>,<bh>,... |
|
1407 * |
|
1408 * "0 0 W B 0 0 W W N E B,W,B, |
|
1409 * |
|
1410 * |
|
1411 */ |
|
1412 |
|
1413 double |
1441 double |
1414 getdouble(const char *s) { |
1442 getdouble(const char *s) { |
1415 char *endp; |
1443 char *endp; |
1416 double result = 0; |
1444 double result = 0; |
1417 |
1445 |
1418 fprintf(stderr, "getdouble '%s'\n", s); |
|
1419 switch(*s) { |
1446 switch(*s) { |
1420 default: |
1447 default: |
1421 result = strtod(s, &endp); |
1448 result = strtod(s, &endp); |
1422 if(s == endp || *endp != 0) |
1449 if(s == endp || *endp != 0) |
1423 result = strtol(s, &endp, 0); |
1450 result = strtol(s, &endp, 0); |
1424 break; |
1451 break; |
1425 case 'B': result = dc.font.height + 2; break; |
1452 case 'B': result = dc.font.height + 2; break; |
1426 case 'W': result = sw; break; |
1453 case 'W': result = sw; break; |
1427 case 'H': result = sh; break; |
1454 case 'H': result = sh; break; |
1428 } |
1455 } |
1429 fprintf(stderr, "getdouble returns '%f'\n", result); |
|
1430 return result; |
1456 return result; |
1431 } |
1457 } |
1432 |
1458 |
1433 void |
1459 void |
1434 setgeom(const char *arg) { |
1460 setgeom(const char *arg) { |
1435 static const char *lastArg = NULL; |
1461 applygeometry(arg); |
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(); |
1462 updatebarpos(); |
1482 arrange(); |
1463 arrange(); |
1483 } |
1464 } |
1484 |
1465 |
1485 void |
1466 void |
1519 /* apply default dimensions */ |
1500 /* apply default dimensions */ |
1520 sx = 0; |
1501 sx = 0; |
1521 sy = 0; |
1502 sy = 0; |
1522 sw = DisplayWidth(dpy, screen); |
1503 sw = DisplayWidth(dpy, screen); |
1523 sh = DisplayHeight(dpy, screen); |
1504 sh = DisplayHeight(dpy, screen); |
1524 setgeom(GEOMETRY); |
1505 applygeometry(GEOMETRY); |
1525 |
1506 |
1526 /* init atoms */ |
1507 /* init atoms */ |
1527 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); |
1508 wmatom[WMProtocols] = XInternAtom(dpy, "WM_PROTOCOLS", False); |
1528 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
1509 wmatom[WMDelete] = XInternAtom(dpy, "WM_DELETE_WINDOW", False); |
1529 wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False); |
1510 wmatom[WMName] = XInternAtom(dpy, "WM_NAME", False); |