wmii

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

commit 429de2d3761035d6b9303faa34c7d19b262c87d4
parent e440ef6cb77145144d3a90f85254cb21dbfdc6a6
Author: Kris Maglione <kris@suckless.org>
Date:   Sat,  7 Nov 2009 18:59:33 -0500

Better color support on non-truecolor displays.

Diffstat:
cmd/wmii/div.c | 6+++---
cmd/wmii/frame.c | 2+-
cmd/wmii/mouse.c | 2+-
cmd/wmii/x11.c | 51++++++++++++++++++++++++++-------------------------
include/x11.h | 29++++++++++++++++++-----------
5 files changed, 49 insertions(+), 41 deletions(-)

diff --git a/cmd/wmii/div.c b/cmd/wmii/div.c @@ -66,7 +66,7 @@ div_set(Divide *d, int x) { } 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 @@ drawimg(Image *img, ulong cbg, ulong cborder, Divide *d) { 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 --git a/cmd/wmii/frame.c b/cmd/wmii/frame.c @@ -483,7 +483,7 @@ frame_draw(Frame *f) { 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 --git a/cmd/wmii/mouse.c b/cmd/wmii/mouse.c @@ -63,7 +63,7 @@ gethsep(Rectangle r) { 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 --git a/cmd/wmii/x11.c b/cmd/wmii/x11.c @@ -26,7 +26,7 @@ static MapEnt* abucket[137]; 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 @@ configwin(Window *w, Rectangle r, int border) { } 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 @@ setshapemask(Window *dst, Image *src, Point pt) { } 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 @@ border(Image *dst, Rectangle r, int w, ulong col) { } 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 @@ convpts(Point *pt, int np) { } 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 @@ drawpoly(Image *dst, Point *pt, int np, int cap, int w, ulong col) { } 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 @@ fillpoly(Image *dst, Point *pt, int np, ulong col) { } 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 @@ drawline(Image *dst, Point p1, Point p2, int cap, int w, ulong col) { 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 @@ copyimage(Image *dst, Rectangle r, Image *src, Point p) { /* 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 @@ loadcolor(CTuple *c, char *str) { } 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 --git a/include/x11.h b/include/x11.h @@ -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 @@ struct Rectangle { 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 WinHints WinHints; 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 @@ XRectangle XRect(Rectangle r); /* 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 @@ Window* createwindow_visual(Window*, Rectangle, int depth, Visual*, uint class, 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 @@ void lowerwin(Window*); 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 reparentwindow(Window*, Window*, Point); 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);