simplified dwm

keyboard
anselm@anselm1 17 years ago
parent 2bfd3fffbf
commit d5178292ed
  1. 4
      config.def.h
  2. 2
      config.mk
  3. 170
      dwm.c

@ -15,8 +15,8 @@
const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "www" }; const char tags[][MAXTAGLEN] = { "1", "2", "3", "4", "5", "6", "7", "8", "www" };
int initags[LENGTH(tags)] = { [0] = 1 }; int initags[LENGTH(tags)] = { [0] = 1 };
Rule rules[] = { Rule rules[] = {
/* class:instance:title regex tags regex isfloating */ /* class:instance:title substr tags ref isfloating */
{ "Firefox", "www", False }, { "Firefox", tags[8], False },
{ "Gimp", NULL, True }, { "Gimp", NULL, True },
{ "MPlayer", NULL, True }, { "MPlayer", NULL, True },
{ "Acroread", NULL, True }, { "Acroread", NULL, True },

@ -17,7 +17,7 @@ LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lXinerama
# flags # flags
CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\" CFLAGS = -Os ${INCS} -DVERSION=\"${VERSION}\"
LDFLAGS = -s ${LIBS} LDFLAGS = -s ${LIBS}
CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" CFLAGS = -g -std=c99 -pedantic -Wall -O2 ${INCS} -DVERSION=\"${VERSION}\" -DAIM_XINERAMA
LDFLAGS = -g ${LIBS} LDFLAGS = -g ${LIBS}
# Solaris # Solaris

170
dwm.c

@ -106,15 +106,10 @@ typedef struct {
typedef struct { typedef struct {
const char *prop; const char *prop;
const char *tags; const char *tag;
Bool isfloating; Bool isfloating;
} Rule; } Rule;
typedef struct {
regex_t *propregex;
regex_t *tagregex;
} Regs;
struct View { struct View {
int id; int id;
int x, y, w, h, wax, way, wah, waw; int x, y, w, h, wax, way, wah, waw;
@ -132,7 +127,6 @@ void ban(Client *c);
void buttonpress(XEvent *e); void buttonpress(XEvent *e);
void checkotherwm(void); void checkotherwm(void);
void cleanup(void); void cleanup(void);
void compileregs(void);
void configure(Client *c); void configure(Client *c);
void configurenotify(XEvent *e); void configurenotify(XEvent *e);
void configurerequest(XEvent *e); void configurerequest(XEvent *e);
@ -210,7 +204,7 @@ void zoom(const char *arg);
void selectview(const char *arg); void selectview(const char *arg);
/* variables */ /* variables */
char stext[256]; char stext[256], buf[256];
int nviews = 1; int nviews = 1;
View *selview; View *selview;
int screen; int screen;
@ -246,7 +240,6 @@ Client *stack = NULL;
Cursor cursor[CurLast]; Cursor cursor[CurLast];
Display *dpy; Display *dpy;
DC dc = {0}; DC dc = {0};
Regs *regs = NULL;
View *views; View *views;
Window root; Window root;
@ -256,10 +249,9 @@ Window root;
/* function implementations */ /* function implementations */
void void
applyrules(Client *c) { applyrules(Client *c) {
static char buf[512]; unsigned int i;
unsigned int i, j;
regmatch_t tmp;
Bool matched_tag = False; Bool matched_tag = False;
Rule *r;
XClassHint ch = { 0 }; XClassHint ch = { 0 };
/* rule matching */ /* rule matching */
@ -267,13 +259,16 @@ applyrules(Client *c) {
snprintf(buf, sizeof buf, "%s:%s:%s", snprintf(buf, sizeof buf, "%s:%s:%s",
ch.res_class ? ch.res_class : "", ch.res_class ? ch.res_class : "",
ch.res_name ? ch.res_name : "", c->name); ch.res_name ? ch.res_name : "", c->name);
for(i = 0; i < LENGTH(rules); i++) for(i = 0; i < LENGTH(rules); i++) {
if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) { r = &rules[i];
c->isfloating = rules[i].isfloating; if(strstr(c->name, r->prop)
for(j = 0; regs[i].tagregex && j < LENGTH(tags); j++) { || (ch.res_class && strstr(ch.res_class, r->prop))
if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) { || (ch.res_name && strstr(ch.res_name, r->prop)))
{
c->isfloating = r->isfloating;
if(r->tag) {
matched_tag = True; matched_tag = True;
c->tags[j] = selview->id; c->tags[idxoftag(r->tag)] = selview->id;
} }
} }
} }
@ -420,32 +415,6 @@ cleanup(void) {
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime); XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
} }
void
compileregs(void) {
unsigned int i;
regex_t *reg;
if(regs)
return;
regs = emallocz(LENGTH(rules) * sizeof(Regs));
for(i = 0; i < LENGTH(rules); i++) {
if(rules[i].prop) {
reg = emallocz(sizeof(regex_t));
if(regcomp(reg, rules[i].prop, REG_EXTENDED))
free(reg);
else
regs[i].propregex = reg;
}
if(rules[i].tags) {
reg = emallocz(sizeof(regex_t));
if(regcomp(reg, rules[i].tags, REG_EXTENDED))
free(reg);
else
regs[i].tagregex = reg;
}
}
}
void void
configure(Client *c) { configure(Client *c) {
XConfigureEvent ce; XConfigureEvent ce;
@ -624,7 +593,6 @@ drawsquare(View *v, Bool filled, Bool empty, Bool invert, unsigned long col[ColL
void void
drawtext(View *v, const char *text, unsigned long col[ColLast], Bool invert) { drawtext(View *v, const char *text, unsigned long col[ColLast], Bool invert) {
int x, y, w, h; int x, y, w, h;
static char buf[256];
unsigned int len, olen; unsigned int len, olen;
XRectangle r = { dc.x, dc.y, dc.w, dc.h }; XRectangle r = { dc.x, dc.y, dc.w, dc.h };
@ -1147,21 +1115,6 @@ maprequest(XEvent *e) {
manage(ev->window, &wa); manage(ev->window, &wa);
} }
View *
viewat() {
int i, x, y;
Window win;
unsigned int mask;
XQueryPointer(dpy, root, &win, &win, &x, &y, &i, &i, &mask);
for(i = 0; i < nviews; i++) {
if((x >= views[i].x && x < views[i].x + views[i].w)
&& (y >= views[i].y && y < views[i].y + views[i].h))
return &views[i];
}
return NULL;
}
void void
movemouse(Client *c) { movemouse(Client *c) {
int x1, y1, ocx, ocy, di, nx, ny; int x1, y1, ocx, ocy, di, nx, ny;
@ -1406,7 +1359,7 @@ restack(View *v) {
void void
run(void) { run(void) {
char *p; char *p;
char buf[sizeof stext]; char sbuf[sizeof stext];
fd_set rd; fd_set rd;
int r, xfd; int r, xfd;
unsigned int len, offset; unsigned int len, offset;
@ -1418,7 +1371,7 @@ run(void) {
readin = True; readin = True;
offset = 0; offset = 0;
len = sizeof stext - 1; len = sizeof stext - 1;
buf[len] = stext[len] = '\0'; /* 0-terminator is never touched */ sbuf[len] = stext[len] = '\0'; /* 0-terminator is never touched */
while(running) { while(running) {
FD_ZERO(&rd); FD_ZERO(&rd);
if(readin) if(readin)
@ -1430,7 +1383,7 @@ run(void) {
eprint("select failed\n"); eprint("select failed\n");
} }
if(FD_ISSET(STDIN_FILENO, &rd)) { if(FD_ISSET(STDIN_FILENO, &rd)) {
switch((r = read(STDIN_FILENO, buf + offset, len - offset))) { switch((r = read(STDIN_FILENO, sbuf + offset, len - offset))) {
case -1: case -1:
strncpy(stext, strerror(errno), len); strncpy(stext, strerror(errno), len);
readin = False; readin = False;
@ -1440,15 +1393,15 @@ run(void) {
readin = False; readin = False;
break; break;
default: default:
for(p = buf + offset; r > 0; p++, r--, offset++) for(p = sbuf + offset; r > 0; p++, r--, offset++)
if(*p == '\n' || *p == '\0') { if(*p == '\n' || *p == '\0') {
*p = '\0'; *p = '\0';
strncpy(stext, buf, len); strncpy(stext, sbuf, len);
p += r - 1; /* p is buf + offset + r - 1 */ p += r - 1; /* p is sbuf + offset + r - 1 */
for(r = 0; *(p - r) && *(p - r) != '\n'; r++); for(r = 0; *(p - r) && *(p - r) != '\n'; r++);
offset = r; offset = r;
if(r) if(r)
memmove(buf, p - r + 1, r); memmove(sbuf, p - r + 1, r);
break; break;
} }
break; break;
@ -1666,9 +1619,6 @@ v->h = DisplayHeight(dpy, screen);
/* grab keys */ /* grab keys */
grabkeys(); grabkeys();
/* init tags */
compileregs();
selview = &views[0]; selview = &views[0];
} }
@ -1950,6 +1900,46 @@ updatewmhints(Client *c) {
} }
} }
void
view(const char *arg) {
unsigned int i;
int tmp[LENGTH(tags)];
for(i = 0; i < LENGTH(tags); i++)
tmp[i] = (NULL == arg) ? selview->id : 0;
tmp[idxoftag(arg)] = selview->id;
if(memcmp(seltags, tmp, sizeof initags) != 0) {
memcpy(prevtags, seltags, sizeof initags);
memcpy(seltags, tmp, sizeof initags);
arrange();
}
}
View *
viewat() {
int i, x, y;
Window win;
unsigned int mask;
XQueryPointer(dpy, root, &win, &win, &x, &y, &i, &i, &mask);
for(i = 0; i < nviews; i++) {
if((x >= views[i].x && x < views[i].x + views[i].w)
&& (y >= views[i].y && y < views[i].y + views[i].h))
return &views[i];
}
return NULL;
}
void
viewprevtag(const char *arg) {
static Bool tmp[LENGTH(tags)];
memcpy(tmp, seltags, sizeof initags);
memcpy(seltags, prevtags, sizeof initags);
memcpy(prevtags, tmp, sizeof initags);
arrange();
}
/* There's no way to check accesses to destroyed windows, thus those cases are /* There's no way to check accesses to destroyed windows, thus those cases are
* ignored (especially on UnmapNotify's). Other types of errors call Xlibs * ignored (especially on UnmapNotify's). Other types of errors call Xlibs
* default error handler, which may call exit. */ * default error handler, which may call exit. */
@ -1982,31 +1972,6 @@ xerrorstart(Display *dpy, XErrorEvent *ee) {
return -1; return -1;
} }
void
view(const char *arg) {
unsigned int i;
int tmp[LENGTH(tags)];
for(i = 0; i < LENGTH(tags); i++)
tmp[i] = (NULL == arg) ? selview->id : 0;
tmp[idxoftag(arg)] = selview->id;
if(memcmp(seltags, tmp, sizeof initags) != 0) {
memcpy(prevtags, seltags, sizeof initags);
memcpy(seltags, tmp, sizeof initags);
arrange();
}
}
void
viewprevtag(const char *arg) {
static Bool tmp[LENGTH(tags)];
memcpy(tmp, seltags, sizeof initags);
memcpy(seltags, prevtags, sizeof initags);
memcpy(prevtags, tmp, sizeof initags);
arrange();
}
void void
zoom(const char *arg) { zoom(const char *arg) {
Client *c = sel; Client *c = sel;
@ -2022,21 +1987,6 @@ zoom(const char *arg) {
arrange(); arrange();
} }
void
selectview(const char *arg) {
int i;
View *v;
if(!arg)
return;
if(arg)
i = atoi(arg);
v = &views[i % nviews];
XWarpPointer(dpy, None, root, 0, 0, 0, 0, v->wax+v->waw/2, v->way+v->wah/2);
focus(NULL);
}
int int
main(int argc, char *argv[]) { main(int argc, char *argv[]) {
if(argc == 2 && !strcmp("-v", argv[1])) if(argc == 2 && !strcmp("-v", argv[1]))

Loading…
Cancel
Save