- if (get_boolean_resource(state->dpy, "random-colors", "Boolean")) {
- XColor fg, bg;
- size_t rand_i = random() % sizeof(color_list)/sizeof(color_list[0]);
- fg.red = color_list[rand_i].fg_red;
- fg.green = color_list[rand_i].fg_green;
- fg.blue = color_list[rand_i].fg_blue;
- bg.red = color_list[rand_i].bg_red;
- bg.green = color_list[rand_i].bg_green;
- bg.blue = color_list[rand_i].bg_blue;
- /* TODO: Since I 'alloc', presumably I must also 'free' these colors */
- /* at some point. Where/how? I don't want to eventually crash my */
- /* X server after months of use. */
- XAllocColor(state->dpy, xgwa.colormap, &fg);
- XAllocColor(state->dpy, xgwa.colormap, &bg);
- state->fg = gcv.foreground = fg.pixel;
- state->bg = gcv.background = bg.pixel;
- } else {
- state->fg = gcv.foreground = get_pixel_resource(state->dpy, xgwa.colormap, "foreground", "Foreground");
- state->bg = gcv.background = get_pixel_resource(state->dpy, xgwa.colormap, "background", "Background");
+ /* Set foreground and background colors for active/inactive cells. Either */
+ /* the user provided an index into the pre-defined color_list[] or a */
+ /* random entry from that same array should be selected. */
+ color_index = get_integer_resource(state->dpy, "color-index", "Integer");
+ if (color_index == -1) {
+ color_index = random() % sizeof(color_list)/sizeof(color_list[0]);
+ } else if (color_index >= sizeof(color_list)/sizeof(color_list[0])) {
+ fprintf(stderr, "WARNING: Color index out of range.\n");
+ color_index = 0;