const char *symbol;
void (*arrange)(void);
Bool isfloating;
-} Layout;
+} Layout;
typedef struct {
const char *class;
Bool isoccupied(unsigned int t);
Bool isprotodel(Client *c);
Bool isurgent(unsigned int t);
-Bool isvisible(Client *c);
+Bool isvisible(Client *c, Bool *cmp);
void keypress(XEvent *e);
void killclient(const char *arg);
void manage(Window w, XWindowAttributes *wa);
int screen, sx, sy, sw, sh;
int (*xerrorxlib)(Display *, XErrorEvent *);
int bx, by, bw, bh, blw, bgw, mx, my, mw, mh, mox, moy, mow, moh, tx, ty, tw, th, wx, wy, ww, wh;
-int viewtags_set = 0;
+int seltags = 0;
double mfact;
unsigned int numlockmask = 0;
void (*handler[LASTEvent]) (XEvent *) = {
Atom wmatom[WMLast], netatom[NetLast];
Bool otherwm, readin;
Bool running = True;
-Bool *seltags;
-Bool *viewtags[2];
+Bool *tagset[2];
Client *clients = NULL;
Client *sel = NULL;
Client *stack = NULL;
Cursor cursor[CurLast];
Display *dpy;
DC dc = {0};
+Geom geoms[];
+Geom *geom = geoms;
+Layout layouts[];
+Layout *lt = layouts;
Window root, barwin;
/* configuration, allows nested code to access above variables */
#include "config.h"
#define TAGSZ (LENGTH(tags) * sizeof(Bool))
-Layout *lt = layouts;
-Geom *geom = geoms;
/* function implementations */
if(ch.res_name)
XFree(ch.res_name);
if(!matched)
- memcpy(c->tags, seltags, TAGSZ);
+ memcpy(c->tags, tagset[seltags], TAGSZ);
}
void
Client *c;
for(c = clients; c; c = c->next)
- if(isvisible(c)) {
+ if(isvisible(c, NULL)) {
unban(c);
if(lt->isfloating || c->isfloating)
resize(c, c->fx, c->fy, c->fw, c->fh, True);
if((ev->value_mask & (CWX|CWY))
&& !(ev->value_mask & (CWWidth|CWHeight)))
configure(c);
- if(isvisible(c))
+ if(isvisible(c, NULL))
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
}
else
drawtext(geom->symbol, dc.norm, False);
dc.x += bgw;
}
- for(c = stack; c && !isvisible(c); c = c->snext);
+ for(c = stack; c && !isvisible(c, NULL); c = c->snext);
for(i = 0; i < LENGTH(tags); i++) {
dc.w = textw(tags[i]);
- if(seltags[i]) {
+ if(tagset[seltags][i]) {
drawtext(tags[i], dc.sel, isurgent(i));
drawsquare(c && c->tags[i], isoccupied(i), isurgent(i), dc.sel);
}
void
focus(Client *c) {
- if(!c || (c && !isvisible(c)))
- for(c = stack; c && !isvisible(c); c = c->snext);
+ if(!c || (c && !isvisible(c, NULL)))
+ for(c = stack; c && !isvisible(c, NULL); c = c->snext);
if(sel && sel != c) {
grabbuttons(sel, False);
XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
if(!sel)
return;
- for(c = sel->next; c && !isvisible(c); c = c->next);
+ for(c = sel->next; c && !isvisible(c, arg ? sel->tags : NULL); c = c->next);
if(!c)
- for(c = clients; c && !isvisible(c); c = c->next);
+ for(c = clients; c && !isvisible(c, arg ? sel->tags : NULL); c = c->next);
if(c) {
focus(c);
restack();
if(!sel)
return;
- for(c = sel->prev; c && !isvisible(c); c = c->prev);
+ for(c = sel->prev; c && !isvisible(c, arg ? sel->tags : NULL); c = c->prev);
if(!c) {
for(c = clients; c && c->next; c = c->next);
- for(; c && !isvisible(c); c = c->prev);
+ for(; c && !isvisible(c, arg ? sel->tags : NULL); c = c->prev);
}
if(c) {
focus(c);
}
Bool
-isvisible(Client *c) {
+isvisible(Client *c, Bool *cmp) {
unsigned int i;
+ if(!cmp)
+ cmp = tagset[seltags];
for(i = 0; i < LENGTH(tags); i++)
- if(c->tags[i] && seltags[i])
+ if(c->tags[i] && cmp[i])
return True;
return False;
}
Client *c;
for(c = clients; c; c = c->next)
- if((lt->isfloating || !c->isfloating) && isvisible(c))
+ if((lt->isfloating || !c->isfloating) && isvisible(c, NULL))
resize(c, mox, moy, mow - 2 * c->bw, moh - 2 * c->bw, RESIZEHINTS);
}
Client *
nexttiled(Client *c) {
- for(; c && (c->isfloating || !isvisible(c)); c = c->next);
+ for(; c && (c->isfloating || !isvisible(c, NULL)); c = c->next);
return c;
}
wc.stack_mode = Below;
wc.sibling = barwin;
for(c = stack; c; c = c->snext)
- if(!c->isfloating && isvisible(c)) {
+ if(!c->isfloating && isvisible(c, NULL)) {
XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
wc.sibling = c->win;
}
XSetFont(dpy, dc.gc, dc.font.xfont->fid);
/* init tags */
- viewtags[0] = emallocz(TAGSZ);
- viewtags[1] = emallocz(TAGSZ);
- viewtags[0][0] = viewtags[1][0] = True;
- seltags = viewtags[0];
+ tagset[0] = emallocz(TAGSZ);
+ tagset[1] = emallocz(TAGSZ);
+ tagset[0][0] = tagset[1][0] = True;
/* init bar */
for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
unsigned int i, j;
i = idxoftag(arg);
- seltags[i] = !seltags[i];
- for(j = 0; j < LENGTH(tags) && !seltags[j]; j++);
+ tagset[seltags][i] = !tagset[seltags][i];
+ for(j = 0; j < LENGTH(tags) && !tagset[seltags][j]; j++);
if(j == LENGTH(tags))
- seltags[i] = True; /* at least one tag must be viewed */
+ tagset[seltags][i] = True; /* at least one tag must be viewed */
arrange();
}
void
view(const char *arg) {
- Bool tmp[LENGTH(tags)];
- unsigned int i;
-
- for(i = 0; i < LENGTH(tags); i++)
- tmp[i] = (NULL == arg);
- tmp[idxoftag(arg)] = True;
-
- if(memcmp(seltags, tmp, TAGSZ) != 0) {
- seltags = viewtags[viewtags_set ^= 1]; /* toggle tagset */
- memcpy(seltags, tmp, TAGSZ);
- arrange();
- }
- else
- viewprevtag(NULL);
+ seltags ^= 1;
+ memset(tagset[seltags], (NULL == arg), TAGSZ);
+ tagset[seltags][idxoftag(arg)] = True;
+ arrange();
}
void
viewprevtag(const char *arg) {
- seltags = viewtags[viewtags_set ^= 1]; /* toggle tagset */
+ seltags ^= 1; /* toggle sel tagset */
arrange();
}
|| (ee->request_code == X_PolyFillRectangle && ee->error_code == BadDrawable)
|| (ee->request_code == X_PolySegment && ee->error_code == BadDrawable)
|| (ee->request_code == X_ConfigureWindow && ee->error_code == BadMatch)
+ || (ee->request_code == X_GrabButton && ee->error_code == BadAccess)
|| (ee->request_code == X_GrabKey && ee->error_code == BadAccess)
|| (ee->request_code == X_CopyArea && ee->error_code == BadDrawable))
return 0;