TODO: xim "how to" faq entry
TODO: reorganize faq
+TODO: support +xxx option syntax (e.g. -tint red +tint)
+TODO: scrollstyle -next, raised/sunken, maybe extra pixels(?) w. halfshadow
+
+ - changed interpretation of [alpha] colour prefix.
+ - further round trip eliminations in the !XFT case by remembering
+ the colour components.
7.5 Tue Jan 31 15:15:43 CET 2006
- further improvements to the careful mode detection, and font width
{
int shade = rs[Rs_shade] ? atoi (rs[Rs_shade]) : 100;
- rxvt_rgba c;
+ rgba c;
pix_colors_focused [Color_tint].get (this, c);
ShadeXImage (this, image, shade, c.r, c.g, c.b);
for (i = 1; i < (int) (sizeof (parent) / sizeof (Window)); i++)
{
oldp = parent[i];
- XQueryTree (xdisp, parent[i - 1], &root,
- &parent[i], &list, &n);
+ XQueryTree (xdisp, parent[i - 1], &root, &parent[i], &list, &n);
XFree (list);
if (parent[i] == display->root)
n = 0;
if (pchanged)
- {
- for (; n < (unsigned int)i; n++)
- {
- XGetWindowAttributes (xdisp, parent[n], &wattr);
- if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
- {
- n = (int) (sizeof (parent) / sizeof (Window)) + 1;
- break;
- }
- }
- }
+ for (; n < (unsigned int)i; n++)
+ {
+ XGetWindowAttributes (xdisp, parent[n], &wattr);
+
+ if (wattr.depth != rootdepth || wattr.c_class == InputOnly)
+ {
+ n = (int) (sizeof (parent) / sizeof (Window)) + 1;
+ break;
+ }
+ }
- if (n > (int) (sizeof (parent) / sizeof (parent[0])))
+ if (n > (sizeof (parent) / sizeof (parent[0])))
{
XSetWindowBackground (xdisp, parent[0], pix_colors_focused[Color_border]);
XSetWindowBackground (xdisp, vt, pix_colors_focused[Color_bg]);
{
if (str[0] == '?' && !str[1])
{
- rxvt_rgba c;
+ rgba c;
pix_colors_focused[color].get (this, c);
#if XFT
- if (c.a != rxvt_rgba::MAX_CC)
+ if (c.a != rgba::MAX_CC)
tt_printf ("\033]%d;rgba:%04x/%04x/%04x/%04x%c", report, c.a, c.r, c.g, c.b, resp);
else
#endif
for (i = 0; i < (depth <= 2 ? 2 : NRS_COLORS); i++)
{
- rxvt_color xcol;
+ const char *name = rs[Rs_color + i];
- if (!rs[Rs_color + i])
+ if (!name)
continue;
- if (!set_color (xcol, rs[Rs_color + i]))
+ rxvt_color xcol;
+
+ if (!set_color (xcol, name))
{
#ifndef XTERM_REVERSE_VIDEO
if (i < 2 && OPTION (Opt_reverseVideo))
- rs[Rs_color + i] = def_colorName[!i];
+ name = def_colorName [1 - i];
else
#endif
- rs[Rs_color + i] = def_colorName[i];
+ name = def_colorName [i];
- if (!rs[Rs_color + i])
+ if (!name)
continue;
- if (!set_color (xcol, rs[Rs_color + i]))
+ if (!set_color (xcol, name))
{
switch (i)
{
case Color_fg:
case Color_bg:
- /* fatal: need bg/fg color */
rxvt_warn ("unable to get foreground/background colour, continuing.\n");
+ name = "";
break;
#ifndef NO_CURSORCOLOR
case Color_cursor2:
- xcol = pix_colors[Color_fg];
- break;
-#endif /* ! NO_CURSORCOLOR */
+#endif
case Color_pointer_fg:
+ name = rs[Rs_color + Color_fg];
xcol = pix_colors[Color_fg];
break;
default:
- xcol = pix_colors[Color_bg]; /* None */
+ name = rs[Rs_color + Color_bg];
+ xcol = pix_colors[Color_bg];
break;
}
}
}
pix_colors[i] = xcol;
- SET_PIXCOLOR (i);
+ rs[Rs_color + i] = name;
}
#ifdef OFF_FOCUS_FADING
if (rs[Rs_fade])
for (i = 0; i < (depth <= 2 ? 2 : NRS_COLORS); i++)
{
- rxvt_rgba c;
+ rgba c;
pix_colors[Color_fade].get (this, c);
pix_colors_focused[i].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused[i],c);
}
* xcol[2] == bot shadow */
xcol[1] = pix_colors[Color_scroll];
- xcol[0].set (this, rxvt_rgba (rxvt_rgba::MAX_CC, rxvt_rgba::MAX_CC, rxvt_rgba::MAX_CC));
+ xcol[0].set (this, rgba (rgba::MAX_CC, rgba::MAX_CC, rgba::MAX_CC));
- rxvt_rgba c0, c1;
+ rgba c0, c1;
xcol[0].get (this, c0);
xcol[1].get (this, c1);
/* topShadowColor */
if (!xcol[1].set (this,
- rxvt_rgba (
+ rgba (
min (c0.r, max (c1.r / 5, c1.r) * 7 / 5),
min (c0.g, max (c1.g / 5, c1.g) * 7 / 5),
min (c0.b, max (c1.b / 5, c1.b) * 7 / 5),
{
rxvt_color xcol;
int i;
-
+
if (color == NULL || *color == '\0')
return;
+ color = strdup (color);
+ allocated.push_back ((void *)color);
+ rs[Rs_color + idx] = color;
+
/* handle color aliases */
if (isdigit (*color))
{
{ /* bright colors */
i -= 8;
pix_colors_focused[idx] = pix_colors_focused[minBrightCOLOR + i];
- SET_PIXCOLOR (idx);
goto done;
}
if (i >= 0 && i <= 7)
{ /* normal colors */
pix_colors_focused[idx] = pix_colors_focused[minCOLOR + i];
- SET_PIXCOLOR (idx);
goto done;
}
}
- if (!set_color (xcol, color))
- return;
-
- /* XStoreColor (xdisp, display->cmap, XColor*); */
+ set_color (xcol, color);
/*
* FIXME: should free colors here, but no idea how to do it so instead,
* so just keep gobbling up the colormap
*/
-# if 0
- for (i = Color_Black; i <= Color_White; i++)
- if (pix_colors[idx] == pix_colors[i])
- break;
- if (i > Color_White)
- {
- /* fprintf (stderr, "XFreeColors: pix_colors [%d] = %lu\n", idx, pix_colors [idx]); */
- XFreeColors (xdisp, display->cmap, (pix_colors + idx), 1,
- DisplayPlanes (xdisp, display->screen));
- }
-# endif
pix_colors_focused[idx] = xcol;
- SET_PIXCOLOR (idx);
/* XSetWindowAttributes attr; */
/* Cursor cursor; */
#if OFF_FOCUS_FADING
if (rs[Rs_fade])
{
- rxvt_rgba c;
+ rgba c;
pix_colors [Color_fade].get (this, c);
pix_colors_focused [idx].fade (this, atoi (rs[Rs_fade]), pix_colors_unfocused [idx], c);
}
#define Color_Bits 7 // 0 .. maxTermCOLOR
-#define NPIXCLR_SETS ((TOTAL_COLORS + 31) / 32)
-#define NPIXCLR_BITS 32
-
/*
* Resource list
*/
#define RS_SAME(a,b) (!(((a) ^ (b)) & ~RS_Careful))
-#define SET_PIXCOLOR(x) (pixcolor_set[(x) / NPIXCLR_BITS] |= (1 << ((x) % NPIXCLR_BITS)))
-#define ISSET_PIXCOLOR(x) (pixcolor_set[(x) / NPIXCLR_BITS] & (1 << ((x) % NPIXCLR_BITS)))
+#define PIXCOLOR_NAME(idx) rs[Rs_color + (idx)]
+#define ISSET_PIXCOLOR(idx) (!!rs[Rs_color + (idx)])
#if ENABLE_STYLES
# define FONTSET(style) fontset[GET_STYLE (style)]
/* ---------- */
rend_t rstyle;
/* ---------- */
- uint32_t pixcolor_set[NPIXCLR_SETS];
-/* ---------- */
#ifdef SELECTION_SCROLLING
int scroll_selection_lines;
enum page_dirn scroll_selection_dir;
/////////////////////////////////////////////////////////////////////////////
bool
-rxvt_color::alloc (rxvt_screen *screen, const rxvt_rgba &color)
+rxvt_color::alloc (rxvt_screen *screen, const rgba &color)
{
#if XFT
XRenderPictFormat *format;
c.color.blue = color.b;
c.color.alpha = color.a;
- c.pixel = ((color.r * format->direct.redMask / rxvt_rgba::MAX_CC) << format->direct.red )
- | ((color.g * format->direct.greenMask / rxvt_rgba::MAX_CC) << format->direct.green)
- | ((color.b * format->direct.blueMask / rxvt_rgba::MAX_CC) << format->direct.blue )
- | ((color.a * format->direct.alphaMask / rxvt_rgba::MAX_CC) << format->direct.alpha);
+ c.pixel = ((color.r * format->direct.redMask / rgba::MAX_CC) << format->direct.red )
+ | ((color.g * format->direct.greenMask / rgba::MAX_CC) << format->direct.green)
+ | ((color.b * format->direct.blueMask / rgba::MAX_CC) << format->direct.blue )
+ | ((color.a * format->direct.alphaMask / rgba::MAX_CC) << format->direct.alpha);
return true;
}
#else
if (screen->visual->c_class == TrueColor || screen->visual->c_class == DirectColor)
{
- p = (color.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask ))
- / rxvt_rgba::MAX_CC) << ctz (screen->visual->red_mask )
- | (color.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask))
- / rxvt_rgba::MAX_CC) << ctz (screen->visual->green_mask)
- | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask ))
- / rxvt_rgba::MAX_CC) << ctz (screen->visual->blue_mask );
+ c.red = color.g;
+ c.green = color.g;
+ c.blue = color.g;
+ c.pixel = (color.r * (screen->visual->red_mask >> ctz (screen->visual->red_mask ))
+ / rgba::MAX_CC) << ctz (screen->visual->red_mask )
+ | (color.g * (screen->visual->green_mask >> ctz (screen->visual->green_mask))
+ / rgba::MAX_CC) << ctz (screen->visual->green_mask)
+ | (color.b * (screen->visual->blue_mask >> ctz (screen->visual->blue_mask ))
+ / rgba::MAX_CC) << ctz (screen->visual->blue_mask );
return true;
}
else
{
- XColor xc;
+ c.red = color.r;
+ c.green = color.g;
+ c.blue = color.b;
- xc.red = color.r;
- xc.green = color.g;
- xc.blue = color.b;
-
- if (XAllocColor (screen->xdisp, screen->cmap, &xc))
- {
- p = xc.pixel;
- return true;
- }
+ if (XAllocColor (screen->xdisp, screen->cmap, &c))
+ return true;
else
- p = (color.r + color.g + color.b) > 128*3
- ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->xdisp))
- : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->xdisp));
+ c.pixel = (color.r + color.g + color.b) > 128*3
+ ? WhitePixelOfScreen (DefaultScreenOfDisplay (screen->xdisp))
+ : BlackPixelOfScreen (DefaultScreenOfDisplay (screen->xdisp));
}
#endif
bool
rxvt_color::set (rxvt_screen *screen, const char *name)
{
- rxvt_rgba c;
+ rgba c;
char eos;
int skip;
if (1 <= sscanf (name, "[%hd]%n", &c.a, &skip))
{
printf ("X %d\n", c.a);
- c.a = lerp<int, int, int> (0, rxvt_rgba::MAX_CC, c.a);
+ c.a = lerp<int, int, int> (0, rgba::MAX_CC, c.a);
name += skip;
printf ("y %04x\n", c.a);
}
else
- c.a = rxvt_rgba::MAX_CC;
+ c.a = rgba::MAX_CC;
// parse the non-standard rgba format
if (strlen (name) != 4+5*4 || 4 != sscanf (name, "rgba:%hx/%hx/%hx/%hx%c", &c.r, &c.g, &c.b, &c.a, &eos))
}
bool
-rxvt_color::set (rxvt_screen *screen, const rxvt_rgba &color)
+rxvt_color::set (rxvt_screen *screen, const rgba &color)
{
bool got = alloc (screen, color);
for (int i = 0; i < cmap_size; i++)
colors [i].pixel = i;
+ // many kilobytes transfer per colour, but pseudocolor isn't worth
+ // many extra optimisations.
XQueryColors (screen->xdisp, screen->cmap, colors, cmap_size);
int diff = 0x7fffffffUL;
//rxvt_warn ("could not allocate %04x %04x %04x, getting %04x %04x %04x instead (%d)\n",
// color.r, color.g, color.b, best->red, best->green, best->blue, diff);
- got = alloc (screen, rxvt_rgba (best->red, best->green, best->blue));
+ got = alloc (screen, rgba (best->red, best->green, best->blue));
delete colors;
}
}
void
-rxvt_color::get (rxvt_screen *screen, rxvt_rgba &color)
+rxvt_color::get (rxvt_screen *screen, rgba &color)
{
#if XFT
color.r = c.color.red;
color.b = c.color.blue;
color.a = c.color.alpha;
#else
- XColor c;
-
- c.pixel = p;
- XQueryColor (screen->xdisp, screen->cmap, &c);
-
color.r = c.red;
color.g = c.green;
color.b = c.blue;
- color.a = rxvt_rgba::MAX_CC;
+ color.a = rgba::MAX_CC;
#endif
}
#if XFT
XftColorFree (screen->xdisp, screen->visual, screen->cmap, &c);
#else
- XFreeColors (screen->xdisp, screen->cmap, &p, 1, AllPlanes);
+ XFreeColors (screen->xdisp, screen->cmap, &c.pixel, 1, AllPlanes);
#endif
}
void
-rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &result, const rxvt_rgba &to)
+rxvt_color::fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to)
{
- rxvt_rgba c;
+ rgba c;
get (screen, c);
result.set (
screen,
- rxvt_rgba (
+ rgba (
lerp (c.r, to.r, percent),
lerp (c.g, to.g, percent),
lerp (c.b, to.b, percent),
typedef unsigned long Pixel;
-struct rxvt_rgba {
+struct rgba {
unsigned short r, g, b, a;
enum { MIN_CC = 0x0000, MAX_CC = 0xffff };
- rxvt_rgba ()
+ rgba ()
{ }
- rxvt_rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC)
+ rgba (unsigned short r, unsigned short g, unsigned short b, unsigned short a = MAX_CC)
: r(r), g(g), b(b), a(a)
{ }
};
struct rxvt_color {
#if XFT
XftColor c;
- operator Pixel () const { return c.pixel; }
#else
- Pixel p;
- operator Pixel () const { return p; }
+ XColor c;
#endif
+ operator Pixel () const { return c.pixel; }
+
bool operator == (const rxvt_color &b) const { return Pixel (*this) == Pixel (b); }
bool operator != (const rxvt_color &b) const { return Pixel (*this) != Pixel (b); }
- bool alloc (rxvt_screen *screen, const rxvt_rgba &color);
+ bool alloc (rxvt_screen *screen, const rgba &color);
void free (rxvt_screen *screen);
- void get (rxvt_screen *screen, rxvt_rgba &color);
+ void get (rxvt_screen *screen, rgba &color);
bool set (rxvt_screen *screen, const char *name);
- bool set (rxvt_screen *screen, const rxvt_rgba &color);
+ bool set (rxvt_screen *screen, const rgba &color);
- void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rxvt_rgba &to = rxvt_rgba (0, 0, 0));
+ void fade (rxvt_screen *screen, int percent, rxvt_color &result, const rgba &to = rgba (0, 0, 0));
};
#endif