[hackers] [wmii] Handle colormapped displays. || Kris Maglione

From: <hg_AT_suckless.org>
Date: Sun, 20 Jun 2010 19:59:37 +0000 (UTC)

changeset: 2736:a8d034ae66de
user: Kris Maglione <kris_AT_suckless.org>
date: Sun Jun 20 14:24:04 2010 -0400
files: alternative_wmiircs/python/pygmi/fs.py cmd/menu/menu.c cmd/tray/client.c cmd/tray/tray.c cmd/wmii/bar.c cmd/wmii/client.c cmd/wmii/dat.h cmd/wmii/div.c cmd/wmii/frame.c cmd/wmii/layout.c cmd/wmii/main.c cmd/wmii/mouse.c cmd/x11/wmii9menu.c include/stuff/x.h include/stuff/x11.h lib/libstuff/Makefile lib/libstuff/x11/colors/loadcolor.c lib/libstuff/x11/colors/parsecolor.c lib/libstuff/x11/colors/xftcolor.c lib/libstuff/x11/drawing/border.c lib/libstuff/x11/drawing/drawline.c lib/libstuff/x11/drawing/drawpoly.c lib/libstuff/x11/drawing/drawstring.c lib/libstuff/x11/drawing/fill.c lib/libstuff/x11/drawing/fillpoly.c lib/libstuff/x11/drawing/setgccol.c lib/libstuff/x11/initdisplay.c lib/libstuff/x11/windows/createwindow_rgba.c lib/libstuff/x11/windows/setborder.c lib/libstuff/x11/x11.h lib/libstuff/xext.c mk/hdr.mk
description:
Handle colormapped displays.

diff -r 5d3772c9c136 -r a8d034ae66de alternative_wmiircs/python/pygmi/fs.py
--- a/alternative_wmiircs/python/pygmi/fs.py Fri Jun 18 16:44:30 2010 -0400
+++ b/alternative_wmiircs/python/pygmi/fs.py Sun Jun 20 14:24:04 2010 -0400
@@ -463,6 +463,8 @@
         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 @@
             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 @@
             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 @@
         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 @@
 
     @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 -r 5d3772c9c136 -r a8d034ae66de cmd/menu/menu.c
--- a/cmd/menu/menu.c Fri Jun 18 16:44:30 2010 -0400
+++ b/cmd/menu/menu.c Sun Jun 20 14:24:04 2010 -0400
@@ -159,7 +159,7 @@
         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 @@
                         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 @@
         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 -r 5d3772c9c136 -r a8d034ae66de cmd/tray/client.c
--- a/cmd/tray/client.c Fri Jun 18 16:44:30 2010 -0400
+++ b/cmd/tray/client.c Sun Jun 20 14:24:04 2010 -0400
@@ -33,12 +33,12 @@
                 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 -r 5d3772c9c136 -r a8d034ae66de cmd/tray/tray.c
--- a/cmd/tray/tray.c Fri Jun 18 16:44:30 2010 -0400
+++ b/cmd/tray/tray.c Sun Jun 20 14:24:04 2010 -0400
@@ -123,9 +123,9 @@
         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 -r 5d3772c9c136 -r a8d034ae66de cmd/wmii/bar.c
--- a/cmd/wmii/bar.c Fri Jun 18 16:44:30 2010 -0400
+++ b/cmd/wmii/bar.c Sun Jun 20 14:24:04 2010 -0400
@@ -181,15 +181,15 @@
         }
 
         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 -r 5d3772c9c136 -r a8d034ae66de cmd/wmii/client.c
--- a/cmd/wmii/client.c Fri Jun 18 16:44:30 2010 -0400
+++ b/cmd/wmii/client.c Sun Jun 20 14:24:04 2010 -0400
@@ -96,10 +96,8 @@
 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 @@
         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 @@
         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 @@
                        | 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 -r 5d3772c9c136 -r a8d034ae66de cmd/wmii/dat.h
