+// unfocused windows get transparent (feature)
+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) {
+ window_set_opacity(c, 0);
+}
+void
+window_set_translucent(Client *c) {
+ window_set_opacity(c, 1);
+}
+void
+window_set_invisible(Client *c) {
+ 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 || (selection_floating && (c == master || c == slave))) {
+ window_set_opaque(c);
+ } else if (c == master || c == slave) {
+ window_set_translucent(c);
+ } else {
+ window_set_opaque(c);
+ }
+ }
+ }
+}
+
+