+static Drw *drw;
+static Fnt *fnt;
+static Monitor *mons, *selmon;
+static Window root;
+
+// 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 Client* choose_slave (Client *master, Client *focused);
+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, *focused, *c;
+ Bool focused_is_floating = False;
+ master = nexttiled(m->clients);
+ focused = (m->sel && ISVISIBLE(m->sel)) ? m->sel : NULL;
+ slave = choose_slave(master, focused);
+ // detect if the focused window is floating (and visible)
+ if (master && focused && focused != slave && focused != master) {
+ if (nexttiled(focused) != focused) {
+ focused_is_floating = True;
+ }
+ }
+ // set opacity of visible floaters, master and slave
+ for (c = nextvisible(m->clients); c; c = nextvisible(c->next)) {
+ if (c->isfloating || c == focused || (focused_is_floating && (c == master || c == slave))) {
+ window_set_opaque(c);
+ } else if (c == master || c == slave) {
+ window_set_translucent(c);
+ }
+ }
+}
+
+