JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
make non-focused windows translucent
authorJason Woofenden <jason@jasonwoof.com>
Mon, 17 Nov 2014 01:29:51 +0000 (20:29 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Mon, 17 Nov 2014 01:29:51 +0000 (20:29 -0500)
dwm.c

diff --git a/dwm.c b/dwm.c
index f896170..31fad43 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -60,7 +60,7 @@
 enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
 enum { SchemeNorm, SchemeSel, SchemeLast }; /* color schemes */
 enum { NetSupported, NetWMName, NetWMState,
-       NetWMFullscreen, NetActiveWindow, NetWMWindowType,
+       NetWMFullscreen, NetWMWindowOpacity, NetActiveWindow, NetWMWindowType,
        NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
 enum { WMProtocols, WMDelete, WMState, WMTakeFocus, WMLast }; /* default atoms */
 enum { ClkTagBar, ClkLtSymbol, ClkStatusText, ClkWinTitle,
@@ -267,6 +267,20 @@ static Fnt *fnt;
 static Monitor *mons, *selmon;
 static Window root;
 
+// unfocused windows get transparent (feature)
+static const unsigned long unfocused_opacity[] = { 0xbfffffff };
+static void window_set_opaque(Client *c);
+static void window_set_translucent(Client *c);
+void
+window_set_opaque(Client *c) {
+       XChangeProperty(dpy, c->win, netatom[NetWMWindowOpacity], XA_CARDINAL, 32, PropModeReplace, (unsigned char *)unfocused_opacity, 1);
+}
+void
+window_set_translucent(Client *c) {
+       XDeleteProperty(dpy, c->win, netatom[NetWMWindowOpacity]);
+}
+
+
 /* configuration, allows nested code to access above variables */
 #include "config.h"
 
@@ -784,6 +798,10 @@ focus(Client *c) {
        /* was if(selmon->sel) */
        if(selmon->sel && selmon->sel != c)
                unfocus(selmon->sel, False);
+       if(selmon->sel && c!=selmon->sel && c && (!root || (selmon->sel->win!=root && c->win!=root)) )
+               window_set_opaque(selmon->sel);
+       if(c && c!=selmon->sel && (!root || (c->win!=root)) )
+               window_set_translucent(c);
        if(c) {
                if(c->mon != selmon)
                        selmon = c->mon;
@@ -801,6 +819,8 @@ focus(Client *c) {
        }
        selmon->sel = c;
        drawbars();
+       if(c)
+               window_set_translucent(c);
 }
 
 void
@@ -1523,6 +1543,7 @@ setup(void) {
        netatom[NetWMName] = XInternAtom(dpy, "_NET_WM_NAME", False);
        netatom[NetWMState] = XInternAtom(dpy, "_NET_WM_STATE", False);
        netatom[NetWMFullscreen] = XInternAtom(dpy, "_NET_WM_STATE_FULLSCREEN", False);
+       netatom[NetWMWindowOpacity] = XInternAtom(dpy, "_NET_WM_WINDOW_OPACITY", False);
        netatom[NetWMWindowType] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE", False);
        netatom[NetWMWindowTypeDialog] = XInternAtom(dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
        netatom[NetClientList] = XInternAtom(dpy, "_NET_CLIENT_LIST", False);