Revamp color handling. Fixes issue #188.

This commit is contained in:
Kris Maglione 2010-06-04 19:38:35 -04:00
parent abefbf048d
commit fd930e89a6
12 changed files with 35 additions and 48 deletions

View File

@ -6,6 +6,7 @@ syntax: regexp
\.(aux|idx|ilg|ind|log|toc)$
^cmd/(stfo|osd|wiwarp|setfocus)(/|$)
^(pkg|src)/
^doxy
/bak/
_dummy\.h$
syntax: glob

View File

@ -33,7 +33,7 @@ client_manage(XWindow w) {
return;
}
wa.background_pixel = tray.selcolors.bg.pixel;
wa.background_pixel = pixelvalue(tray.selcolors.bg);
size = max(tray.iconsize / 4, 4);
c->indicator = createwindow(tray.win, Rect(0, 0, size, size), scr.depth,

View File

@ -78,7 +78,7 @@ gethsep(Rectangle r) {
Window *w;
WinAttr wa;
wa.background_pixel = def.normcolor.border.pixel;
wa.background_pixel = pixelvalue(def.normcolor.border);
w = createwindow(&scr.root, r, scr.depth, InputOutput, &wa, CWBackPixel);
mapwin(w);
raisewin(w);

View File

@ -34,7 +34,7 @@ typedef enum WindowType WindowType;
typedef XSetWindowAttributes WinAttr;
typedef union ClientMessageData ClientMessageData;
typedef struct Color Color;
typedef XRenderColor Color;
typedef struct CTuple CTuple;
typedef struct ErrorCode ErrorCode;
typedef struct Ewmh Ewmh;
@ -56,11 +56,6 @@ union ClientMessageData {
long l[5];
};
struct Color {
ulong pixel;
XRenderColor render;
};
struct CTuple {
Color bg;
Color fg;
@ -274,8 +269,9 @@ Font* loadfont(const char*);
void lowerwin(Window*);
int mapwin(Window*);
void movewin(Window*, Point);
bool namedcolor(char *name, Color*);
bool parsecolor(const char *name, Color*);
bool parsekey(char*, int*, char**);
ulong pixelvalue(Color);
int pointerscreen(void);
bool pophandler(Window*, Handlers*);
void pushhandler(Window*, Handlers*, void*);

View File

@ -89,13 +89,12 @@ OBJ=\
x11/initdisplay \
x11/sendevent \
x11/sendmessage \
x11/setgccol \
x11/sync \
x11/x11 \
x11/xatom \
x11/xft \
x11/colors/loadcolor \
x11/colors/namedcolor \
x11/colors/parsecolor \
x11/colors/xftcolor \
x11/drawing/border \
x11/drawing/drawline \
@ -103,6 +102,7 @@ OBJ=\
x11/drawing/drawstring \
x11/drawing/fill \
x11/drawing/fillpoly \
x11/drawing/setgccol \
x11/focus/getfocus \
x11/focus/setfocus \
x11/geometry/XRect \

View File

@ -12,7 +12,7 @@ loadcolor(CTuple *c, const char *str) {
memcpy(c->colstr, str, sizeof c->colstr);
buf[7] = buf[15] = buf[23] = '\0';
return namedcolor(buf, &c->fg)
&& namedcolor(buf+8, &c->bg)
&& namedcolor(buf+16, &c->border);
return parsecolor(buf, &c->fg)
&& parsecolor(buf+8, &c->bg)
&& parsecolor(buf+16, &c->border);
}

View File

@ -1,22 +0,0 @@
/* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail>
* See LICENSE file for license details.
*/
#include "../x11.h"
bool
namedcolor(char *name, Color *ret) {
XColor c, c2;
if(XAllocNamedColor(display, scr.colormap, name, &c, &c2)) {
*ret = (Color) {
c.pixel, {
c.red,
c.green,
c.blue,
0xffff
},
};
return true;
}
return false;
}

View File

@ -0,0 +1,18 @@
/* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail>
* See LICENSE file for license details.
*/
#include "../x11.h"
ulong
pixelvalue(Color c) {
return ((ulong)(c.alpha&0xff00) << 16)
| ((ulong)(c.red&0xff00) << 8)
| ((ulong)(c.green&0xff00) << 0)
| ((ulong)(c.blue&0xff00) >> 8);
}
bool
parsecolor(const char *name, Color *ret) {
return XRenderParseColor(display, (char*)(uintptr_t)name, ret);
}

View File

@ -8,12 +8,6 @@ xftcolor(Color col) {
XftColor *c;
c = emallocz(sizeof *c);
*c = (XftColor) {
((col.render.alpha&0xff00) << 24)
| ((col.render.red&0xff00) << 8)
| ((col.render.green&0xff00) << 0)
| ((col.render.blue&0xff00) >> 8),
col.render
};
*c = (XftColor){ pixelvalue(col), col };
return freelater(c);
}

View File

@ -15,5 +15,5 @@ border(Image *dst, Rectangle r, int w, Color col) {
XSetLineAttributes(display, dst->gc, w, LineSolid, CapButt, JoinMiter);
setgccol(dst, col);
XDrawRectangle(display, dst->xid, dst->gc,
r.min.x, r.min.y, Dx(r), Dy(r));
r.min.x, r.min.y, Dx(r), Dy(r));
}

View File

@ -1,9 +1,9 @@
/* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail>
* See LICENSE file for license details.
*/
#include "x11.h"
#include "../x11.h"
void
setgccol(Image *dst, Color col) {
XSetForeground(display, dst->gc, col.pixel);
setgccol(Image *dst, Color c) {
XSetForeground(display, dst->gc, pixelvalue(c));
}

View File

@ -8,7 +8,7 @@ setborder(Window *w, int width, Color col) {
assert(w->type == WWindow);
if(width)
XSetWindowBorder(display, w->xid, col.pixel);
XSetWindowBorder(display, w->xid, pixelvalue(col));
if(width != w->border)
configwin(w, w->r, width);
}