X-Git-Url: http://git.draconx.ca/gitweb/rrace.git/blobdiff_plain/2345a9dba343693668ece5abbba1fe58e0e18ed8..b4b5688edd332e17591ca7bc1cdd64c296abe1c5:/src/ewmhicon.c?ds=sidebyside diff --git a/src/ewmhicon.c b/src/ewmhicon.c index 7e69ec8..8b731a3 100644 --- a/src/ewmhicon.c +++ b/src/ewmhicon.c @@ -20,6 +20,7 @@ #include #include #include +#include #if !X_DISPLAY_MISSING # include @@ -32,17 +33,29 @@ enum { ICON_16x16, ICON_24x24, ICON_32x32, ICON_48x48, ICON_MAX }; -static unsigned long scale16to8(unsigned x) +static unsigned long scale16to8(uint_least32_t x) { - return x*0xfful / 0xffff; + return x*0xff / 0xffff; } static unsigned long wm_pixel(const XColor *c) { - return 0xff000000 - | scale16to8(c->red) << 16 - | scale16to8(c->green) << 8 - | scale16to8(c->blue); + uint_least32_t t = -1; + + t = (t << 8) + scale16to8(c->red); + t = (t << 8) + scale16to8(c->green); + t = (t << 8) + scale16to8(c->blue); + + return t & 0xffffffff; +} + +void ewmh_icon_prepare_cmap(XColor *map, unsigned n) +{ + unsigned i; + + for (i = 0; i < n; i++) { + map[i].pixel = wm_pixel(&map[i]); + } } static void do_remap(void *icon, unsigned area, const XColor *map) @@ -53,7 +66,7 @@ static void do_remap(void *icon, unsigned area, const XColor *map) area--; for (i = 0; i <= area; i++) { - argb[area-i] = wm_pixel(map + index[area-i]); + argb[area-i] = (map + index[area-i])->pixel; } }