dvtm

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

commit 9d3389445c4dde861b0a58e461b8c0e87e780bb4
parent d0e265e9632e848d0f003995bb94580f5199a861
Author: Marc Andre Tanner <mat@brain-dump.org>
Date:   Sun, 12 Jun 2011 14:08:09 +0200

Group most screen related variables into struct

Signed-off-by: Marc Andre Tanner <mat@brain-dump.org>

Diffstat:
bstack.c | 2+-
config.h | 8++++----
dvtm.c | 66++++++++++++++++++++++++++++++++++++------------------------------
statusbar.c | 6+++---
tile.c | 2+-
tstack.c | 2+-
6 files changed, 46 insertions(+), 40 deletions(-)

diff --git a/bstack.c b/bstack.c @@ -12,7 +12,7 @@ bstack(void) { else if(n - 1 == m) mh = wah - m; else - mh = mwfact * (wah - m); + mh = screen.mfact * (wah - m); /* true if there are at least 2 non minimized clients */ if(n - 1 > m) tw = waw / (n - m - 1); diff --git a/config.h b/config.h @@ -36,9 +36,9 @@ * the SEPARATOR, %d stands for the window number */ #define TITLE "[%s%s#%d]" /* master width factor [0.1 .. 0.9] */ -#define MWFACT 0.5 +#define MFACT 0.5 /* scroll back buffer size in lines */ -#define SCROLL_BUF_SIZE 500 +#define SCROLL_HISTORY 500 #include "tile.c" #include "grid.c" @@ -68,8 +68,8 @@ Key keys[] = { { MOD, 'b', { setlayout, { "TTT" } } }, { MOD, 'm', { setlayout, { "[ ]" } } }, { MOD, ' ', { setlayout, { NULL } } }, - { MOD, 'h', { setmwfact, { "-0.05" } } }, - { MOD, 'l', { setmwfact, { "+0.05" } } }, + { MOD, 'h', { setmfact, { "-0.05" } } }, + { MOD, 'l', { setmfact, { "+0.05" } } }, { MOD, '.', { toggleminimize, { NULL } } }, { MOD, 's', { togglebar, { NULL } } }, { MOD, 'M', { mouse_toggle, { NULL } } }, diff --git a/dvtm.c b/dvtm.c @@ -35,6 +35,14 @@ #include "madtty.h" typedef struct { + double mfact; + int history; + int w; + int h; + bool need_resize; +} Screen; + +typedef struct { const char *symbol; void (*arrange)(void); } Layout; @@ -137,7 +145,7 @@ static void focusprev(const char *args[]); static void focusprevnm(const char *args[]); static void togglebell(const char *key[]); static void toggleminimize(const char *args[]); -static void setmwfact(const char *args[]); +static void setmfact(const char *args[]); static void setlayout(const char *args[]); static void scrollback(const char *args[]); static void redraw(const char *args[]); @@ -167,18 +175,16 @@ static void keypress(int code); static unsigned int waw, wah, wax, way; static Client *clients = NULL; -extern double mwfact; +extern Screen screen; #include "config.h" +Screen screen = { MFACT, SCROLL_HISTORY }; static Client *sel = NULL; -double mwfact = MWFACT; static Layout *layout = layouts; static StatusBar bar = { -1, "", BARPOS, 1, 0 }; static CmdFifo cmdfifo = { -1 }; static const char *shell; -static bool need_screen_resize; -static int width, height, scroll_buf_size = SCROLL_BUF_SIZE; static bool running = true; static bool runinall = false; @@ -432,23 +438,23 @@ setlayout(const char *args[]) { } static void -setmwfact(const char *args[]) { +setmfact(const char *args[]) { double delta; if (isarrange(fullscreen) || isarrange(grid)) return; - /* arg handling, manipulate mwfact */ + /* arg handling, manipulate mfact */ if (args[0] == NULL) - mwfact = MWFACT; + screen.mfact = MFACT; else if (1 == sscanf(args[0], "%lf", &delta)) { if (args[0][0] == '+' || args[0][0] == '-') - mwfact += delta; + screen.mfact += delta; else - mwfact = delta; - if (mwfact < 0.1) - mwfact = 0.1; - else if (mwfact > 0.9) - mwfact = 0.9; + screen.mfact = delta; + if (screen.mfact < 0.1) + screen.mfact = 0.1; + else if (screen.mfact > 0.9) + screen.mfact = 0.9; } arrange(); } @@ -670,15 +676,15 @@ create(const char *args[]) { }; c->window = newwin(wah, waw, way, wax); - c->term = madtty_create(height - 1, width, scroll_buf_size); + c->term = madtty_create(screen.h - 1, screen.w, screen.history); c->cmd = cmd; if (args && args[1]) strncpy(c->title, args[1], sizeof(c->title)); c->pid = madtty_forkpty(c->term, "/bin/sh", pargs, env, &c->pty); madtty_set_data(c->term, c); madtty_set_handler(c->term, title_escape_seq_handler); - c->w = width; - c->h = height; + c->w = screen.w; + c->h = screen.h; c->x = wax; c->y = way; c->order = 0; @@ -807,7 +813,7 @@ sigchld_handler(int sig) { static void sigwinch_handler(int sig) { signal(SIGWINCH, sigwinch_handler); - need_screen_resize = true; + screen.need_resize = true; } static void @@ -822,22 +828,22 @@ resize_screen() { if (ioctl(0, TIOCGWINSZ, &ws) == -1) return; - width = ws.ws_col; - height = ws.ws_row; + screen.w = ws.ws_col; + screen.h = ws.ws_row; - debug("resize_screen(), w: %d h: %d\n", width, height); + debug("resize_screen(), w: %d h: %d\n", screen.w, screen.h); #if defined(__OpenBSD__) || defined(__NetBSD__) - resizeterm(height, width); + resizeterm(screen.h, screen.w); #else - resize_term(height, width); + resize_term(screen.h, screen.w); #endif - wresize(stdscr, height, width); + wresize(stdscr, screen.h, screen.w); wrefresh(curscr); refresh(); - waw = width; - wah = height; + waw = screen.w; + wah = screen.h; updatebarpos(); drawbar(); arrange(); @@ -861,7 +867,7 @@ setup() { mouse_setup(); raw(); madtty_init(); - getmaxyx(stdscr, height, width); + getmaxyx(stdscr, screen.h, screen.w); resize_screen(); signal(SIGWINCH, sigwinch_handler); signal(SIGCHLD, sigchld_handler); @@ -951,7 +957,7 @@ parse_args(int argc, char *argv[]) { ESCDELAY = 1000; break; case 'h': - scroll_buf_size = atoi(argv[++arg]); + screen.history = atoi(argv[++arg]); break; case 's': bar.fd = open_or_create_fifo(argv[++arg]); @@ -1008,9 +1014,9 @@ main(int argc, char *argv[]) { int r, nfds = 0; fd_set rd; - if (need_screen_resize) { + if (screen.need_resize) { resize_screen(); - need_screen_resize = false; + screen.need_resize = false; } FD_ZERO(&rd); diff --git a/statusbar.c b/statusbar.c @@ -3,7 +3,7 @@ updatebarpos(void) { bar.y = 0; wax = 0; way = 0; - wah = height; + wah = screen.h; if (bar.fd == -1) return; if (bar.pos == BarTop) { @@ -18,7 +18,7 @@ updatebarpos(void) { static void drawbar() { wchar_t wbuf[sizeof bar.text]; - int w, maxwidth = width - 2; + int w, maxwidth = screen.w - 2; if (bar.pos == BarOff || !bar.text[0]) return; curs_set(0); @@ -38,7 +38,7 @@ drawbar() { for (; w < maxwidth; w++) addch(' '); } - mvaddch(bar.y, width - 1, ']'); + mvaddch(bar.y, screen.w - 1, ']'); attrset(NORMAL_ATTR); if (sel) curs_set(madtty_cursor(sel->term)); diff --git a/tile.c b/tile.c @@ -8,7 +8,7 @@ tile(void) { m++; nm = n - m; /* window geoms */ - mw = (n == 1 || n - 1 == m) ? waw : mwfact * waw; + 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); diff --git a/tstack.c b/tstack.c @@ -8,7 +8,7 @@ tstack(void) { m++; /* relative height */ - mh = (wah - m) * (n == 1 || n - 1 == m ? 1 : mwfact); + mh = (wah - m) * (n == 1 || n - 1 == m ? 1 : screen.mfact); /* true if there are at least 2 non minimized clients */ if(n - 1 > m)