JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fix deck layout
authorJason Woofenden <jason@jasonwoof.com>
Tue, 2 Dec 2014 18:12:02 +0000 (13:12 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Tue, 2 Dec 2014 18:12:02 +0000 (13:12 -0500)
dwm.c

diff --git a/dwm.c b/dwm.c
index d5eec04..71ab0f2 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -90,6 +90,7 @@ struct Client {
        int oldx, oldy, oldw, oldh;
        int basew, baseh, incw, inch, maxw, maxh, minw, minh;
        int bw, oldbw;
+       int opacity;
        unsigned int tags;
        Bool isfixed, isfloating, isurgent, neverfocus, oldstate, isfullscreen, screen_hog;
        Client *next;
@@ -272,22 +273,59 @@ static Monitor *mons, *selmon;
 static Window root;
 
 // unfocused windows get transparent (feature)
-static const unsigned long unfocused_opacity[] = { 0xbfffffff };
-static const unsigned long invisible_opacity[] = { 0x00000000 };
+static const unsigned long opacities[] = { 0, 0xbfffffff, 0x00000000 }; // first unused
 static void window_set_opaque(Client *c);
 static void window_set_translucent(Client *c);
 static void window_set_invisible(Client *c);
+static void window_set_opacity(Client *c, int opacity_index);
+static void update_window_opacities(Monitor *m);
+void
+window_set_opacity(Client *c, int opacity_index) {
+       if (c->opacity == opacity_index) {
+               return;
+       }
+       c->opacity = opacity_index;
+       if (opacity_index == 0) {
+               XDeleteProperty(dpy, c->win, netatom[NetWMWindowOpacity]);
+       } else {
+               XChangeProperty(dpy, c->win, netatom[NetWMWindowOpacity], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)(&opacities[opacity_index]), 1);
+       }
+}
 void
 window_set_opaque(Client *c) {
-       XDeleteProperty(dpy, c->win, netatom[NetWMWindowOpacity]);
+       window_set_opacity(c, 0);
 }
 void
 window_set_translucent(Client *c) {
-       XChangeProperty(dpy, c->win, netatom[NetWMWindowOpacity], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)unfocused_opacity, 1);
+       window_set_opacity(c, 1);
 }
 void
 window_set_invisible(Client *c) {
-       XChangeProperty(dpy, c->win, netatom[NetWMWindowOpacity], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)invisible_opacity, 1);
+       window_set_opacity(c, 2);
+}
+void
+update_window_opacities(Monitor *m) {
+       Client *master, *slave, *c;
+       Bool selection_floating = False;
+       slave = master = nexttiled(m->clients);
+       if (master) slave = nexttiled(master->next);
+       if (m->sel && m->sel != master) {
+               if (nexttiled(m->sel) == m->sel) // if selection is tiled
+                       slave = m->sel;
+               else
+                       selection_floating = True;
+       }
+       for (c = m->clients; c; c = c->next) {
+               if (ISVISIBLE(c)) {
+                       if (c->isfloating || c == m->sel || (c == master && selection_floating)) {
+                               window_set_opaque(c);
+                       } else if (c == master || c == slave) {
+                               window_set_translucent(c);
+                       } else {
+                               window_set_invisible(c);
+                       }
+               }
+       }
 }
 
 
@@ -849,6 +887,7 @@ focus(Client *c) {
                XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
        }
        selmon->sel = c;
+       update_window_opacities(selmon);
        drawbars();
        if(c && (!root || (c->win!=root)) )
                window_set_opaque(c);
@@ -1069,6 +1108,7 @@ manage(Window w, XWindowAttributes *wa) {
 
        if(!(c = calloc(1, sizeof(Client))))
                die("fatal: could not malloc() %u bytes\n", sizeof(Client));
+       c->opacity = -1; // who knows
        c->win = w;
        updatetitle(c);
        if(XGetTransientForHint(dpy, w, &trans) && (t = wintoclient(trans))) {
@@ -1804,32 +1844,8 @@ toggleview(const Arg *arg) {
 
 void
 unfocus(Client *c, Bool setfocus) {
-       Client *w;
        if(!c)
                return;
-       if(!root || c->win!=root) {
-               w = nexttiled(c->mon->clients);
-               if (!w) {
-                       // no tiled windows
-                       window_set_translucent(c);
-               } else if (w == c) {
-                       // master
-                       window_set_translucent(c);
-               } else {
-                       w = nexttiled(w->next);
-                       if (!w) {
-                               // c must not be tiled
-                               window_set_translucent(c);
-                       } else {
-                               if (w == c) { // first slave
-                                       window_set_translucent(c);
-                               } else {
-                                       window_set_invisible(c);
-                                       window_set_translucent(w);
-                               }
-                       }
-               }
-       }
        grabbuttons(c, False);
        XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->rgb);
        if(setfocus) {