summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoranselm@anselm1 <unknown>2008-02-26 22:51:23 +0000
committeranselm@anselm1 <unknown>2008-02-26 22:51:23 +0000
commitd5178292edebb0db2cf9f22aaf1a8effe7529aae (patch)
tree7d161dbcca7b6d8deff1c561feda10f100bd17b6
parentcertain fixes, though still a lot of the mutex stuff missing (diff)
downloaddwm-d5178292edebb0db2cf9f22aaf1a8effe7529aae.tar.gz
dwm-d5178292edebb0db2cf9f22aaf1a8effe7529aae.zip
simplified dwm
Diffstat (limited to '')
-rw-r--r--config.def.h4
-rw-r--r--config.mk2
-rw-r--r--dwm.c174
3 files changed, 65 insertions, 115 deletions
diff --git a/config.def.h b/config.def.h
index cf6fdde..1db4d59 100644
--- a/config.def.h
+++ b/config.def.h
@@ -15,8 +15,8 @@
15const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "www" }; 15const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "www" };
16int initags[LENGTH(tags)] = { [0] = 1 }; 16int initags[LENGTH(tags)] = { [0] = 1 };
17Rule rules[] = { 17Rule rules[] = {
18 /* class:instance:title regex tags regex isfloating */ 18 /* class:instance:title substr tags ref isfloating */
19 { "Firefox", "www", False }, 19 { "Firefox", tags[8], False },
20 { "Gimp", NULL, True }, 20 { "Gimp", NULL, True },
21 { "MPlayer", NULL, True }, 21 { "MPlayer", NULL, True },
22 { "Acroread", NULL, True }, 22 { "Acroread", NULL, True },
diff --git a/config.mk b/config.mk
index f2335ac..87e5eb2 100644
--- a/config.mk
+++ b/config.mk
@@ -17,7 +17,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXinerama
17# flags 17# flags
18CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" 18CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
19LDFLAGS = -s ${LIBS} 19LDFLAGS = -s ${LIBS}
20CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" 20CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" -DAIM_XINERAMA
21LDFLAGS = -g ${LIBS} 21LDFLAGS = -g ${LIBS}
22 22
23# Solaris 23# Solaris
diff --git a/dwm.c b/dwm.c
index 3a789d9..f477847 100644
--- a/dwm.c
+++ b/dwm.c
@@ -106,15 +106,10 @@ typedef struct {
106 106
107typedef struct { 107typedef struct {
108 const char *prop; 108 const char *prop;
109 const char *tags; 109 const char *tag;
110 Bool isfloating; 110 Bool isfloating;
111} Rule; 111} Rule;
112 112
113typedef struct {
114 regex_t *propregex;
115 regex_t *tagregex;
116} Regs;
117
118struct View { 113struct View {
119 int id; 114 int id;
120 int x, y, w, h, wax, way, wah, waw; 115 int x, y, w, h, wax, way, wah, waw;
@@ -132,7 +127,6 @@ void ban(Client *c);
132void buttonpress(XEvent *e); 127void buttonpress(XEvent *e);
133void checkotherwm(void); 128void checkotherwm(void);
134void cleanup(void); 129void cleanup(void);
135void compileregs(void);
136void configure(Client *c); 130void configure(Client *c);
137void configurenotify(XEvent *e); 131void configurenotify(XEvent *e);
138void configurerequest(XEvent *e); 132void configurerequest(XEvent *e);
@@ -210,7 +204,7 @@ void zoom(const char *arg);
210void selectview(const char *arg); 204void selectview(const char *arg);
211 205
212/* variables */ 206/* variables */
213char stext[256]; 207char stext[256], buf[256];
214int nviews = 1; 208int nviews = 1;
215View *selview; 209View *selview;
216int screen; 210int screen;
@@ -246,7 +240,6 @@ Client *stack = NULL;
246Cursor cursor[CurLast]; 240Cursor cursor[CurLast];
247Display *dpy; 241Display *dpy;
248DC dc = {0}; 242DC dc = {0};
249Regs *regs = NULL;
250View *views; 243View *views;
251Window root; 244Window root;
252 245
@@ -256,10 +249,9 @@ Window root;
256/* function implementations */ 249/* function implementations */
257void 250void
258applyrules(Client *c) { 251applyrules(Client *c) {
259 static char buf[512]; 252 unsigned int i;
260 unsigned int i, j;
261 regmatch_t tmp;
262 Bool matched_tag = False; 253 Bool matched_tag = False;
254 Rule *r;
263 XClassHint ch = { 0 }; 255 XClassHint ch = { 0 };
264 256
265 /* rule matching */ 257 /* rule matching */
@@ -267,16 +259,19 @@ applyrules(Client *c) {
267 snprintf(buf, sizeof buf, "%s:%s:%s", 259 snprintf(buf, sizeof buf, "%s:%s:%s",
268 ch.res_class ? ch.res_class : "", 260 ch.res_class ? ch.res_class : "",
269 ch.res_name ? ch.res_name : "", c->name); 261 ch.res_name ? ch.res_name : "", c->name);
270 for(i = 0; i < LENGTH(rules); i++) 262 for(i = 0; i < LENGTH(rules); i++) {
271 if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) { 263 r = &rules[i];
272 c->isfloating = rules[i].isfloating; 264 if(strstr(c->name, r->prop)
273 for(j = 0; regs[i].tagregex && j < LENGTH(tags); j++) { 265 || (ch.res_class && strstr(ch.res_class, r->prop))
274 if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) { 266 || (ch.res_name && strstr(ch.res_name, r->prop)))
275 matched_tag = True; 267 {
276 c->tags[j] = selview->id; 268 c->isfloating = r->isfloating;
277 } 269 if(r->tag) {
270 matched_tag = True;
271 c->tags[idxoftag(r->tag)] = selview->id;
278 } 272 }
279 } 273 }
274 }
280 if(ch.res_class) 275 if(ch.res_class)
281 XFree(ch.res_class); 276 XFree(ch.res_class);
282 if(ch.res_name) 277 if(ch.res_name)
@@ -421,32 +416,6 @@ cleanup(void) {
421} 416}
422 417
423void 418void
424compileregs(void) {
425 unsigned int i;
426 regex_t *reg;
427
428 if(regs)
429 return;
430 regs = emallocz(LENGTH(rules) * sizeof(Regs));
431 for(i = 0; i < LENGTH(rules); i++) {
432 if(rules[i].prop) {
433 reg = emallocz(sizeof(regex_t));
434 if(regcomp(reg, rules[i].prop, REG_EXTENDED))
435 free(reg);
436 else
437 regs[i].propregex = reg;
438 }
439 if(rules[i].tags) {
440 reg = emallocz(sizeof(regex_t));
441 if(regcomp(reg, rules[i].tags, REG_EXTENDED))
442 free(reg);
443 else
444 regs[i].tagregex = reg;
445 }
446 }
447}
448
449void
450configure(Client *c) { 419configure(Client *c) {
451 XConfigureEvent ce; 420 XConfigureEvent ce;
452 421
@@ -624,7 +593,6 @@ drawsquare(View *v, Bool filled, Bool empty, Bool invert, unsigned long col[ColL
624void 593void
625drawtext(View *v, const char *text, unsigned long col[ColLast], Bool invert) { 594drawtext(View *v, const char *text, unsigned long col[ColLast], Bool invert) {
626 int x, y, w, h; 595 int x, y, w, h;
627 static char buf[256];
628 unsigned int len, olen; 596 unsigned int len, olen;
629 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; 597 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
630 598
@@ -1147,21 +1115,6 @@ maprequest(XEvent *e) {
1147 manage(ev->window, &wa); 1115 manage(ev->window, &wa);
1148} 1116}
1149 1117
1150View *
1151viewat() {
1152 int i, x, y;
1153 Window win;
1154 unsigned int mask;
1155
1156 XQueryPointer(dpy, root, &win, &win, &x, &y, &i, &i, &mask);
1157 for(i = 0; i < nviews; i++) {
1158 if((x >= views[i].x && x < views[i].x + views[i].w)
1159 && (y >= views[i].y && y < views[i].y + views[i].h))
1160 return &views[i];
1161 }
1162 return NULL;
1163}
1164
1165void 1118void
1166movemouse(Client *c) { 1119movemouse(Client *c) {
1167 int x1, y1, ocx, ocy, di, nx, ny; 1120 int x1, y1, ocx, ocy, di, nx, ny;
@@ -1406,7 +1359,7 @@ restack(View *v) {
1406void 1359void
1407run(void) { 1360run(void) {
1408 char *p; 1361 char *p;
1409 char buf[sizeof stext]; 1362 char sbuf[sizeof stext];
1410 fd_set rd; 1363 fd_set rd;
1411 int r, xfd; 1364 int r, xfd;
1412 unsigned int len, offset; 1365 unsigned int len, offset;
@@ -1418,7 +1371,7 @@ run(void) {
1418 readin = True; 1371 readin = True;
1419 offset = 0; 1372 offset = 0;
1420 len = sizeof stext - 1; 1373 len = sizeof stext - 1;
1421 buf[len] = stext[len] = '\0'; /* 0-terminator is never touched */ 1374 sbuf[len] = stext[len] = '\0'; /* 0-terminator is never touched */
1422 while(running) { 1375 while(running) {
1423 FD_ZERO(&rd); 1376 FD_ZERO(&rd);
1424 if(readin) 1377 if(readin)
@@ -1430,7 +1383,7 @@ run(void) {
1430 eprint("select failed\n"); 1383 eprint("select failed\n");
1431 } 1384 }
1432 if(FD_ISSET(STDIN_FILENO, &rd)) { 1385 if(FD_ISSET(STDIN_FILENO, &rd)) {
1433 switch((r = read(STDIN_FILENO, buf + offset, len - offset))) { 1386 switch((r = read(STDIN_FILENO, sbuf + offset, len - offset))) {
1434 case -1: 1387 case -1:
1435 strncpy(stext, strerror(errno), len); 1388 strncpy(stext, strerror(errno), len);
1436 readin = False; 1389 readin = False;
@@ -1440,15 +1393,15 @@ run(void) {
1440 readin = False; 1393 readin = False;
1441 break; 1394 break;
1442 default: 1395 default:
1443 for(p = buf + offset; r > 0; p++, r--, offset++) 1396 for(p = sbuf + offset; r > 0; p++, r--, offset++)
1444 if(*p == '\n' || *p == '\0') { 1397 if(*p == '\n' || *p == '\0') {
1445 *p = '\0'; 1398 *p = '\0';
1446 strncpy(stext, buf, len); 1399 strncpy(stext, sbuf, len);
1447 p += r - 1; /* p is buf + offset + r - 1 */ 1400 p += r - 1; /* p is sbuf + offset + r - 1 */
1448 for(r = 0; *(p - r) && *(p - r) != '\n'; r++); 1401 for(r = 0; *(p - r) && *(p - r) != '\n'; r++);
1449 offset = r; 1402 offset = r;
1450 if(r) 1403 if(r)
1451 memmove(buf, p - r + 1, r); 1404 memmove(sbuf, p - r + 1, r);
1452 break; 1405 break;
1453 } 1406 }
1454 break; 1407 break;
@@ -1666,9 +1619,6 @@ v->h = DisplayHeight(dpy, screen);
1666 /* grab keys */ 1619 /* grab keys */
1667 grabkeys(); 1620 grabkeys();
1668 1621
1669 /* init tags */
1670 compileregs();
1671
1672 selview = &views[0]; 1622 selview = &views[0];
1673} 1623}
1674 1624
@@ -1950,6 +1900,46 @@ updatewmhints(Client *c) {
1950 } 1900 }
1951} 1901}
1952 1902
1903void
1904view(const char *arg) {
1905 unsigned int i;
1906 int tmp[LENGTH(tags)];
1907
1908 for(i = 0; i < LENGTH(tags); i++)
1909 tmp[i] = (NULL == arg) ? selview->id : 0;
1910 tmp[idxoftag(arg)] = selview->id;
1911 if(memcmp(seltags, tmp, sizeof initags) != 0) {
1912 memcpy(prevtags, seltags, sizeof initags);
1913 memcpy(seltags, tmp, sizeof initags);
1914 arrange();
1915 }
1916}
1917
1918View *
1919viewat() {
1920 int i, x, y;
1921 Window win;
1922 unsigned int mask;
1923
1924 XQueryPointer(dpy, root, &win, &win, &x, &y, &i, &i, &mask);
1925 for(i = 0; i < nviews; i++) {
1926 if((x >= views[i].x && x < views[i].x + views[i].w)
1927 && (y >= views[i].y && y < views[i].y + views[i].h))
1928 return &views[i];
1929 }
1930 return NULL;
1931}
1932
1933void
1934viewprevtag(const char *arg) {
1935 static Bool tmp[LENGTH(tags)];
1936
1937 memcpy(tmp, seltags, sizeof initags);
1938 memcpy(seltags, prevtags, sizeof initags);
1939 memcpy(prevtags, tmp, sizeof initags);
1940 arrange();
1941}
1942
1953/* There's no way to check accesses to destroyed windows, thus those cases are 1943/* There's no way to check accesses to destroyed windows, thus those cases are
1954 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs 1944 * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
1955 * default error handler, which may call exit. */ 1945 * default error handler, which may call exit. */
@@ -1983,31 +1973,6 @@ xerrorstart(Display *dpy, XErrorEvent *ee) {
1983} 1973}
1984 1974
1985void 1975void
1986view(const char *arg) {
1987 unsigned int i;
1988 int tmp[LENGTH(tags)];
1989
1990 for(i = 0; i < LENGTH(tags); i++)
1991 tmp[i] = (NULL == arg) ? selview->id : 0;
1992 tmp[idxoftag(arg)] = selview->id;
1993 if(memcmp(seltags, tmp, sizeof initags) != 0) {
1994 memcpy(prevtags, seltags, sizeof initags);
1995 memcpy(seltags, tmp, sizeof initags);
1996 arrange();
1997 }
1998}
1999
2000void
2001viewprevtag(const char *arg) {
2002 static Bool tmp[LENGTH(tags)];
2003
2004 memcpy(tmp, seltags, sizeof initags);
2005 memcpy(seltags, prevtags, sizeof initags);
2006 memcpy(prevtags, tmp, sizeof initags);
2007 arrange();
2008}
2009
2010void
2011zoom(const char *arg) { 1976zoom(const char *arg) {
2012 Client *c = sel; 1977 Client *c = sel;
2013 1978
@@ -2022,21 +1987,6 @@ zoom(const char *arg) {
2022 arrange(); 1987 arrange();
2023} 1988}
2024 1989
2025void
2026selectview(const char *arg) {
2027 int i;
2028 View *v;
2029
2030 if(!arg)
2031 return;
2032 if(arg)
2033 i = atoi(arg);
2034 v = &views[i % nviews];
2035 XWarpPointer(dpy, None, root, 0, 0, 0, 0, v->wax+v->waw/2, v->way+v->wah/2);
2036 focus(NULL);
2037}
2038
2039
2040int 1990int
2041main(int argc, char *argv[]) { 1991main(int argc, char *argv[]) {
2042 if(argc == 2 && !strcmp("-v", argv[1])) 1992 if(argc == 2 && !strcmp("-v", argv[1]))