wmii

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

commit 683b3ed89507cb9c91f84f330f1434e9694311f4
parent e1f621dba013418d1bb16e853ef1f5e44f924c9f
Author: Kris Maglione <kris@suckless.org>
Date:   Sun, 20 Jun 2010 14:24:04 -0400

Handle colormapped displays.

Diffstat:
alternative_wmiircs/python/pygmi/fs.py | 36+++++++++++++++++++++---------------
cmd/menu/menu.c | 18+++++++++---------
cmd/tray/client.c | 4++--
cmd/tray/tray.c | 4++--
cmd/wmii/bar.c | 10+++++-----
cmd/wmii/client.c | 23++---------------------
cmd/wmii/dat.h | 3---
cmd/wmii/div.c | 6+++---
cmd/wmii/frame.c | 34+++++++++++++++++-----------------
cmd/wmii/layout.c | 8++++----
cmd/wmii/main.c | 12+++++-------
cmd/wmii/mouse.c | 8++++----
cmd/x11/wmii9menu.c | 6+++---
include/stuff/x.h | 1+
include/stuff/x11.h | 30+++++++++++++++++++-----------
lib/libstuff/Makefile | 1+
lib/libstuff/x11/colors/loadcolor.c | 2+-
lib/libstuff/x11/colors/parsecolor.c | 29++++++++++++++++++++++-------
lib/libstuff/x11/colors/xftcolor.c | 10+++++-----
lib/libstuff/x11/drawing/border.c | 2+-
lib/libstuff/x11/drawing/drawline.c | 2+-
lib/libstuff/x11/drawing/drawpoly.c | 2+-
lib/libstuff/x11/drawing/drawstring.c | 4++--
lib/libstuff/x11/drawing/fill.c | 2+-
lib/libstuff/x11/drawing/fillpoly.c | 2+-
lib/libstuff/x11/drawing/setgccol.c | 4++--
lib/libstuff/x11/initdisplay.c | 15+++++++++++----
lib/libstuff/x11/windows/createwindow_rgba.c | 18++++++++++++++++++
lib/libstuff/x11/windows/setborder.c | 4++--
lib/libstuff/x11/x11.h | 4++--
lib/libstuff/xext.c | 4+++-
mk/hdr.mk | 2+-
32 files changed, 172 insertions(+), 138 deletions(-)

