dvtm

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

commit 1004850fd7e9484c9c2073344cd02835d81f64f1
parent 85247a8819a844ab74cf0fc44e7c4e89ce4dc363
Author: Marc André Tanner <mat@brain-dump.org>
Date:   Tue,  7 Oct 2014 11:39:54 +0200

Improve color reservation

All user defined colors should be reserved upfront and not upon
first use.

Diffstat:
config.def.h | 24+++++++++++++++---------
dvtm.c | 28++++++++++++++++++++++------
2 files changed, 37 insertions(+), 15 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -10,13 +10,23 @@ * A_PROTECT Protected mode * A_INVIS Invisible or blank mode */ -#define BLUE (COLORS==256 ? 68 : COLOR_BLUE) + +enum { + DEFAULT, + BLUE, +}; + +static Color colors[] = { + [DEFAULT] = { .fg = -1, .bg = -1, .fg256 = -1, .bg256 = -1, }, + [BLUE] = { .fg = COLOR_BLUE, .bg = -1, .fg256 = 68, .bg256 = -1, }, +}; + /* curses attributes for the currently focused window */ -#define SELECTED_ATTR COLOR(BLUE, -1) | A_NORMAL +#define SELECTED_ATTR (COLOR(BLUE) | A_NORMAL) /* curses attributes for normal (not selected) windows */ -#define NORMAL_ATTR COLOR(-1, -1) | A_NORMAL +#define NORMAL_ATTR (COLOR(DEFAULT) | A_NORMAL) /* curses attributes for the status bar */ -#define BAR_ATTR COLOR(BLUE, -1) | A_NORMAL +#define BAR_ATTR (COLOR(BLUE) | A_NORMAL) /* status bar (command line option -s) position */ #define BAR_POS BAR_TOP /* BAR_BOTTOM, BAR_OFF */ /* determines whether the statusbar text should be right or left aligned */ @@ -94,11 +104,7 @@ static Key keys[] = { }; static const ColorRule colorrules[] = { - { "", A_NORMAL, -1, -1 }, /* default */ -#if 0 - /* title attrs fgcolor bgcolor */ - { "ssh", A_NORMAL, COLOR_BLACK, 224 }, -#endif + { "", A_NORMAL, &colors[DEFAULT] }, /* default */ }; /* possible values for the mouse buttons are listed below: diff --git a/dvtm.c b/dvtm.c @@ -75,10 +75,17 @@ struct Client { }; typedef struct { - const char *title; - unsigned attrs; short fg; short bg; + short fg256; + short bg256; + short pair; +} Color; + +typedef struct { + const char *title; + attr_t attrs; + Color *color; } ColorRule; #define ALT(k) ((k) + (161 - 'a')) @@ -180,7 +187,7 @@ extern Screen screen; static unsigned int waw, wah, wax, way; static Client *clients = NULL; static char *title; -#define COLOR(fg, bg) COLOR_PAIR(vt_color_reserve(fg, bg)) +#define COLOR(c) COLOR_PAIR(colors[c].pair) #define NOMOD ERR #include "config.h" @@ -410,15 +417,15 @@ focus(Client *c) { static void applycolorrules(Client *c) { const ColorRule *r = colorrules; - short fg = r->fg, bg = r->bg; + short fg = r->color->fg, bg = r->color->bg; unsigned attrs = r->attrs; for (unsigned int i = 1; i < countof(colorrules); i++) { r = &colorrules[i]; if (strstr(c->title, r->title)) { attrs = r->attrs; - fg = r->fg; - bg = r->bg; + fg = r->color->fg; + bg = r->color->bg; break; } } @@ -654,6 +661,15 @@ setup() { raw(); vt_init(); vt_set_keytable(keytable, countof(keytable)); + for (unsigned int i = 0; i < countof(colors); i++) { + if (COLORS == 256) { + if (colors[i].fg256) + colors[i].fg = colors[i].fg256; + if (colors[i].bg256) + colors[i].bg = colors[i].bg256; + } + colors[i].pair = vt_color_reserve(colors[i].fg, colors[i].bg); + } resize_screen(); struct sigaction sa; sa.sa_flags = 0;