this fixes cases where the window is using a different colormap than what 
DefaultColormap returns
in that case the borders will be drawn with the wrong colors
for instance: st with argbbg patch applied

adapted for git master from
https://gist.github.com/richardgv/ee2fe54d9753d1e6a071#file-dwm-6-0-argb-border-color-fix-patch
---
 dwm.c | 23 ++++++++++++++++++++---
 1 file changed, 20 insertions(+), 3 deletions(-)

diff --git a/dwm.c b/dwm.c
index 96b43f7..5af74a2 100644
--- a/dwm.c
+++ b/dwm.c
@@ -170,6 +170,7 @@ static void focus(Client *c);
 static void focusin(XEvent *e);
 static void focusmon(const Arg *arg);
 static void focusstack(const Arg *arg);
+static unsigned long getcolor_in_window(const char *colstr, Window w, unsigned 
long fallback);
 static Bool getrootptr(int *x, int *y);
 static long getstate(Window w);
 static Bool gettextprop(Window w, Atom atom, char *text, unsigned int size);
@@ -791,7 +792,7 @@ focus(Client *c) {
                detachstack(c);
                attachstack(c);
                grabbuttons(c, True);
-               XSetWindowBorder(dpy, c->win, scheme[SchemeSel].border->pix);
+               XSetWindowBorder(dpy, c->win, 
getcolor_in_window(selbordercolor, c->win, scheme[SchemeSel].border->pix));
                setfocus(c);
        }
        else {
@@ -865,6 +866,22 @@ getatomprop(Client *c, Atom prop) {
        return atom;
 }
 
+unsigned long
+getcolor_in_window(const char *colstr, Window w, unsigned long fallback) {
+       if (!w)
+               return fallback;
+       XWindowAttributes attr;
+       if (!XGetWindowAttributes(dpy, w, &attr))
+               return fallback;
+
+       Colormap cmap = attr.colormap;
+       XColor color;
+
+       if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
+               return fallback;
+       return color.pixel;
+}
+
 Bool
 getrootptr(int *x, int *y) {
        int di;
@@ -1038,7 +1055,7 @@ manage(Window w, XWindowAttributes *wa) {
 
        wc.border_width = c->bw;
        XConfigureWindow(dpy, w, CWBorderWidth, &wc);
-       XSetWindowBorder(dpy, w, scheme[SchemeNorm].border->pix);
+       XSetWindowBorder(dpy, w, getcolor_in_window(normbordercolor, w, 
scheme[SchemeNorm].border->pix));
        configure(c); /* propagates border_width, if size doesn't change */
        updatewindowtype(c);
        updatesizehints(c);
@@ -1684,7 +1701,7 @@ unfocus(Client *c, Bool setfocus) {
        if(!c)
                return;
        grabbuttons(c, False);
-       XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->pix);
+       XSetWindowBorder(dpy, c->win, getcolor_in_window(normbordercolor, 
c->win, scheme[SchemeNorm].border->pix));
        if(setfocus) {
                XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
                XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
-- 
2.6.2


Reply via email to