dvtm

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

commit e2620ab134b08abc10e3d8363487961499905741
parent f4ce2696fba32b145c61553f450608779d046b29
Author: Ross Mohn <rpmohn@waxandwane.org>
Date:   Thu, 12 Feb 2015 10:44:09 +0100

Implement nmaster functionality via MOD+{i,d}

Diffstat:
bstack.c | 41+++++++++++++++++++++++++++++------------
config.def.h | 6+++++-
dvtm.c | 25++++++++++++++++++++++++-
tile.c | 32+++++++++++++++++++++-----------
tstack.c | 36++++++++++++++++++++----------------
vstack.c | 11++++++-----
6 files changed, 105 insertions(+), 46 deletions(-)

diff --git a/bstack.c b/bstack.c @@ -1,41 +1,58 @@ static void bstack(void) { - unsigned int i, n, nx, ny, nw, nh, mh, tw; + unsigned int i, n, nx, ny, nw, nh, m, mw, mh, tw; Client *c; for (n = 0, c = nextvisible(clients); c; c = nextvisible(c->next)) if (!c->minimized) n++; - mh = n <= 1 ? wah : screen.mfact * wah; - tw = n <= 1 ? 0 : waw / (n - 1); + m = MAX(1, MIN(n, screen.nmaster)); + mh = n == m ? wah : screen.mfact * wah; + mw = waw / m; + tw = n == m ? 0 : waw / (n - m); nx = wax; ny = way; for (i = 0, c = nextvisible(clients); c; c = nextvisible(c->next)) { if (c->minimized) continue; - if (i == 0) { /* master */ + if (i < m) { /* master */ + if (i > 0) { + mvvline(ny, nx, ACS_VLINE, nh); + mvaddch(ny, nx, ACS_TTEE); + nx++; + } nh = mh; - nw = waw; + nw = (i < m - 1) ? mw : (wax + waw) - nx; } else { /* tile window */ - if (i == 1) { + if (i == m) { nx = wax; ny += mh; nh = (way + wah) - ny; } - nw = (i < n - 1) ? tw : (wax + waw) - nx; - if (i > 1) { + if (i > m) { mvvline(ny, nx, ACS_VLINE, nh); mvaddch(ny, nx, ACS_TTEE); - nx++, nw--; + nx++; } + nw = (i < n - 1) ? tw : (wax + waw) - nx; } - resize(c, nx, ny, nw, nh); + nx += nw; + i++; + } - if (i > 0) + /* Fill in nmaster intersections */ + if (n > m) { + nx = wax; + for (i = 0; i < m; i++) { + if (i > 0) { + mvaddch(ny, nx, ACS_PLUS); + nx++; + } + nw = (i < m - 1) ? mw : (wax + waw) - nx; nx += nw; - i++; + } } } diff --git a/config.def.h b/config.def.h @@ -44,6 +44,8 @@ static Color colors[] = { #define TITLE "[%s%s#%d]" /* master width factor [0.1 .. 0.9] */ #define MFACT 0.5 +/* number of clients in master area */ +#define NMASTER 1 /* scroll back buffer size in lines */ #define SCROLL_HISTORY 500 /* printf format string for the tag in the status bar */ @@ -83,11 +85,13 @@ static KeyBinding bindings[] = { { { MOD, 'J', }, { focusnextnm, { NULL } } }, { { MOD, 'K', }, { focusprevnm, { NULL } } }, { { MOD, 'k', }, { focusprev, { NULL } } }, - { { MOD, 'd', }, { setlayout, { "[]=" } } }, + { { MOD, 'f', }, { setlayout, { "[]=" } } }, { { MOD, 'g', }, { setlayout, { "+++" } } }, { { MOD, 'b', }, { setlayout, { "TTT" } } }, { { MOD, 'm', }, { setlayout, { "[ ]" } } }, { { MOD, ' ', }, { setlayout, { NULL } } }, + { { MOD, 'i', }, { incnmaster, { "+1" } } }, + { { MOD, 'd', }, { incnmaster, { "-1" } } }, { { MOD, 'h', }, { setmfact, { "-0.05" } } }, { { MOD, 'l', }, { setmfact, { "+0.05" } } }, { { MOD, '.', }, { toggleminimize, { NULL } } }, diff --git a/dvtm.c b/dvtm.c @@ -46,6 +46,7 @@ int ESCDELAY; typedef struct { float mfact; + unsigned int nmaster; int history; int w; int h; @@ -166,6 +167,7 @@ typedef struct { #define LENGTH(arr) (sizeof(arr) / sizeof((arr)[0])) #define STRLEN(str) (sizeof(str) - 1) #define MAX(x, y) ((x) > (y) ? (x) : (y)) +#define MIN(x, y) ((x) < (y) ? (x) : (y)) #define TAGMASK ((1 << LENGTH(tags)) - 1) #ifdef NDEBUG @@ -190,6 +192,7 @@ static void redraw(const char *args[]); static void scrollback(const char *args[]); static void send(const char *args[]); static void setlayout(const char *args[]); +static void incnmaster(const char *args[]); static void setmfact(const char *args[]); static void startup(const char *args[]); static void tag(const char *args[]); @@ -223,7 +226,7 @@ static char *title; /* global variables */ static const char *dvtm_name = "dvtm"; -Screen screen = { .mfact = MFACT, .history = SCROLL_HISTORY }; +Screen screen = { .mfact = MFACT, .nmaster = NMASTER, .history = SCROLL_HISTORY }; static Client *stack = NULL; static Client *sel = NULL; static Client *lastsel = NULL; @@ -1249,6 +1252,26 @@ setlayout(const char *args[]) { } static void +incnmaster(const char *args[]) { + int delta; + + if (isarrange(fullscreen) || isarrange(grid)) + return; + /* arg handling, manipulate nmaster */ + if (args[0] == NULL) { + screen.nmaster = NMASTER; + } else if (1 == sscanf(args[0], "%d", &delta)) { + if (args[0][0] == '+' || args[0][0] == '-') + screen.nmaster += delta; + else + screen.nmaster = delta; + if (screen.nmaster < 1) + screen.nmaster = 1; + } + arrange(); +} + +static void setmfact(const char *args[]) { float delta; diff --git a/tile.c b/tile.c @@ -1,39 +1,49 @@ static void tile(void) { - unsigned int i, n, nx, ny, nw, nh, mw, th; + unsigned int i, n, nx, ny, nw, nh, m, mw, mh, th; Client *c; for (n = 0, c = nextvisible(clients); c; c = nextvisible(c->next)) if (!c->minimized) n++; - mw = n <= 1 ? waw : screen.mfact * waw; - th = n <= 1 ? 0 : wah / (n - 1); + m = MAX(1, MIN(n, screen.nmaster)); + mw = n == m ? waw : screen.mfact * waw; + mh = wah / m; + th = n == m ? 0 : wah / (n - m); nx = wax; ny = way; for (i = 0, c = nextvisible(clients); c; c = nextvisible(c->next)) { if (c->minimized) continue; - if (i == 0) { /* master */ + if (i < m) { /* master */ nw = mw; - nh = wah; + nh = (i < m - 1) ? mh : (way + wah) - ny; } else { /* tile window */ - if (i == 1) { + if (i == m) { ny = way; nx += mw; - nw = waw - mw; mvvline(ny, nx, ACS_VLINE, wah); mvaddch(ny, nx, ACS_TTEE); - nx++, nw--; + nx++; + nw = waw - mw -1; } nh = (i < n - 1) ? th : (way + wah) - ny; - if (i > 1) + if (i > m) mvaddch(ny, nx - 1, ACS_LTEE); } resize(c, nx, ny, nw, nh); - if (i > 0) - ny += nh; + ny += nh; i++; } + + /* Fill in nmaster intersections */ + if (n > m) { + ny = way + mh; + for (i = 1; i < m; i++) { + mvaddch(ny, nx - 1, ((ny - 1) % th ? ACS_RTEE : ACS_PLUS)); + ny += mh; + } + } } diff --git a/tstack.c b/tstack.c @@ -1,41 +1,45 @@ -void tstack(void) +static void tstack(void) { - unsigned int i, n, nx, ny, nw, nh, mh, tw; + unsigned int i, n, nx, ny, nw, nh, m, mw, mh, tw; Client *c; for (n = 0, c = nextvisible(clients); c; c = nextvisible(c->next)) if (!c->minimized) n++; - mh = n <= 1 ? wah : screen.mfact * wah; - tw = n <= 1 ? 0 : waw / (n - 1); + m = MAX(1, MIN(n, screen.nmaster)); + mh = n == m ? wah : screen.mfact * wah; + mw = waw / m; + tw = n == m ? 0 : waw / (n - m); nx = wax; - nw = waw; + ny = way + wah - mh; for (i = 0, c = nextvisible(clients); c; c = nextvisible(c->next)) { if (c->minimized) continue; - if (i == 0) { /* master */ - ny = way + wah - mh; + if (i < m) { /* master */ + if (i > 0) { + mvvline(ny, nx, ACS_VLINE, nh); + mvaddch(ny, nx, ACS_TTEE); + nx++; + } nh = mh; + nw = (i < m - 1) ? mw : (wax + waw) - nx; } else { /* tile window */ - if (i == 1) { + if (i == m) { nx = wax; ny = way; - nh = wah - mh - ny + way; + nh = (way + wah) - ny - mh; } - nw = (i < n - 1) ? tw : (wax + waw) - nx; - if (i > 1) { + if (i > m) { mvvline(ny, nx, ACS_VLINE, nh); mvaddch(ny, nx, ACS_TTEE); - ++nx, --nw; + nx++; } + nw = (i < n - 1) ? tw : (wax + waw) - nx; } - resize(c, nx, ny, nw, nh); - - if (i > 0) - nx += nw; + nx += nw; i++; } } diff --git a/vstack.c b/vstack.c @@ -1,22 +1,23 @@ /* A vertical stack layout, all windows have the full screen width. */ static void vstack(void) { - unsigned int i, n, ny, nh, mh, th; + unsigned int i, n, ny, nh, m, mh, th; Client *c; for (n = 0, c = nextvisible(clients); c; c = nextvisible(c->next)) if (!c->minimized) n++; - mh = n <= 1 ? wah : screen.mfact * wah; - th = n <= 1 ? 0 : (wah - mh) / (n - 1); + m = MAX(1, MIN(n, screen.nmaster)); + mh = (n == m ? wah : screen.mfact * wah); + th = n == m ? 0 : (wah - mh) / (n - m); ny = way; for (i = 0, c = nextvisible(clients); c; c = nextvisible(c->next)) { if (c->minimized) continue; - if (i == 0) /* master */ - nh = mh; + if (i < m) /* master */ + nh = (i < m - 1) ? mh / m : (way + mh) - ny; else /* tile window */ nh = (i < n - 1) ? th : (way + wah) - ny; resize(c, wax, ny, waw, nh);