0
* Each child of the root window is called a client, except windows which have
0
* set the override_redirect flag. Clients are organized in a global
0
- * doubly-linked client list, the focus history is remembered through a global
0
- * stack list. Each client contains an array of Bools of the same size as the
0
- * global tags array to indicate the tags of a client. For each client dwm
0
- * creates a small title window, which is resized whenever the (_NET_)WM_NAME
0
- * properties are updated or the client is moved/resized.
0
+ * linked client list, the focus history is remembered through a global
0
+ * stack list. Each client contains a bit array to indicate the tags of a
0
* Keys and tagging rules are organized as arrays and defined in config.h.
0
#include <sys/select.h>
0
#include <X11/cursorfont.h>
0
#include <X11/keysym.h>
0
#include <X11/Xproto.h>
0
+#include <X11/extensions/Xinerama.h>
0
-#define BUTTONMASK (ButtonPressMask | ButtonReleaseMask)
0
-#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
0
-#define MOUSEMASK (BUTTONMASK | PointerMotionMask)
0
+#define BUTTONMASK (ButtonPressMask|ButtonReleaseMask)
0
+#define CLEANMASK(mask) (mask & ~(numlockmask|LockMask))
0
+#define INRECT(X,Y,RX,RY,RW,RH) ((X) >= (RX) && (X) < (RX) + (RW) && (Y) >= (RY) && (Y) < (RY) + (RH))
0
+#define ISVISIBLE(x) (x->tags & tagset[seltags])
0
+#define LENGTH(x) (sizeof x / sizeof x[0])
0
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
0
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
0
+#define MOUSEMASK (BUTTONMASK|PointerMotionMask)
0
+#define WIDTH(x) ((x)->w + 2 * (x)->bw)
0
+#define HEIGHT(x) ((x)->h + 2 * (x)->bw)
0
+#define TAGMASK ((int)((1LL << LENGTH(tags)) - 1))
0
+#define TEXTW(x) (textnw(x, strlen(x)) + dc.font.height)
0
-enum { BarTop, BarBot, BarOff }; /* bar position */
0
-enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
0
-enum { ColBorder, ColFG, ColBG, ColLast }; /* color */
0
-enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */
0
-enum { WMProtocols, WMDelete, WMName, WMState, WMLast };/* default atoms */
0
+enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
0
+enum { ColBorder, ColFG, ColBG, ColLast }; /* color */
0
+enum { NetSupported, NetWMName, NetLast }; /* EWMH atoms */
0
+enum { WMProtocols, WMDelete, WMState, WMLast }; /* default atoms */
0
+enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
0
+ ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
0
+ void (*func)(const Arg *arg);
0
typedef struct Client Client;
0
- int rx, ry, rw, rh; /* revert geometry */
0
int basew, baseh, incw, inch, maxw, maxh, minw, minh;
0
- int minax, maxax, minay, maxay;
0
- unsigned int border, oldborder;
0
- Bool isbanned, isfixed, ismax, isfloating, wasfloating;
0
+ Bool isfixed, isfloating, isurgent;
0
@@ -89,10 +111,10 @@ typedef struct {
0
} DC; /* draw context */
0
- void (*func)(const char *arg);
0
+ void (*func)(const Arg *);
0
@@ -101,191 +123,165 @@ typedef struct {
0
/* function declarations */
0
-void applyrules(Client *c);
0
-void attach(Client *c);
0
-void attachstack(Client *c);
0
-void buttonpress(XEvent *e);
0
-void checkotherwm(void);
0
-void compileregs(void);
0
-void configure(Client *c);
0
-void configurenotify(XEvent *e);
0
-void configurerequest(XEvent *e);
0
-void destroynotify(XEvent *e);
0
-void detach(Client *c);
0
-void detachstack(Client *c);
0
-void drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]);
0
-void drawtext(const char *text, unsigned long col[ColLast]);
0
-void *emallocz(unsigned int size);
0
-void enternotify(XEvent *e);
0
-void eprint(const char *errstr, ...);
0
-void expose(XEvent *e);
0
-void floating(void); /* default floating layout */
0
-void focusnext(const char *arg);
0
-void focusprev(const char *arg);
0
-Client *getclient(Window w);
0
-unsigned long getcolor(const char *colstr);
0
-long getstate(Window w);
0
-Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
0
-void grabbuttons(Client *c, Bool focused);
0
-unsigned int idxoftag(const char *tag);
0
-void initfont(const char *fontstr);
0
-Bool isarrange(void (*func)());
0
-Bool isoccupied(unsigned int t);
0
-Bool isprotodel(Client *c);
0
-Bool isvisible(Client *c);
0
-void keypress(XEvent *e);
0
-void killclient(const char *arg);
0
-void leavenotify(XEvent *e);
0
-void manage(Window w, XWindowAttributes *wa);
0
-void mappingnotify(XEvent *e);
0
-void maprequest(XEvent *e);
0
-void movemouse(Client *c);
0
-Client *nexttiled(Client *c);
0
-void propertynotify(XEvent *e);
0
-void quit(const char *arg);
0
-void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
0
-void resizemouse(Client *c);
0
-void setclientstate(Client *c, long state);
0
-void setlayout(const char *arg);
0
-void setmwfact(const char *arg);
0
-void spawn(const char *arg);
0
-void tag(const char *arg);
0
-unsigned int textnw(const char *text, unsigned int len);
0
-unsigned int textw(const char *text);
0
-void togglebar(const char *arg);
0
-void togglefloating(const char *arg);
0
-void togglemax(const char *arg);
0
-void toggletag(const char *arg);
0
-void toggleview(const char *arg);
0
-void unmanage(Client *c);
0
-void unmapnotify(XEvent *e);
0
-void updatebarpos(void);
0
-void updatesizehints(Client *c);
0
-void updatetitle(Client *c);
0
-void view(const char *arg);
0
-void viewprevtag(const char *arg); /* views previous selected tags */
0
-int xerror(Display *dpy, XErrorEvent *ee);
0
-int xerrordummy(Display *dsply, XErrorEvent *ee);
0
-int xerrorstart(Display *dsply, XErrorEvent *ee);
0
-void zoom(const char *arg);
0
+static void applyrules(Client *c);
0
+static void arrange(void);
0
+static void attach(Client *c);
0
+static void attachstack(Client *c);
0
+static void buttonpress(XEvent *e);
0
+static void checkotherwm(void);
0
+static void cleanup(void);
0
+static void clearurgent(Client *c);
0
+static void configure(Client *c);
0
+static void configurenotify(XEvent *e);
0
+static void configurerequest(XEvent *e);
0
+static void destroynotify(XEvent *e);
0
+static void detach(Client *c);
0
+static void detachstack(Client *c);
0
+static void die(const char *errstr, ...);
0
+static void drawbar(void);
0
+static void drawsquare(Bool filled, Bool empty, Bool invert, unsigned long col[ColLast]);
0
+static void drawtext(const char *text, unsigned long col[ColLast], Bool invert);
0
+static void enternotify(XEvent *e);
0
+static void expose(XEvent *e);
0
+static void focus(Client *c);
0
+static void focusin(XEvent *e);
0
+static void focusstack(const Arg *arg);
0
+static Client *getclient(Window w);
0
+static unsigned long getcolor(const char *colstr);
0
+static long getstate(Window w);
0
+static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
0
+static void grabbuttons(Client *c, Bool focused);
0
+static void grabkeys(void);
0
+static void initfont(const char *fontstr);
0
+static Bool isprotodel(Client *c);
0
+static void keypress(XEvent *e);
0
+static void killclient(const Arg *arg);
0
+static void manage(Window w, XWindowAttributes *wa);
0
+static void mappingnotify(XEvent *e);
0
+static void maprequest(XEvent *e);
0
+static void monocle(void);
0
+static void movemouse(const Arg *arg);
0
+static Client *nexttiled(Client *c);
0
+static void propertynotify(XEvent *e);
0
+static void quit(const Arg *arg);
0
+static void resize(Client *c, int x, int y, int w, int h, Bool sizehints);
0
+static void resizemouse(const Arg *arg);
0
+static void restack(void);
0
+static void scan(void);
0
+static void setclientstate(Client *c, long state);
0
+static void setlayout(const Arg *arg);
0
+static void setmfact(const Arg *arg);
0
+static void setup(void);
0
+static void showhide(Client *c);
0
+static void spawn(const Arg *arg);
0
+static void tag(const Arg *arg);
0
+static int textnw(const char *text, unsigned int len);
0
+static void tile(void);
0
+static void togglebar(const Arg *arg);
0
+static void togglefloating(const Arg *arg);
0
+static void toggletag(const Arg *arg);
0
+static void toggleview(const Arg *arg);
0
+static void unmanage(Client *c);
0
+static void unmapnotify(XEvent *e);
0
+static void updatebar(void);
0
+static void updategeom(void);
0
+static void updatenumlockmask(void);
0
+static void updatesizehints(Client *c);
0
+static void updatetitle(Client *c);
0
+static void updatewmhints(Client *c);
0
+static void view(const Arg *arg);
0
+static int xerror(Display *dpy, XErrorEvent *ee);
0
+static int xerrordummy(Display *dpy, XErrorEvent *ee);
0
+static int xerrorstart(Display *dpy, XErrorEvent *ee);
0
+static void zoom(const Arg *arg);
0
-int screen, sx, sy, sw, sh, wax, way, waw, wah;
0
-int (*xerrorxlib)(Display *, XErrorEvent *);
0
-unsigned int ltidx = 0; /* default */
0
-unsigned int nlayouts = 0;
0
-unsigned int nrules = 0;
0
-unsigned int numlockmask = 0;
0
-void (*handler[LASTEvent]) (XEvent *) = {
0
+static char stext[256];
0
+static int sx, sy, sw, sh; /* X display screen geometry x, y, width, height */
0
+static int by, bh, blw; /* bar geometry y, height and layout symbol width */
0
+static int wx, wy, ww, wh; /* window area geometry x, y, width, height, bar excluded */
0
+static unsigned int seltags = 0, sellt = 0;
0
+static int (*xerrorxlib)(Display *, XErrorEvent *);
0
+static unsigned int numlockmask = 0;
0
+static void (*handler[LASTEvent]) (XEvent *) = {
0
[ButtonPress] = buttonpress,
0
[ConfigureRequest] = configurerequest,
0
[ConfigureNotify] = configurenotify,
0
[DestroyNotify] = destroynotify,
0
[EnterNotify] = enternotify,
0
- [LeaveNotify] = leavenotify,
0
[MappingNotify] = mappingnotify,
0
[MapRequest] = maprequest,
0
[PropertyNotify] = propertynotify,
0
[UnmapNotify] = unmapnotify
0
-Atom wmatom[WMLast], netatom[NetLast];
0
-Client *clients = NULL;
0
-Cursor cursor[CurLast];
0
+static Atom wmatom[WMLast], netatom[NetLast];
0
+static Bool running = True;
0
+static Client *clients = NULL;
0
+static Client *sel = NULL;
0
+static Client *stack = NULL;
0
+static Cursor cursor[CurLast];
0
+static Layout *lt[] = { NULL, NULL };
0
+static Window root, barwin;
0
/* configuration, allows nested code to access above variables */
0
-#define NTAGS (sizeof tags / sizeof tags[0])
0
-Bool seltags[NTAGS] = {[0] = True};
0
-Bool prevtags[NTAGS] = {[0] = True};
0
+/* compile-time check if all tags fit into an unsigned int bit array. */
0
+struct NumTags { char limitexceeded[sizeof(unsigned int) * 8 < LENGTH(tags) ? -1 : 1]; };
0
/* function implementations */
0
applyrules(Client *c) {
0
- XGetClassHint(dpy, c->win, &ch);
0
- snprintf(buf, sizeof buf, "%s:%s:%s",
0
- ch.res_class ? ch.res_class : "",
0
- ch.res_name ? ch.res_name : "", c->name);
0
- for(i = 0; i < nrules; i++)
0
- if(regs[i].propregex && !regexec(regs[i].propregex, buf, 1, &tmp, 0)) {
0
- c->isfloating = rules[i].isfloating;
0
- for(j = 0; regs[i].tagregex && j < NTAGS; j++) {
0
- if(!regexec(regs[i].tagregex, tags[j], 1, &tmp, 0)) {
0
+ if(XGetClassHint(dpy, c->win, &ch)) {
0
+ for(i = 0; i < LENGTH(rules); i++) {
0
+ if((!r->title || strstr(c->name, r->title))
0
+ && (!r->class || (ch.res_class && strstr(ch.res_class, r->class)))
0
+ && (!r->instance || (ch.res_name && strstr(ch.res_name, r->instance)))) {
0
+ c->isfloating = r->isfloating;
0
+ c->tags |= r->tags & TAGMASK;
0
- memcpy(c->tags, seltags, sizeof seltags);
0
+ c->tags = tagset[seltags];
0
- for(c = clients; c; c = c->next)
0
- layouts[ltidx].arrange();
0
+ if(lt[sellt]->arrange)
0
@@ -297,92 +293,62 @@ attachstack(Client *c) {
0
- XMoveWindow(dpy, c->win, c->x + 2 * sw, c->y);
0
buttonpress(XEvent *e) {
0
+ unsigned int i, x, click;
0
XButtonPressedEvent *ev = &e->xbutton;
0
- if(barwin == ev->window) {
0
- for(i = 0; i < NTAGS; i++) {
0
- if(ev->button == Button1) {
0
- if(ev->state & MODKEY)
0
- else if(ev->button == Button3) {
0
- if(ev->state & MODKEY)
0
+ if(ev->window == barwin) {
0
+ do x += TEXTW(tags[i]); while(ev->x >= x && ++i < LENGTH(tags));
0
+ if(i < LENGTH(tags)) {
0
- if((ev->x < x + blw) && ev->button == Button1)
0
+ else if(ev->x < x + blw)
0
+ else if(ev->x > wx + ww - TEXTW(stext))
0
+ click = ClkStatusText;
0
else if((c = getclient(ev->window))) {
0
- if(CLEANMASK(ev->state) != MODKEY)
0
- if(ev->button == Button1) {
0
- if(isarrange(floating) || c->isfloating)
0
- else if(ev->button == Button2) {
0
- if((ISTILE) && !c->isfixed && c->isfloating)
0
- else if(ev->button == Button3 && !c->isfixed) {
0
- if(isarrange(floating) || c->isfloating)
0
+ for(i = 0; i < LENGTH(buttons); i++)
0
+ if(click == buttons[i].click && buttons[i].func && buttons[i].button == ev->button
0
+ && CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
0
+ buttons[i].func(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
0
-
XSetErrorHandler(xerrorstart);
0
+
xerrorxlib = XSetErrorHandler(xerrorstart);
0
/* this causes an error if some other window manager is running */
0
- XSelectInput(dpy,
root, SubstructureRedirectMask);
0
+ XSelectInput(dpy,
DefaultRootWindow(dpy), SubstructureRedirectMask);
0
- eprint("dwm: another window manager is already running\n");
0
- XSetErrorHandler(NULL);
0
- xerrorxlib = XSetErrorHandler(xerror);
0
+ die("dwm: another window manager is already running\n");
0
+ XSetErrorHandler(xerror);
0
+ Layout foo = { "", NULL };
0
XFreeFontSet(dpy, dc.font.set);
0
@@ -390,39 +356,24 @@ cleanup(void) {
0
XUngrabKey(dpy, AnyKey, AnyModifier, root);
0
XFreePixmap(dpy, dc.drawable);
0
- XDestroyWindow(dpy, barwin);
0
XFreeCursor(dpy, cursor[CurNormal]);
0
XFreeCursor(dpy, cursor[CurResize]);
0
XFreeCursor(dpy, cursor[CurMove]);
0
- X
SetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
0
+ X
DestroyWindow(dpy, barwin);
0
+ XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
0
+clearurgent(Client *c) {
0
+ if(!(wmh = XGetWMHints(dpy, c->win)))
0
- nrules = sizeof rules / sizeof rules[0];
0
- regs = emallocz(nrules * sizeof(Regs));
0
- for(i = 0; i < nrules; i++) {
0
- reg = emallocz(sizeof(regex_t));
0
- if(regcomp(reg, rules[i].prop, REG_EXTENDED))
0
- regs[i].propregex = reg;
0
- reg = emallocz(sizeof(regex_t));
0
- if(regcomp(reg, rules[i].tags, REG_EXTENDED))
0
- regs[i].tagregex = reg;
0
+ wmh->flags &= ~XUrgencyHint;
0
+ XSetWMHints(dpy, c->win, wmh);
0
@@ -437,7 +388,7 @@ configure(Client *c) {
0
- ce.border_width = c->b
order;
0
+ ce.border_width = c->b
w;
0
ce.override_redirect = False;
0
XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
0
@@ -450,10 +401,8 @@ configurenotify(XEvent *e) {
0
if(ev->window == root && (ev->width != sw || ev->height != sh)) {
0
- XFreePixmap(dpy, dc.drawable);
0
- dc.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
0
- XResizeWindow(dpy, barwin, sw, bh);
0
@@ -465,26 +414,24 @@ configurerequest(XEvent *e) {
0
if((c = getclient(ev->window))) {
0
if(ev->value_mask & CWBorderWidth)
0
- c->border = ev->border_width;
0
- if(c->isfixed || c->isfloating || isarrange(floating)) {
0
+ c->bw = ev->border_width;
0
+ else if(c->isfloating || !lt[sellt]->arrange) {
0
if(ev->value_mask & CWX)
0
if(ev->value_mask & CWY)
0
if(ev->value_mask & CWWidth)
0
if(ev->value_mask & CWHeight)
0
- if((c->x + c->w) > sw && c->isfloating)
0
- c->x = sw / 2 - c->w / 2; /* center in x direction */
0
- if((c->y + c->h) > sh && c->isfloating)
0
- c->y = sh / 2 - c->h / 2; /* center in y direction */
0
- if((ev->value_mask & (CWX | CWY))
0
- && !(ev->value_mask & (CWWidth | CWHeight)))
0
+ if((c->x - sx + c->w) > sw && c->isfloating)
0
+ c->x = sx + (sw / 2 - c->w / 2); /* center in x direction */
0
+ if((c->y - sy + c->h) > sh && c->isfloating)
0
+ c->y = sy + (sh / 2 - c->h / 2); /* center in y direction */
0
+ if((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
0
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
0
@@ -514,70 +461,85 @@ destroynotify(XEvent *e) {
0
- c->prev->next = c->next;
0
- c->next->prev = c->prev;
0
- c->next = c->prev = NULL;
0
+ for(tc = &clients; *tc && *tc != c; tc = &(*tc)->next);
0
detachstack(Client *c) {
0
- for(tc
=&stack; *tc && *tc != c; tc=&(*tc)->snext);
0
+ for(tc
= &stack; *tc && *tc != c; tc = &(*tc)->snext);
0
+die(const char *errstr, ...) {
0
+ vfprintf(stderr, errstr, ap);
0
- for(i = 0; i < NTAGS; i++) {
0
- dc.w = textw(tags[i]);
0
- drawtext(tags[i], dc.sel);
0
- drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel);
0
- drawtext(tags[i], dc.norm);
0
- drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm);
0
+ unsigned int i, occ = 0, urg = 0;
0
+ for(c = clients; c; c = c->next) {
0
+ for(i = 0; i < LENGTH(tags); i++) {
0
+ dc.w = TEXTW(tags[i]);
0
+ col = tagset[seltags] & 1 << i ? dc.sel : dc.norm;
0
+ drawtext(tags[i], col, urg & 1 << i);
0
+ drawsquare(sel && sel->tags & 1 << i, occ & 1 << i, urg & 1 << i, col);
0
- drawtext(layouts[ltidx].symbol, dc.norm);
0
+ drawtext(lt[sellt]->symbol, dc.norm, False);
0
- drawtext(stext, dc.norm
);
0
+ drawtext(stext, dc.norm
, False);
0
if((dc.w = dc.x - x) > bh) {
0
- drawtext(sel->name, dc.sel);
0
- drawsquare(sel->ismax, sel->isfloating, dc.sel);
0
+ drawtext(sel->name, dc.sel, False);
0
+ drawsquare(sel->isfixed, sel->isfloating, False, dc.sel);
0
- drawtext(NULL, dc.norm
);
0
+ drawtext(NULL, dc.norm
, False);
0
- XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0,
sw, bh, 0, 0);
0
+ XCopyArea(dpy, dc.drawable, barwin, dc.gc, 0, 0,
ww, bh, 0, 0);
0
-drawsquare(Bool filled, Bool empty,
unsigned long col[ColLast]) {
0
+drawsquare(Bool filled, Bool empty,
Bool invert, unsigned long col[ColLast]) {
0
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
0
- gcv.foreground = col[
ColFG];
0
+ gcv.foreground = col[
invert ? ColBG : ColFG];
0
XChangeGC(dpy, dc.gc, GCForeground, &gcv);
0
x = (dc.font.ascent + dc.font.descent + 2) / 4;
0
@@ -593,148 +555,104 @@ drawsquare(Bool filled, Bool empty, unsigned long col[ColLast]) {
0
-drawtext(const char *text, unsigned long col[ColLast]) {
0
- unsigned int len, olen;
0
+drawtext(const char *text, unsigned long col[ColLast], Bool invert) {
0
+ int i, x, y, h, len, olen;
0
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
0
- XSetForeground(dpy, dc.gc, col[
ColBG]);
0
+ XSetForeground(dpy, dc.gc, col[
invert ? ColFG : ColBG]);
0
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
0
- olen = len = strlen(text);
0
- memcpy(buf, text, len);
0
h = dc.font.ascent + dc.font.descent;
0
y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
0
/* shorten text if necessary */
0
- while(len && (w = textnw(buf, len)) > dc.w - h)
0
- return; /* too long */
0
- XSetForeground(dpy, dc.gc, col[ColFG]);
0
+ for(len = MIN(olen, sizeof buf); len && textnw(text, len) > dc.w - h; len--);
0
+ memcpy(buf, text, len);
0
+ for(i = len; i && i > len - 3; buf[--i] = '.');
0
+ XSetForeground(dpy, dc.gc, col[invert ? ColBG : ColFG]);
0
XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
0
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
0
-emallocz(unsigned int size) {
0
- void *res = calloc(1, size);
0
- eprint("fatal: could not malloc() %u bytes\n", size);
0
enternotify(XEvent *e) {
0
XCrossingEvent *ev = &e->xcrossing;
0
- if(
ev->mode != NotifyNormal || ev->detail == NotifyInferior)
0
+ if(
(ev->mode != NotifyNormal || ev->detail == NotifyInferior) && ev->window != root)
0
if((c = getclient(ev->window)))
0
- else if(ev->window == root) {
0
-eprint(const char *errstr, ...) {
0
- vfprintf(stderr, errstr, ap);
0
XExposeEvent *ev = &e->xexpose;
0
- if(barwin == ev->window)
0
-floating(void) { /* default floating layout */
0
- for(c = clients; c; c = c->next)
0
- resize(c, c->x, c->y, c->w, c->h, True);
0
+ if(ev->count == 0 && (ev->window == barwin))
0
- if((!c && selscreen) || (c && !isvisible(c)))
0
- for(c = stack; c && !isvisible(c); c = c->snext);
0
+ if(!c || !ISVISIBLE(c))
0
+ for(c = stack; c && !ISVISIBLE(c); c = c->snext);
0
grabbuttons(sel, False);
0
XSetWindowBorder(dpy, sel->win, dc.norm[ColBorder]);
0
XSetWindowBorder(dpy, c->win, dc.sel[ColBorder]);
0
XSetInputFocus(dpy, c->win, RevertToPointerRoot, CurrentTime);
0
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
0
-focusnext(const char *arg) {
0
+focusin(XEvent *e) { /* there are some broken focus acquiring clients */
0
+ XFocusChangeEvent *ev = &e->xfocus;
0
- for(c = sel->next; c && !isvisible(c); c = c->next);
0
- for(c = clients; c && !isvisible(c); c = c->next);
0
+ if(sel && ev->window != sel->win)
0
+ XSetInputFocus(dpy, sel->win, RevertToPointerRoot, CurrentTime);
0
-focusprev(const char *arg) {
0
+focusstack(const Arg *arg) {
0
- for(c = sel->prev; c && !isvisible(c); c = c->prev);
0
- for(c = clients; c && c->next; c = c->next);
0
- for(; c && !isvisible(c); c = c->prev);
0
+ for(c = sel->next; c && !ISVISIBLE(c); c = c->next);
0
+ for(c = clients; c && !ISVISIBLE(c); c = c->next);
0
+ for(i = clients; i != sel; i = i->next)
0
@@ -756,7 +674,7 @@ getcolor(const char *colstr) {
0
if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
0
-
eprint("error, cannot allocate color '%s'\n", colstr);
0
+
die("error, cannot allocate color '%s'\n", colstr);
0
@@ -794,8 +712,7 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size) {
0
strncpy(text, (char *)name.value, size - 1);
0
if(XmbTextPropertyToTextList(dpy, &name, &list, &n) >= Success
0
strncpy(text, *list, size - 1);
0
@@ -807,47 +724,38 @@ gettextprop(Window w, Atom atom, char *text, unsigned int size) {
0
grabbuttons(Client *c, Bool focused) {
0
- XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
0
- XGrabButton(dpy, Button1, MODKEY, c->win, False, BUTTONMASK,
0
- GrabModeAsync, GrabModeSync, None, None);
0
- XGrabButton(dpy, Button1, MODKEY | LockMask, c->win, False, BUTTONMASK,
0
- GrabModeAsync, GrabModeSync, None, None);
0
- XGrabButton(dpy, Button1, MODKEY | numlockmask, c->win, False, BUTTONMASK,
0
- GrabModeAsync, GrabModeSync, None, None);
0
- XGrabButton(dpy, Button1, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
0
- GrabModeAsync, GrabModeSync, None, None);
0
- XGrabButton(dpy, Button2, MODKEY, c->win, False, BUTTONMASK,
0
- GrabModeAsync, GrabModeSync, None, None);
0
- XGrabButton(dpy, Button2, MODKEY | LockMask, c->win, False, BUTTONMASK,
0
- GrabModeAsync, GrabModeSync, None, None);
0
- XGrabButton(dpy, Button2, MODKEY | numlockmask, c->win, False, BUTTONMASK,
0
- GrabModeAsync, GrabModeSync, None, None);
0
- XGrabButton(dpy, Button2, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
0
- GrabModeAsync, GrabModeSync, None, None);
0
- XGrabButton(dpy, Button3, MODKEY, c->win, False, BUTTONMASK,
0
- GrabModeAsync, GrabModeSync, None, None);
0
- XGrabButton(dpy, Button3, MODKEY | LockMask, c->win, False, BUTTONMASK,
0
- GrabModeAsync, GrabModeSync, None, None);
0
- XGrabButton(dpy, Button3, MODKEY | numlockmask, c->win, False, BUTTONMASK,
0
- GrabModeAsync, GrabModeSync, None, None);
0
- XGrabButton(dpy, Button3, MODKEY | numlockmask | LockMask, c->win, False, BUTTONMASK,
0
- GrabModeAsync, GrabModeSync, None, None);
0
+ unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
0
+ XUngrabButton(dpy, AnyButton, AnyModifier, c->win);
0
+ for(i = 0; i < LENGTH(buttons); i++)
0
+ if(buttons[i].click == ClkClientWin)
0
+ for(j = 0; j < LENGTH(modifiers); j++)
0
+ XGrabButton(dpy, buttons[i].button, buttons[i].mask | modifiers[j], c->win, False, BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
0
+ XGrabButton(dpy, AnyButton, AnyModifier, c->win, False,
0
+ BUTTONMASK, GrabModeAsync, GrabModeSync, None, None);
0
- XGrabButton(dpy, AnyButton, AnyModifier, c->win, False, BUTTONMASK,
0
- GrabModeAsync, GrabModeSync, None, None);
0
-idxoftag(const char *tag) {
0
+ unsigned int modifiers[] = { 0, LockMask, numlockmask, numlockmask|LockMask };
0
- for(i = 0; (i < NTAGS) && (tags[i] != tag); i++);
0
- return (i < NTAGS) ? i : 0;
0
+ XUngrabKey(dpy, AnyKey, AnyModifier, root);
0
+ for(i = 0; i < LENGTH(keys); i++) {
0
+ if((code = XKeysymToKeycode(dpy, keys[i].keysym)))
0
+ for(j = 0; j < LENGTH(modifiers); j++)
0
+ XGrabKey(dpy, code, keys[i].mod | modifiers[j], root,
0
+ True, GrabModeAsync, GrabModeAsync);
0
@@ -856,8 +764,6 @@ initfont(const char *fontstr) {
0
- XFreeFontSet(dpy, dc.font.set);
0
dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
0
@@ -872,20 +778,15 @@ initfont(const char *fontstr) {
0
font_extents = XExtentsOfFontSet(dc.font.set);
0
n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
0
for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
0
- if(dc.font.ascent < (*xfonts)->ascent)
0
- dc.font.ascent = (*xfonts)->ascent;
0
- if(dc.font.descent < (*xfonts)->descent)
0
- dc.font.descent = (*xfonts)->descent;
0
+ dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
0
+ dc.font.descent = MAX(dc.font.descent,(*xfonts)->descent);
0
- XFreeFont(dpy, dc.font.xfont);
0
if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
0
&& !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
0
-
eprint("error, cannot load font: '%s'\n", fontstr);
0
+
die("error, cannot load font: '%s'\n", fontstr);
0
dc.font.ascent = dc.font.xfont->ascent;
0
dc.font.descent = dc.font.xfont->descent;
0
@@ -893,22 +794,6 @@ initfont(const char *fontstr) {
0
-isarrange(void (*func)())
0
- return func == layouts[ltidx].arrange;
0
-isoccupied(unsigned int t) {
0
- for(c = clients; c; c = c->next)
0
isprotodel(Client *c) {
0
@@ -923,53 +808,23 @@ isprotodel(Client *c) {
0
- for(i = 0; i < NTAGS; i++)
0
- if(c->tags[i] && seltags[i])
0
- unsigned int len = sizeof keys / sizeof keys[0];
0
- if(!e) { /* grabkeys */
0
- XUngrabKey(dpy, AnyKey, AnyModifier, root);
0
- for(i = 0; i < len; i++) {
0
- code = XKeysymToKeycode(dpy, keys[i].keysym);
0
- XGrabKey(dpy, code, keys[i].mod, root, True,
0
- GrabModeAsync, GrabModeAsync);
0
- XGrabKey(dpy, code, keys[i].mod | LockMask, root, True,
0
- GrabModeAsync, GrabModeAsync);
0
- XGrabKey(dpy, code, keys[i].mod | numlockmask, root, True,
0
- GrabModeAsync, GrabModeAsync);
0
- XGrabKey(dpy, code, keys[i].mod | numlockmask | LockMask, root, True,
0
- GrabModeAsync, GrabModeAsync);
0
keysym = XKeycodeToKeysym(dpy, (KeyCode)ev->keycode, 0);
0
- for(i = 0; i <
len; i++)
0
+ for(i = 0; i <
LENGTH(keys); i++)
0
if(keysym == keys[i].keysym
0
- && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state))
0
- keys[i].func(keys[i].arg);
0
+ && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
0
+ keys[i].func(&(keys[i].arg));
0
-killclient(const
char *arg) {
0
+killclient(const
Arg *arg) {
0
@@ -988,66 +843,60 @@ killclient(const char *arg) {
0
-leavenotify(XEvent *e) {
0
- XCrossingEvent *ev = &e->xcrossing;
0
- if((ev->window == root) && !ev->same_screen) {
0
manage(Window w, XWindowAttributes *wa) {
0
- c = emallocz(sizeof(Client));
0
- c->tags = emallocz(sizeof seltags);
0
+ if(!(c = malloc(sizeof(Client))))
0
+ die("fatal: could not malloc() %u bytes\n", sizeof(Client));
0
- c->oldb
order = wa->border_width;
0
+ c->oldb
w = wa->border_width;
0
if(c->w == sw && c->h == sh) {
0
- c->b
order = wa->border_width;
0
- if(c->x + c->w + 2 * c->border > wax + waw)
0
- c->x = wax + waw - c->w - 2 * c->border;
0
- if(c->y + c->h + 2 * c->border > way + wah)
0
- c->y = way + wah - c->h - 2 * c->border;
0
+ if(c->x + WIDTH(c) > sx + sw)
0
+ c->x = sx + sw - WIDTH(c);
0
+ if(c->y + HEIGHT(c) > sy + sh)
0
+ c->y = sy + sh - HEIGHT(c);
0
+ /* only fix client y-offset, if the client center might cover the bar */
0
+ c->y = MAX(c->y, ((by == 0) && (c->x + (c->w / 2) >= wx) && (c->x + (c->w / 2) < wx + ww)) ? bh : sy);
0
- wc.border_width = c->border;
0
+ wc.border_width = c->bw;
0
XConfigureWindow(dpy, w, CWBorderWidth, &wc);
0
XSetWindowBorder(dpy, w, dc.norm[ColBorder]);
0
configure(c); /* propagates border_width, if size doesn't change */
0
- StructureNotifyMask | PropertyChangeMask | EnterWindowMask);
0
+ XSelectInput(dpy, w, EnterWindowMask|FocusChangeMask|PropertyChangeMask|StructureNotifyMask);
0
- if((rettrans = XGetTransientForHint(dpy, w, &trans) == Success))
0
- for(t = clients; t && t->win != trans; t = t->next);
0
+ if(XGetTransientForHint(dpy, w, &trans))
0
- memcpy(c->tags, t->tags, sizeof seltags);
0
- c->isfloating = (rettrans == Success) || c->isfixed;
0
+ c->isfloating = trans != None || c->isfixed;
0
+ XRaiseWindow(dpy, c->win);
0
- XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); /* some windows require this */
0
+ XMoveResizeWindow(dpy, c->win, c->x + 2 * sw, c->y, c->w, c->h); /* some windows require this */
0
XMapWindow(dpy, c->win);
0
setclientstate(c, NormalState);
0
@@ -1059,7 +908,7 @@ mappingnotify(XEvent *e) {
0
XRefreshKeyboardMapping(ev);
0
if(ev->request == MappingKeyboard)
0
@@ -1076,51 +925,70 @@ maprequest(XEvent *e) {
0
- int x1, y1, ocx, ocy, di, nx, ny;
0
+ for(c = nexttiled(clients); c; c = nexttiled(c->next))
0
+ resize(c, wx, wy, ww - 2 * c->bw, wh - 2 * c->bw, resizehints);
0
+movemouse(const Arg *arg) {
0
+ int x, y, ocx, ocy, di, nx, ny;
0
if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
0
-
None, cursor[CurMove], CurrentTime) != GrabSuccess)
0
+
None, cursor[CurMove], CurrentTime) != GrabSuccess)
0
- XQueryPointer(dpy, root, &dummy, &dummy, &x1, &y1, &di, &di, &dui);
0
- XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask, &ev);
0
+ XQueryPointer(dpy, root, &dummy, &dummy, &x, &y, &di, &di, &dui);
0
+ XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
0
- XUngrabPointer(dpy, CurrentTime);
0
- nx = ocx + (ev.xmotion.x - x1);
0
- ny = ocy + (ev.xmotion.y - y1);
0
- if(abs(wax + nx) < SNAP)
0
- else if(abs((wax + waw) - (nx + c->w + 2 * c->border)) < SNAP)
0
- nx = wax + waw - c->w - 2 * c->border;
0
- if(abs(way - ny) < SNAP)
0
- else if(abs((way + wah) - (ny + c->h + 2 * c->border)) < SNAP)
0
- ny = way + wah - c->h - 2 * c->border;
0
- resize(c, nx, ny, c->w, c->h, False);
0
+ nx = ocx + (ev.xmotion.x - x);
0
+ ny = ocy + (ev.xmotion.y - y);
0
+ if(snap && nx >= wx && nx <= wx + ww
0
+ && ny >= wy && ny <= wy + wh) {
0
+ if(abs(wx - nx) < snap)
0
+ else if(abs((wx + ww) - (nx + WIDTH(c))) < snap)
0
+ nx = wx + ww - WIDTH(c);
0
+ if(abs(wy - ny) < snap)
0
+ else if(abs((wy + wh) - (ny + HEIGHT(c))) < snap)
0
+ ny = wy + wh - HEIGHT(c);
0
+ if(!c->isfloating && lt[sellt]->arrange && (abs(nx - c->x) > snap || abs(ny - c->y) > snap))
0
+ if(!lt[sellt]->arrange || c->isfloating)
0
+ resize(c, nx, ny, c->w, c->h, False);
0
+ while(ev.type != ButtonRelease);
0
+ XUngrabPointer(dpy, CurrentTime);
0
- for(; c && (c->isfloating || !
isvisible(c)); c = c->next);
0
+ for(; c && (c->isfloating || !
ISVISIBLE(c)); c = c->next);
0
@@ -1134,15 +1002,19 @@ propertynotify(XEvent *e) {
0
if((c = getclient(ev->window))) {
0
- case XA_WM_TRANSIENT_FOR:
0
- XGetTransientForHint(dpy, c->win, &trans);
0
- if(!c->isfloating && (c->isfloating = (NULL != getclient(trans))))
0
- case XA_WM_NORMAL_HINTS:
0
+ case XA_WM_TRANSIENT_FOR:
0
+ XGetTransientForHint(dpy, c->win, &trans);
0
+ if(!c->isfloating && (c->isfloating = (getclient(trans) != NULL)))
0
+ case XA_WM_NORMAL_HINTS:
0
if(ev->atom == XA_WM_NAME || ev->atom == netatom[NetWMName]) {
0
@@ -1153,7 +1025,7 @@ propertynotify(XEvent *e) {
0
-quit(const
char *arg) {
0
readin = running = False;
0
@@ -1162,22 +1034,29 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
0
+ /* see last two sentences in ICCCM 4.1.2.3 */
0
+ Bool baseismin = c->basew == c->minw && c->baseh == c->minh;
0
/* set minimum possible */
0
- /* temporarily remove base dimensions */
0
+ if(!baseismin) { /* temporarily remove base dimensions */
0
/* adjust for aspect limits */
0
- if (c->minay > 0 && c->maxay > 0 && c->minax > 0 && c->maxax > 0) {
0
- if (w * c->maxay > h * c->maxax)
0
- w = h * c->maxax / c->maxay;
0
- else if (w * c->minay < h * c->minax)
0
- h = w * c->minay / c->minax;
0
+ if(c->mina > 0 && c->maxa > 0) {
0
+ if(c->maxa < (float)w / h)
0
+ else if(c->mina < (float)h / w)
0
+ if(baseismin) { /* increment calculation requires this */
0
/* adjust for increment value */
0
@@ -1190,75 +1069,89 @@ resize(Client *c, int x, int y, int w, int h, Bool sizehints) {
0
- if(c->minw > 0 && w < c->minw)
0
- if(c->minh > 0 && h < c->minh)
0
- if(c->maxw > 0 && w > c->maxw)
0
- if(c->maxh > 0 && h > c->maxh)
0
- /* offscreen appearance fixes */
0
- x = sw - w - 2 * c->border;
0
- y = sh - h - 2 * c->border;
0
- if(x + w + 2 * c->border < sx)
0
+ if(x + w + 2 * c->bw < sx)
0
- if(y + h + 2 * c->b
order < sy)
0
+ if(y + h + 2 * c->b
w < sy)
0
if(c->x != x || c->y != y || c->w != w || c->h != h) {
0
- wc.border_width = c->border;
0
- XConfigureWindow(dpy, c->win, CWX | CWY | CWWidth | CWHeight | CWBorderWidth, &wc);
0
+ wc.border_width = c->bw;
0
+ XConfigureWindow(dpy, c->win,
0
+ CWX|CWY|CWWidth|CWHeight|CWBorderWidth, &wc);
0
-resizemouse(
Client *c) {
0
+resizemouse(
const Arg *arg) {
0
if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
0
-
None, cursor[CurResize], CurrentTime) != GrabSuccess)
0
+
None, cursor[CurResize], CurrentTime) != GrabSuccess)
0
- XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->border - 1, c->h + c->border - 1);
0
- XMaskEvent(dpy, MOUSEMASK | ExposureMask | SubstructureRedirectMask , &ev);
0
+ XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
0
+ XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
0
- XWarpPointer(dpy, None, c->win, 0, 0, 0, 0,
0
- c->w + c->border - 1, c->h + c->border - 1);
0
- XUngrabPointer(dpy, CurrentTime);
0
- while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
0
- if((nw = ev.xmotion.x - ocx - 2 * c->border + 1) <= 0)
0
- if((nh = ev.xmotion.y - ocy - 2 * c->border + 1) <= 0)
0
- resize(c, c->x, c->y, nw, nh, True);
0
+ nw = MAX(ev.xmotion.x - ocx - 2*c->bw + 1, 1);
0
+ nh = MAX(ev.xmotion.y - ocy - 2*c->bw + 1, 1);
0
+ if(snap && nw >= wx && nw <= wx + ww
0
+ && nh >= wy && nh <= wy + wh) {
0
+ if(!c->isfloating && lt[sellt]->arrange
0
+ && (abs(nw - c->w) > snap || abs(nh - c->h) > snap))
0
+ if(!lt[sellt]->arrange || c->isfloating)
0
+ resize(c, c->x, c->y, nw, nh, True);
0
+ while(ev.type != ButtonRelease);
0
+ XWarpPointer(dpy, None, c->win, 0, 0, 0, 0, c->w + c->bw - 1, c->h + c->bw - 1);
0
+ XUngrabPointer(dpy, CurrentTime);
0
+ while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
0
@@ -1270,21 +1163,16 @@ restack(void) {
0
- if(sel->isfloating ||
isarrange(floating))
0
+ if(sel->isfloating ||
!lt[sellt]->arrange)
0
XRaiseWindow(dpy, sel->win);
0
- if(
!isarrange(floating)) {
0
+ if(
lt[sellt]->arrange) {
0
- if(!sel->isfloating) {
0
- XConfigureWindow(dpy, sel->win, CWSibling | CWStackMode, &wc);
0
- wc.sibling = sel->win;
0
- for(c = nexttiled(clients); c; c = nexttiled(c->next)) {
0
- XConfigureWindow(dpy, c->win, CWSibling | CWStackMode, &wc);
0
+ for(c = stack; c; c = c->snext)
0
+ if(!c->isfloating && ISVISIBLE(c)) {
0
+ XConfigureWindow(dpy, c->win, CWSibling|CWStackMode, &wc);
0
while(XCheckMaskEvent(dpy, EnterWindowMask, &ev));
0
@@ -1293,14 +1181,18 @@ restack(void) {
0
+
char sbuf[sizeof stext];
0
+ unsigned int len, offset;
0
/* main event loop, also reads status text from stdin */
0
xfd = ConnectionNumber(dpy);
0
+ len = sizeof stext - 1;
0
+ sbuf[len] = stext[len] = '\0'; /* 0-terminator is never touched */
0
@@ -1309,13 +1201,12 @@ run(void) {
0
if(select(xfd + 1, &rd, NULL, NULL, NULL) == -1) {
0
-
eprint("select failed\n");
0
+
die("select failed\n");
0
if(FD_ISSET(STDIN_FILENO, &rd)) {
0
- switch(
r = read(STDIN_FILENO, stext, sizeof stext - 1)) {
0
+ switch(
(r = read(STDIN_FILENO, sbuf + offset, len - offset))) {
0
- strncpy(stext, strerror(errno), sizeof stext - 1);
0
- stext[sizeof stext - 1] = '\0';
0
+ strncpy(stext, strerror(errno), len);
0
@@ -1323,10 +1214,18 @@ run(void) {
0
- for(stext[r] = '\0', p = stext + strlen(stext) - 1; p >= stext && *p == '\n'; *p-- = '\0');
0
- for(; p >= stext && *p != '\n'; --p);
0
- strncpy(stext, p + 1, sizeof stext);
0
+ for(p = sbuf + offset; r > 0; p++, r--, offset++)
0
+ if(*p == '\n' || *p == '\0') {
0
+ strncpy(stext, sbuf, len);
0
+ p += r - 1; /* p is sbuf + offset + r - 1 */
0
+ for(r = 0; *(p - r) && *(p - r) != '\n'; r++);
0
+ memmove(sbuf, p - r + 1, r);
0
@@ -1341,10 +1240,9 @@ run(void) {