JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
make tabs out of extra slave windows
authorJason Woofenden <jason@jasonwoof.com>
Wed, 18 Feb 2015 18:07:33 +0000 (13:07 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Wed, 18 Feb 2015 18:07:33 +0000 (13:07 -0500)
dwm.c

diff --git a/dwm.c b/dwm.c
index 0d68749..362e902 100644 (file)
--- a/dwm.c
+++ b/dwm.c
@@ -1367,6 +1367,7 @@ resizeclient(Client *c, int x, int y, int w, int h, Client *base) {
        c->oldy = c->y; c->y = wc.y = y;
        c->oldw = c->w; c->w = wc.width = w;
        c->oldh = c->h; c->h = wc.height = h;
+       base = 0;
        if (base) {
                wc.stack_mode = Above;
                wc.sibling = base->win;
@@ -1764,24 +1765,39 @@ tile(Monitor *m) {
                }
 }
 
+#define TAB_HEIGHT 19
+#define TAB_PAD     7
+
 void
 jason_layout(Monitor *m) {
-       unsigned int i, tiled_count, mw, right_width, tabs_count, cur_tab;
-       Client *c, *vis_slave, *base = 0;
+       unsigned int i, tiled_count, mw, right_width, tab_counts[2] = {0,0}, cur_tab = 0, *tab_count;
+       int tab_top;
+       Client *c, *vis_slave = 0, *base = 0;
+
+       tab_count = &(tab_counts[0]);
 
-       for(tiled_count = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), tiled_count++);
+       for(tiled_count = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), tiled_count++) {
+               if (tiled_count == 0) { // master
+                       if (c == m->sel) {
+                               if (c->next) {
+                                       vis_slave = nexttiled(c->next);
+                               }
+                       } else {
+                               vis_slave = m->sel;
+                       }
+               } else {
+                       if (c == vis_slave) {
+                               tab_count = &(tab_counts[1]);
+                       } else {
+                               (*tab_count) += 1;
+                       }
+               }
+       }
        if(tiled_count == 0) {
                return;
        }
 
-       c = nexttiled(m->clients);
-       if (c == m->sel) {
-               // if master is selected, show first slave
-               vis_slave = nexttiled(c->next);
-       } else {
-               vis_slave = m->sel;
-       }
-       if(tiled_count > 1 || (tiled_count == 1 && !c->screen_hog)) {
+       if(tiled_count > 1 || (tiled_count == 1 && !nexttiled(m->clients)->screen_hog)) {
                mw = m->ww * m->mfact;
        } else {
                // one of these:
@@ -1791,18 +1807,21 @@ jason_layout(Monitor *m) {
                mw = m->ww;
        }
        right_width = m->ww - mw;
-       tabs_count = tiled_count - 2;
-       cur_tab = 0;
+       tab_count = &(tab_counts[0]);
+       tab_top = m->wy - (m->wh - (2 * (TAB_HEIGHT + TAB_PAD))) + TAB_HEIGHT;
        for (i = 0, c = nexttiled(m->clients); c; c = nexttiled(c->next), i++) {
                if (i == 0) {
                        resize(c, m->wx, m->wy, mw, m->wh, False, 0);
                } else {
                        if (c == vis_slave) {
-                               resize(c, m->wx + mw, m->wy, right_width, m->wh - 30, False, base);
+                               resize(c, m->wx + mw, m->wy + TAB_HEIGHT + TAB_PAD, right_width, m->wh - 2 * (TAB_HEIGHT + TAB_PAD), False, base);
+                               tab_count = &(tab_counts[1]);
+                               tab_top = m->wy + m->wh - TAB_HEIGHT;
+                               cur_tab = 0;
                        } else {
                                // this function does not get called when focus changes
                                // resize(c, m->wx + m->ww, m->wy, m->ww - mw, m->wh, False);
-                               resize(c, m->wx + mw + right_width * cur_tab / tabs_count, m->wy + m->wh - 20, right_width, m->wh - 30, False, base);
+                               resize(c, m->wx + mw + right_width * cur_tab / (*tab_count), tab_top, right_width, m->wh - 2 * (TAB_HEIGHT + TAB_PAD), False, base);
                                cur_tab += 1;
                        }
                }