dvtm

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

commit 9e63513c516e0a7503ff83973648ace5760faf79
parent 69e91c9fcbb7f820403c42dc3eaaf54eeaeb8567
Author: Marc Andre Tanner <mat@brain-dump.org>
Date:   Sun, 16 Sep 2012 11:29:15 +0200

Simplify color configuration

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

Diffstat:
config.h | 18+++++-------------
dvtm.c | 14++------------
vt.c | 10++++++----
vt.h | 2+-
4 files changed, 14 insertions(+), 30 deletions(-)

diff --git a/config.h b/config.h @@ -1,4 +1,3 @@ -/* curses attributes for the currently focused window */ /* valid curses attributes are listed below they can be ORed * * A_NORMAL Normal display (no highlight) @@ -10,23 +9,16 @@ * A_BOLD Extra bright or bold * A_PROTECT Protected mode * A_INVIS Invisible or blank mode - * */ #define BLUE (COLORS==256 ? 68 : COLOR_BLUE) - -#define SELECTED_ATTR A_NORMAL -#define SELECTED_FG BLUE -#define SELECTED_BG -1 +/* curses attributes for the currently focused window */ +#define SELECTED_ATTR COLOR(BLUE, -1) | A_NORMAL /* curses attributes for normal (not selected) windows */ -#define NORMAL_ATTR A_NORMAL -#define NORMAL_FG -1 -#define NORMAL_BG -1 +#define NORMAL_ATTR COLOR(-1, -1) | A_NORMAL +/* curses attributes for the status bar */ +#define BAR_ATTR COLOR(BLUE, -1) | A_NORMAL /* status bar (command line option -s) position */ #define BAR_POS BAR_TOP /* BAR_BOTTOM, BAR_OFF */ -/* curses attributes for the status bar */ -#define BAR_ATTR A_NORMAL -#define BAR_FG BLUE -#define BAR_BG -1 /* determines whether the statusbar text should be right or left aligned */ #define BAR_ALIGN ALIGN_RIGHT /* separator between window title and window number */ diff --git a/dvtm.c b/dvtm.c @@ -179,6 +179,7 @@ static void resize(Client *c, int x, int y, int w, int h); extern Screen screen; static unsigned int waw, wah, wax, way; static Client *clients = NULL; +#define COLOR(fg, bg) COLOR_PAIR(vt_color_reserve(fg, bg)) #include "config.h" @@ -231,7 +232,6 @@ drawbar() { return; curs_set(0); attrset(BAR_ATTR); - wcolor_set(stdscr, vt_color_get(NULL, BAR_FG, BAR_BG), NULL); mvaddch(bar.y, 0, '['); if (mbstowcs(wbuf, bar.text, sizeof bar.text) == (size_t)-1) return; @@ -258,13 +258,7 @@ draw_border(Client *c) { char t = '\0'; int x, y, maxlen; - if (sel == c || (runinall && !c->minimized)) { - wattrset(c->window, SELECTED_ATTR); - wcolor_set(c->window, vt_color_get(NULL, SELECTED_FG, SELECTED_BG), NULL); - } else { - wattrset(c->window, NORMAL_ATTR); - wcolor_set(c->window, vt_color_get(NULL, NORMAL_FG, NORMAL_BG), NULL); - } + wattrset(c->window, (sel == c || (runinall && !c->minimized)) ? SELECTED_ATTR : NORMAL_ATTR); getyx(c->window, y, x); curs_set(0); mvwhline(c->window, 0, 0, ACS_HLINE, c->w); @@ -333,7 +327,6 @@ static void arrange() { clear_workspace(); attrset(NORMAL_ATTR); - color_set(vt_color_get(NULL, NORMAL_FG, NORMAL_BG), NULL); layout->arrange(); wnoutrefresh(stdscr); draw_all(true); @@ -643,9 +636,6 @@ setup() { mouse_setup(); raw(); vt_init(); - vt_color_reserve(NORMAL_FG, NORMAL_BG); - vt_color_reserve(SELECTED_FG, SELECTED_BG); - vt_color_reserve(BAR_FG, BAR_BG); getmaxyx(stdscr, screen.h, screen.w); resize_screen(); signal(SIGWINCH, sigwinch_handler); diff --git a/vt.c b/vt.c @@ -1576,21 +1576,23 @@ short vt_color_get(Vt *t, short fg, short bg) return color_pair >= 0 ? color_pair : -color_pair; } -void vt_color_reserve(short fg, short bg) +short vt_color_reserve(short fg, short bg) { - if (!color2palette || fg >= COLORS || bg >= COLORS || color_pairs_reserved > color_pairs_max / 2) - return; + if (!color2palette || fg >= COLORS || bg >= COLORS) + return 0; if (!has_default_colors && fg == -1) fg = default_fg; if (!has_default_colors && bg == -1) bg = default_bg; if (fg == -1 && bg == -1) - return; + return 0; unsigned int index = color_hash(fg, bg); if (color2palette[index] >= 0) { if (init_pair(++color_pairs_reserved, fg, bg) == OK) color2palette[index] = -color_pairs_reserved; } + short color_pair = color2palette[index]; + return color_pair >= 0 ? color_pair : -color_pair; } static void init_colors(void) diff --git a/vt.h b/vt.h @@ -81,7 +81,7 @@ void vt_mouse(Vt *t, int x, int y, mmask_t mask); void vt_dirty(Vt *t); void vt_draw(Vt *, WINDOW *win, int startrow, int startcol); short vt_color_get(Vt *t, short fg, short bg); -void vt_color_reserve(short fg, short bg); +short vt_color_reserve(short fg, short bg); void vt_scroll(Vt *, int rows); void vt_noscroll(Vt *);