[hackers] [wmii] Revamp color handling. Fixes issue #188. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Fri, 4 Jun 2010 23:38:49 +0000 (UTC)

changeset: 2705:5637453286cb
tag: tip
user: Kris Maglione <kris_AT_suckless.org>
date: Fri Jun 04 19:38:35 2010 -0400
files: .hgignore cmd/tray/client.c cmd/wmii/mouse.c include/stuff/x11.h lib/libstuff/Makefile lib/libstuff/x11/colors/loadcolor.c lib/libstuff/x11/colors/namedcolor.c lib/libstuff/x11/colors/parsecolor.c lib/libstuff/x11/colors/xftcolor.c lib/libstuff/x11/drawing/border.c lib/libstuff/x11/drawing/setgccol.c lib/libstuff/x11/setgccol.c lib/libstuff/x11/windows/setborder.c
description:
Revamp color handling. Fixes issue #188.

diff -r da2adf9451d0 -r 5637453286cb .hgignore
--- a/.hgignore Fri Jun 04 18:15:11 2010 -0400
+++ b/.hgignore Fri Jun 04 19:38:35 2010 -0400
@@ -6,6 +6,7 @@
 \.(aux|idx|ilg|ind|log|toc)$
 ^cmd/(stfo|osd|wiwarp|setfocus)(/|$)
 ^(pkg|src)/
+^doxy
 /bak/
 _dummy\.h$
 syntax: glob
diff -r da2adf9451d0 -r 5637453286cb cmd/tray/client.c
--- a/cmd/tray/client.c Fri Jun 04 18:15:11 2010 -0400
+++ b/cmd/tray/client.c Fri Jun 04 19:38:35 2010 -0400
@@ -33,7 +33,7 @@
                 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 -r da2adf9451d0 -r 5637453286cb cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Fri Jun 04 18:15:11 2010 -0400
+++ b/cmd/wmii/mouse.c Fri Jun 04 19:38:35 2010 -0400
@@ -78,7 +78,7 @@
         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 -r da2adf9451d0 -r 5637453286cb include/stuff/x11.h
--- a/include/stuff/x11.h Fri Jun 04 18:15:11 2010 -0400
+++ b/include/stuff/x11.h Fri Jun 04 19:38:35 2010 -0400
@@ -34,7 +34,7 @@
 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 @@
         long l[5];
 };
 
-struct Color {
- ulong pixel;
- XRenderColor render;
-};
-
 struct CTuple {
         Color bg;
         Color fg;
@@ -274,8 +269,9 @@
 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 -r da2adf9451d0 -r 5637453286cb lib/libstuff/Makefile
--- a/lib/libstuff/Makefile Fri Jun 04 18:15:11 2010 -0400
+++ b/lib/libstuff/Makefile Fri Jun 04 19:38:35 2010 -0400
@@ -89,13 +89,12 @@
         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 @@
         x11/drawing/drawstring \
         x11/drawing/fill \
         x11/drawing/fillpoly \
+ x11/drawing/setgccol \
         x11/focus/getfocus \
         x11/focus/setfocus \
         x11/geometry/XRect \
diff -r da2adf9451d0 -r 5637453286cb lib/libstuff/x11/colors/loadcolor.c
--- a/lib/libstuff/x11/colors/loadcolor.c Fri Jun 04 18:15:11 2010 -0400
+++ b/lib/libstuff/x11/colors/loadcolor.c Fri Jun 04 19:38:35 2010 -0400
@@ -12,7 +12,7 @@
         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 -r da2adf9451d0 -r 5637453286cb lib/libstuff/x11/colors/namedcolor.c
--- a/lib/libstuff/x11/colors/namedcolor.c Fri Jun 04 18:15:11 2010 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 -r da2adf9451d0 -r 5637453286cb lib/libstuff/x11/colors/parsecolor.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libstuff/x11/colors/parsecolor.c Fri Jun 04 19:38:35 2010 -0400
@@ -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 -r da2adf9451d0 -r 5637453286cb lib/libstuff/x11/colors/xftcolor.c
--- a/lib/libstuff/x11/colors/xftcolor.c Fri Jun 04 18:15:11 2010 -0400
+++ b/lib/libstuff/x11/colors/xftcolor.c Fri Jun 04 19:38:35 2010 -0400
@@ -8,12 +8,6 @@
         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 -r da2adf9451d0 -r 5637453286cb lib/libstuff/x11/drawing/border.c
--- a/lib/libstuff/x11/drawing/border.c Fri Jun 04 18:15:11 2010 -0400
+++ b/lib/libstuff/x11/drawing/border.c Fri Jun 04 19:38:35 2010 -0400
@@ -15,5 +15,5 @@
         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 -r da2adf9451d0 -r 5637453286cb lib/libstuff/x11/drawing/setgccol.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libstuff/x11/drawing/setgccol.c Fri Jun 04 19:38:35 2010 -0400
@@ -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 -r da2adf9451d0 -r 5637453286cb lib/libstuff/x11/setgccol.c
--- a/lib/libstuff/x11/setgccol.c Fri Jun 04 18:15:11 2010 -0400
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -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 -r da2adf9451d0 -r 5637453286cb lib/libstuff/x11/windows/setborder.c
--- a/lib/libstuff/x11/windows/setborder.c Fri Jun 04 18:15:11 2010 -0400
+++ b/lib/libstuff/x11/windows/setborder.c Fri Jun 04 19:38:35 2010 -0400
@@ -8,7 +8,7 @@
 
         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);
 }
Received on Fri Jun 04 2010 - 23:38:49 UTC

This archive was generated by hypermail 2.2.0 : Fri Jun 04 2010 - 23:48:04 UTC