From 85522c518d168600f1a3038aebfdd87bc9b62c3d Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Tue, 8 Mar 2022 01:08:29 -0500 Subject: [PATCH] Use XPM as icon test output format. The output of this test program is very close to XPM format. So why not make it actually produce XPM format. This gives us a good way to have it output actual colour icons too. --- Makefile.am | 2 +- src/ewmhicon.h | 1 + t/ewmhicon.c | 193 ++++++++++++++++++++++++++++------ tests/gui.at | 280 +++++++++++++++++++++++++++---------------------- 4 files changed, 316 insertions(+), 160 deletions(-) diff --git a/Makefile.am b/Makefile.am index 9c76dd4..acd8c2b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -74,7 +74,7 @@ t_boardmove_SOURCES = t/boardmove.c src/game.c t_boardmove_LDADD = libgnu.a $(t_boardmove_OBJECTS): $(gnulib_headers) -t_ewmhicon_SOURCES = t/ewmhicon.c src/ewmhicon.c +t_ewmhicon_SOURCES = t/ewmhicon.c src/ewmhicon.c common/src/help.c t_ewmhicon_LDADD = libgnu.a $(MOTIF_LIBS) $(t_ewmhicon_OBJECTS): $(gnulib_headers) diff --git a/src/ewmhicon.h b/src/ewmhicon.h index cd006c3..d073067 100644 --- a/src/ewmhicon.h +++ b/src/ewmhicon.h @@ -28,6 +28,7 @@ /* Stub types to allow compilation */ typedef struct { + unsigned long pixel; unsigned short red, green, blue; } XColor; diff --git a/t/ewmhicon.c b/t/ewmhicon.c index 88ecfed..2ce721c 100644 --- a/t/ewmhicon.c +++ b/t/ewmhicon.c @@ -24,21 +24,76 @@ #include #include #include +#include #include "ewmhicon.h" +#include "help.h" static const char *progname = "ewmhicon"; +static const char sopts[] = "c:VH"; +static const struct option lopts[] = { + { "colourseq", 1, NULL, 'c' }, + { "version", 0, NULL, 'V' }, + { "help", 0, NULL, 'H' }, + { 0 } +}; + +#define S8TO16(x) ((x) * 0xfffful / 0xff) +#define RGB8(r, g, b) { \ + 0xff000000|(r ## ul)<<16|(g ## ul)<<8|(b ## ul), \ + S8TO16(r), S8TO16(g), S8TO16(b) } + +static const XColor colours[7][3] = { + { + { 0xffff0000, 0xffff }, + { 0xff00ff00, 0, 0xffff }, + { 0xff0000ff, 0, 0, 0xffff } + }, + { RGB8(0x8d,0x2e,0x28), RGB8(0x6a,0x1b,0x17), RGB8(0xa1,0x48,0x42) }, + { RGB8(0xb4,0x6e,0x28), RGB8(0x92,0x4a,0x16), RGB8(0xc7,0x90,0x4f) }, + { RGB8(0xd8,0xb7,0x40), RGB8(0xc5,0x9f,0x39), RGB8(0xe2,0xc6,0x5d) }, + { RGB8(0x28,0x64,0x28), RGB8(0x19,0x47,0x19), RGB8(0x4e,0x87,0x4e) }, + { RGB8(0x00,0x34,0x71), RGB8(0x00,0x1f,0x4f), RGB8(0x00,0x52,0x8b) }, + { RGB8(0xdc,0xdc,0xdc), RGB8(0xc0,0xc0,0xc0), RGB8(0xea,0xea,0xea) } +}; static void print_usage(FILE *f) { fprintf(f, "Usage: %s size\n", progname); + if (f != stdout) + fprintf(f, "Try %s --help for more information.\n", progname); +} + +static void print_help(void) +{ + const struct option *opt; + + print_usage(stdout); + putchar('\n'); + puts("Options:"); + for (opt = lopts; opt->name; opt++) { + if (help_print_optstring(opt, "ARG", 20)) + putchar('\n'); + } + putchar('\n'); + + printf("Report bugs to <%s>.\n", PACKAGE_BUGREPORT); +} + +static void print_version(void) +{ + printf("ewmhicon (%s) %s\n", PACKAGE, PACKAGE_VERSION); + printf("Copyright (C) 2022 Nick Bowler\n"); + puts("License GPLv3+: GNU GPL version 3 or any later version"); + puts("This is free software: you are free to change and redistribute it."); + puts("There is NO WARRANTY, to the extent permitted by law."); } static const char sizes[][6] = { "16x16", "24x24", "32x32", "48x48" }; -int to_size_enum(const char *arg) +static int to_size_enum(const char *arg) { char buf[8]; unsigned i; @@ -56,27 +111,12 @@ int to_size_enum(const char *arg) return -1; } -static unsigned long icon_buf[48*48]; - -int main(int argc, char **argv) +static void gen_icon(int size, const char *colourseq) { void (*tilefunc)(unsigned long *, const XColor *, int, int); - XColor c[COLOUR_MAX] = {0}; - int size, x, y, w, h; - - if (argc > 0) - progname = argv[0]; - - if (argc != 2) { - print_usage(stderr); - return EXIT_FAILURE; - } - - size = to_size_enum(argv[1]); - if (size < 0) { - printf("%s: error: invalid size %s\n", progname, argv[1]); - return EXIT_FAILURE; - } + static unsigned long icon_buf[48*48]; + const char colourchars[21] = ".%+"",Rr""-Oo""'Yy"":Gg"";Bb"" Ww"; + unsigned i, j, x, y, w, h, n; switch (size) { case ICON_16x16: tilefunc = ewmh_tile16; w = h = 16; break; @@ -86,29 +126,120 @@ int main(int argc, char **argv) default: assert(0); } - c[COLOUR_PRIMARY].red = 0xffff; - c[COLOUR_DARK].green = 0xffff; - c[COLOUR_LIGHT].blue = 0xffff; + for (i = 0; i < 9; i++) { + const XColor *c; + + assert(colourseq[i] >= '0' && colourseq[i] <= '6'); + c = colours[colourseq[i]-'0']; + + tilefunc(icon_buf, c, i%3, i/3); + } + + n = 7; + for (i = 0; i < 7; i++) + n -= !strchr(colourseq, '0'+i); + + puts("/* XPM */"); + puts("static char *icon[] = {"); + printf("\"%u %u %u 1\",\n", w, h, 3*n); + for (i = 0; i < 7; i++) { + if (!strchr(colourseq, '0'+i)) + continue; - for (x = 0; x < 3; x++) { - for (y = 0; y < 3; y++) { - tilefunc(icon_buf, c, x, y); + for (j = 0; j < 3; j++) { + printf("\"%c c #%.6lx\",\n", colourchars[3*i+j], + colours[i][j].pixel & 0xffffff); } } for (y = 0; y < h; y++) { + putchar('"'); for (x = 0; x < w; x++) { unsigned long val = icon_buf[y*h+x]; - int c = ' '; + int c = '#'; - if (val == 0xffff0000) c = '.'; // primary - else if (val == 0xff00ff00) c = '%'; // dark - else if (val == 0xff0000ff) c = '+'; // light + for (i = 0; i < sizeof colourchars; i++) { + if (colours[i/3][i%3].pixel == val) { + c = colourchars[i]; + break; + } + } putchar(c); } - putchar('\n'); + printf("\"%.*s\n", y+1 0) + progname = argv[0]; + + while ((opt = getopt_long(argc, argv, sopts, lopts, 0)) != -1) { + switch (opt) { + case 'c': + if (decode_colourseq(colourseq, optarg) != 0) + return EXIT_FAILURE; + break; + case 'H': + print_help(); + return EXIT_SUCCESS; + case 'V': + print_version(); + return EXIT_SUCCESS; + default: + print_usage(stderr); + return EXIT_FAILURE; + } + } + + if (argc != optind+1) { + printf("%s: error: size not specified\n", progname); + print_usage(stderr); + return EXIT_FAILURE; + } + + size = to_size_enum(argv[optind]); + if (size < 0) { + printf("%s: error: invalid size %s\n", progname, argv[optind]); + print_usage(stderr); + return EXIT_FAILURE; } + gen_icon(size, colourseq); return 0; } diff --git a/tests/gui.at b/tests/gui.at index 95d33fd..7d47052 100644 --- a/tests/gui.at +++ b/tests/gui.at @@ -15,148 +15,172 @@ AT_SETUP([_NET_WM_ICON tiles (16x16)]) -AT_CHECK([ewmhicon 16x16], [0], [dnl -....%+....%+.... -....%+....%+.... -....%+....%+.... -....%+....%+.... -%%%%%+%%%%%+%%%% -++++++++++++++++ -....%+....%+.... -....%+....%+.... -....%+....%+.... -....%+....%+.... -%%%%%+%%%%%+%%%% -++++++++++++++++ -....%+....%+.... -....%+....%+.... -....%+....%+.... -....%+....%+.... -]) +AT_CHECK([ewmhicon 16x16], [0], [[/* XPM */ +static char *icon[] = { +"16 16 3 1", +". c #ff0000", +"% c #00ff00", +"+ c #0000ff", +"....%+....%+....", +"....%+....%+....", +"....%+....%+....", +"....%+....%+....", +"%%%%%+%%%%%+%%%%", +"++++++++++++++++", +"....%+....%+....", +"....%+....%+....", +"....%+....%+....", +"....%+....%+....", +"%%%%%+%%%%%+%%%%", +"++++++++++++++++", +"....%+....%+....", +"....%+....%+....", +"....%+....%+....", +"....%+....%+...." +}; +]]) AT_CLEANUP AT_SETUP([_NET_WM_ICON tiles (24x24)]) -AT_CHECK([ewmhicon 24x24], [0], [dnl -++++++++++++++++++++++++ -+......%+......%+......% -+......%+......%+......% -+......%+......%+......% -+......%+......%+......% -+......%+......%+......% -+......%+......%+......% -+%%%%%%%+%%%%%%%+%%%%%%% -++++++++++++++++++++++++ -+......%+......%+......% -+......%+......%+......% -+......%+......%+......% -+......%+......%+......% -+......%+......%+......% -+......%+......%+......% -+%%%%%%%+%%%%%%%+%%%%%%% -++++++++++++++++++++++++ -+......%+......%+......% -+......%+......%+......% -+......%+......%+......% -+......%+......%+......% -+......%+......%+......% -+......%+......%+......% -+%%%%%%%+%%%%%%%+%%%%%%% -]) +AT_CHECK([ewmhicon 24x24], [0], [[/* XPM */ +static char *icon[] = { +"24 24 3 1", +". c #ff0000", +"% c #00ff00", +"+ c #0000ff", +"++++++++++++++++++++++++", +"+......%+......%+......%", +"+......%+......%+......%", +"+......%+......%+......%", +"+......%+......%+......%", +"+......%+......%+......%", +"+......%+......%+......%", +"+%%%%%%%+%%%%%%%+%%%%%%%", +"++++++++++++++++++++++++", +"+......%+......%+......%", +"+......%+......%+......%", +"+......%+......%+......%", +"+......%+......%+......%", +"+......%+......%+......%", +"+......%+......%+......%", +"+%%%%%%%+%%%%%%%+%%%%%%%", +"++++++++++++++++++++++++", +"+......%+......%+......%", +"+......%+......%+......%", +"+......%+......%+......%", +"+......%+......%+......%", +"+......%+......%+......%", +"+......%+......%+......%", +"+%%%%%%%+%%%%%%%+%%%%%%%" +}; +]]) AT_CLEANUP AT_SETUP([_NET_WM_ICON tiles (32x32)]) -AT_CHECK([ewmhicon 32x32], [0], [dnl -++++++++++++++++++++++++++++++++ -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+%%%%%%%%%%+%%%%%%%%%+%%%%%%%%%% -++++++++++++++++++++++++++++++++ -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+%%%%%%%%%%+%%%%%%%%%+%%%%%%%%%% -++++++++++++++++++++++++++++++++ -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+.........%+........%+.........% -+%%%%%%%%%%+%%%%%%%%%+%%%%%%%%%% -]) +AT_CHECK([ewmhicon 32x32], [0], [[/* XPM */ +static char *icon[] = { +"32 32 3 1", +". c #ff0000", +"% c #00ff00", +"+ c #0000ff", +"++++++++++++++++++++++++++++++++", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+%%%%%%%%%%+%%%%%%%%%+%%%%%%%%%%", +"++++++++++++++++++++++++++++++++", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+%%%%%%%%%%+%%%%%%%%%+%%%%%%%%%%", +"++++++++++++++++++++++++++++++++", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+.........%+........%+.........%", +"+%%%%%%%%%%+%%%%%%%%%+%%%%%%%%%%" +}; +]]) AT_CLEANUP AT_SETUP([_NET_WM_ICON tiles (48x48)]) -AT_CHECK([ewmhicon 48x48], [0], [dnl -++++++++++++++++++++++++++++++++++++++++++++++++ -+++++++++++++++%+++++++++++++++%+++++++++++++++% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++%%%%%%%%%%%%%%++%%%%%%%%%%%%%%++%%%%%%%%%%%%%% -+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%% -++++++++++++++++++++++++++++++++++++++++++++++++ -+++++++++++++++%+++++++++++++++%+++++++++++++++% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++%%%%%%%%%%%%%%++%%%%%%%%%%%%%%++%%%%%%%%%%%%%% -+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%% -++++++++++++++++++++++++++++++++++++++++++++++++ -+++++++++++++++%+++++++++++++++%+++++++++++++++% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++............%%++............%%++............%% -++%%%%%%%%%%%%%%++%%%%%%%%%%%%%%++%%%%%%%%%%%%%% -+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%% -]) +AT_CHECK([ewmhicon 48x48], [0], [[/* XPM */ +static char *icon[] = { +"48 48 3 1", +". c #ff0000", +"% c #00ff00", +"+ c #0000ff", +"++++++++++++++++++++++++++++++++++++++++++++++++", +"+++++++++++++++%+++++++++++++++%+++++++++++++++%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++%%%%%%%%%%%%%%++%%%%%%%%%%%%%%++%%%%%%%%%%%%%%", +"+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%", +"++++++++++++++++++++++++++++++++++++++++++++++++", +"+++++++++++++++%+++++++++++++++%+++++++++++++++%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++%%%%%%%%%%%%%%++%%%%%%%%%%%%%%++%%%%%%%%%%%%%%", +"+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%", +"++++++++++++++++++++++++++++++++++++++++++++++++", +"+++++++++++++++%+++++++++++++++%+++++++++++++++%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++............%%++............%%++............%%", +"++%%%%%%%%%%%%%%++%%%%%%%%%%%%%%++%%%%%%%%%%%%%%", +"+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%+%%%%%%%%%%%%%%%" +}; +]]) AT_CLEANUP -- 2.43.2