wmii

git clone git://oldgit.suckless.org/wmii/
Log | Files | Refs | README | LICENSE

commit fd930e89a6725bd83f6c7bf306924c79bf323a6e
parent abefbf048dc4172644b578d97620a04ca400dbee
Author: Kris Maglione <kris@suckless.org>
Date:   Fri,  4 Jun 2010 19:38:35 -0400

Revamp color handling. Fixes issue #188.

Diffstat:
.hgignore | 1+
cmd/tray/client.c | 2+-
cmd/wmii/mouse.c | 2+-
include/stuff/x11.h | 10+++-------
lib/libstuff/Makefile | 4++--
lib/libstuff/x11/colors/loadcolor.c | 6+++---
lib/libstuff/x11/colors/namedcolor.c | 22----------------------
lib/libstuff/x11/colors/parsecolor.c | 18++++++++++++++++++
lib/libstuff/x11/colors/xftcolor.c | 8+-------
lib/libstuff/x11/drawing/border.c | 2+-
lib/libstuff/x11/drawing/setgccol.c | 9+++++++++
lib/libstuff/x11/setgccol.c | 9---------
lib/libstuff/x11/windows/setborder.c | 2+-
13 files changed, 41 insertions(+), 54 deletions(-)

diff --git a/.hgignore b/.hgignore @@ -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 diff --git a/cmd/tray/client.c b/cmd/tray/client.c @@ -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, diff --git a/cmd/wmii/mouse.c b/cmd/wmii/mouse.c @@ -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); diff --git a/include/stuff/x11.h b/include/stuff/x11.h @@ -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*); diff --git a/lib/libstuff/Makefile b/lib/libstuff/Makefile @@ -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 \ diff --git a/lib/libstuff/x11/colors/loadcolor.c b/lib/libstuff/x11/colors/loadcolor.c @@ -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); } diff --git a/lib/libstuff/x11/colors/namedcolor.c b/lib/libstuff/x11/colors/namedcolor.c @@ -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; -} diff --git a/lib/libstuff/x11/colors/parsecolor.c b/lib/libstuff/x11/colors/parsecolor.c @@ -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); +} diff --git a/lib/libstuff/x11/colors/xftcolor.c b/lib/libstuff/x11/colors/xftcolor.c @@ -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); } diff --git a/lib/libstuff/x11/drawing/border.c b/lib/libstuff/x11/drawing/border.c @@ -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)); } diff --git a/lib/libstuff/x11/drawing/setgccol.c b/lib/libstuff/x11/drawing/setgccol.c @@ -0,0 +1,9 @@ +/* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> + * See LICENSE file for license details. + */ +#include "../x11.h" + +void +setgccol(Image *dst, Color c) { + XSetForeground(display, dst->gc, pixelvalue(c)); +} diff --git a/lib/libstuff/x11/setgccol.c b/lib/libstuff/x11/setgccol.c @@ -1,9 +0,0 @@ -/* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> - * See LICENSE file for license details. - */ -#include "x11.h" - -void -setgccol(Image *dst, Color col) { - XSetForeground(display, dst->gc, col.pixel); -} diff --git a/lib/libstuff/x11/windows/setborder.c b/lib/libstuff/x11/windows/setborder.c @@ -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); }