--- a/cmd/wmii/dat.h Fri Jun 18 16:44:30 2010 -0400
+++ b/cmd/wmii/dat.h Sun Jun 20 14:24:04 2010 -0400
@@ -164,7 +164,6 @@
         Frame* sel;
         Window w;
         Window* framewin;
- Image** ibuf;
         XWindow trans;
         Regex tagre;
         Regex tagvre;
@@ -349,8 +348,6 @@
 EXTERN Ixp9Srv p9srv;
 
 /* X11 */
-EXTERN Image* ibuf32;
-EXTERN Image* ibuf;
 EXTERN uint numlock_mask;
 EXTERN uint valid_mask;
 
diff -r 5d3772c9c136 -r a8d034ae66de cmd/wmii/div.c
--- a/cmd/wmii/div.c Fri Jun 18 16:44:30 2010 -0400
+++ b/cmd/wmii/div.c Sun Jun 20 14:24:04 2010 -0400
@@ -86,14 +86,14 @@
         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 -r 5d3772c9c136 -r a8d034ae66de cmd/wmii/frame.c
--- a/cmd/wmii/frame.c Fri Jun 18 16:44:30 2010 -0400
+++ b/cmd/wmii/frame.c Sun Jun 20 14:24:04 2010 -0400
@@ -404,9 +404,9 @@
                 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 @@
                 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 @@
 
         /* 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 @@
         /* 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 @@
         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 @@
                 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 @@
                 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 @@
         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 -r 5d3772c9c136 -r a8d034ae66de cmd/wmii/layout.c
--- a/cmd/wmii/layout.c Fri Jun 18 16:44:30 2010 -0400
+++ b/cmd/wmii/layout.c Sun Jun 20 14:24:04 2010 -0400
@@ -111,10 +111,10 @@
         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 -r 5d3772c9c136 -r a8d034ae66de cmd/wmii/main.c
--- a/cmd/wmii/main.c Fri Jun 18 16:44:30 2010 -0400
+++ b/cmd/wmii/main.c Sun Jun 20 14:24:04 2010 -0400
@@ -186,14 +186,12 @@
         }
 
         /* 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 -r 5d3772c9c136 -r a8d034ae66de cmd/wmii/mouse.c
--- a/cmd/wmii/mouse.c Fri Jun 18 16:44:30 2010 -0400
+++ b/cmd/wmii/mouse.c Sun Jun 20 14:24:04 2010 -0400
@@ -31,8 +31,8 @@
 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 @@
                 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 @@
         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 -r 5d3772c9c136 -r a8d034ae66de cmd/x11/wmii9menu.c
--- a/cmd/x11/wmii9menu.c Fri Jun 18 16:44:30 2010 -0400
+++ b/cmd/x11/wmii9menu.c Sun Jun 20 14:24:04 2010 -0400
@@ -286,7 +286,7 @@
         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 @@
                 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 -r 5d3772c9c136 -r a8d034ae66de include/stuff/x.h
--- a/include/stuff/x.h Fri Jun 18 16:44:30 2010 -0400
+++ b/include/stuff/x.h Sun Jun 20 14:24:04 2010 -0400
@@ -73,6 +73,7 @@
 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 -r 5d3772c9c136 -r a8d034ae66de include/stuff/x11.h
--- a/include/stuff/x11.h Fri Jun 18 16:44:30 2010 -0400
+++ b/include/stuff/x11.h Sun Jun 20 14:24:04 2010 -0400
@@ -36,7 +36,7 @@
 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 @@
         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 @@
         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);
 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 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 @@
 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 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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/Makefile
--- a/lib/libstuff/Makefile Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/Makefile Sun Jun 20 14:24:04 2010 -0400
@@ -167,6 +167,7 @@
         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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/colors/loadcolor.c
--- a/lib/libstuff/x11/colors/loadcolor.c Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/x11/colors/loadcolor.c Sun Jun 20 14:24:04 2010 -0400
@@ -18,6 +18,6 @@
            && 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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/colors/parsecolor.c
--- a/lib/libstuff/x11/colors/parsecolor.c Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/x11/colors/parsecolor.c Sun Jun 20 14:24:04 2010 -0400
@@ -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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/colors/xftcolor.c
--- a/lib/libstuff/x11/colors/xftcolor.c Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/x11/colors/xftcolor.c Sun Jun 20 14:24:04 2010 -0400
@@ -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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/drawing/border.c
--- a/lib/libstuff/x11/drawing/border.c Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/x11/drawing/border.c Sun Jun 20 14:24:04 2010 -0400
@@ -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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/drawing/drawline.c
--- a/lib/libstuff/x11/drawing/drawline.c Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/x11/drawing/drawline.c Sun Jun 20 14:24:04 2010 -0400
@@ -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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/drawing/drawpoly.c
--- a/lib/libstuff/x11/drawing/drawpoly.c Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/x11/drawing/drawpoly.c Sun Jun 20 14:24:04 2010 -0400
@@ -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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/drawing/drawstring.c
--- a/lib/libstuff/x11/drawing/drawstring.c Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/x11/drawing/drawstring.c Sun Jun 20 14:24:04 2010 -0400
@@ -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 @@
                                 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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/drawing/fill.c
--- a/lib/libstuff/x11/drawing/fill.c Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/x11/drawing/fill.c Sun Jun 20 14:24:04 2010 -0400
@@ -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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/drawing/fillpoly.c
--- a/lib/libstuff/x11/drawing/fillpoly.c Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/x11/drawing/fillpoly.c Sun Jun 20 14:24:04 2010 -0400
@@ -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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/drawing/setgccol.c
--- a/lib/libstuff/x11/drawing/setgccol.c Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/x11/drawing/setgccol.c Sun Jun 20 14:24:04 2010 -0400
@@ -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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/initdisplay.c
--- a/lib/libstuff/x11/initdisplay.c Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/x11/initdisplay.c Sun Jun 20 14:24:04 2010 -0400
@@ -19,6 +19,16 @@
 }
 
 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 @@
         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 @@
         atomnamemap.nhash = nelem(anamebucket);
 
         fmtinstall('A', Afmt);
+ fmtinstall('L', Lfmt);
         fmtinstall('R', Rfmt);
         fmtinstall('P', Pfmt);
         fmtinstall('W', Wfmt);
diff -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/windows/createwindow_rgba.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libstuff/x11/windows/createwindow_rgba.c Sun Jun 20 14:24:04 2010 -0400
@@ -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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/windows/setborder.c
--- a/lib/libstuff/x11/windows/setborder.c Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/x11/windows/setborder.c Sun Jun 20 14:24:04 2010 -0400
@@ -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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/x11/x11.h
--- a/lib/libstuff/x11/x11.h Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/x11/x11.h Sun Jun 20 14:24:04 2010 -0400
@@ -19,7 +19,7 @@
 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 -r 5d3772c9c136 -r a8d034ae66de lib/libstuff/xext.c
--- a/lib/libstuff/xext.c Fri Jun 18 16:44:30 2010 -0400
+++ b/lib/libstuff/xext.c Sun Jun 20 14:24:04 2010 -0400
@@ -18,7 +18,7 @@
 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 @@
                         break;
                 }
         XFree(vip);
+ if(render_visual)
+ scr.colormap32 = XCreateColormap(display, scr.root.xid, render_visual, AllocNone);
 }
 
 bool
diff -r 5d3772c9c136 -r a8d034ae66de mk/hdr.mk
--- a/mk/hdr.mk Fri Jun 18 16:44:30 2010 -0400
+++ b/mk/hdr.mk Sun Jun 20 14:24:04 2010 -0400
@@ -63,7 +63,7 @@
 .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:
         :
Received on Sun Jun 20 2010 - 19:59:37 UTC

This archive was generated by hypermail 2.2.0 : Sun Jun 20 2010 - 20:00:08 UTC