[hackers] [wmii] Better color support on non-truecolor displays. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Sat, 7 Nov 2009 23:59:43 +0000 (UTC)

changeset: 2587:7b4154e0c31b
tag: tip
user: Kris Maglione <kris_AT_suckless.org>
date: Sat Nov 07 18:59:33 2009 -0500
files: cmd/wmii/div.c cmd/wmii/frame.c cmd/wmii/mouse.c cmd/wmii/x11.c include/x11.h
description:
Better color support on non-truecolor displays.

diff -r d05e980e9d45 -r 7b4154e0c31b cmd/wmii/div.c
--- a/cmd/wmii/div.c Sat Nov 07 17:27:10 2009 -0500
+++ b/cmd/wmii/div.c Sat Nov 07 18:59:33 2009 -0500
@@ -66,7 +66,7 @@
 }
 
 static void
-drawimg(Image *img, ulong cbg, ulong cborder, Divide *d) {
+drawimg(Image *img, Color cbg, Color cborder, Divide *d) {
         Point pt[8];
         int n, start, w;
 
@@ -93,8 +93,8 @@
 static void
 drawdiv(Divide *d) {
 
- fill(divmask, divmask->r, 0);
- drawimg(divmask, 1, 1, d);
+ fill(divmask, divmask->r, (Color){0});
+ drawimg(divmask, (Color){1}, (Color){1}, d);
         drawimg(divimg, divcolor.bg, divcolor.border, d);
 
         copyimage(d->w, divimg->r, divimg, ZP);
diff -r d05e980e9d45 -r 7b4154e0c31b cmd/wmii/frame.c
--- a/cmd/wmii/frame.c Sat Nov 07 17:27:10 2009 -0500
+++ b/cmd/wmii/frame.c Sat Nov 07 18:59:33 2009 -0500
@@ -483,7 +483,7 @@
         if(f->area->floating && c->borderless && c->titleless && !c->fullscreen && c == selclient())
                 setborder(c->framewin, def.border, def.focuscolor.border);
         else
- setborder(c->framewin, 0, 0);
+ setborder(c->framewin, 0, def.focuscolor.border);
 
         /* Label */
         r.min.x = r.max.x;
diff -r d05e980e9d45 -r 7b4154e0c31b cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Sat Nov 07 17:27:10 2009 -0500
+++ b/cmd/wmii/mouse.c Sat Nov 07 18:59:33 2009 -0500
@@ -63,7 +63,7 @@
         Window *w;
         WinAttr wa;
         
- wa.background_pixel = def.normcolor.border;
+ wa.background_pixel = def.normcolor.border.pixel;
         w = createwindow(&scr.root, r, scr.depth, InputOutput, &wa, CWBackPixel);
         mapwin(w);
         raisewin(w);
diff -r d05e980e9d45 -r 7b4154e0c31b cmd/wmii/x11.c
--- a/cmd/wmii/x11.c Sat Nov 07 17:27:10 2009 -0500
+++ b/cmd/wmii/x11.c Sat Nov 07 18:59:33 2009 -0500
@@ -26,7 +26,7 @@
 static int errorhandler(Display*, XErrorEvent*);
 static int (*xlib_errorhandler) (Display*, XErrorEvent*);
 
-static XftColor* xftcolor(ulong);
+static XftColor* xftcolor(Color);
 
 
 /* Rectangles/Points */
@@ -366,11 +366,11 @@
 }
 
 void
-setborder(Window *w, int width, long pixel) {
+setborder(Window *w, int width, Color col) {
 
         assert(w->type == WWindow);
         if(width)
- XSetWindowBorder(display, w->xid, pixel);
+ XSetWindowBorder(display, w->xid, col.pixel);
         if(width != w->border)
                 configwin(w, w->r, width);
 }
@@ -465,13 +465,13 @@
 }
 
 static void
-setgccol(Image *dst, ulong col) {
- XSetForeground(display, dst->gc, col);
+setgccol(Image *dst, Color col) {
+ XSetForeground(display, dst->gc, col.pixel);
 }
 
 /* Drawing */
 void
-border(Image *dst, Rectangle r, int w, ulong col) {
+border(Image *dst, Rectangle r, int w, Color col) {
         if(w == 0)
                 return;
 
@@ -486,7 +486,7 @@
 }
 
 void
-fill(Image *dst, Rectangle r, ulong col) {
+fill(Image *dst, Rectangle r, Color col) {
         setgccol(dst, col);
         XFillRectangle(display, dst->xid, dst->gc,
                 r.min.x, r.min.y, Dx(r), Dy(r));
@@ -506,7 +506,7 @@
 }
 
 void
-drawpoly(Image *dst, Point *pt, int np, int cap, int w, ulong col) {
+drawpoly(Image *dst, Point *pt, int np, int cap, int w, Color col) {
         XPoint *xp;
         
         xp = convpts(pt, np);
@@ -517,7 +517,7 @@
 }
 
 void
-fillpoly(Image *dst, Point *pt, int np, ulong col) {
+fillpoly(Image *dst, Point *pt, int np, Color col) {
         XPoint *xp;
 
         xp = convpts(pt, np);
@@ -527,7 +527,7 @@
 }
 
 void
-drawline(Image *dst, Point p1, Point p2, int cap, int w, ulong col) {
+drawline(Image *dst, Point p1, Point p2, int cap, int w, Color col) {
         XSetLineAttributes(display, dst->gc, w, LineSolid, cap, JoinMiter);
         setgccol(dst, col);
         XDrawLine(display, dst->xid, dst->gc, p1.x, p1.y, p2.x, p2.y);
@@ -536,7 +536,7 @@
 uint
 drawstring(Image *dst, Font *font,
            Rectangle r, Align align,
- char *text, ulong col) {
+ char *text, Color col) {
         Rectangle tr;
         char *buf;
         uint x, y, width, height, len;
@@ -628,16 +628,18 @@
 
 /* Colors */
 bool
-namedcolor(char *name, ulong *ret) {
+namedcolor(char *name, Color *ret) {
         XColor c, c2;
 
         if(XAllocNamedColor(display, scr.colormap, name, &c, &c2)) {
- /* FIXME: Kludge. */
- /* This isn't garunteed to work. In the case of RGBA
- * visuals, we need the Alpha set to 1.0. This
- * could, in theory, break plain RGB, or even RGBA.
- */
- *ret = c.pixel | 0xff000000;
+ *ret = (Color) {
+ c.pixel, {
+ c.red,
+ c.green,
+ c.blue,
+ 0xffff
+ },
+ };
                 return true;
         }
         return false;
@@ -657,17 +659,16 @@
 }
 
 static XftColor*
-xftcolor(ulong col) {
+xftcolor(Color col) {
         XftColor *c;
 
         c = emallocz(sizeof *c);
         *c = (XftColor) {
- col, {
- (col>>8) & 0xff00,
- (col>>0) & 0xff00,
- (col<<8) & 0xff00,
- (col>>16) & 0xff00,
- }
+ ((col.render.alpha&0xff00) << 24)
+ | ((col.render.red&0xff00) << 8)
+ | ((col.render.green&0xff00) << 0)
+ | ((col.render.blue&0xff00) >> 8),
+ col.render
         };
         return freelater(c);
 }
diff -r d05e980e9d45 -r 7b4154e0c31b include/x11.h
--- a/include/x11.h Sat Nov 07 17:27:10 2009 -0500
+++ b/include/x11.h Sat Nov 07 18:59:33 2009 -0500
@@ -7,6 +7,7 @@
 #include <X11/Xlib.h>
 #include <X11/Xutil.h>
 #include <X11/Xft/Xft.h>
+#include <X11/extensions/Xrender.h>
 #ifdef _X11_VISIBLE
 # include <X11/Xatom.h>
 # include <X11/extensions/shape.h>
@@ -56,6 +57,7 @@
         Point min, max;
 };
 
+typedef struct Color Color;
 typedef struct CTuple CTuple;
 typedef struct ErrorCode ErrorCode;
 typedef struct Ewmh Ewmh;
@@ -66,10 +68,15 @@
 typedef struct Window Image;
 typedef struct Window Window;
 
+struct Color {
+ ulong pixel;
+ XRenderColor render;
+};
+
 struct CTuple {
- ulong bg;
- ulong fg;
- ulong border;
+ Color bg;
+ Color fg;
+ Color border;
         char colstr[24]; /* #RRGGBB #RRGGBB #RRGGBB */
 };
 
@@ -201,7 +208,7 @@
 /* x11.c */
 Point addpt(Point, Point);
 Image* allocimage(int w, int h, int depth);
-void border(Image *dst, Rectangle, int w, ulong col);
+void border(Image *dst, Rectangle, int w, Color);
 void changeprop_char(Window*, char*, char*, char[], int);
 void changeprop_long(Window*, char*, char*, long[], int);
 void changeprop_short(Window*, char*, char*, short[], int);
@@ -215,13 +222,13 @@
 void delproperty(Window*, char*);
 void destroywindow(Window*);
 Point divpt(Point, Point);
-void drawline(Image*, Point, Point, int cap, int w, ulong col);
-void drawpoly(Image*, Point*, int, int cap, int w, ulong col);
-uint drawstring(Image*, Font*, Rectangle, Align, char*, ulong col);
+void drawline(Image*, Point, Point, int cap, int w, Color);
+void drawpoly(Image*, Point*, int, int cap, int w, Color);
+uint drawstring(Image*, Font*, Rectangle, Align, char*, Color);
 int eqpt(Point, Point);
 int eqrect(Rectangle, Rectangle);
-void fill(Image*, Rectangle, ulong col);
-void fillpoly(Image*, Point*, int, ulong col);
+void fill(Image*, Rectangle, Color);
+void fillpoly(Image*, Point*, int, Color);
 Window* findwin(XWindow);
 void freefont(Font*);
 void freeimage(Image *);
@@ -243,7 +250,7 @@
 int mapwin(Window*);
 void movewin(Window*, Point);
 Point mulpt(Point p, Point q);
-bool namedcolor(char *name, ulong*);
+bool namedcolor(char *name, Color*);
 bool parsekey(char*, int*, char**);
 int pointerscreen(void);
 Point querypointer(Window*);
@@ -252,7 +259,7 @@
 void reshapewin(Window*, Rectangle);
 void selectinput(Window*, long);
 void sendevent(Window*, bool propegate, long mask, XEvent*);
-void setborder(Window*, int, long);
+void setborder(Window*, int, Color);
 void setfocus(Window*, int mode);
 void sethints(Window*);
 void setshapemask(Window *dst, Image *src, Point);
Received on Sat Nov 07 2009 - 23:59:43 UTC

This archive was generated by hypermail 2.2.0 : Sun Nov 08 2009 - 00:00:09 UTC