X-Git-Url: https://git.draconx.ca/gitweb/rrace.git/blobdiff_plain/43a709ff25b9973a83327a06a6ecc94b09e7787b..5a4a23e5e8032dfa1f7b73facb32f0c9ab200765:/src/ewmhicon.c diff --git a/src/ewmhicon.c b/src/ewmhicon.c index e071cec..319ed3a 100644 --- a/src/ewmhicon.c +++ b/src/ewmhicon.c @@ -21,9 +21,51 @@ #include #include -#include -#include -#include "motif.h" +#if !X_DISPLAY_MISSING +# include +# include +#endif + +#include "ewmhicon.h" +#include "colour.h" +#include "icon.h" + +enum { ICON_16x16, ICON_24x24, ICON_32x32, ICON_48x48, ICON_MAX }; + +/* + * Allocate storage for the EWMH _NET_WM_ICON array. The sizes array is + * populated with pointers to the beginning of each icon's pixel data. For + * example, sizes[ICON_24x24] points to the first pixel of the 24x24 image. + * + * The returned value can then be passed to XChangeProperty to set the icon, + * (use EWMH_ICON_NELEM for the number of elements) and must be freed by the + * caller. + */ +static void *ewmh_icon_alloc(unsigned long **sizes) +{ + unsigned long *buf; + + buf = calloc(sizeof *buf, EWMH_ICON_NELEM); + if (buf) { + sizes[ICON_16x16] = buf; + *sizes[ICON_16x16]++ = 16; + *sizes[ICON_16x16]++ = 16; + + sizes[ICON_24x24] = sizes[ICON_16x16] + 16*16; + *sizes[ICON_24x24]++ = 24; + *sizes[ICON_24x24]++ = 24; + + sizes[ICON_32x32] = sizes[ICON_24x24] + 24*24; + *sizes[ICON_32x32]++ = 32; + *sizes[ICON_32x32]++ = 32; + + sizes[ICON_48x48] = sizes[ICON_32x32] + 32*32; + *sizes[ICON_48x48]++ = 48; + *sizes[ICON_48x48]++ = 48; + } + + return buf; +} static unsigned long scale16to8(unsigned x) { @@ -38,111 +80,52 @@ static unsigned long wm_pixel(const XColor *c) | scale16to8(c->blue); } -/* - * The 16x16 icon is drawn with 1px shadow, 6x6 tiles, with 1 pixel cropped off - * all the edge tiles - */ -void ewmh_tile16(unsigned long *icon, const XColor *c, int tile_x, int tile_y) +static void do_remap(void *icon, unsigned size, const XColor *map) { - int out_x, out_y, out_w, x, y; - unsigned long row[6]; - - out_x = tile_x * 11 / 2; - out_y = tile_y * 11 / 2; - out_w = (5 + (tile_x == 1)) * sizeof row[0]; - - for (y = 0+(tile_y == 0); y < 6-(tile_y == 2); y++) { - for (x = 0+(tile_x == 0); x < 6-(tile_x==2); x++) { - if (x == 0 || y == 0) - row[x] = wm_pixel(&c[COLOUR_LIGHT]); - else if (x == 5 || y == 5) - row[x] = wm_pixel(&c[COLOUR_DARK]); - else - row[x] = wm_pixel(&c[COLOUR_PRIMARY]); - } - memcpy(&icon[16 * out_y++ + out_x], &row[tile_x == 0], out_w); + unsigned char *index = icon; + unsigned long *argb = icon; + unsigned i, count = size*size; + + for (i = 0; i < count; i++) { + argb[count-i-1] = wm_pixel(map + index[count-i-1]); } } -/* - * The 24x24 icon is drawn with 1px shadow and 8x8 tiles. - */ -void ewmh_tile24(unsigned long *icon, const XColor *c, int tile_x, int tile_y) +void *ewmh_icon_generate(const unsigned long *seq, const XColor *map) { - int out_x, out_y, x, y; - unsigned long row[8]; - - out_x = tile_x * 8; - out_y = tile_y * 8; - - for (y = 0; y < 8; y++) { - for (x = 0; x < 8; x++) { - if (x == 0 || y == 0) - row[x] = wm_pixel(&c[COLOUR_LIGHT]); - else if (x == 7 || y == 7) - row[x] = wm_pixel(&c[COLOUR_DARK]); - else - row[x] = wm_pixel(&c[COLOUR_PRIMARY]); - } - memcpy(&icon[24 * out_y++ + out_x], row, sizeof row); + unsigned long *buf, *sizes[ICON_MAX]; + unsigned i, j; + + buf = ewmh_icon_alloc(sizes); + if (!buf) + return NULL; + + for (i = 0; i < 9; i++) { + unsigned x = i%3, y = i/3; + + icon_tile16((void *)sizes[ICON_16x16], seq[i], x, y); + icon_tile24((void *)sizes[ICON_24x24], seq[i], x, y); + icon_tile32((void *)sizes[ICON_32x32], seq[i], x, y); + icon_tile48((void *)sizes[ICON_48x48], seq[i], x, y); } -} -/* - * The 32x32 icon is drawn with 1px shadow with slightly uneven tiles on - * an 11-10-11 pixel grid. - */ -void ewmh_tile32(unsigned long *icon, const XColor *c, int tile_x, int tile_y) -{ - int out_x, out_y, out_w, out_h, x, y; - unsigned long row[11]; - - out_x = 10*tile_x + (tile_x > 0); - out_y = 10*tile_y + (tile_y > 0); - out_w = 10 + (tile_x != 1); - out_h = 10 + (tile_y != 1); - - for (y = 0; y < out_h; y++) { - for (x = 0; x < out_w; x++) { - if (x == 0 || y == 0) - row[x] = wm_pixel(&c[COLOUR_LIGHT]); - else if (x == out_w-1 || y == out_h-1) - row[x] = wm_pixel(&c[COLOUR_DARK]); - else - row[x] = wm_pixel(&c[COLOUR_PRIMARY]); - } - memcpy(&icon[32 * out_y++ + out_x], row, out_w * sizeof row[0]); + for (i = 0; i < ICON_MAX; i++) { + /* Produces the sequence 16, 24, 32, 48 */ + unsigned size = 16 + (1u< 0 && bytes_after > 0); return 0; } -void *ewmh_icon_alloc(unsigned long **sizes) -{ - unsigned long *buf; - - buf = calloc(sizeof *buf, EWMH_ICON_NELEM); - if (buf) { - sizes[ICON_16x16] = buf; - *sizes[ICON_16x16]++ = 16; - *sizes[ICON_16x16]++ = 16; - - sizes[ICON_24x24] = sizes[ICON_16x16] + 16*16; - *sizes[ICON_24x24]++ = 24; - *sizes[ICON_24x24]++ = 24; - - sizes[ICON_32x32] = sizes[ICON_24x24] + 24*24; - *sizes[ICON_32x32]++ = 32; - *sizes[ICON_32x32]++ = 32; - - sizes[ICON_48x48] = sizes[ICON_32x32] + 32*32; - *sizes[ICON_48x48]++ = 48; - *sizes[ICON_48x48]++ = 48; - } - - return buf; -} +#endif