#define CAT(x,y) CAT2(x,y)
#define ASSERT(x) enum {CAT(assertion_,__LINE__) = 1 / (x)}
-#define NCOLOURS (lenof(((Config *)0)->colours))
+/* Colours come in two flavours: configurable, and xterm-extended. */
+#define NCFGCOLOURS (lenof(((Config *)0)->colours))
+#define NEXTCOLOURS 240 /* 216 colour-cube plus 24 shades of grey */
+#define NALLCOLOURS (NCFGCOLOURS + NEXTCOLOURS)
GdkAtom compound_text_atom, utf8_string_atom;
} fontinfo[4];
int xpos, ypos, gotpos, gravity;
GdkCursor *rawcursor, *textcursor, *blankcursor, *currcursor;
- GdkColor cols[NCOLOURS];
+ GdkColor cols[NALLCOLOURS];
GdkColormap *colmap;
wchar_t *pastein_data;
int direct_to_font;
void draw_backing_rect(struct gui_data *inst)
{
GdkGC *gc = gdk_gc_new(inst->area->window);
- gdk_gc_set_foreground(gc, &inst->cols[18]); /* default background */
+ gdk_gc_set_foreground(gc, &inst->cols[258]); /* default background */
gdk_draw_rectangle(inst->pixmap, gc, 1, 0, 0,
inst->cfg.width * inst->font_width + 2*inst->cfg.window_border,
inst->cfg.height * inst->font_height + 2*inst->cfg.window_border);
void set_window_background(struct gui_data *inst)
{
if (inst->area && inst->area->window)
- gdk_window_set_background(inst->area->window, &inst->cols[18]);
+ gdk_window_set_background(inst->area->window, &inst->cols[258]);
if (inst->window && inst->window->window)
- gdk_window_set_background(inst->window->window, &inst->cols[18]);
+ gdk_window_set_background(inst->window->window, &inst->cols[258]);
}
void palette_set(void *frontend, int n, int r, int g, int b)
{
struct gui_data *inst = (struct gui_data *)frontend;
- static const int first[21] = {
- 0, 2, 4, 6, 8, 10, 12, 14,
- 1, 3, 5, 7, 9, 11, 13, 15,
- 16, 17, 18, 20, 22
- };
- real_palette_set(inst, first[n], r, g, b);
- if (first[n] >= 18)
- real_palette_set(inst, first[n] + 1, r, g, b);
- if (first[n] == 18)
+ if (n >= 16)
+ n += 256 - 16;
+ if (n > NALLCOLOURS)
+ return;
+ real_palette_set(inst, n, r, g, b);
+ if (n == 258)
set_window_background(inst);
}
struct gui_data *inst = (struct gui_data *)frontend;
/* This maps colour indices in inst->cfg to those used in inst->cols. */
static const int ww[] = {
- 6, 7, 8, 9, 10, 11, 12, 13,
- 14, 15, 16, 17, 18, 19, 20, 21,
- 0, 1, 2, 3, 4, 5
+ 256, 257, 258, 259, 260, 261,
+ 0, 8, 1, 9, 2, 10, 3, 11,
+ 4, 12, 5, 13, 6, 14, 7, 15
};
- gboolean success[NCOLOURS];
+ gboolean success[NALLCOLOURS];
int i;
- assert(lenof(ww) == NCOLOURS);
+ assert(lenof(ww) == NCFGCOLOURS);
if (!inst->colmap) {
inst->colmap = gdk_colormap_get_system();
} else {
- gdk_colormap_free_colors(inst->colmap, inst->cols, NCOLOURS);
+ gdk_colormap_free_colors(inst->colmap, inst->cols, NALLCOLOURS);
}
- for (i = 0; i < NCOLOURS; i++) {
- inst->cols[i].red = inst->cfg.colours[ww[i]][0] * 0x0101;
- inst->cols[i].green = inst->cfg.colours[ww[i]][1] * 0x0101;
- inst->cols[i].blue = inst->cfg.colours[ww[i]][2] * 0x0101;
+ for (i = 0; i < NCFGCOLOURS; i++) {
+ inst->cols[ww[i]].red = inst->cfg.colours[i][0] * 0x0101;
+ inst->cols[ww[i]].green = inst->cfg.colours[i][1] * 0x0101;
+ inst->cols[ww[i]].blue = inst->cfg.colours[i][2] * 0x0101;
}
- gdk_colormap_alloc_colors(inst->colmap, inst->cols, NCOLOURS,
+ for (i = 0; i < NEXTCOLOURS; i++) {
+ if (i < 216) {
+ int r = i / 36, g = (i / 6) % 6, b = i % 6;
+ inst->cols[i+16].red = r * 0x3333;
+ inst->cols[i+16].green = g * 0x3333;
+ inst->cols[i+16].blue = b * 0x3333;
+ } else {
+ int shade = i - 216;
+ shade = (shade + 1) * 0xFFFF / (NEXTCOLOURS - 216 + 1);
+ inst->cols[i+16].red = inst->cols[i+16].green =
+ inst->cols[i+16].blue = shade;
+ }
+ }
+
+ gdk_colormap_alloc_colors(inst->colmap, inst->cols, NALLCOLOURS,
FALSE, FALSE, success);
- for (i = 0; i < NCOLOURS; i++) {
+ for (i = 0; i < NALLCOLOURS; i++) {
if (!success[i])
g_error("%s: couldn't allocate colour %d (#%02x%02x%02x)\n",
appname, i, inst->cfg.colours[i][0],
ncombining = 1;
nfg = ((attr & ATTR_FGMASK) >> ATTR_FGSHIFT);
- nfg = 2 * (nfg & 0xF) + (nfg & 0x10 ? 1 : 0);
nbg = ((attr & ATTR_BGMASK) >> ATTR_BGSHIFT);
- nbg = 2 * (nbg & 0xF) + (nbg & 0x10 ? 1 : 0);
if (attr & ATTR_REVERSE) {
t = nfg;
nfg = nbg;
nbg = t;
}
- if (inst->cfg.bold_colour && (attr & ATTR_BOLD))
- nfg |= 1;
- if (inst->cfg.bold_colour && (attr & ATTR_BLINK))
- nbg |= 1;
+ if (inst->cfg.bold_colour && (attr & ATTR_BOLD)) {
+ if (nfg < 16) nfg |= 8;
+ else if (nfg >= 256) nfg |= 1;
+ }
+ if (inst->cfg.bold_colour && (attr & ATTR_BLINK)) {
+ if (nbg < 16) nbg |= 8;
+ else if (nbg >= 256) nbg |= 1;
+ }
if (attr & TATTR_ACTCURS) {
- nfg = NCOLOURS-2;
- nbg = NCOLOURS-1;
+ nfg = 260;
+ nbg = 261;
}
fontid = shadow = 0;
* if it's passive.
*/
if (passive) {
- gdk_gc_set_foreground(gc, &inst->cols[NCOLOURS-1]);
+ gdk_gc_set_foreground(gc, &inst->cols[261]);
gdk_draw_rectangle(inst->pixmap, gc, 0,
x*inst->font_width+inst->cfg.window_border,
y*inst->font_height+inst->cfg.window_border,
length = inst->font_height;
}
- gdk_gc_set_foreground(gc, &inst->cols[NCOLOURS-1]);
+ gdk_gc_set_foreground(gc, &inst->cols[261]);
if (passive) {
for (i = 0; i < length; i++) {
if (i % 2 == 0) {
return err;
}
-static void block_signal(int sig, int block_it) {
- sigset_t ss;
-
- sigemptyset(&ss);
- sigaddset(&ss, sig);
- if(sigprocmask(block_it ? SIG_BLOCK : SIG_UNBLOCK, &ss, 0) < 0) {
- perror("sigprocmask");
- exit(1);
- }
-}
-
/*
* This function retrieves the character set encoding of a font. It
* returns the character set without the X11 hack (in case the user
{
/* This maps colour indices in inst->cfg to those used in inst->cols. */
static const int ww[] = {
- 6, 7, 8, 9, 10, 11, 12, 13,
- 14, 15, 16, 17, 18, 19, 20, 21,
- 0, 1, 2, 3, 4, 5
+ 256, 257, 258, 259, 260, 261,
+ 0, 8, 1, 9, 2, 10, 3, 11,
+ 4, 12, 5, 13, 6, 14, 7, 15
};
struct gui_data *inst = (struct gui_data *)data;
char *title = dupcat(appname, " Reconfiguration", NULL);
Config cfg2, oldcfg;
int i, need_size;
+ assert(lenof(ww) == NCFGCOLOURS);
+
cfg2 = inst->cfg; /* structure copy */
if (do_config_box(title, &cfg2, 1)) {
* have to the new default, on the assumption that the user
* is most likely to want an immediate update.
*/
- for (i = 0; i < NCOLOURS; i++) {
- if (oldcfg.colours[ww[i]][0] != cfg2.colours[ww[i]][0] ||
- oldcfg.colours[ww[i]][1] != cfg2.colours[ww[i]][1] ||
- oldcfg.colours[ww[i]][2] != cfg2.colours[ww[i]][2]) {
- real_palette_set(inst, i, cfg2.colours[ww[i]][0],
- cfg2.colours[ww[i]][1],
- cfg2.colours[ww[i]][2]);
+ for (i = 0; i < NCFGCOLOURS; i++) {
+ if (oldcfg.colours[i][0] != cfg2.colours[i][0] ||
+ oldcfg.colours[i][1] != cfg2.colours[i][1] ||
+ oldcfg.colours[i][2] != cfg2.colours[i][2]) {
+ real_palette_set(inst, ww[i], cfg2.colours[i][0],
+ cfg2.colours[i][1],
+ cfg2.colours[i][2]);
/*
* If the default background has changed, we must
* repaint the space in between the window border
* and the text area.
*/
- if (i == 18) {
+ if (i == 258) {
set_window_background(inst);
draw_backing_rect(inst);
}