2 * Test app for _NET_WM_ICON formatting.
3 * Copyright © 2022 Nick Bowler
5 * Use a fake colour scheme to generate an icon of the chosen size (16x16,
6 * 24x24, 32x32 or 48x48) and display the pixels as characters.
8 * This program is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 #include <X11/Intrinsic.h>
30 static const char *progname = "ewmhicon";
32 static void print_usage(FILE *f)
34 fprintf(f, "Usage: %s size\n", progname);
37 static const char sizes[][6] = {
38 "16x16", "24x24", "32x32", "48x48"
41 int to_size_enum(const char *arg)
46 if (!strchr(arg, 'x')) {
47 sprintf(buf, "%.3sx%.3s", arg, arg);
51 for (i = 0; i < sizeof sizes / sizeof sizes[0]; i++) {
52 if (!strcmp(arg, sizes[i]))
59 static unsigned long icon_buf[48*48];
61 int main(int argc, char **argv)
63 void (*tilefunc)(unsigned long *, const XColor *, int, int);
64 XColor c[COLOUR_MAX] = {0};
75 size = to_size_enum(argv[1]);
77 printf("%s: error: invalid size %s\n", progname, argv[1]);
82 case ICON_16x16: tilefunc = ewmh_tile16; w = h = 16; break;
83 case ICON_24x24: tilefunc = ewmh_tile24; w = h = 24; break;
84 case ICON_32x32: tilefunc = ewmh_tile32; w = h = 32; break;
85 case ICON_48x48: tilefunc = ewmh_tile48; w = h = 48; break;
89 c[COLOUR_PRIMARY].red = 0xffff;
90 c[COLOUR_DARK].green = 0xffff;
91 c[COLOUR_LIGHT].blue = 0xffff;
93 for (x = 0; x < 3; x++) {
94 for (y = 0; y < 3; y++) {
95 tilefunc(icon_buf, c, x, y);
99 for (y = 0; y < h; y++) {
100 for (x = 0; x < w; x++) {
101 unsigned long val = icon_buf[y*h+x];
104 if (val == 0xffff0000) c = '.'; // primary
105 else if (val == 0xff00ff00) c = '%'; // dark
106 else if (val == 0xff0000ff) c = '+'; // light