void setclientstate(Client *c, long state);
void setgeom(const char *arg);
void setlayout(const char *arg);
+void setmfact(const char *arg);
void setup(void);
void spawn(const char *arg);
void tag(const char *arg);
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;
+double mfact;
unsigned int numlockmask = 0;
void (*handler[LASTEvent]) (XEvent *) = {
[ButtonPress] = buttonpress,
Cursor cursor[CurLast];
Display *dpy;
DC dc = {0};
-Geom *geom = NULL;
-Layout *lt = NULL;
Window root, barwin;
/* configuration, allows nested code to access above variables */
#include "config.h"
#define TAGSZ (LENGTH(tags) * sizeof(Bool))
-static Bool tmp[LENGTH(tags)];
+Bool tmp[LENGTH(tags)];
+Layout *lt = layouts;
+Geom *geom = geoms;
/* function implementations */
XGetClassHint(dpy, c->win, &ch);
for(i = 0; i < LENGTH(rules); i++) {
r = &rules[i];
- if(r->title && strstr(c->name, r->title)
- || (ch.res_class && r->class && strstr(ch.res_class, r->class))
- || (ch.res_name && r->instance && strstr(ch.res_name, r->instance)))
- {
+ if((!r->title || strstr(c->name, r->title))
+ && (!r->class || (ch.res_class && strstr(ch.res_class, r->class)))
+ && (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) {
c->isfloating = r->isfloating;
if(r->tag) {
c->tags[idxoftag(r->tag)] = True;
XButtonPressedEvent *ev = &e->xbutton;
if(ev->window == barwin) {
+ if((ev->x < bgw) && ev->button == Button1) {
+ setgeom(NULL);
+ return;
+ }
x = bgw;
for(i = 0; i < LENGTH(tags); i++) {
x += textw(tags[i]);
- if(ev->x > bgw && ev->x < x) {
+ if(ev->x >= bgw && ev->x < x) {
if(ev->button == Button1) {
if(ev->state & MODKEY)
tag(tags[i]);
return;
}
}
+ if((ev->x < x + blw) && ev->button == Button1)
+ setlayout(NULL);
}
else if((c = getclient(ev->window))) {
focus(c);
configurenotify(XEvent *e) {
XConfigureEvent *ev = &e->xconfigure;
- if(ev->window == root && (ev->width != sw || ev->height != sh))
- setgeom(NULL);
+ if(ev->window == root && (ev->width != sw || ev->height != sh)) {
+ sw = ev->width;
+ sh = ev->height;
+ setgeom(geom->symbol);
+ }
}
void
Client *c;
dc.x = 0;
- dc.w = bgw;
- drawtext(geom->symbol, dc.norm, False);
- dc.x += bgw;
+ if(bgw > 0) {
+ dc.w = bgw;
+ drawtext(geom->symbol, dc.norm, False);
+ dc.x += bgw;
+ }
for(c = stack; c && !isvisible(c); c = c->snext);
for(i = 0; i < LENGTH(tags); i++) {
dc.w = textw(tags[i]);
}
dc.x += dc.w;
}
- dc.w = blw;
- drawtext(lt->symbol, dc.norm, False);
- x = dc.x + dc.w;
+ if(blw > 0) {
+ dc.w = blw;
+ drawtext(lt->symbol, dc.norm, False);
+ x = dc.x + dc.w;
+ }
+ else
+ x = dc.x;
dc.w = textw(stext);
dc.x = bw - dc.w;
if(dc.x < x) {
void
grabbuttons(Client *c, Bool focused) {
- XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
+ int i, j;
+ unsigned int buttons[] = { Button1, Button2, Button3 };
+ unsigned int modifiers[] = { MODKEY, MODKEY|LockMask, MODKEY|numlockmask,
+ MODKEY|numlockmask|LockMask} ;
- if(focused) {
- XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
- GrabModeAsync, GrabModeSync, None, None);
- XGrabButton(dpy, Button1, MODKEY|LockMask, c->win, False, BUTTONMASK,
- GrabModeAsync, GrabModeSync, None, None);
- XGrabButton(dpy, Button1, MODKEY|numlockmask, c->win, False, BUTTONMASK,
- GrabModeAsync, GrabModeSync, None, None);
- XGrabButton(dpy, Button1, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
- GrabModeAsync, GrabModeSync, None, None);
-
- XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
- GrabModeAsync, GrabModeSync, None, None);
- XGrabButton(dpy, Button2, MODKEY|LockMask, c->win, False, BUTTONMASK,
- GrabModeAsync, GrabModeSync, None, None);
- XGrabButton(dpy, Button2, MODKEY|numlockmask, c->win, False, BUTTONMASK,
- GrabModeAsync, GrabModeSync, None, None);
- XGrabButton(dpy, Button2, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
- GrabModeAsync, GrabModeSync, None, None);
-
- XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
- GrabModeAsync, GrabModeSync, None, None);
- XGrabButton(dpy, Button3, MODKEY|LockMask, c->win, False, BUTTONMASK,
- GrabModeAsync, GrabModeSync, None, None);
- XGrabButton(dpy, Button3, MODKEY|numlockmask, c->win, False, BUTTONMASK,
- GrabModeAsync, GrabModeSync, None, None);
- XGrabButton(dpy, Button3, MODKEY|numlockmask|LockMask, c->win, False, BUTTONMASK,
- GrabModeAsync, GrabModeSync, None, None);
- }
+ XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
+ 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
- XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
- GrabModeAsync, GrabModeSync, None, None);
+ XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
+ BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
}
void
idxoftag(const char *t) {
unsigned int i;
- for(i = 0; (i < LENGTH(tags)) && strcmp(tags[i], t); i++);
+ for(i = 0; (i < LENGTH(tags)) && t && strcmp(tags[i], t); i++);
return (i < LENGTH(tags)) ? i : 0;
}
Client *c;
for(c = clients; c; c = c->next)
- if(isvisible(c))
+ if((lt->isfloating || !c->isfloating) && isvisible(c))
resize(c, mox, moy, mow - 2 * c->bw, moh - 2 * c->bw, RESIZEHINTS);
}
if(sizehints) {
/* set minimum possible */
- if (w < 1)
+ if(w < 1)
w = 1;
- if (h < 1)
+ if(h < 1)
h = 1;
/* temporarily remove base dimensions */
h -= c->baseh;
/* adjust for aspect limits */
- if (c->minay > 0 && c->maxay > 0 && c->minax > 0 && c->maxax > 0) {
- if (w * c->maxay > h * c->maxax)
+ if(c->minax != c->maxax && c->minay != c->maxay
+ && c->minax > 0 && c->maxax > 0 && c->minay > 0 && c->maxay > 0)
+ {
+ if(w * c->maxay > h * c->maxax)
w = h * c->maxax / c->maxay;
- else if (w * c->minay < h * c->minax)
+ else if(w * c->minay < h * c->minax)
h = w * c->minay / c->minax;
}
setgeom(const char *arg) {
unsigned int i;
- for(i = 0; arg && i < LENGTH(geoms); i++)
- if(!strcmp(geoms[i].symbol, arg))
- break;
- if(i == LENGTH(geoms))
- return;
- geom = &geoms[i];
+ if(!arg) {
+ if(++geom == &geoms[LENGTH(geoms)])
+ geom = &geoms[0];
+ }
+ else {
+ for(i = 0; i < LENGTH(geoms); i++)
+ if(!strcmp(geoms[i].symbol, arg))
+ break;
+ if(i == LENGTH(geoms))
+ return;
+ geom = &geoms[i];
+ }
geom->apply();
updatebarpos();
arrange();
void
setlayout(const char *arg) {
- static Layout *revert = 0;
unsigned int i;
- if(!arg)
- return;
- for(i = 0; i < LENGTH(layouts); i++)
- if(!strcmp(arg, layouts[i].symbol))
- break;
- if(i == LENGTH(layouts))
- return;
- if(revert && &layouts[i] == lt)
- lt = revert;
+ if(!arg) {
+ if(++lt == &layouts[LENGTH(layouts)])
+ lt = &layouts[0];
+ }
else {
- revert = lt;
+ for(i = 0; i < LENGTH(layouts); i++)
+ if(!strcmp(arg, layouts[i].symbol))
+ break;
+ if(i == LENGTH(layouts))
+ return;
lt = &layouts[i];
}
if(sel)
drawbar();
}
+void
+setmfact(const char *arg) {
+ double d;
+
+ if(lt->isfloating)
+ return;
+ if(!arg)
+ mfact = MFACT;
+ else {
+ d = strtod(arg, NULL);
+ if(arg[0] == '-' || arg[0] == '+')
+ d += mfact;
+ if(d < 0.1 || d > 0.9)
+ return;
+ mfact = d;
+ }
+ setgeom(geom->symbol);
+}
+
void
setup(void) {
- unsigned int i;
+ unsigned int i, w;
XSetWindowAttributes wa;
/* init screen */
sw = DisplayWidth(dpy, screen);
sh = DisplayHeight(dpy, screen);
bh = dc.font.height + 2;
- geom = &geoms[0];
+ mfact = MFACT;
geom->apply();
/* init atoms */
prevtags = emallocz(TAGSZ);
seltags[0] = prevtags[0] = True;
- /* init layouts */
- lt = &layouts[0];
-
/* init bar */
- for(blw = i = 0; i < LENGTH(layouts); i++) {
- i = textw(layouts[i].symbol);
- if(i > blw)
- blw = i;
+ for(blw = i = 0; LENGTH(layouts) > 1 && i < LENGTH(layouts); i++) {
+ w = textw(layouts[i].symbol);
+ if(w > blw)
+ blw = w;
}
- for(bgw = i = 0; i < LENGTH(geoms); i++) {
- i = textw(geoms[i].symbol);
- if(i > bgw)
- bgw = i;
+ for(bgw = i = 0; LENGTH(geoms) > 1 && i < LENGTH(geoms); i++) {
+ w = textw(geoms[i].symbol);
+ if(w > bgw)
+ bgw = w;
}
wa.override_redirect = 1;
XCloseDisplay(dpy);
return 0;
}
+