dvtm

dynamic virtual terminal manager - with my changes
git clone https://pi.duncano.de/git/dvtm.git
Log | Files | Refs | README | LICENSE

commit 55b7600862ea00d2414a346a441312d8648e2135
parent 1004850fd7e9484c9c2073344cd02835d81f64f1
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Wed,  8 Oct 2014 11:52:58 +0200

Move placement of minimized windows out of layouts

All minimized windows are now always displayed on a single
line at the bottom of the screen.

Diffstat:
bstack.c | 41++++++++++-------------------------------
dvtm.c | 20+++++++++++++++++---
fibonacci.c | 28++++++++++++----------------
grid.c | 82+++++++++++++++++++++++++++++++------------------------------------------------
tile.c | 50+++++++++++++++++---------------------------------
tstack.c | 40+++++++++++-----------------------------
vstack.c | 34+++++++++-------------------------
7 files changed, 108 insertions(+), 187 deletions(-)

diff --git a/bstack.c b/bstack.c @@ -1,25 +1,16 @@ static void bstack(void) { - unsigned int i, m, n, nx, ny, nw, nh, mh, tw; + unsigned int i, n, nx, ny, nw, nh, mh, tw; Client *c; - for (n = 0, m = 0, c = clients; c; c = c->next, n++) - if (c->minimized) - m++; - - if (n == 1) - mh = wah; - else if (n - 1 == m) - mh = wah - m; - else - mh = screen.mfact * (wah - m); - /* true if there are at least 2 non minimized clients */ - if (n - 1 > m) - tw = waw / (n - m - 1); + for (n = 0, c = clients; c && !c->minimized; c = c->next, n++); + mh = n <= 1 ? wah : screen.mfact * wah; + tw = n <= 1 ? 0 : waw / (n - 1); nx = wax; ny = way; - for (i = 0, c = clients; c; c = c->next, i++) { + + for (i = 0, c = clients; c && !c->minimized; c = c->next, i++) { if (i == 0) { /* master */ nh = mh; nw = waw; @@ -27,22 +18,10 @@ static void bstack(void) if (i == 1) { nx = wax; ny += mh; - nh = (way + wah - m) - ny; + nh = (way + wah) - ny; } - if (i == n - m - 1) { /* last not minimized client */ - nw = (wax + waw) - nx; - } else if (i == n - m) { /* first minimized client */ - ny += nh; - nx = wax; - nw = waw; - nh = 1; - } else if (c->minimized) { /* minimized window */ - nw = waw; - nh = 1; - ny++; - } else /* normal non minimized tile window */ - nw = tw; - if (i > 1 && !c->minimized) { + nw = (i < n - 1) ? tw : (wax + waw) - nx; + if (i > 1) { mvvline(ny, nx, ACS_VLINE, nh); mvaddch(ny, nx, ACS_TTEE); nx++, nw--; @@ -51,7 +30,7 @@ static void bstack(void) resize(c, nx, ny, nw, nh); - if (n > 1 && i < n - m - 1) + if (i > 0) nx += nw; } } diff --git a/dvtm.c b/dvtm.c @@ -332,10 +332,26 @@ draw_all() { static void arrange() { + int m = 0; + for (Client *c = clients; c; c = c->next) + if (c->minimized) + m++; erase(); drawbar(); attrset(NORMAL_ATTR); + if (m && !isarrange(fullscreen)) + wah--; layout->arrange(); + if (m && !isarrange(fullscreen)) { + int nw = waw / m, nx = wax; + for (Client *c = clients; c; c = c->next) { + if (c->minimized) { + resize(c, nx, way+wah, nw, 1); + nx += nw; + } + } + wah++; + } wnoutrefresh(stdscr); draw_all(); } @@ -557,6 +573,7 @@ updatebarpos(void) { wax = 0; way = 0; wah = screen.h; + waw = screen.w; if (bar.fd == -1) return; if (bar.pos == BAR_TOP) { @@ -583,9 +600,6 @@ resize_screen() { resizeterm(screen.h, screen.w); wresize(stdscr, screen.h, screen.w); - - waw = screen.w; - wah = screen.h; updatebarpos(); clear(); arrange(); diff --git a/fibonacci.c b/fibonacci.c @@ -1,13 +1,9 @@ static void fibonacci(int s) { - unsigned int nx, ny, nw, nnw, nh, nnh, i, n, m, nm, mod; + unsigned int nx, ny, nw, nnw, nh, nnh, i, n, mod; Client *c; - for (n = 0, m = 0, c = clients; c; c = c->next, n++) - if (c->minimized) - m++; - /* number of non minimized windows */ - nm = n - m; + for (n = 0, c = clients; c && !c->minimized; c = c->next, n++); /* initial position and dimensions */ nx = wax; @@ -18,12 +14,12 @@ static void fibonacci(int s) * variables for the next new width/height */ nnw = waw - nw - 1; - nnh = nh = (wah - m); /* leave space for the minimized clients */ + nnh = nh = wah; /* set the mod factor, 2 for dwindle, 4 for spiral */ mod = s ? 4 : 2; - for (i = 0, c = clients; c; c = c->next, i++) { + for (i = 0, c = clients; c && !c->minimized; c = c->next, i++) { if (!c->minimized) { /* dwindle: even case, spiral: case 0 */ if (i % mod == 0) { @@ -35,8 +31,8 @@ static void fibonacci(int s) ny += nh; nh = nnh; } - /* don't adjust the width for the last non-minimized client */ - if (i < nm - 1) { + /* don't adjust the width for the last client */ + if (i < n - 1) { nw /= 2; nnw -= nw + 1; } @@ -48,16 +44,16 @@ static void fibonacci(int s) mvaddch(ny, nx, ACS_TTEE); ++nx; nw = nnw; - /* don't adjust the height for the last non-minimized client */ - if (i < nm - 1) { + /* don't adjust the height for the last client */ + if (i < n - 1) { nh /= 2; nnh -= nh; } } else if (i % mod == 2 && s) { /* spiral: case 2 */ ny += nh; nh = nnh; - /* don't adjust the width for the last non-minimized client */ - if (i < nm - 1) { + /* don't adjust the width for the last client */ + if (i < n - 1) { nw /= 2; nnw -= nw + 1; nx += nnw; @@ -70,8 +66,8 @@ static void fibonacci(int s) } else if (s) { /* spiral: case 3 */ nw = nnw; nx -= nw + 1; /* border */ - /* don't adjust the height for the last non-minimized client */ - if (i < nm - 1) { + /* don't adjust the height for the last client */ + if (i < n - 1) { nh /= 2; nnh -= nh; ny += nnh; diff --git a/grid.c b/grid.c @@ -1,62 +1,44 @@ static void grid(void) { - unsigned int i, m, nm, n, nx, ny, nw, nh, aw, ah, cols, rows; + unsigned int i, n, nx, ny, nw, nh, aw, ah, cols, rows; Client *c; - for (n = 0, m = 0, c = clients; c; c = c->next, n++) - if (c->minimized) - m++; - /* number of non minimized windows */ - nm = n - m; + for (n = 0, c = clients; c && !c->minimized; c = c->next, n++); /* grid dimensions */ - for (cols = 0; cols <= nm / 2; cols++) - if (cols * cols >= nm) + for (cols = 0; cols <= n / 2; cols++) + if (cols * cols >= n) break; - rows = (cols && (cols - 1) * cols >= nm) ? cols - 1 : cols; + rows = (cols && (cols - 1) * cols >= n) ? cols - 1 : cols; /* window geoms (cell height/width) */ - nh = (wah - m) / (rows ? rows : 1); + nh = wah / (rows ? rows : 1); nw = waw / (cols ? cols : 1); - for (i = 0, c = clients; c; c = c->next, i++) { - if (!c->minimized) { - /* if there are less clients in the last row than normal adjust the - * split rate to fill the empty space */ - if (rows > 1 && i == (rows * cols) - cols - && (nm - i) <= (nm % cols)) - nw = waw / (nm - i); - nx = (i % cols) * nw + wax; - ny = (i / cols) * nh + way; - /* adjust height/width of last row/column's windows */ - ah = (i >= cols * (rows - 1)) ? wah - m - nh * rows : 0; - /* special case if there are less clients in the last row */ - if (rows > 1 && i == nm - 1 && (nm - i) < (nm % cols)) - /* (n % cols) == number of clients in the last row */ - aw = waw - nw * (nm % cols); + for (i = 0, c = clients; c && !c->minimized; c = c->next, i++) { + /* if there are less clients in the last row than normal adjust the + * split rate to fill the empty space */ + if (rows > 1 && i == (rows * cols) - cols && (n - i) <= (n % cols)) + nw = waw / (n - i); + nx = (i % cols) * nw + wax; + ny = (i / cols) * nh + way; + /* adjust height/width of last row/column's windows */ + ah = (i >= cols * (rows - 1)) ? wah - nh * rows : 0; + /* special case if there are less clients in the last row */ + if (rows > 1 && i == n - 1 && (n - i) < (n % cols)) + /* (n % cols) == number of clients in the last row */ + aw = waw - nw * (n % cols); + else + aw = ((i + 1) % cols == 0) ? waw - nw * cols : 0; + if (i % cols) { + mvvline(ny, nx, ACS_VLINE, nh + ah); + /* if we are on the first row, or on the last one and there are fewer clients + * than normal whose border does not match the line above, print a top tree char + * otherwise a plus sign. */ + if (i <= cols + || (i >= rows * cols - cols && n % cols + && (cols - (n % cols)) % 2)) + mvaddch(ny, nx, ACS_TTEE); else - aw = ((i + 1) % cols == - 0) ? waw - nw * cols : 0; - if (i % cols) { - mvvline(ny, nx, ACS_VLINE, nh + ah); - /* if we are on the first row, or on the last one and there are fewer clients - * than normal whose border does not match the line above, print a top tree char - * otherwise a plus sign. */ - if (i <= cols - || (i >= rows * cols - cols && nm % cols - && (cols - (nm % cols)) % 2)) - mvaddch(ny, nx, ACS_TTEE); - else - mvaddch(ny, nx, ACS_PLUS); - nx++, aw--; - } - } else { - if (i == nm) { /* first minimized client */ - ny = way + wah - m; - nx = wax; - nw = waw; - nh = 1; - aw = 0; - ah = 0; - } else - ny++; + mvaddch(ny, nx, ACS_PLUS); + nx++, aw--; } resize(c, nx, ny, nw + aw, nh + ah); } diff --git a/tile.c b/tile.c @@ -1,50 +1,34 @@ static void tile(void) { - unsigned int i, m, n, nx, ny, nw, nh, nm, mw, th; + unsigned int i, n, nx, ny, nw, nh, mw, th; Client *c; - for (n = 0, m = 0, c = clients; c; c = c->next, n++) - if (c->minimized) - m++; - nm = n - m; - /* window geoms */ - mw = (n == 1 || n - 1 == m) ? waw : screen.mfact * waw; - /* check if there are at least 2 non minimized clients */ - if (n - 1 > m) - th = (wah - m) / (nm - 1); + for (n = 0, c = clients; c && !c->minimized; c = c->next, n++); + mw = n <= 1 ? waw : screen.mfact * waw; + th = n <= 1 ? 0 : wah / (n - 1); nx = wax; ny = way; - for (i = 0, c = clients; c; c = c->next, i++) { + + for (i = 0, c = clients; c && !c->minimized; c = c->next, i++) { if (i == 0) { /* master */ nw = mw; - nh = (n - 1 > m) ? wah : wah - m; + nh = wah; } else { /* tile window */ - if (!c->minimized) { - if (i == 1) { - ny = way; - nx += mw; - nw = waw - mw; - mvvline(ny, nx, ACS_VLINE, wah); - mvaddch(ny, nx, ACS_TTEE); - nx++, nw--; - } - /* remainder */ - if (m == 0 && i + 1 == n) /* no minimized clients */ - nh = (way + wah) - ny; - else if (i == nm - 1) /* last not minimized client */ - nh = (way + wah - (n - i - 1)) - ny; - else - nh = th; - } else { - nh = 1; - ny = way + wah - (n - i); + if (i == 1) { + ny = way; + nx += mw; + nw = waw - mw; + mvvline(ny, nx, ACS_VLINE, wah); + mvaddch(ny, nx, ACS_TTEE); + nx++, nw--; } - if (i > 1 && nm > 1) + nh = (i < n - 1) ? th : (way + wah) - ny; + if (i > 1) mvaddch(ny, nx - 1, ACS_LTEE); } resize(c, nx, ny, nw, nh); - if (n > 1 && th != wah) + if (i > 0) ny += nh; } } diff --git a/tstack.c b/tstack.c @@ -1,45 +1,27 @@ void tstack(void) { - unsigned int i, m, n, nx, ny, nw, nh, mh, tw; + unsigned int i, n, nx, ny, nw, nh, mh, tw; Client *c; - for (n = 0, m = 0, c = clients; c; c = c->next, n++) - if (c->minimized) - m++; + for (n = 0, c = clients; c && !c->minimized; c = c->next, n++); - /* relative height */ - mh = (wah - m) * (n == 1 || n - 1 == m ? 1 : screen.mfact); + mh = n <= 1 ? wah : screen.mfact * wah; + tw = n <= 1 ? 0 : waw / (n - 1); + nx = wax; + nw = waw; - /* true if there are at least 2 non minimized clients */ - if (n - 1 > m) - tw = waw / (n - m - 1); - - nx = wax, nw = waw; - for (i = 0, c = clients; c; c = c->next, i++) { + for (i = 0, c = clients; c && !c->minimized; c = c->next, i++) { if (i == 0) { /* master */ ny = way + wah - mh; nh = mh; } else { /* tile window */ if (i == 1) { nx = wax; - ny = way + m; + ny = way; nh = wah - mh - ny + way; } - if (i == n - m - 1) { /* last not minimized client */ - nw = (wax + waw) - nx; - } else if (i == n - m) { /* first minimized client */ - nx = wax; - --ny; - nh = 1; - nw = waw; - } else if (c->minimized) { /* minimized window */ - --ny; - nh = 1; - nw = waw; - } else /* normal non minimized tile window */ - nw = tw; - - if (i > 1 && !c->minimized) { + nw = (i < n - 1) ? tw : (wax + waw) - nx; + if (i > 1) { mvvline(ny, nx, ACS_VLINE, nh); mvaddch(ny, nx, ACS_TTEE); ++nx, --nw; @@ -48,7 +30,7 @@ void tstack(void) resize(c, nx, ny, nw, nh); - if (n > 1 && i < n - m - 1) + if (i > 0) nx += nw; } } diff --git a/vstack.c b/vstack.c @@ -1,36 +1,20 @@ /* A vertical stack layout, all windows have the full screen width. */ static void vstack(void) { - unsigned int i, m, n, ny, nh, mh, th; + unsigned int i, n, ny, nh, mh, th; Client *c; - for (n = 0, m = 0, c = clients; c; c = c->next, n++) - if (c->minimized) - m++; - - if (n == 1) - mh = wah; - else if (n - 1 == m) - mh = wah - m; - else - mh = screen.mfact * (wah - m); - /* true if there are at least 2 non minimized clients */ - if (n - 1 > m) - th = (wah - mh) / (n - 1 - m); - - /* TODO: place all minimized windows on the last line */ + for (n = 0, c = clients; c && !c->minimized; c = c->next, n++); + mh = n <= 1 ? wah : screen.mfact * wah; + th = n <= 1 ? 0 : (wah - mh) / (n - 1); ny = way; - for (i = 0, c = clients; c; c = c->next, i++) { - if (i == 0) { /* master */ + + for (i = 0, c = clients; c && !c->minimized; c = c->next, i++) { + if (i == 0) /* master */ nh = mh; - } else if (i == n - m - 1) { /* last not minimized client */ - nh = (way + wah) - ny - m; - } else if (c->minimized) { - nh = 1; - } else { /* normal non minimized tile window */ - nh = th; - } + else /* tile window */ + nh = (i < n - 1) ? th : (way + wah) - ny; resize(c, wax, ny, waw, nh); ny += nh; }