simplify color handling

This commit is contained in:
Julien Danjou 2007-10-10 13:07:12 +02:00
parent ec6525883e
commit 1a755ff245
6 changed files with 32 additions and 42 deletions

View File

@ -319,7 +319,7 @@ focus(Display *disp, DC *drawcontext, Client * c, Bool selscreen, awesome_config
if(sel && sel != c) if(sel && sel != c)
{ {
grabbuttons(sel, False, awesomeconf->modkey, awesomeconf->numlockmask); 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); setclienttrans(sel, awesomeconf->opacity_unfocused);
} }
if(sel == c) if(sel == c)
@ -336,7 +336,7 @@ focus(Display *disp, DC *drawcontext, Client * c, Bool selscreen, awesome_config
drawstatusbar(disp, drawcontext, awesomeconf); drawstatusbar(disp, drawcontext, awesomeconf);
if(sel) 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); XSetInputFocus(sel->display, sel->win, RevertToPointerRoot, CurrentTime);
for(c = stack; c; c = c->snext) for(c = stack; c; c = c->snext)
if(c != sel) if(c != sel)
@ -427,7 +427,7 @@ manage(Display *disp, DC *drawcontext, Window w, XWindowAttributes *wa, awesome_
XFree(si); XFree(si);
wc.border_width = c->border; wc.border_width = c->border;
XConfigureWindow(disp, w, CWBorderWidth, &wc); 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 */ configure(c); /* propagates border_width, if size doesn't change */
updatesizehints(c); updatesizehints(c);
XSelectInput(disp, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask); XSelectInput(disp, w, StructureNotifyMask | PropertyChangeMask | EnterWindowMask);

View File

@ -260,7 +260,6 @@ parse_config(Display * disp, int scr, DC * drawcontext, const char *confpatharg,
char *confpath; char *confpath;
KeySym tmp_key; KeySym tmp_key;
ssize_t confpath_len, txtlen; ssize_t confpath_len, txtlen;
XColor colorbuf;
if(confpatharg) if(confpatharg)
confpath = a_strdup(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"); eprint("awesome: cannot init font\n");
/* Colors */ /* Colors */
drawcontext->norm[ColBorder] = initxcolor(disp, awesomeconf->phys_screen, awesomeconf->colors_normal[ColBorder] = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "normal_border"));
cfg_getstr(cfg_colors, "normal_border")).pixel; awesomeconf->colors_normal[ColBG] = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "normal_bg"));
drawcontext->norm[ColBG] = initxcolor(disp, awesomeconf->phys_screen, awesomeconf->colors_normal[ColFG] = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "normal_fg"));
cfg_getstr(cfg_colors, "normal_bg")).pixel; awesomeconf->colors_selected[ColBorder] = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "focus_border"));
drawcontext->sel[ColBorder] = initxcolor(disp, awesomeconf->phys_screen, awesomeconf->colors_selected[ColBG] = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "focus_bg"));
cfg_getstr(cfg_colors, "focus_border")).pixel; awesomeconf->colors_selected[ColFG] = initxcolor(disp, awesomeconf->phys_screen, cfg_getstr(cfg_colors, "focus_fg"));
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;
/* Statusbar */ /* Statusbar */
tmp = cfg_getstr(cfg_statusbar, "position"); tmp = cfg_getstr(cfg_statusbar, "position");

View File