diff --git a/alternative_wmiircs/python/pygmi/fs.py b/alternative_wmiircs/python/pygmi/fs.py @@ -463,6 +463,8 @@ class Button(object): self.base_path = self.sides[side] self.path = '%s/%s' % (self.base_path, self.name) self.file = None + self._colors = wmii.cache['normcolors'] + self._label = '' if colors or label: self.create(colors, label) @@ -471,10 +473,8 @@ class Button(object): self.file = None if not self.file: self.file = client.create(self.path, ORDWR) - if colors: + if colors or label: self.file.awrite(self.getval(colors, label), offset=0, fail=fail) - elif label: - self.file.awrite(label, offset=24, fail=fail) def remove(self): if self.file: @@ -482,19 +482,18 @@ class Button(object): self.file = None def getval(self, colors=None, label=None): - if label is None: - label = self.label - if colors is None and re.match( - r'#[0-9a-f]{6} #[0-9a-f]{6} #[0-9a-f]{6}', label, re.I): - colors = self.colors - if not colors: - return str(label) - return ' '.join([Color(c).hex for c in colors] + [str(label)]) + if label is not None: + self._label = label + if colors is not None: + self._colors = colors + try: + unicode(self._label) + except: + print repr(self._label) + return ' '.join([Color(c).hex for c in self._colors or self.colors] + [unicode(self._label or '')]) colors = property( - lambda self: self.file and - tuple(map(Color, self.file.read(offset=0).split(' ')[:3])) - or (), + lambda self: self.file and Colors(self.file.read(offset=0).split(' ')[:3]) or (), lambda self, val: self.create(colors=val)) label = property( @@ -538,8 +537,11 @@ class Color(utf8): if isinstance(colors, Color): colors = colors.rgb elif isinstance(colors, basestring): - match = re.match(r'^#(..)(..)(..)$', colors) + match = (re.match(r'^#(..)(..)(..)((?:..)?)$', colors) or + re.match(r'^rgba:(..)/(..)/(..)/(..)$', colors)) colors = tuple(int(match.group(group), 16) for group in range(1, 4)) + if match.group(4): + colors += int(match.group(4), 16), def toint(val): if isinstance(val, float): val = int(255 * val) @@ -554,9 +556,13 @@ class Color(utf8): @property def hex(self): + if len(self.rgb) > 3: + return 'rgba:%02x/%02x/%02x/%02x' % self.rgb return '#%02x%02x%02x' % self.rgb def __unicode__(self): + if len(self.rgb) > 3: + return 'rgba(%d, %d, %d, %d)' % self.rgb return 'rgb(%d, %d, %d)' % self.rgb def __repr__(self): return 'Color(%s)' % repr(self.rgb) diff --git a/cmd/menu/menu.c b/cmd/menu/menu.c @@ -159,7 +159,7 @@ _menu_draw(bool draw) { itemoff = inputw + 2 * ltwidth; end = Dx(rd) - ltwidth; - fill(ibuf, r, cnorm.bg); + fill(ibuf, r, &cnorm.bg); if(matchend && matchidx == matchend->next) matchstart = matchidx; @@ -193,8 +193,8 @@ _menu_draw(bool draw) { break; c = (i == matchidx) ? &csel : &cnorm; - fill(ibuf, r2, c->bg); - drawstring(ibuf, font, r2, Center, i->string, c->fg); + fill(ibuf, r2, &c->bg); + drawstring(ibuf, font, r2, Center, i->string, &c->fg); matchend = i; if(i->next == matchfirst) break; @@ -203,25 +203,25 @@ _menu_draw(bool draw) { r2 = rd; r2.min.x = promptw + inputw; if(matchstart != matchfirst) - drawstring(ibuf, font, r2, West, "<", cnorm.fg); + drawstring(ibuf, font, r2, West, "<", &cnorm.fg); if(matchend->next != matchfirst) - drawstring(ibuf, font, r2, East, ">", cnorm.fg); + drawstring(ibuf, font, r2, East, ">", &cnorm.fg); r2 = rd; r2.max.x = promptw + inputw; - drawstring(ibuf, font, r2, West, input.string, cnorm.fg); + drawstring(ibuf, font, r2, West, input.string, &cnorm.fg); extent = textextents_l(font, input.string, input.pos - input.string, &offset); r2.min.x = promptw + offset + font->pad.min.x - extent.min.x + pad/2 - 1; r2.max.x = r2.min.x + 2; r2.min.y++; r2.max.y--; - border(ibuf, r2, 1, cnorm.border); + border(ibuf, r2, 1, &cnorm.border); if (prompt) - drawstring(ibuf, font, rp, West, prompt, cnorm.fg); + drawstring(ibuf, font, rp, West, prompt, &cnorm.fg); - border(ibuf, rd, 1, cnorm.border); + border(ibuf, rd, 1, &cnorm.border); copyimage(barwin, r, ibuf, ZP); } diff --git a/cmd/tray/client.c b/cmd/tray/client.c @@ -33,12 +33,12 @@ client_manage(XWindow w) { return; } - wa.background_pixel = pixelvalue(tray.selcolors.bg); + wa.background_pixel = pixelvalue(&scr.root, &tray.selcolors.bg); size = max(tray.iconsize / 4, 4); c->indicator = createwindow(tray.win, Rect(0, 0, size, size), scr.depth, InputOutput, &wa, CWBackPixel); - setborder(c->indicator, 1, tray.selcolors.border); + setborder(c->indicator, 1, &tray.selcolors.border); sethandler(&c->w, &handlers); diff --git a/cmd/tray/tray.c b/cmd/tray/tray.c @@ -123,9 +123,9 @@ tray_draw(Rectangle r) { borderwidth = 1; r = rectsetorigin(r, ZP); - border(tray.pixmap, r, borderwidth, tray.selcolors.border); + border(tray.pixmap, r, borderwidth, &tray.selcolors.border); r = insetrect(r, borderwidth); - fill(tray.pixmap, r, tray.selcolors.bg); + fill(tray.pixmap, r, &tray.selcolors.bg); XClearWindow(display, tray.win->xid); } diff --git a/cmd/wmii/bar.c b/cmd/wmii/bar.c @@ -181,15 +181,15 @@ bar_draw(WMScreen *s) { } r = rectsubpt(s->brect, s->brect.min); - fill(disp.ibuf, r, def.normcolor.bg); - border(disp.ibuf, r, 1, def.normcolor.border); + fill(disp.ibuf, r, &def.normcolor.bg); + border(disp.ibuf, r, 1, &def.normcolor.border); foreach_bar(s, b) { align = Center; if(b == s->bar[BRight]) align = East; - fill(disp.ibuf, b->r, b->col.bg); - drawstring(disp.ibuf, def.font, b->r, align, b->text, b->col.fg); - border(disp.ibuf, b->r, 1, b->col.border); + fill(disp.ibuf, b->r, &b->col.bg); + drawstring(disp.ibuf, def.font, b->r, align, b->text, &b->col.fg); + border(disp.ibuf, b->r, 1, &b->col.border); } copyimage(s->barwin, r, disp.ibuf, ZP); } diff --git a/cmd/wmii/client.c b/cmd/wmii/client.c @@ -96,10 +96,8 @@ Client* client_create(XWindow w, XWindowAttributes *wa) { Client **t, *c; WinAttr fwa; - Visual *vis; char **host = nil; ulong *pid = nil; - int depth; c = emallocz(sizeof *c); c->fullscreen = -1; @@ -112,7 +110,7 @@ client_create(XWindow w, XWindowAttributes *wa) { c->w.xid = w; c->w.r = c->r; - setborder(&c->w, 0, (Color){0}); + setborder(&c->w, 0, &(Color){0}); client_prop(c, xatom("WM_PROTOCOLS")); client_prop(c, xatom("WM_TRANSIENT_FOR")); @@ -129,20 +127,8 @@ client_create(XWindow w, XWindowAttributes *wa) { freestringlist(host); free(pid); - if(have_render) { /* render_argb_p(wa->visual) */ - depth = 32; - vis = scr.visual32; - c->ibuf = &ibuf32; - }else { - depth = scr.depth; - vis = scr.visual; - c->ibuf = &ibuf; - } - fwa.background_pixmap = None; fwa.bit_gravity = NorthWestGravity; - fwa.border_pixel = 0; /* Required for ARGB windows. */ - fwa.colormap = XCreateColormap(display, scr.root.xid, vis, AllocNone); fwa.event_mask = ButtonPressMask | ButtonReleaseMask | EnterWindowMask @@ -152,16 +138,11 @@ client_create(XWindow w, XWindowAttributes *wa) { | SubstructureNotifyMask | SubstructureRedirectMask; fwa.override_redirect = true; - c->framewin = createwindow_visual(&scr.root, c->r, - depth, vis, InputOutput, + c->framewin = createwindow_rgba(&scr.root, c->r, &fwa, CWBackPixmap | CWBitGravity - /* These next two matter for ARGB windows. Donno why. */ - | CWBorderPixel - | CWColormap | CWEventMask | CWOverrideRedirect); - XFreeColormap(display, fwa.colormap); c->framewin->aux = c; c->w.aux = c; diff --git a/cmd/wmii/dat.h b/cmd/wmii/dat.h @@ -164,7 +164,6 @@ struct Client { Frame* sel; Window w; Window* framewin; - Image** ibuf; XWindow trans; Regex tagre; Regex tagvre; @@ -349,8 +348,6 @@ EXTERN IxpServer srv; EXTERN Ixp9Srv p9srv; /* X11 */ -EXTERN Image* ibuf32; -EXTERN Image* ibuf; EXTERN uint numlock_mask; EXTERN uint valid_mask; diff --git a/cmd/wmii/div.c b/cmd/wmii/div.c @@ -86,14 +86,14 @@ drawimg(Image *img, Color cbg, Color cborder, Divide *d) { start = d->left ? 0 : n/2; n = d->right && d->left ? n : n/2; - fillpoly(img, pt + start, n, cbg); - drawpoly(img, pt + start, n, CapNotLast, 1, cborder); + fillpoly(img, pt + start, n, &cbg); + drawpoly(img, pt + start, n, CapNotLast, 1, &cborder); } static void drawdiv(Divide *d) { - fill(divmask, divmask->r, (Color){0}); + fill(divmask, divmask->r, &(Color){0}); drawimg(divmask, (Color){~0,~0,~0}, (Color){~0,~0,~0}, d); drawimg(divimg, divcolor.bg, divcolor.border, d); diff --git a/cmd/wmii/frame.c b/cmd/wmii/frame.c @@ -404,9 +404,9 @@ pushlabel(Image *img, Rectangle *rp, char *s, CTuple *col) { if(0) drawline(img, Pt(rp->max.x, r.min.y+2), Pt(rp->max.x, r.max.y-2), - CapButt, 1, col->border); + CapButt, 1, &col->border); drawstring(img, def.font, r, East, - s, col->fg); + s, &col->fg); } } @@ -424,7 +424,7 @@ frame_draw(Frame *f) { return; c = f->client; - img = *c->ibuf; + img = c->framewin->depth == 32 ? disp.ibuf32 : disp.ibuf; fr = rectsetorigin(c->framewin->r, ZP); /* Pick colors. */ @@ -435,12 +435,12 @@ frame_draw(Frame *f) { /* Background/border */ r = fr; - fill(img, r, col->bg); - border(img, r, 1, col->border); + fill(img, r, &col->bg); + border(img, r, 1, &col->border); /* Title border */ r.max.y = r.min.y + labelh(def.font); - border(img, r, 1, col->border); + border(img, r, 1, &col->border); f->titlebar = insetrect(r, 3); f->titlebar.max.y += 3; @@ -448,8 +448,8 @@ frame_draw(Frame *f) { /* Odd focus. Unselected, with keyboard focus. */ /* Draw a border just inside the titlebar. */ if(c != selclient() && c == disp.focus) { - border(img, insetrect(r, 1), 1, def.normcolor.bg); - border(img, insetrect(r, 2), 1, def.focuscolor.border); + border(img, insetrect(r, 1), 1, &def.normcolor.bg); + border(img, insetrect(r, 2), 1, &def.focuscolor.border); } /* grabbox */ @@ -459,19 +459,19 @@ frame_draw(Frame *f) { f->grabbox = r; if(c->urgent) - fill(img, r, col->fg); - border(img, r, 1, col->border); + fill(img, r, &col->fg); + border(img, r, 1, &col->border); /* Odd focus. Selected, without keyboard focus. */ /* Draw a border around the grabbox. */ if(c != disp.focus && col == &def.focuscolor) - border(img, insetrect(r, -1), 1, def.normcolor.bg); + border(img, insetrect(r, -1), 1, &def.normcolor.bg); /* Draw a border on borderless+titleless selected apps. */ if(f->area->floating && c->borderless && c->titleless && !c->fullscreen && c == selclient()) - setborder(c->framewin, def.border, def.focuscolor.border); + setborder(c->framewin, def.border, &def.focuscolor.border); else - setborder(c->framewin, 0, def.focuscolor.border); + setborder(c->framewin, 0, &def.focuscolor.border); /* Label */ r.min.x = r.max.x; @@ -494,8 +494,8 @@ frame_draw(Frame *f) { r.max.x -= Dx(f->grabbox); if(!ewmh_responsive_p(c)) - r.min.x += drawstring(img, def.font, r, West, "(wedged) ", col->fg); - w = drawstring(img, def.font, r, West, c->name, col->fg); + r.min.x += drawstring(img, def.font, r, West, "(wedged) ", &col->fg); + w = drawstring(img, def.font, r, West, c->name, &col->fg); /* Draw inner border on floating clients. */ if(f->area->floating) { @@ -503,7 +503,7 @@ frame_draw(Frame *f) { r.max.x += Dx(f->grabbox); r.min.y = f->grabbox.min.y; r.max.y = f->grabbox.max.y; - border(img, r, 1, col->border); + border(img, r, 1, &col->border); } /* Border increment gaps... */ @@ -511,7 +511,7 @@ frame_draw(Frame *f) { r.min.x = max(1, f->crect.min.x - 1); r.max.x = min(fr.max.x - 1, f->crect.max.x + 1); r.max.y = min(fr.max.y - 1, f->crect.max.y + 1); - border(img, r, 1, col->border); + border(img, r, 1, &col->border); /* Why? Because some non-ICCCM-compliant apps feel the need to * change the background properties of all of their ancestor windows diff --git a/cmd/wmii/layout.c b/cmd/wmii/layout.c @@ -111,10 +111,10 @@ expose_event(Window *w, void *aux, XExposeEvent *e) { buf = disp.ibuf; r = rectsubpt(w->r, w->r.min); - fill(buf, r, c->bg); - border(buf, r, 1, c->border); - border(buf, f->grabbox, 1, c->border); - border(buf, insetrect(f->grabbox, -f->grabbox.min.x), 1, c->border); + fill(buf, r, &c->bg); + border(buf, r, 1, &c->border); + border(buf, f->grabbox, 1, &c->border); + border(buf, insetrect(f->grabbox, -f->grabbox.min.x), 1, &c->border); copyimage(w, r, buf, ZP); return false; diff --git a/cmd/wmii/main.c b/cmd/wmii/main.c @@ -186,14 +186,12 @@ init_screens(void) { } /* Reallocate buffers. */ - freeimage(ibuf); - freeimage(ibuf32); - ibuf = allocimage(Dx(scr.rect), Dy(scr.rect), scr.depth); - ibuf32 = nil; /* Probably shouldn't do this until it's needed. */ + freeimage(disp.ibuf); + freeimage(disp.ibuf32); + disp.ibuf = allocimage(Dx(scr.rect), Dy(scr.rect), scr.depth); + disp.ibuf32 = nil; /* Probably shouldn't do this until it's needed. */ if(render_visual) - ibuf32 = allocimage(Dx(scr.rect), Dy(scr.rect), 32); - disp.ibuf = ibuf; - disp.ibuf32 = ibuf32; + disp.ibuf32 = allocimage(Dx(scr.rect), Dy(scr.rect), 32); /* Resize and initialize screens. */ for(i=0; i < nscreens; i++) { diff --git a/cmd/wmii/mouse.c b/cmd/wmii/mouse.c @@ -31,8 +31,8 @@ quad_cursor(Align align) { static bool cwin_expose(Window *w, void *aux, XExposeEvent *e) { - fill(w, rectsubpt(w->r, w->r.min), def.focuscolor.bg); - fill(w, w->r, def.focuscolor.bg); + fill(w, rectsubpt(w->r, w->r.min), &def.focuscolor.bg); + fill(w, w->r, &def.focuscolor.bg); return false; } @@ -52,7 +52,7 @@ constraintwin(Rectangle r) { selectinput(w2, ExposureMask); w->aux = w2; - setborder(w2, 1, def.focuscolor.border); + setborder(w2, 1, &def.focuscolor.border); sethandler(w2, &chandler); mapwin(w2); raisewin(w2); @@ -78,7 +78,7 @@ gethsep(Rectangle r) { Window *w; WinAttr wa; - wa.background_pixel = pixelvalue(def.normcolor.border); + wa.background_pixel = pixelvalue(&scr.root, &def.normcolor.border); w = createwindow(&scr.root, r, scr.depth, InputOutput, &wa, CWBackPixel); mapwin(w); raisewin(w); diff --git a/cmd/x11/wmii9menu.c b/cmd/x11/wmii9menu.c @@ -286,7 +286,7 @@ size_window(int wide, int high) reshapewin(menuwin, rectaddpt(r, p)); //XSetWindowBackground(display, menuwin->xid, cnorm.bg); - setborder(menuwin, 1, cnorm.border); + setborder(menuwin, 1, &cnorm.border); } /* redraw --- actually redraw the menu */ @@ -305,8 +305,8 @@ redraw(int high, int wide) else c = &cnorm; r = rectsetorigin(r, Pt(0, i * high)); - fill(menuwin, r, c->bg); - drawstring(menuwin, font, r, Center, labels[i], c->fg); + fill(menuwin, r, &c->bg); + drawstring(menuwin, font, r, Center, labels[i], &c->fg); } } diff --git a/include/stuff/x.h b/include/stuff/x.h @@ -73,6 +73,7 @@ extern bool event_looprunning; extern void (*event_debug)(XEvent*); extern Visual* render_visual; +extern Colormap render_colormap; extern bool have_RandR; extern bool have_render; extern bool have_xinerama; diff --git a/include/stuff/x11.h b/include/stuff/x11.h @@ -36,7 +36,7 @@ typedef enum WindowType WindowType; typedef XSetWindowAttributes WinAttr; typedef union ClientMessageData ClientMessageData; -typedef XRenderColor Color; +typedef struct Color Color; typedef struct CTuple CTuple; typedef struct ErrorCode ErrorCode; typedef struct Ewmh Ewmh; @@ -58,6 +58,14 @@ union ClientMessageData { long l[5]; }; +struct Color { + ushort red; + ushort green; + ushort blue; + ushort alpha; + ulong pixel; +}; + struct CTuple { Color bg; Color fg; @@ -188,13 +196,12 @@ struct Screen { Window root; GC gc; Colormap colormap; + Colormap colormap32; Visual* visual; Visual* visual32; Rectangle rect; int depth; int fd; - ulong black; - ulong white; }; #ifdef VARARGCK @@ -228,7 +235,7 @@ XRectangle XRect(Rectangle r); XRectangle XRect(Rectangle); Image* allocimage(int w, int h, int depth); char* atomname(ulong); -void border(Image *dst, Rectangle, int w, Color); +void border(Image *dst, Rectangle, int w, Color*); void changeprop_char(Window*, const char*, const char*, const char*, int); void changeprop_long(Window*, const char*, const char*, long[], int); void changeprop_short(Window*, const char*, const char*, short[], int); @@ -240,14 +247,15 @@ void cleanupwindow(Window*); void clientmessage(Window*, const char*, long, int, ClientMessageData); void copyimage(Image*, Rectangle, Image*, Point); Window* createwindow(Window*, Rectangle, int depth, uint class, WinAttr*, int valuemask); +Window* createwindow_rgba(Window*, Rectangle, WinAttr*, int valuemask); Window* createwindow_visual(Window*, Rectangle, int depth, Visual*, uint class, WinAttr*, int); void delproperty(Window*, const char*); void destroywindow(Window*); -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, const char*, Color); -void fill(Image*, Rectangle, Color); -void fillpoly(Image*, Point*, int, Color); +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, const char*, Color*); +void fill(Image*, Rectangle, Color*); +void fillpoly(Image*, Point*, int, Color*); Window* findwin(XWindow); void freefont(Font*); void freeimage(Image *); @@ -275,7 +283,7 @@ void movewin(Window*, Point); int numlockmask(void); bool parsecolor(const char *name, Color*); bool parsekey(char*, int*, char**); -ulong pixelvalue(Color); +ulong pixelvalue(Image*, Color*); int pointerscreen(void); bool pophandler(Window*, Handlers*); void pushhandler(Window*, Handlers*, void*); @@ -286,7 +294,7 @@ void reshapewin(Window*, Rectangle); void selectinput(Window*, long); void sendevent(Window*, bool propagate, long mask, void*); void sendmessage(Window*, const char*, long, long, long, long, long); -void setborder(Window*, int, Color); +void setborder(Window*, int, Color*); void setfocus(Window*, int mode); Handlers* sethandler(Window*, Handlers*); void sethints(Window*, WinHints*); diff --git a/lib/libstuff/Makefile b/lib/libstuff/Makefile @@ -167,6 +167,7 @@ OBJ=\ x11/text/textwidth_l \ x11/windows/configwin \ x11/windows/createwindow \ + x11/windows/createwindow_rgba \ x11/windows/createwindow_visual \ x11/windows/destroywindow \ x11/windows/findwin \ diff --git a/lib/libstuff/x11/colors/loadcolor.c b/lib/libstuff/x11/colors/loadcolor.c @@ -18,6 +18,6 @@ loadcolor(CTuple *c, const char *str, const char *end) { && parsecolor(toks[2], &c->border))) return 0; - snprint(c->colstr, sizeof c->colstr, "%s %s %s", toks[0], toks[1], toks[2]); + snprint(c->colstr, sizeof c->colstr, "%L %L %L", c->fg, c->bg, c->border); return toks[2] + strlen(toks[2]) - buf; } diff --git a/lib/libstuff/x11/colors/parsecolor.c b/lib/libstuff/x11/colors/parsecolor.c @@ -4,15 +4,30 @@ #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); +pixelvalue(Window *w, Color *c) { + XColor xc; + ulong pixel; + + if(w->visual->class != TrueColor) { + if(c->pixel != ~0UL) + return c->pixel; + xc.red = c->red; + xc.green = c->green; + xc.blue = c->blue; + XAllocColor(display, w->colormap, &xc); + return c->pixel = xc.pixel; + } + pixel = ((ulong)(c->alpha&0xff00) << 16) + | ((ulong)(c->red&0xff00) << 8) + | ((ulong)(c->green&0xff00) << 0) + | ((ulong)(c->blue&0xff00) >> 8); + if(w->depth < 32) + pixel |= 0xffUL << 24; + return pixel; } bool parsecolor(const char *name, Color *ret) { - - return XRenderParseColor(display, (char*)(uintptr_t)name, ret); + ret->pixel = ~0UL; + return XRenderParseColor(display, (char*)(uintptr_t)name, (XRenderColor*)ret); } diff --git a/lib/libstuff/x11/colors/xftcolor.c b/lib/libstuff/x11/colors/xftcolor.c @@ -4,10 +4,10 @@ #include "../x11.h" XftColor* -xftcolor(Color col) { - XftColor *c; +xftcolor(Image *i, Color *c) { + XftColor *xc; - c = emallocz(sizeof *c); - *c = (XftColor){ pixelvalue(col), col }; - return freelater(c); + xc = emallocz(sizeof *c); + *xc = (XftColor){ pixelvalue(i, c), c->red, c->green, c->blue, c->alpha }; + return freelater(xc); } diff --git a/lib/libstuff/x11/drawing/border.c b/lib/libstuff/x11/drawing/border.c @@ -4,7 +4,7 @@ #include "../x11.h" void -border(Image *dst, Rectangle r, int w, Color col) { +border(Image *dst, Rectangle r, int w, Color *col) { if(w == 0) return; diff --git a/lib/libstuff/x11/drawing/drawline.c b/lib/libstuff/x11/drawing/drawline.c @@ -4,7 +4,7 @@ #include "../x11.h" void -drawline(Image *dst, Point p1, Point p2, int cap, int w, Color 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); diff --git a/lib/libstuff/x11/drawing/drawpoly.c b/lib/libstuff/x11/drawing/drawpoly.c @@ -4,7 +4,7 @@ #include "../x11.h" void -drawpoly(Image *dst, Point *pt, int np, int cap, int w, Color col) { +drawpoly(Image *dst, Point *pt, int np, int cap, int w, Color *col) { XPoint *xp; xp = convpts(pt, np); diff --git a/lib/libstuff/x11/drawing/drawstring.c b/lib/libstuff/x11/drawing/drawstring.c @@ -7,7 +7,7 @@ uint drawstring(Image *dst, Font *font, Rectangle r, Align align, - const char *text, Color col) { + const char *text, Color *col) { Rectangle tr; char *buf; uint x, y, width, height, len; @@ -70,7 +70,7 @@ drawstring(Image *dst, Font *font, buf, len); break; case FXft: - xft->drawstring(xftdrawable(dst), xftcolor(col), + xft->drawstring(xftdrawable(dst), xftcolor(dst, col), font->font.xft, x, y, buf, len); break; diff --git a/lib/libstuff/x11/drawing/fill.c b/lib/libstuff/x11/drawing/fill.c @@ -4,7 +4,7 @@ #include "../x11.h" void -fill(Image *dst, Rectangle r, Color 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)); diff --git a/lib/libstuff/x11/drawing/fillpoly.c b/lib/libstuff/x11/drawing/fillpoly.c @@ -4,7 +4,7 @@ #include "../x11.h" void -fillpoly(Image *dst, Point *pt, int np, Color col) { +fillpoly(Image *dst, Point *pt, int np, Color *col) { XPoint *xp; xp = convpts(pt, np); diff --git a/lib/libstuff/x11/drawing/setgccol.c b/lib/libstuff/x11/drawing/setgccol.c @@ -4,6 +4,6 @@ #include "../x11.h" void -setgccol(Image *dst, Color c) { - XSetForeground(display, dst->gc, pixelvalue(c)); +setgccol(Image *dst, Color *c) { + XSetForeground(display, dst->gc, pixelvalue(dst, c)); } diff --git a/lib/libstuff/x11/initdisplay.c b/lib/libstuff/x11/initdisplay.c @@ -19,6 +19,16 @@ Afmt(Fmt *f) { } static int +Lfmt(Fmt *f) { + Color c; + + c = va_arg(f->args, Color); + return fmtprint(f, c.alpha < 0xff00 ? "rgba:%02uhx/%02uhx/%02uhx/%02uhx" + : "#%02uhx%02uhx%02uhx", + c.red >> 8, c.green >> 8, c.blue >> 8, c.alpha >> 8); +} + +static int Pfmt(Fmt *f) { Point p; @@ -52,13 +62,9 @@ initdisplay(void) { scr.screen = DefaultScreen(display); scr.colormap = DefaultColormap(display, scr.screen); scr.visual = DefaultVisual(display, scr.screen); - scr.visual32 = DefaultVisual(display, scr.screen); scr.gc = DefaultGC(display, scr.screen); scr.depth = DefaultDepth(display, scr.screen); - scr.white = WhitePixel(display, scr.screen); - scr.black = BlackPixel(display, scr.screen); - scr.root.xid = RootWindow(display, scr.screen); scr.root.r = Rect(0, 0, DisplayWidth(display, scr.screen), @@ -75,6 +81,7 @@ initdisplay(void) { atomnamemap.nhash = nelem(anamebucket); fmtinstall('A', Afmt); + fmtinstall('L', Lfmt); fmtinstall('R', Rfmt); fmtinstall('P', Pfmt); fmtinstall('W', Wfmt); diff --git a/lib/libstuff/x11/windows/createwindow_rgba.c b/lib/libstuff/x11/windows/createwindow_rgba.c @@ -0,0 +1,18 @@ +/* Copyright ©2007-2010 Kris Maglione <maglione.k at Gmail> + * See LICENSE file for license details. + */ +#include "../x11.h" + +Window* +createwindow_rgba(Window *parent, Rectangle r, WinAttr *wa, int valmask) { + WinAttr attr; + + if(scr.visual32 == nil) + return createwindow(parent, r, scr.depth, InputOutput, wa, valmask); + + attr = wa ? *wa : (WinAttr){0}; + valmask |= CWBorderPixel | CWColormap; + attr.border_pixel = 0; + attr.colormap = scr.colormap32; + return createwindow_visual(parent, r, 32, scr.visual32, InputOutput, &attr, valmask); +} diff --git a/lib/libstuff/x11/windows/setborder.c b/lib/libstuff/x11/windows/setborder.c @@ -4,11 +4,11 @@ #include "../x11.h" void -setborder(Window *w, int width, Color col) { +setborder(Window *w, int width, Color *col) { assert(w->type == WWindow); if(width) - XSetWindowBorder(display, w->xid, pixelvalue(col)); + XSetWindowBorder(display, w->xid, pixelvalue(w, col)); if(width != w->border) configwin(w, w->r, width); } diff --git a/lib/libstuff/x11/x11.h b/lib/libstuff/x11/x11.h @@ -19,7 +19,7 @@ extern int (*xlib_errorhandler) (Display*, XErrorEvent*); void configwin(Window*, Rectangle, int); XPoint* convpts(Point*, int); int errorhandler(Display*, XErrorEvent*); -void setgccol(Image*, Color); -XftColor* xftcolor(Color); +void setgccol(Image*, Color*); +XftColor* xftcolor(Image*, Color*); XftDraw* xftdrawable(Image*); diff --git a/lib/libstuff/xext.c b/lib/libstuff/xext.c @@ -18,7 +18,7 @@ static void randr_init(void); static void render_init(void); static void xinerama_init(void); -typedef void (*EvHandler)(XEvent*); +typedef void (*EvHandler)(XEvent*); static EvHandler randr_handlers[RRNumberEvents]; bool have_RandR; @@ -108,6 +108,8 @@ render_init(void) { break; } XFree(vip); + if(render_visual) + scr.colormap32 = XCreateColormap(display, scr.root.xid, render_visual, AllocNone); } bool diff --git a/mk/hdr.mk b/mk/hdr.mk @@ -63,7 +63,7 @@ MAKEFILES=.depend .c.depend: echo MKDEP $< [ -n "$(noisycc)" ] && echo $(MKDEP) $(COMPILE_FLAGS) $< || true - eval "$(MKDEP) $(COMPILE_FLAGS)" $< >>.depend + eval "$(MKDEP) $(COMPILE_FLAGS)" $< | sed '1s|.*:|$(<:%.c=%.o):|' >>.depend .sh.depend .rc.depend .1.depend .awk.depend: :