From 1a755ff245a90bf5b4e2dad97d86771a05903630 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 10 Oct 2007 13:07:12 +0200 Subject: [PATCH] simplify color handling --- client.c | 6 +++--- config.c | 22 ++++++---------------- config.h | 8 ++++---- draw.c | 14 +++++++------- draw.h | 4 ++-- statusbar.c | 20 ++++++++++---------- 6 files changed, 32 insertions(+), 42 deletions(-) diff --git a/client.c b/client.c index 5e7a8ccf..4264aec5 100644 --- a/client.c +++ b/client.c @@ -319,7 +319,7 @@ focus(Display *disp, DC *drawcontext, Client * c, Bool selscreen, awesome_config if(sel && sel != c) { grabbuttons(sel, False, awesomeconf->modkey, awesomeconf->numlockmask); - XSetWindowBorder(sel->display, sel->win, drawcontext->norm[ColBorder]); + XSetWindowBorder(sel->display, sel->win, awesomeconf->colors_normal[ColBorder].pixel); setclienttrans(sel, awesomeconf->opacity_unfocused); } if(sel == c) @@ -336,7 +336,7 @@ focus(Display *disp, DC *drawcontext, Client * c, Bool selscreen, awesome_config drawstatusbar(disp, drawcontext, awesomeconf); if(sel) { - XSetWindowBorder(sel->display, sel->win, drawcontext->sel[ColBorder]); + XSetWindowBorder(sel->display, sel->win, awesomeconf->colors_selected[ColBorder].pixel); XSetInputFocus(sel->display, sel->win, RevertToPointerRoot, CurrentTime); for(c = stack; c; c = c->snext) if(c != sel) @@ -427,7 +427,7 @@ manage(Display *disp, DC *drawcontext, Window w, XWindowAttributes *wa, awesome_ XFree(si); wc.border_width = c->border; XConfigureWindow(disp, w, CWBorderWidth, &wc); - XSetWindowBorder(disp, w, drawcontext->norm[ColBorder]); + XSetWindowBorder(disp, w, awesomeconf->colors_normal[ColBorder].pixel); configure(c); /* propagates border_width, if size doesn't change */ updatesizehints(c); XSelectInput(disp, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask); diff --git a/config.c b/config.c index 2e83bed5..828be430 100644 --- a/config.c +++ b/config.c @@ -260,7 +260,6 @@ parse_config(Display * disp, int scr, DC * drawcontext, const char *confpatharg, char *confpath; KeySym tmp_key; ssize_t confpath_len, txtlen; - XColor colorbuf; if(confpatharg) confpath = a_strdup(confpatharg); @@ -308,21 +307,12 @@ parse_config(Display * disp, int scr, DC * drawcontext, const char *confpatharg, eprint("awesome: cannot init font\n"); /* Colors */ - drawcontext->norm[ColBorder] = initxcolor(disp, awesomeconf->phys_screen, - cfg_getstr(cfg_colors, "normal_border")).pixel; - drawcontext->norm[ColBG] = initxcolor(disp, awesomeconf->phys_screen, - cfg_getstr(cfg_colors, "normal_bg")).pixel; - drawcontext->sel[ColBorder] = initxcolor(disp, awesomeconf->phys_screen, - cfg_getstr(cfg_colors, "focus_border")).pixel; - drawcontext->sel[ColBG] = initxcolor(disp, awesomeconf->phys_screen, - cfg_getstr(cfg_colors, "focus_bg")).pixel; - - colorbuf = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "normal_fg")); - drawcontext->norm[ColFG] = colorbuf.pixel; - drawcontext->text_normal = colorbuf; - colorbuf = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "focus_fg")); - drawcontext->sel[ColFG] = colorbuf.pixel; - drawcontext->text_selected = colorbuf; + awesomeconf->colors_normal[ColBorder] = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "normal_border")); + awesomeconf->colors_normal[ColBG] = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "normal_bg")); + awesomeconf->colors_normal[ColFG] = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "normal_fg")); + awesomeconf->colors_selected[ColBorder] = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "focus_border")); + awesomeconf->colors_selected[ColBG] = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "focus_bg")); + awesomeconf->colors_selected[ColFG] = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "focus_fg")); /* Statusbar */ tmp = cfg_getstr(cfg_statusbar, "position"); diff --git a/config.h b/config.h index a74742ca..916f8b00 100644 --- a/config.h +++ b/config.h @@ -39,10 +39,6 @@ enum typedef struct { - unsigned long norm[ColLast]; - unsigned long sel[ColLast]; - XColor text_normal; - XColor text_selected; GC gc; Cursor cursor[CurLast]; XftFont *font; @@ -158,6 +154,10 @@ struct awesome_config Bool have_shape; /** Check for XRandR extension */ Bool have_randr; + /** Normal colors */ + XColor colors_normal[ColLast]; + /** Selected colors */ + XColor colors_selected[ColLast]; }; void parse_config(Display *, int, DC *, const char *, awesome_config *); /* parse configuration file */ diff --git a/draw.c b/draw.c index 0367e7f8..cf24b92e 100644 --- a/draw.c +++ b/draw.c @@ -24,7 +24,7 @@ #include "draw.h" void -drawtext(Display *disp, int screen, int x, int y, int w, int h, GC gc, Drawable drawable, XftFont *font, const char *text, unsigned long col[ColLast], XColor textcolor) +drawtext(Display *disp, int screen, int x, int y, int w, int h, GC gc, Drawable drawable, XftFont *font, const char *text, XColor color[ColLast]) { int nw = 0; static char buf[256]; @@ -34,7 +34,7 @@ drawtext(Display *disp, int screen, int x, int y, int w, int h, GC gc, Drawable XftColor xftcolor; XftDraw *xftdrawable; - XSetForeground(disp, gc, col[ColBG]); + XSetForeground(disp, gc, color[ColBG].pixel); XFillRectangles(disp, drawable, gc, &r, 1); if(!text) return; @@ -56,9 +56,9 @@ drawtext(Display *disp, int screen, int x, int y, int w, int h, GC gc, Drawable if(len > 3) buf[len - 3] = '.'; } - xrcolor.red = textcolor.red; - xrcolor.green = textcolor.green; - xrcolor.blue = textcolor.blue; + xrcolor.red = color[ColFG].red; + xrcolor.green = color[ColFG].green; + xrcolor.blue = color[ColFG].blue; XftColorAllocValue(disp, DefaultVisual(disp, screen), DefaultColormap(disp, screen), &xrcolor, &xftcolor); xftdrawable = XftDrawCreate(disp, drawable, DefaultVisual(disp, screen), DefaultColormap(disp, screen)); XftDrawStringUtf8(xftdrawable, &xftcolor, font, @@ -69,12 +69,12 @@ drawtext(Display *disp, int screen, int x, int y, int w, int h, GC gc, Drawable } void -drawsquare(Display *disp, int x, int y, int h, GC gc, Drawable drawable, Bool filled, unsigned long col) +drawsquare(Display *disp, int x, int y, int h, GC gc, Drawable drawable, Bool filled, XColor color) { XGCValues gcv; XRectangle r = { x, y, h, h }; - gcv.foreground = col; + gcv.foreground = color.pixel; XChangeGC(disp, gc, GCForeground, &gcv); if(filled) { diff --git a/draw.h b/draw.h index 860134e2..e508e628 100644 --- a/draw.h +++ b/draw.h @@ -24,7 +24,7 @@ #include "config.h" -void drawtext(Display *, int, int, int, int, int, GC, Drawable, XftFont *, const char *, unsigned long *, XColor); -void drawsquare(Display *, int, int, int, GC, Drawable, Bool, unsigned long); +void drawtext(Display *, int, int, int, int, int, GC, Drawable, XftFont *, const char *, XColor []); +void drawsquare(Display *, int, int, int, GC, Drawable, Bool, XColor); inline unsigned short textwidth(Display *, XftFont *, char *, ssize_t); #endif diff --git a/statusbar.c b/statusbar.c index d4b767ab..3e6d91a0 100644 --- a/statusbar.c +++ b/statusbar.c @@ -58,20 +58,20 @@ drawstatusbar(Display *disp, DC *drawcontext, awesome_config * awesomeconf) w = textwidth(disp, drawcontext->font, awesomeconf->tags[i].name, a_strlen(awesomeconf->tags[i].name)) + drawcontext->font->height; if(awesomeconf->tags[i].selected) { - drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, awesomeconf->tags[i].name, drawcontext->sel, drawcontext->text_selected); + drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, awesomeconf->tags[i].name, awesomeconf->colors_selected); if(isoccupied(i, awesomeconf->screen)) - drawsquare(disp, x, y, (drawcontext->font->height + 2) / 4, drawcontext->gc, awesomeconf->statusbar.drawable, sel && sel->tags[i], drawcontext->sel[ColFG]); + drawsquare(disp, x, y, (drawcontext->font->height + 2) / 4, drawcontext->gc, awesomeconf->statusbar.drawable, sel && sel->tags[i], awesomeconf->colors_selected[ColFG]); } else { - drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, awesomeconf->tags[i].name, drawcontext->norm, drawcontext->text_normal); + drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, awesomeconf->tags[i].name, awesomeconf->colors_normal); if(isoccupied(i, awesomeconf->screen)) - drawsquare(disp, x, y, (drawcontext->font->height + 2) / 4, drawcontext->gc, awesomeconf->statusbar.drawable, sel && sel->tags[i], drawcontext->norm[ColFG]); + drawsquare(disp, x, y, (drawcontext->font->height + 2) / 4, drawcontext->gc, awesomeconf->statusbar.drawable, sel && sel->tags[i], awesomeconf->colors_normal[ColFG]); } x += w; } w = awesomeconf->statusbar.width; - drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, awesomeconf->current_layout->symbol, drawcontext->norm, drawcontext->text_normal); + drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, awesomeconf->current_layout->symbol, awesomeconf->colors_normal); z = x + w; w = textwidth(disp, drawcontext->font, awesomeconf->statustext, a_strlen(awesomeconf->statustext)) + drawcontext->font->height; x = si[awesomeconf->screen].width - w; @@ -80,24 +80,24 @@ drawstatusbar(Display *disp, DC *drawcontext, awesome_config * awesomeconf) x = z; w = si[awesomeconf->screen].width - z; } - drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, awesomeconf->statustext, drawcontext->norm, drawcontext->text_normal); + drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, awesomeconf->statustext, awesomeconf->colors_normal); if((w = x - z) > awesomeconf->statusbar.height) { x = z; if(sel) { - drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, sel->name, drawcontext->sel, drawcontext->text_selected); + drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, sel->name, awesomeconf->colors_selected); if(sel->isfloating) - drawsquare(disp, x, y, (drawcontext->font->height + 2) / 4, drawcontext->gc, awesomeconf->statusbar.drawable, sel->ismax, drawcontext->sel[ColFG]); + drawsquare(disp, x, y, (drawcontext->font->height + 2) / 4, drawcontext->gc, awesomeconf->statusbar.drawable, sel->ismax, awesomeconf->colors_selected[ColFG]); } else if(IS_ARRANGE(layout_tile) || IS_ARRANGE(layout_tileleft)) { char buf[256]; snprintf(buf, sizeof(buf), "nmaster: %d ncol: %d mwfact: %.2lf", awesomeconf->nmaster, awesomeconf->ncol, awesomeconf->mwfact); - drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, buf, drawcontext->norm, drawcontext->text_normal); + drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, buf, awesomeconf->colors_normal); } else - drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, NULL, drawcontext->norm, drawcontext->text_normal); + drawtext(disp, awesomeconf->phys_screen, x, y, w, awesomeconf->statusbar.height, drawcontext->gc, awesomeconf->statusbar.drawable, drawcontext->font, NULL, awesomeconf->colors_normal); } XCopyArea(disp, awesomeconf->statusbar.drawable, awesomeconf->statusbar.window, drawcontext->gc, 0, 0, si[awesomeconf->screen].width, awesomeconf->statusbar.height, 0, 0); XSync(disp, False);