]> git.corax.cc Git - dwm/commitdiff
Add bookshelf and bookstack window layouts
authorMatthias Kruk <mk@mi.m10k.eu>
Thu, 19 Mar 2020 16:43:31 +0000 (01:43 +0900)
committerMatthias Kruk <mk@mi.m10k.eu>
Thu, 19 Mar 2020 16:43:31 +0000 (01:43 +0900)
dwm.c

diff --git a/dwm.c b/dwm.c
index e67c733abe95c5cf6a5d486a729d5545826623ff..9f9ee2a94a1c05e149550b3993b781c57397fa7d 100755 (executable)
--- a/dwm.c
+++ b/dwm.c
@@ -295,6 +295,8 @@ static int xerrorstart(Display *dpy, XErrorEvent *ee);
 static void zoom(const Arg *arg);
 static Atom getatomprop(Client *c, Atom prop);
 static unsigned int getsystraywidth(void);
+static void bookshelf(Monitor*);
+static void bookstack(Monitor*);
 
 /* variables */
 static Systray *systray = NULL;
@@ -1909,6 +1911,73 @@ tile(Monitor *m) {
                }
 }
 
+static void bookshelf(Monitor *m)
+{
+        int n, w, x;
+        Client *c;
+
+       /* count the clients on this monitor */
+        for(n = 0, c = nexttiled(m->clients); c;
+           c = nexttiled(c->next), n++);
+
+        if(!n) {
+               /* nothing to do */
+                return;
+        }
+
+       /*
+        * Start at x position m->wx, which is likely not going to be
+        * 0 in a multi-head setup. In other words, m->wx and m->wy
+        * are absolute coordinates on a virtual screen spanning all
+        * physical screens. This caused a bit of confusion since I
+        * first implemented this on a laptop and things broke when I
+        * plugged in a second screen at work.
+        */
+        w = m->ww / n;
+        x = m->wx;
+
+       /* assign positions and sizes to all clients on this screen */
+        for(c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
+                resize(c, x, m->wy, w, m->wh, False);
+
+               /*
+                * Since all clients are horizontally aligned and the
+                * same size, only the x coordinate changes.
+                */
+                x += WIDTH(c);
+        }
+
+        return;
+}
+
+static void bookstack(Monitor *m)
+{
+        int n, h, y;
+        Client *c;
+
+       /*
+        * The logic is essentially the same as in bookshelf(), though
+        * much more vertical, literally speaking.
+        */
+
+        for(n = 0, c = nexttiled(m->clients); c;
+           c = nexttiled(c->next), n++);
+
+        if(!n) {
+                return;
+        }
+
+        h = m->wh / n;
+        y = m->wy;
+
+        for(c = nexttiled(m->clients); c; c = nexttiled(c->next)) {
+                resize(c, m->wx, y, m->ww, h, False);
+                y += HEIGHT(c);
+        }
+
+        return;
+}
+
 void
 togglebar(const Arg *arg) {
        selmon->showbar = !selmon->showbar;