diff --git a/.hgignore b/.hgignore index c6a46955..c6079afb 100644 --- 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 index 0e8e59f7..e961c20c 100644 --- 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 index a629f857..f3ff1245 100644 --- 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 index 5270f350..1ce197d5 100644 --- 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 index 1670d12c..51e22c48 100644 --- 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 index 22d7c3b7..cefa5cf8 100644 --- 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 deleted file mode 100644 index 3ecfff65..00000000 --- a/lib/libstuff/x11/colors/namedcolor.c +++ /dev/null @@ -1,22 +0,0 @@ -/* Copyright ©2007-2010 Kris Maglione - * 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 new file mode 100644 index 00000000..857ef164 --- /dev/null +++ b/lib/libstuff/x11/colors/parsecolor.c @@ -0,0 +1,18 @@ +/* Copyright ©2007-2010 Kris Maglione + * 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 index 2efbadf9..a352d0d7 100644 --- 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 index 66340e31..d37da306 100644 --- 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/setgccol.c b/lib/libstuff/x11/drawing/setgccol.c similarity index 52% rename from lib/libstuff/x11/setgccol.c rename to lib/libstuff/x11/drawing/setgccol.c index a4b09bbc..c2f94924 100644 --- a/lib/libstuff/x11/setgccol.c +++ b/lib/libstuff/x11/drawing/setgccol.c @@ -1,9 +1,9 @@ /* Copyright ©2007-2010 Kris Maglione * 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)); } diff --git a/lib/libstuff/x11/windows/setborder.c b/lib/libstuff/x11/windows/setborder.c index d2a98755..9c80a4f9 100644 --- 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); }