#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
#define TAGMASK ((int)((1LL << LENGTH(tags)) - 1))
#define TEXTW(x) (textnw(x, strlen(x)) + dc.font.height)
+#define ISVISIBLE(x) (x->tags & tagset[seltags])
/* enums */
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
enum { ColBorder, ColFG, ColBG, ColLast }; /* color */
enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */
enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
-enum { ClkLtSymbol = 64, ClkStatusText, ClkWinTitle,
+enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
/* typedefs */
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
int bw, oldbw;
uint tags;
- Bool isbanned, isfixed, isfloating, isurgent;
+ Bool isfixed, isfloating, isurgent;
Client *next;
Client *snext;
Window win;
Client *c;
for(c = clients; c; c = c->next)
- if(c->tags & tagset[seltags]) { /* is visible */
+ if(ISVISIBLE(c)) {
+ XMoveWindow(dpy, c->win, c->x, c->y);
if(!lt[sellt]->arrange || c->isfloating)
resize(c, c->x, c->y, c->w, c->h, True);
- c->isbanned = False;
}
- else if(!c->isbanned) {
+ else {
XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
- c->isbanned = True;
}
focus(NULL);
void
buttonpress(XEvent *e) {
uint i, x, click;
+ Arg arg = {0};
Client *c;
XButtonPressedEvent *ev = &e->xbutton;
click = ClkRootWin;
if(ev->window == barwin) {
i = x = 0;
- do
- x += TEXTW(tags[i]);
- while(ev->x >= x && ++i < LENGTH(tags));
- if(i < LENGTH(tags))
- click = i;
+ do x += TEXTW(tags[i]); while(ev->x >= x && ++i < LENGTH(tags));
+ if(i < LENGTH(tags)) {
+ click = ClkTagBar;
+ arg.ui = 1 << i;
+ }
else if(ev->x < x + blw)
click = ClkLtSymbol;
else if(ev->x > wx + ww - TEXTW(stext))
for(i = 0; i < LENGTH(buttons); i++)
if(click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
&& CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
- buttons[i].func(&buttons[i].arg);
+ buttons[i].func(click == ClkTagBar ? &arg : &buttons[i].arg);
}
void
c->y = sy + (sh / 2 - c->h / 2); /* center in y direction */
if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
configure(c);
- if(!c->isbanned)
+ if(ISVISIBLE(c))
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
}
else
void
drawbar(void) {
int i, x;
- Client *c;
dc.x = 0;
- for(c = stack; c && c->isbanned; c = c->snext);
for(i = 0; i < LENGTH(tags); i++) {
dc.w = TEXTW(tags[i]);
if(tagset[seltags] & 1 << i) {
drawtext(tags[i], dc.sel, isurgent(i));
- drawsquare(c && c->tags & 1 << i, isoccupied(i), isurgent(i), dc.sel);
+ drawsquare(sel && sel->tags & 1 << i, isoccupied(i), isurgent(i), dc.sel);
}
else {
drawtext(tags[i], dc.norm, isurgent(i));
- drawsquare(c && c->tags & 1 << i, isoccupied(i), isurgent(i), dc.norm);
+ drawsquare(sel && sel->tags & 1 << i, isoccupied(i), isurgent(i), dc.norm);
}
dc.x += dc.w;
}
drawtext(stext, dc.norm, False);
if((dc.w = dc.x - x) > bh) {
dc.x = x;
- if(c) {
- drawtext(c->name, dc.sel, False);
- drawsquare(c->isfixed, c->isfloating, False, dc.sel);
+ if(sel) {
+ drawtext(sel->name, dc.sel, False);
+ drawsquare(sel->isfixed, sel->isfloating, False, dc.sel);
}
else
drawtext(NULL, dc.norm, False);
void
focus(Client *c) {
- if(!c || c->isbanned)
- for(c = stack; c && c->isbanned; c = c->snext);
+ if(!c || !ISVISIBLE(c))
+ for(c = stack; c && !ISVISIBLE(c); c = c->snext);
if(sel && sel != c) {
grabbuttons(sel, False);
XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
if(!sel)
return;
if (arg->i > 0) {
- for(c = sel->next; c && c->isbanned; c = c->next);
+ for(c = sel->next; c && !ISVISIBLE(c); c = c->next);
if(!c)
- for(c = clients; c && c->isbanned; c = c->next);
+ for(c = clients; c && !ISVISIBLE(c); c = c->next);
}
else {
for(i = clients; i != sel; i = i->next)
- if (!i->isbanned)
+ if(ISVISIBLE(i))
c = i;
if(!c)
for(; i; i = i->next)
- if (!i->isbanned)
+ if(ISVISIBLE(i))
c = i;
}
if(c) {
void
grabbuttons(Client *c, Bool focused) {
- int i, j;
- uint buttons[] = { Button1, Button2, Button3 };
- uint modifiers[] = { MODKEY, MODKEY|LockMask, MODKEY|numlockmask, MODKEY|numlockmask|LockMask };
+ uint i, j;
+ uint modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
- if(focused)
+ if(focused) {
for(i = 0; i < LENGTH(buttons); i++)
- for(j = 0; j < LENGTH(modifiers); j++)
- XGrabButton(dpy, buttons[i], modifiers[j], c->win, False,
- BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
- else
+ if(buttons[i].click == ClkClientWin)
+ for(j = 0; j < LENGTH(modifiers); j++)
+ XGrabButton(dpy, buttons[i].button, buttons[i].mask | modifiers[j], c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
+ } else
XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
- BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
+ BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
}
void
XRaiseWindow(dpy, c->win);
attach(c);
attachstack(c);
- XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
+ XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
XMapWindow(dpy, c->win);
setclientstate(c, NormalState);
arrange();
Client *c;
for(c = nexttiled(clients); c; c = nexttiled(c->next))
- resize(c, wx, wy, ww, wh, resizehints);
+ resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, resizehints);
}
void
Client *
nexttiled(Client *c) {
- for(; c && (c->isfloating || c->isbanned); c = c->next);
+ for(; c && (c->isfloating || !ISVISIBLE(c)); c = c->next);
return c;
}
h = bh;
if(w < bh)
w = bh;
- if(!c->isbanned || c->x != x || c->y != y || c->w != w || c->h != h) {
+ if(c->x != x || c->y != y || c->w != w || c->h != h) {
c->x = wc.x = x;
c->y = wc.y = y;
c->w = wc.width = w;
wc.stack_mode = Below;
wc.sibling = barwin;
for(c = stack; c; c = c->snext)
- if(!c->isfloating && !c->isbanned) {
+ if(!c->isfloating && ISVISIBLE(c)) {
XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
wc.sibling = c->win;
}
void
setlayout(const Arg *arg) {
- sellt ^= 1;
- if(arg && arg->v && arg->v != lt[sellt])
+ if(!arg || !arg->v || arg->v != lt[sellt])
+ sellt ^= 1;
+ if(arg && arg->v)
lt[sellt] = (Layout *)arg->v;
if(sel)
arrange();
else if(argc != 1)
eprint("usage: dwm [-v]\n");
- setlocale(LC_CTYPE, "");
+ if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
+ fprintf(stderr, "warning: no locale support\n");
+
if(!(dpy = XOpenDisplay(0)))
eprint("dwm: cannot open display\n");