@ -39,10 +39,6 @@ enum
typedef struct typedef struct
{ {
unsigned long norm[ColLast];
unsigned long sel[ColLast];
XColor text_normal;
XColor text_selected;
GC gc; GC gc;
Cursor cursor[CurLast]; Cursor cursor[CurLast];
XftFont *font; XftFont *font;
@ -158,6 +154,10 @@ struct awesome_config
Bool have_shape; Bool have_shape;
/** Check for XRandR extension */ /** Check for XRandR extension */
Bool have_randr; 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 */ void parse_config(Display *, int, DC *, const char *, awesome_config *); /* parse configuration file */

14
draw.c
View File

@ -24,7 +24,7 @@
#include "draw.h" #include "draw.h"
void 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; int nw = 0;
static char buf[256]; 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; XftColor xftcolor;
XftDraw *xftdrawable; XftDraw *xftdrawable;
XSetForeground(disp, gc, col[ColBG]); XSetForeground(disp, gc, color[ColBG].pixel);
XFillRectangles(disp, drawable, gc, &r, 1); XFillRectangles(disp, drawable, gc, &r, 1);
if(!text) if(!text)
return; return;
@ -56,9 +56,9 @@ drawtext(Display *disp, int screen, int x, int y, int w, int h, GC gc, Drawable
if(len > 3) if(len > 3)
buf[len - 3] = '.'; buf[len - 3] = '.';
} }
xrcolor.red = textcolor.red; xrcolor.red = color[ColFG].red;
xrcolor.green = textcolor.green; xrcolor.green = color[ColFG].green;
xrcolor.blue = textcolor.blue; xrcolor.blue = color[ColFG].blue;
XftColorAllocValue(disp, DefaultVisual(disp, screen), DefaultColormap(disp, screen), &xrcolor, &xftcolor); XftColorAllocValue(disp, DefaultVisual(disp, screen), DefaultColormap(disp, screen), &xrcolor, &xftcolor);
xftdrawable = XftDrawCreate(disp, drawable, DefaultVisual(disp, screen), DefaultColormap(disp, screen)); xftdrawable = XftDrawCreate(disp, drawable, DefaultVisual(disp, screen), DefaultColormap(disp, screen));
XftDrawStringUtf8(xftdrawable, &xftcolor, font, 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 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; XGCValues gcv;
XRectangle r = { x, y, h, h }; XRectangle r = { x, y, h, h };
gcv.foreground = col; gcv.foreground = color.pixel;
XChangeGC(disp, gc, GCForeground, &gcv); XChangeGC(disp, gc, GCForeground, &gcv);
if(filled) if(filled)
{ {

4
draw.h
View File

@ -24,7 +24,7 @@
#include "config.h" #include "config.h"
void drawtext(Display *, int, int, int, int, int, GC, Drawable, XftFont *, const char *, unsigned long *, XColor); void drawtext(Display *, int, int, int, int, int, GC, Drawable, XftFont *, const char *, XColor []);
void drawsquare(Display *, int, int, int, GC, Drawable, Bool, unsigned long); void drawsquare(Display *, int, int, int, GC, Drawable, Bool, XColor);
inline unsigned short textwidth(Display *, XftFont *, char *, ssize_t); inline unsigned short textwidth(Display *, XftFont *, char *, ssize_t);
#endif #endif

View File

@ -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; w = textwidth(disp, drawcontext->font, awesomeconf->tags[i].name, a_strlen(awesomeconf->tags[i].name)) + drawcontext->font->height;
if(awesomeconf->tags[i].selected) 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)) 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 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)) 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; x += w;
} }
w = awesomeconf->statusbar.width; 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; z = x + w;
w = textwidth(disp, drawcontext->font, awesomeconf->statustext, a_strlen(awesomeconf->statustext)) + drawcontext->font->height; w = textwidth(disp, drawcontext->font, awesomeconf->statustext, a_strlen(awesomeconf->statustext)) + drawcontext->font->height;
x = si[awesomeconf->screen].width - w; x = si[awesomeconf->screen].width - w;
@ -80,24 +80,24 @@ drawstatusbar(Display *disp, DC *drawcontext, awesome_config * awesomeconf)
x = z; x = z;
w = si[awesomeconf->screen].width - 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) if((w = x - z) > awesomeconf->statusbar.height)
{ {
x = z; x = z;
if(sel) 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) 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)) else if(IS_ARRANGE(layout_tile) || IS_ARRANGE(layout_tileleft))
{ {
char buf[256]; char buf[256];
snprintf(buf, sizeof(buf), "nmaster: %d ncol: %d mwfact: %.2lf", awesomeconf->nmaster, awesomeconf->ncol, awesomeconf->mwfact); 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 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); XCopyArea(disp, awesomeconf->statusbar.drawable, awesomeconf->statusbar.window, drawcontext->gc, 0, 0, si[awesomeconf->screen].width, awesomeconf->statusbar.height, 0, 0);
XSync(disp, False); XSync(disp, False);