t* dwm + patches
       
   URI git clone git://git.codevoid.de/dwm-sdk
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 3b59a15d64e38b4196139bb05bb08b8d2ef49335
   DIR parent 03ad240e77c1286808933fed7c3555a905042106
   URI Author: Stefan Hagen <sh+git[at]codevoid[dot]de>
       Date:   Thu, 31 Oct 2019 20:04:50 +0100
       
       %retab
       
       Diffstat:
         M dwm.c                               |    3552 +++++++++++++++----------------
       
       1 file changed, 1769 insertions(+), 1783 deletions(-)
       ---
   DIR diff --git a/dwm.c b/dwm.c
       t@@ -86,93 +86,93 @@ enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
               ClkClientWin, ClkRootWin, ClkLast }; /* clicks */
        
        typedef union {
       -        int i;
       -        unsigned int ui;
       -        float f;
       -        const void *v;
       +    int i;
       +    unsigned int ui;
       +    float f;
       +    const void *v;
        } Arg;
        
        typedef struct {
       -        unsigned int click;
       -        unsigned int mask;
       -        unsigned int button;
       -        void (*func)(const Arg *arg);
       -        const Arg arg;
       +    unsigned int click;
       +    unsigned int mask;
       +    unsigned int button;
       +    void (*func)(const Arg *arg);
       +    const Arg arg;
        } Button;
        
        typedef struct Monitor Monitor;
        typedef struct Client Client;
        struct Client {
       -        char name[256];
       -        float mina, maxa;
       -        int x, y, w, h;
       -        int oldx, oldy, oldw, oldh;
       -        int basew, baseh, incw, inch, maxw, maxh, minw, minh;
       -        int bw, oldbw;
       -        unsigned int tags;
       -        int ismax, wasfloating, isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
       -        Client *next;
       -        Client *snext;
       -        Monitor *mon;
       -        Window win;
       +    char name[256];
       +    float mina, maxa;
       +    int x, y, w, h;
       +    int oldx, oldy, oldw, oldh;
       +    int basew, baseh, incw, inch, maxw, maxh, minw, minh;
       +    int bw, oldbw;
       +    unsigned int tags;
       +    int ismax, wasfloating, isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen;
       +    Client *next;
       +    Client *snext;
       +    Monitor *mon;
       +    Window win;
        };
        
        typedef struct {
       -        unsigned int mod;
       -        KeySym keysym;
       -        void (*func)(const Arg *);
       -        const Arg arg;
       +    unsigned int mod;
       +    KeySym keysym;
       +    void (*func)(const Arg *);
       +    const Arg arg;
        } Key;
        
        typedef struct {
       -        const char *symbol;
       -        void (*arrange)(Monitor *);
       +    const char *symbol;
       +    void (*arrange)(Monitor *);
        } Layout;
        
        typedef struct Pertag Pertag;
        struct Monitor {
       -        char ltsymbol[16];
       -        float mfact;
       -        int nmaster;
       -        int num;
       -        int by;               /* bar geometry */
       -        int mx, my, mw, mh;   /* screen size */
       -        int wx, wy, ww, wh;   /* window area  */
       -        unsigned int seltags;
       -        unsigned int sellt;
       -        unsigned int tagset[2];
       -        int showbar;
       -        int topbar;
       -        Client *clients;
       -        Client *sel;
       -        Client *stack;
       -        Monitor *next;
       -        Window barwin;
       -        const Layout *lt[2];
       +    char ltsymbol[16];
       +    float mfact;
       +    int nmaster;
       +    int num;
       +    int by;               /* bar geometry */
       +    int mx, my, mw, mh;   /* screen size */
       +    int wx, wy, ww, wh;   /* window area  */
       +    unsigned int seltags;
       +    unsigned int sellt;
       +    unsigned int tagset[2];
       +    int showbar;
       +    int topbar;
       +    Client *clients;
       +    Client *sel;
       +    Client *stack;
       +    Monitor *next;
       +    Window barwin;
       +    const Layout *lt[2];
            Pertag *pertag;
        };
        
        typedef struct {
       -        const char *class;
       -        const char *instance;
       -        const char *title;
       -        unsigned int tags;
       -        int isfloating;
       -        int monitor;
       +    const char *class;
       +    const char *instance;
       +    const char *title;
       +    unsigned int tags;
       +    int isfloating;
       +    int monitor;
            int neverfocus;
        } Rule;
        
        typedef struct {
       -        int y;
       -        Bool show;
       -        Window win;
       -        char text[256];
       +    int y;
       +    Bool show;
       +    Window win;
       +    char text[256];
        } Bar;
        
        typedef struct Systray   Systray;
        struct Systray {
       -        Window win;
       -        Client *icons;
       +    Window win;
       +    Client *icons;
        };
        
        /* function declarations */
       t@@ -292,21 +292,21 @@ static int lrpad;            /* sum of left and right padding for text */
        static int (*xerrorxlib)(Display *, XErrorEvent *);
        static unsigned int numlockmask = 0;
        static void (*handler[LASTEvent]) (XEvent *) = {
       -        [ButtonPress] = buttonpress,
       -        [ClientMessage] = clientmessage,
       -        [ConfigureRequest] = configurerequest,
       -        [ConfigureNotify] = configurenotify,
       -        [DestroyNotify] = destroynotify,
       -        [EnterNotify] = enternotify,
       -        [Expose] = expose,
       -        [FocusIn] = focusin,
       -        [KeyPress] = keypress,
       -        [MappingNotify] = mappingnotify,
       -        [MapRequest] = maprequest,
       -        [MotionNotify] = motionnotify,
       -        [PropertyNotify] = propertynotify,
       -        [ResizeRequest] = resizerequest,
       -        [UnmapNotify] = unmapnotify
       +    [ButtonPress] = buttonpress,
       +    [ClientMessage] = clientmessage,
       +    [ConfigureRequest] = configurerequest,
       +    [ConfigureNotify] = configurenotify,
       +    [DestroyNotify] = destroynotify,
       +    [EnterNotify] = enternotify,
       +    [Expose] = expose,
       +    [FocusIn] = focusin,
       +    [KeyPress] = keypress,
       +    [MappingNotify] = mappingnotify,
       +    [MapRequest] = maprequest,
       +    [MotionNotify] = motionnotify,
       +    [PropertyNotify] = propertynotify,
       +    [ResizeRequest] = resizerequest,
       +    [UnmapNotify] = unmapnotify
        };
        static Atom wmatom[WMLast], netatom[NetLast], xatom[XLast];
        static int running = 1;
       t@@ -322,12 +322,12 @@ static Bar eb;
        #include "config.h"
        
        struct Pertag {
       -        unsigned int curtag, prevtag; /* current and previous tag */
       -        int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
       -        float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
       -        unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
       -        const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes  */
       -        Bool showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
       +    unsigned int curtag, prevtag; /* current and previous tag */
       +    int nmasters[LENGTH(tags) + 1]; /* number of windows in master area */
       +    float mfacts[LENGTH(tags) + 1]; /* mfacts per tag */
       +    unsigned int sellts[LENGTH(tags) + 1]; /* selected layouts */
       +    const Layout *ltidxs[LENGTH(tags) + 1][2]; /* matrix of tags and layouts indexes  */
       +    Bool showbars[LENGTH(tags) + 1]; /* display bar for the current tag */
        };
        
        static unsigned int scratchtag = 1 << LENGTH(tags);
       t@@ -339,550 +339,550 @@ struct NumTags { char limitexceeded[LENGTH(tags) > 31 ? -1 : 1]; };
        void
        applyrules(Client *c)
        {
       -        const char *class, *instance;
       -        unsigned int i;
       -        const Rule *r;
       -        Monitor *m;
       -        XClassHint ch = { NULL, NULL };
       -
       -        /* rule matching */
       -        c->isfloating = 0;
       -        c->neverfocus = 0;
       -        c->tags = 0;
       -        XGetClassHint(dpy, c->win, &ch);
       -        class    = ch.res_class ? ch.res_class : broken;
       -        instance = ch.res_name  ? ch.res_name  : broken;
       -
       -        for (i = 0; i < LENGTH(rules); i++) {
       -                r = &rules[i];
       -                if ((!r->title || strstr(c->name, r->title))
       -                && (!r->class || strstr(class, r->class))
       -                && (!r->instance || strstr(instance, r->instance)))
       -                {
       -                        c->isfloating = r->isfloating;
       +    const char *class, *instance;
       +    unsigned int i;
       +    const Rule *r;
       +    Monitor *m;
       +    XClassHint ch = { NULL, NULL };
       +
       +    /* rule matching */
       +    c->isfloating = 0;
       +    c->neverfocus = 0;
       +    c->tags = 0;
       +    XGetClassHint(dpy, c->win, &ch);
       +    class    = ch.res_class ? ch.res_class : broken;
       +    instance = ch.res_name  ? ch.res_name  : broken;
       +
       +    for (i = 0; i < LENGTH(rules); i++) {
       +        r = &rules[i];
       +        if ((!r->title || strstr(c->name, r->title))
       +        && (!r->class || strstr(class, r->class))
       +        && (!r->instance || strstr(instance, r->instance)))
       +        {
       +            c->isfloating = r->isfloating;
                    c->neverfocus = r->neverfocus;
       -                        c->tags |= r->tags;
       -                        for (m = mons; m && m->num != r->monitor; m = m->next);
       -                        if (m)
       -                                c->mon = m;
       -                }
       -        }
       -        if (ch.res_class)
       -                XFree(ch.res_class);
       -        if (ch.res_name)
       -                XFree(ch.res_name);
       -        c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
       +            c->tags |= r->tags;
       +            for (m = mons; m && m->num != r->monitor; m = m->next);
       +            if (m)
       +                c->mon = m;
       +        }
       +    }
       +    if (ch.res_class)
       +        XFree(ch.res_class);
       +    if (ch.res_name)
       +        XFree(ch.res_name);
       +    c->tags = c->tags & TAGMASK ? c->tags & TAGMASK : c->mon->tagset[c->mon->seltags];
        }
        
        int
        applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact)
        {
       -        int baseismin;
       -        Monitor *m = c->mon;
       -
       -        /* set minimum possible */
       -        *w = MAX(1, *w);
       -        *h = MAX(1, *h);
       -        if (interact) {
       -                if (*x > sw)
       -                        *x = sw - WIDTH(c);
       -                if (*y > sh)
       -                        *y = sh - HEIGHT(c);
       -                if (*x + *w + 2 * c->bw < 0)
       -                        *x = 0;
       -                if (*y + *h + 2 * c->bw < 0)
       -                        *y = 0;
       -        } else {
       -                if (*x >= m->wx + m->ww)
       -                        *x = m->wx + m->ww - WIDTH(c);
       -                if (*y >= m->wy + m->wh)
       -                        *y = m->wy + m->wh - HEIGHT(c);
       -                if (*x + *w + 2 * c->bw <= m->wx)
       -                        *x = m->wx;
       -                if (*y + *h + 2 * c->bw <= m->wy)
       -                        *y = m->wy;
       -        }
       -        if (*h < bh)
       -                *h = bh;
       -        if (*w < bh)
       -                *w = bh;
       -        if (resizehints || !c->mon->lt[c->mon->sellt]->arrange) {
       -                /* see last two sentences in ICCCM 4.1.2.3 */
       -                baseismin = c->basew == c->minw && c->baseh == c->minh;
       -                if (!baseismin) { /* temporarily remove base dimensions */
       -                        *w -= c->basew;
       -                        *h -= c->baseh;
       -                }
       -                /* adjust for aspect limits */
       -                if (c->mina > 0 && c->maxa > 0) {
       -                        if (c->maxa < (float)*w / *h)
       -                                *w = *h * c->maxa + 0.5;
       -                        else if (c->mina < (float)*h / *w)
       -                                *h = *w * c->mina + 0.5;
       -                }
       -                if (baseismin) { /* increment calculation requires this */
       -                        *w -= c->basew;
       -                        *h -= c->baseh;
       -                }
       -                /* adjust for increment value */
       -                if (c->incw)
       -                        *w -= *w % c->incw;
       -                if (c->inch)
       -                        *h -= *h % c->inch;
       -                /* restore base dimensions */
       -                *w = MAX(*w + c->basew, c->minw);
       -                *h = MAX(*h + c->baseh, c->minh);
       -                if (c->maxw)
       -                        *w = MIN(*w, c->maxw);
       -                if (c->maxh)
       -                        *h = MIN(*h, c->maxh);
       -        }
       -        return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
       +    int baseismin;
       +    Monitor *m = c->mon;
       +
       +    /* set minimum possible */
       +    *w = MAX(1, *w);
       +    *h = MAX(1, *h);
       +    if (interact) {
       +        if (*x > sw)
       +            *x = sw - WIDTH(c);
       +        if (*y > sh)
       +            *y = sh - HEIGHT(c);
       +        if (*x + *w + 2 * c->bw < 0)
       +            *x = 0;
       +        if (*y + *h + 2 * c->bw < 0)
       +            *y = 0;
       +    } else {
       +        if (*x >= m->wx + m->ww)
       +            *x = m->wx + m->ww - WIDTH(c);
       +        if (*y >= m->wy + m->wh)
       +            *y = m->wy + m->wh - HEIGHT(c);
       +        if (*x + *w + 2 * c->bw <= m->wx)
       +            *x = m->wx;
       +        if (*y + *h + 2 * c->bw <= m->wy)
       +            *y = m->wy;
       +    }
       +    if (*h < bh)
       +        *h = bh;
       +    if (*w < bh)
       +        *w = bh;
       +    if (resizehints || !c->mon->lt[c->mon->sellt]->arrange) {
       +        /* see last two sentences in ICCCM 4.1.2.3 */
       +        baseismin = c->basew == c->minw && c->baseh == c->minh;
       +        if (!baseismin) { /* temporarily remove base dimensions */
       +            *w -= c->basew;
       +            *h -= c->baseh;
       +        }
       +        /* adjust for aspect limits */
       +        if (c->mina > 0 && c->maxa > 0) {
       +            if (c->maxa < (float)*w / *h)
       +                *w = *h * c->maxa + 0.5;
       +            else if (c->mina < (float)*h / *w)
       +                *h = *w * c->mina + 0.5;
       +        }
       +        if (baseismin) { /* increment calculation requires this */
       +            *w -= c->basew;
       +            *h -= c->baseh;
       +        }
       +        /* adjust for increment value */
       +        if (c->incw)
       +            *w -= *w % c->incw;
       +        if (c->inch)
       +            *h -= *h % c->inch;
       +        /* restore base dimensions */
       +        *w = MAX(*w + c->basew, c->minw);
       +        *h = MAX(*h + c->baseh, c->minh);
       +        if (c->maxw)
       +            *w = MIN(*w, c->maxw);
       +        if (c->maxh)
       +            *h = MIN(*h, c->maxh);
       +    }
       +    return *x != c->x || *y != c->y || *w != c->w || *h != c->h;
        }
        
        void
        arrange(Monitor *m)
        {
       -        if (m)
       -                showhide(m->stack);
       -        else for (m = mons; m; m = m->next)
       -                showhide(m->stack);
       -        if (m) {
       -                arrangemon(m);
       -                restack(m);
       -        } else for (m = mons; m; m = m->next)
       -                arrangemon(m);
       +    if (m)
       +        showhide(m->stack);
       +    else for (m = mons; m; m = m->next)
       +        showhide(m->stack);
       +    if (m) {
       +        arrangemon(m);
       +        restack(m);
       +    } else for (m = mons; m; m = m->next)
       +        arrangemon(m);
        }
        
        void
        arrangemon(Monitor *m)
        {
       -        strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
       -        if (m->lt[m->sellt]->arrange)
       -                m->lt[m->sellt]->arrange(m);
       +    strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, sizeof m->ltsymbol);
       +    if (m->lt[m->sellt]->arrange)
       +        m->lt[m->sellt]->arrange(m);
        }
        
        void
        attach(Client *c)
        {
       -        c->next = c->mon->clients;
       -        c->mon->clients = c;
       +    c->next = c->mon->clients;
       +    c->mon->clients = c;
        }
        
        void
        attachstack(Client *c)
        {
       -        c->snext = c->mon->stack;
       -        c->mon->stack = c;
       +    c->snext = c->mon->stack;
       +    c->mon->stack = c;
        }
        
        void
        buttonpress(XEvent *e)
        {
       -        unsigned int i, x, click;
       -        Arg arg = {0};
       -        Client *c;
       -        Monitor *m;
       -        XButtonPressedEvent *ev = &e->xbutton;
       -
       -        click = ClkRootWin;
       -        /* focus monitor if necessary */
       -        if ((m = wintomon(ev->window)) && m != selmon) {
       -                unfocus(selmon->sel, 1);
       -                selmon = m;
       -                focus(NULL);
       -        }
       -        if (ev->window == selmon->barwin) {
       -                i = x = 0;
       -                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 > selmon->ww - TEXTW(stext) - getsystraywidth())
       -                        click = ClkStatusText;
       -                else
       -                        click = ClkWinTitle;
       -        } else if ((c = wintoclient(ev->window))) {
       -                focus(c);
       -                restack(selmon);
       -                XAllowEvents(dpy, ReplayPointer, CurrentTime);
       -                click = ClkClientWin;
       -        }
       -        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(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
       +    unsigned int i, x, click;
       +    Arg arg = {0};
       +    Client *c;
       +    Monitor *m;
       +    XButtonPressedEvent *ev = &e->xbutton;
       +
       +    click = ClkRootWin;
       +    /* focus monitor if necessary */
       +    if ((m = wintomon(ev->window)) && m != selmon) {
       +        unfocus(selmon->sel, 1);
       +        selmon = m;
       +        focus(NULL);
       +    }
       +    if (ev->window == selmon->barwin) {
       +        i = x = 0;
       +        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 > selmon->ww - TEXTW(stext) - getsystraywidth())
       +            click = ClkStatusText;
       +        else
       +            click = ClkWinTitle;
       +    } else if ((c = wintoclient(ev->window))) {
       +        focus(c);
       +        restack(selmon);
       +        XAllowEvents(dpy, ReplayPointer, CurrentTime);
       +        click = ClkClientWin;
       +    }
       +    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(click == ClkTagBar && buttons[i].arg.i == 0 ? &arg : &buttons[i].arg);
        }
        
        void
        checkotherwm(void)
        {
       -        xerrorxlib = XSetErrorHandler(xerrorstart);
       -        /* this causes an error if some other window manager is running */
       -        XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
       -        XSync(dpy, False);
       -        XSetErrorHandler(xerror);
       -        XSync(dpy, False);
       +    xerrorxlib = XSetErrorHandler(xerrorstart);
       +    /* this causes an error if some other window manager is running */
       +    XSelectInput(dpy, DefaultRootWindow(dpy), SubstructureRedirectMask);
       +    XSync(dpy, False);
       +    XSetErrorHandler(xerror);
       +    XSync(dpy, False);
        }
        
        void
        cleanup(void)
        {
       -        Arg a = {.ui = ~0};
       -        Layout foo = { "", NULL };
       -        Monitor *m;
       -        size_t i;
       -
       -        view(&a);
       -        selmon->lt[selmon->sellt] = &foo;
       -        for (m = mons; m; m = m->next)
       -                while (m->stack)
       -                        unmanage(m->stack, 0);
       -        XUngrabKey(dpy, AnyKey, AnyModifier, root);
       +    Arg a = {.ui = ~0};
       +    Layout foo = { "", NULL };
       +    Monitor *m;
       +    size_t i;
       +
       +    view(&a);
       +    selmon->lt[selmon->sellt] = &foo;
       +    for (m = mons; m; m = m->next)
       +        while (m->stack)
       +            unmanage(m->stack, 0);
       +    XUngrabKey(dpy, AnyKey, AnyModifier, root);
            XUnmapWindow(dpy, eb.win);
            XDestroyWindow(dpy, eb.win);
       -        while (mons)
       -                cleanupmon(mons);
       -        if (showsystray) {
       -                XUnmapWindow(dpy, systray->win);
       -                XDestroyWindow(dpy, systray->win);
       -                free(systray);
       -        }
       -        for (i = 0; i < CurLast; i++)
       -                drw_cur_free(drw, cursor[i]);
       -        for (i = 0; i < LENGTH(colors); i++)
       -                free(scheme[i]);
       -        XDestroyWindow(dpy, wmcheckwin);
       -        drw_free(drw);
       -        XSync(dpy, False);
       -        XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
       -        XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
       +    while (mons)
       +        cleanupmon(mons);
       +    if (showsystray) {
       +        XUnmapWindow(dpy, systray->win);
       +        XDestroyWindow(dpy, systray->win);
       +        free(systray);
       +    }
       +    for (i = 0; i < CurLast; i++)
       +        drw_cur_free(drw, cursor[i]);
       +    for (i = 0; i < LENGTH(colors); i++)
       +        free(scheme[i]);
       +    XDestroyWindow(dpy, wmcheckwin);
       +    drw_free(drw);
       +    XSync(dpy, False);
       +    XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
       +    XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
        }
        
        void
        cleanupmon(Monitor *mon)
        {
       -        Monitor *m;
       +    Monitor *m;
        
       -        if (mon == mons)
       -                mons = mons->next;
       -        else {
       -                for (m = mons; m && m->next != mon; m = m->next);
       -                m->next = mon->next;
       -        }
       -        XUnmapWindow(dpy, mon->barwin);
       -        XDestroyWindow(dpy, mon->barwin);
       -        free(mon);
       +    if (mon == mons)
       +        mons = mons->next;
       +    else {
       +        for (m = mons; m && m->next != mon; m = m->next);
       +        m->next = mon->next;
       +    }
       +    XUnmapWindow(dpy, mon->barwin);
       +    XDestroyWindow(dpy, mon->barwin);
       +    free(mon);
        }
        
        void
        clientmessage(XEvent *e)
        {
       -        XWindowAttributes wa;
       -        XSetWindowAttributes swa;
       -        XClientMessageEvent *cme = &e->xclient;
       -        Client *c = wintoclient(cme->window);
       -
       -        if (showsystray && cme->window == systray->win && cme->message_type == netatom[NetSystemTrayOP]) {
       -                /* add systray icons */
       -                if (cme->data.l[1] == SYSTEM_TRAY_REQUEST_DOCK) {
       -                        if (!(c = (Client *)calloc(1, sizeof(Client))))
       -                                die("fatal: could not malloc() %u bytes\n", sizeof(Client));
       -                        if (!(c->win = cme->data.l[2])) {
       -                                free(c);
       -                                return;
       -                        }
       -                        c->mon = selmon;
       -                        c->next = systray->icons;
       -                        systray->icons = c;
       -                        XGetWindowAttributes(dpy, c->win, &wa);
       -                        c->x = c->oldx = c->y = c->oldy = 0;
       -                        c->w = c->oldw = wa.width;
       -                        c->h = c->oldh = wa.height;
       -                        c->oldbw = wa.border_width;
       -                        c->bw = 0;
       -                        c->isfloating = True;
       -                        /* reuse tags field as mapped status */
       -                        c->tags = 1;
       -                        updatesizehints(c);
       -                        updatesystrayicongeom(c, wa.width, wa.height);
       -                        XAddToSaveSet(dpy, c->win);
       -                        XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask);
       -                        XReparentWindow(dpy, c->win, systray->win, 0, 0);
       -                        /* use parents background color */
       -                        swa.background_pixel  = scheme[SchemeNorm][ColBg].pixel;
       -                        XChangeWindowAttributes(dpy, c->win, CWBackPixel, &swa);
       -                        sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_EMBEDDED_NOTIFY, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
       -                        /* FIXME not sure if I have to send these events, too */
       -                        sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_FOCUS_IN, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
       -                        sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_WINDOW_ACTIVATE, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
       -                        sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_MODALITY_ON, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
       -                        XSync(dpy, False);
       -                        resizebarwin(selmon);
       -                        updatesystray();
       -                        setclientstate(c, NormalState);
       -                }
       -                return;
       -        }
       -        if (!c)
       -                return;
       -        if (cme->message_type == netatom[NetWMState]) {
       -                if (cme->data.l[1] == netatom[NetWMFullscreen]
       -                || cme->data.l[2] == netatom[NetWMFullscreen])
       -                        setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD    */
       -                                || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen)));
       -        } else if (cme->message_type == netatom[NetActiveWindow]) {
       -                if (c != selmon->sel && !c->isurgent)
       -                        seturgent(c, 1);
       -        }
       +    XWindowAttributes wa;
       +    XSetWindowAttributes swa;
       +    XClientMessageEvent *cme = &e->xclient;
       +    Client *c = wintoclient(cme->window);
       +
       +    if (showsystray && cme->window == systray->win && cme->message_type == netatom[NetSystemTrayOP]) {
       +        /* add systray icons */
       +        if (cme->data.l[1] == SYSTEM_TRAY_REQUEST_DOCK) {
       +            if (!(c = (Client *)calloc(1, sizeof(Client))))
       +                die("fatal: could not malloc() %u bytes\n", sizeof(Client));
       +            if (!(c->win = cme->data.l[2])) {
       +                free(c);
       +                return;
       +            }
       +            c->mon = selmon;
       +            c->next = systray->icons;
       +            systray->icons = c;
       +            XGetWindowAttributes(dpy, c->win, &wa);
       +            c->x = c->oldx = c->y = c->oldy = 0;
       +            c->w = c->oldw = wa.width;
       +            c->h = c->oldh = wa.height;
       +            c->oldbw = wa.border_width;
       +            c->bw = 0;
       +            c->isfloating = True;
       +            /* reuse tags field as mapped status */
       +            c->tags = 1;
       +            updatesizehints(c);
       +            updatesystrayicongeom(c, wa.width, wa.height);
       +            XAddToSaveSet(dpy, c->win);
       +            XSelectInput(dpy, c->win, StructureNotifyMask | PropertyChangeMask | ResizeRedirectMask);
       +            XReparentWindow(dpy, c->win, systray->win, 0, 0);
       +            /* use parents background color */
       +            swa.background_pixel  = scheme[SchemeNorm][ColBg].pixel;
       +            XChangeWindowAttributes(dpy, c->win, CWBackPixel, &swa);
       +            sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_EMBEDDED_NOTIFY, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
       +            /* FIXME not sure if I have to send these events, too */
       +            sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_FOCUS_IN, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
       +            sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_WINDOW_ACTIVATE, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
       +            sendevent(c->win, netatom[Xembed], StructureNotifyMask, CurrentTime, XEMBED_MODALITY_ON, 0 , systray->win, XEMBED_EMBEDDED_VERSION);
       +            XSync(dpy, False);
       +            resizebarwin(selmon);
       +            updatesystray();
       +            setclientstate(c, NormalState);
       +        }
       +        return;
       +    }
       +    if (!c)
       +        return;
       +    if (cme->message_type == netatom[NetWMState]) {
       +        if (cme->data.l[1] == netatom[NetWMFullscreen]
       +        || cme->data.l[2] == netatom[NetWMFullscreen])
       +            setfullscreen(c, (cme->data.l[0] == 1 /* _NET_WM_STATE_ADD    */
       +                || (cme->data.l[0] == 2 /* _NET_WM_STATE_TOGGLE */ && !c->isfullscreen)));
       +    } else if (cme->message_type == netatom[NetActiveWindow]) {
       +        if (c != selmon->sel && !c->isurgent)
       +            seturgent(c, 1);
       +    }
        }
        
        void
        configure(Client *c)
        {
       -        XConfigureEvent ce;
       +    XConfigureEvent ce;
        
       -        ce.type = ConfigureNotify;
       -        ce.display = dpy;
       -        ce.event = c->win;
       -        ce.window = c->win;
       -        ce.x = c->x;
       -        ce.y = c->y;
       -        ce.width = c->w;
       -        ce.height = c->h;
       -        ce.border_width = c->bw;
       -        ce.above = None;
       -        ce.override_redirect = False;
       -        XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
       +    ce.type = ConfigureNotify;
       +    ce.display = dpy;
       +    ce.event = c->win;
       +    ce.window = c->win;
       +    ce.x = c->x;
       +    ce.y = c->y;
       +    ce.width = c->w;
       +    ce.height = c->h;
       +    ce.border_width = c->bw;
       +    ce.above = None;
       +    ce.override_redirect = False;
       +    XSendEvent(dpy, c->win, False, StructureNotifyMask, (XEvent *)&ce);
        }
        
        void
        configurenotify(XEvent *e)
        {
       -        Monitor *m;
       -        Client *c;
       -        XConfigureEvent *ev = &e->xconfigure;
       -        int dirty;
       -
       -        /* TODO: updategeom handling sucks, needs to be simplified */
       -        if (ev->window == root) {
       -                dirty = (sw != ev->width || sh != ev->height);
       -                sw = ev->width;
       -                sh = ev->height;
       -                if (updategeom() || dirty) {
       -                        drw_resize(drw, sw, bh);
       -                        updatebars();
       -                        for (m = mons; m; m = m->next) {
       -                                for (c = m->clients; c; c = c->next)
       -                                        if (c->isfullscreen)
       -                                                resizeclient(c, m->mx, m->my, m->mw, m->mh);
       -                                //XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
       +    Monitor *m;
       +    Client *c;
       +    XConfigureEvent *ev = &e->xconfigure;
       +    int dirty;
       +
       +    /* TODO: updategeom handling sucks, needs to be simplified */
       +    if (ev->window == root) {
       +        dirty = (sw != ev->width || sh != ev->height);
       +        sw = ev->width;
       +        sh = ev->height;
       +        if (updategeom() || dirty) {
       +            drw_resize(drw, sw, bh);
       +            updatebars();
       +            for (m = mons; m; m = m->next) {
       +                for (c = m->clients; c; c = c->next)
       +                    if (c->isfullscreen)
       +                        resizeclient(c, m->mx, m->my, m->mw, m->mh);
       +                //XMoveResizeWindow(dpy, m->barwin, m->wx, m->by, m->ww, bh);
                        resizebarwin(m);
       -                        }
       +            }
                    XMoveResizeWindow(dpy, eb.win, mons->wx, eb.y, mons->ww, bh);
       -                        focus(NULL);
       -                        arrange(NULL);
       -                }
       -        }
       +            focus(NULL);
       +            arrange(NULL);
       +        }
       +    }
        }
        
        void
        configurerequest(XEvent *e)
        {
       -        Client *c;
       -        Monitor *m;
       -        XConfigureRequestEvent *ev = &e->xconfigurerequest;
       -        XWindowChanges wc;
       -
       -        if ((c = wintoclient(ev->window))) {
       -                if (ev->value_mask & CWBorderWidth)
       -                        c->bw = ev->border_width;
       -                else if (c->isfloating || !selmon->lt[selmon->sellt]->arrange) {
       -                        m = c->mon;
       -                        if (ev->value_mask & CWX) {
       -                                c->oldx = c->x;
       -                                c->x = m->mx + ev->x;
       -                        }
       -                        if (ev->value_mask & CWY) {
       -                                c->oldy = c->y;
       -                                c->y = m->my + ev->y;
       -                        }
       -                        if (ev->value_mask & CWWidth) {
       -                                c->oldw = c->w;
       -                                c->w = ev->width;
       -                        }
       -                        if (ev->value_mask & CWHeight) {
       -                                c->oldh = c->h;
       -                                c->h = ev->height;
       -                        }
       -                        if ((c->x + c->w) > m->mx + m->mw && c->isfloating)
       -                                c->x = m->mx + (m->mw / 2 - WIDTH(c) / 2); /* center in x direction */
       -                        if ((c->y + c->h) > m->my + m->mh && c->isfloating)
       -                                c->y = m->my + (m->mh / 2 - HEIGHT(c) / 2); /* center in y direction */
       -                        if ((ev->value_mask & (CWX|CWY)) && !(ev->value_mask & (CWWidth|CWHeight)))
       -                                configure(c);
       -                        if (ISVISIBLE(c))
       -                                XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
       -                } else
       -                        configure(c);
       -        } else {
       -                wc.x = ev->x;
       -                wc.y = ev->y;
       -                wc.width = ev->width;
       -                wc.height = ev->height;
       -                wc.border_width = ev->border_width;
       -                wc.sibling = ev->above;
       -                wc.stack_mode = ev->detail;
       -                XConfigureWindow(dpy, ev->window, ev->value_mask, &wc);
       -        }
       -        XSync(dpy, False);
       +    Client *c;
       +    Monitor *m;
       +    XConfigureR