mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-08 08:58:00 +00:00
Bring some order to colour palette indexing.
There are three separate indexing schemes in use by various bits of the PuTTY front ends, and _none_ of them was clearly documented, let alone all in the same place. Worse, functions that looked obviously related, like win_palette_set and win_palette_get, used different encodings. Now all the encodings are defined together in putty.h, with explanation of why there are three in the first place and clear documentation of where each one is used; terminal.c provides mapping tables that convert between them; the terminology is consistent throughout; and win_palette_set has been converted to use the sensible encoding.
This commit is contained in:
parent
61571376cc
commit
da3197f395
16
config.c
16
config.c
@ -854,18 +854,12 @@ struct colour_data {
|
||||
union control *listbox, *redit, *gedit, *bedit, *button;
|
||||
};
|
||||
|
||||
/* Array of the user-visible colour names defined in the list macro in
|
||||
* putty.h */
|
||||
static const char *const colours[] = {
|
||||
"Default Foreground", "Default Bold Foreground",
|
||||
"Default Background", "Default Bold Background",
|
||||
"Cursor Text", "Cursor Colour",
|
||||
"ANSI Black", "ANSI Black Bold",
|
||||
"ANSI Red", "ANSI Red Bold",
|
||||
"ANSI Green", "ANSI Green Bold",
|
||||
"ANSI Yellow", "ANSI Yellow Bold",
|
||||
"ANSI Blue", "ANSI Blue Bold",
|
||||
"ANSI Magenta", "ANSI Magenta Bold",
|
||||
"ANSI Cyan", "ANSI Cyan Bold",
|
||||
"ANSI White", "ANSI White Bold"
|
||||
#define CONF_COLOUR_NAME_DECL(id,name) name,
|
||||
CONF_COLOUR_LIST(CONF_COLOUR_NAME_DECL)
|
||||
#undef CONF_COLOUR_NAME_DECL
|
||||
};
|
||||
|
||||
static void colour_handler(union control *ctrl, dlgparam *dlg,
|
||||
|
@ -91,9 +91,9 @@ static void fuzz_set_minimised(TermWin *tw, bool minimised) {}
|
||||
static void fuzz_set_maximised(TermWin *tw, bool maximised) {}
|
||||
static void fuzz_move(TermWin *tw, int x, int y) {}
|
||||
static void fuzz_set_zorder(TermWin *tw, bool top) {}
|
||||
static bool fuzz_palette_get(TermWin *tw, int n, int *r, int *g, int *b)
|
||||
static bool fuzz_palette_get(TermWin *tw, unsigned n, int *r, int *g, int *b)
|
||||
{ return false; }
|
||||
static void fuzz_palette_set(TermWin *tw, int n, int r, int g, int b) {}
|
||||
static void fuzz_palette_set(TermWin *tw, unsigned n, int r, int g, int b) {}
|
||||
static void fuzz_palette_reset(TermWin *tw) {}
|
||||
static void fuzz_get_pos(TermWin *tw, int *x, int *y) { *x = *y = 0; }
|
||||
static void fuzz_get_pixels(TermWin *tw, int *x, int *y) { *x = *y = 0; }
|
||||
|
189
putty.h
189
putty.h
@ -30,6 +30,151 @@
|
||||
#define PGP_PREV_MASTER_KEY_FP \
|
||||
"440D E3B5 B7A1 CA85 B3CC 1718 AB58 5DC6 0467 6F7C"
|
||||
|
||||
/*
|
||||
* Definitions of three separate indexing schemes for colour palette
|
||||
* entries.
|
||||
*
|
||||
* Why three? Because history, sorry.
|
||||
*
|
||||
* Two of the colour indexings are used in escape sequences. The
|
||||
* Linux-console style OSC P sequences for setting the palette use an
|
||||
* indexing in which the eight standard ANSI SGR colours come first,
|
||||
* then their bold versions, and then six extra colours for default
|
||||
* fg/bg and the terminal cursor. And the xterm OSC 4 sequences for
|
||||
* querying the palette use a related indexing in which the six extra
|
||||
* colours are pushed up to indices 256 and onwards, with the previous
|
||||
* 16 being the first part of the xterm 256-colour space, and 240
|
||||
* additional terminal-accessible colours inserted in the middle.
|
||||
*
|
||||
* The third indexing is the order that the colours appear in the
|
||||
* PuTTY configuration panel, and also the order in which they're
|
||||
* described in the saved session files. This order specifies the same
|
||||
* set of colours as the OSC P encoding, but in a different order,
|
||||
* with the default fg/bg colours (which users are most likely to want
|
||||
* to reconfigure) at the start, and the ANSI SGR colours coming
|
||||
* later.
|
||||
*
|
||||
* So all three indices really are needed, because all three appear in
|
||||
* protocols or file formats outside the PuTTY binary. (Changing the
|
||||
* saved-session encoding would have a backwards-compatibility impact;
|
||||
* also, if we ever do, it would be better to replace the numeric
|
||||
* indices with descriptive keywords.)
|
||||
*
|
||||
* Since the OSC 4 encoding contains the full set of colours used in
|
||||
* the terminal display, that's the encoding used by front ends to
|
||||
* store any actual data associated with their palette entries. So the
|
||||
* TermWin palette_{set,get} methods use that encoding, and so does
|
||||
* the bitwise encoding of attribute words used in terminal redraw
|
||||
* operations.
|
||||
*
|
||||
* The Conf encoding, of course, is used by config.c and settings.c.
|
||||
*
|
||||
* The aim is that those two sections of the code should never need to
|
||||
* come directly into contact, and the only module that should have to
|
||||
* deal directly with the mapping between these colour encodings - or
|
||||
* to deal _at all_ with the intermediate OSC P encoding - is
|
||||
* terminal.c itself.
|
||||
*/
|
||||
|
||||
#define CONF_NCOLOURS 22 /* 16 + 6 special ones */
|
||||
#define OSCP_NCOLOURS 22 /* same as CONF, but different order */
|
||||
#define OSC4_NCOLOURS 262 /* 256 + the same 6 special ones */
|
||||
|
||||
/* The list macro for the conf colours also gives the textual names
|
||||
* used in the GUI configurer */
|
||||
#define CONF_COLOUR_LIST(X) \
|
||||
X(fg, "Default Foreground") \
|
||||
X(fg_bold, "Default Bold Foreground") \
|
||||
X(bg, "Default Background") \
|
||||
X(bg_bold, "Default Bold Background") \
|
||||
X(cursor_fg, "Cursor Text") \
|
||||
X(cursor_bg, "Cursor Colour") \
|
||||
X(black, "ANSI Black") \
|
||||
X(black_bold, "ANSI Black Bold") \
|
||||
X(red, "ANSI Red") \
|
||||
X(red_bold, "ANSI Red Bold") \
|
||||
X(green, "ANSI Green") \
|
||||
X(green_bold, "ANSI Green Bold") \
|
||||
X(yellow, "ANSI Yellow") \
|
||||
X(yellow_bold, "ANSI Yellow Bold") \
|
||||
X(blue, "ANSI Blue") \
|
||||
X(blue_bold, "ANSI Blue Bold") \
|
||||
X(magenta, "ANSI Magenta") \
|
||||
X(magenta_bold, "ANSI Magenta Bold") \
|
||||
X(cyan, "ANSI Cyan") \
|
||||
X(cyan_bold, "ANSI Cyan Bold") \
|
||||
X(white, "ANSI White") \
|
||||
X(white_bold, "ANSI White Bold") \
|
||||
/* end of list */
|
||||
|
||||
#define OSCP_COLOUR_LIST(X) \
|
||||
X(black) \
|
||||
X(red) \
|
||||
X(green) \
|
||||
X(yellow) \
|
||||
X(blue) \
|
||||
X(magenta) \
|
||||
X(cyan) \
|
||||
X(white) \
|
||||
X(black_bold) \
|
||||
X(red_bold) \
|
||||
X(green_bold) \
|
||||
X(yellow_bold) \
|
||||
X(blue_bold) \
|
||||
X(magenta_bold) \
|
||||
X(cyan_bold) \
|
||||
X(white_bold) \
|
||||
/*
|
||||
* In the OSC 4 indexing, this is where the extra 240 colours go.
|
||||
* They consist of:
|
||||
*
|
||||
* - 216 colours forming a 6x6x6 cube, with R the most
|
||||
* significant colour and G the least. In other words, these
|
||||
* occupy the space of indices 16 <= i < 232, with each
|
||||
* individual colour found as i = 16 + 36*r + 6*g + b, for all
|
||||
* 0 <= r,g,b <= 5.
|
||||
*
|
||||
* - The remaining indices, 232 <= i < 256, consist of a uniform
|
||||
* series of grey shades running between black and white (but
|
||||
* not including either, since actual black and white are
|
||||
* already provided in the previous colour cube).
|
||||
*
|
||||
* After that, we have the remaining 6 special colours:
|
||||
*/ \
|
||||
X(fg) \
|
||||
X(fg_bold) \
|
||||
X(bg) \
|
||||
X(bg_bold) \
|
||||
X(cursor_fg) \
|
||||
X(cursor_bg) \
|
||||
/* end of list */
|
||||
|
||||
/* Enumerations of the colour lists. These are available everywhere in
|
||||
* the code. The OSC P encoding shouldn't be used outside terminal.c,
|
||||
* but the easiest way to define the OSC 4 enum is to have the OSC P
|
||||
* one available to compute with. */
|
||||
enum {
|
||||
#define ENUM_DECL(id,name) CONF_COLOUR_##id,
|
||||
CONF_COLOUR_LIST(ENUM_DECL)
|
||||
#undef ENUM_DECL
|
||||
};
|
||||
enum {
|
||||
#define ENUM_DECL(id) OSCP_COLOUR_##id,
|
||||
OSCP_COLOUR_LIST(ENUM_DECL)
|
||||
#undef ENUM_DECL
|
||||
};
|
||||
enum {
|
||||
#define ENUM_DECL(id) OSC4_COLOUR_##id = \
|
||||
OSCP_COLOUR_##id + (OSCP_COLOUR_##id >= 16 ? 240 : 0),
|
||||
OSCP_COLOUR_LIST(ENUM_DECL)
|
||||
#undef ENUM_DECL
|
||||
};
|
||||
|
||||
/* Mapping tables defined in terminal.c */
|
||||
extern const int colour_indices_conf_to_oscp[CONF_NCOLOURS];
|
||||
extern const int colour_indices_conf_to_osc4[CONF_NCOLOURS];
|
||||
extern const int colour_indices_oscp_to_osc4[OSCP_NCOLOURS];
|
||||
|
||||
/* Three attribute types:
|
||||
* The ATTRs (normal attributes) are stored with the characters in
|
||||
* the main display arrays
|
||||
@ -102,35 +247,16 @@
|
||||
#define ATTR_UNDER 0x0080000U
|
||||
#define ATTR_REVERSE 0x0100000U
|
||||
#define ATTR_BLINK 0x0200000U
|
||||
#define ATTR_FGMASK 0x00001FFU
|
||||
#define ATTR_BGMASK 0x003FE00U
|
||||
#define ATTR_FGMASK 0x00001FFU /* stores a colour in OSC 4 indexing */
|
||||
#define ATTR_BGMASK 0x003FE00U /* stores a colour in OSC 4 indexing */
|
||||
#define ATTR_COLOURS 0x003FFFFU
|
||||
#define ATTR_DIM 0x1000000U
|
||||
#define ATTR_STRIKE 0x2000000U
|
||||
#define ATTR_FGSHIFT 0
|
||||
#define ATTR_BGSHIFT 9
|
||||
|
||||
/*
|
||||
* The definitive list of colour numbers stored in terminal
|
||||
* attribute words is kept here. It is:
|
||||
*
|
||||
* - 0-7 are ANSI colours (KRGYBMCW).
|
||||
* - 8-15 are the bold versions of those colours.
|
||||
* - 16-255 are the remains of the xterm 256-colour mode (a
|
||||
* 216-colour cube with R at most significant and B at least,
|
||||
* followed by a uniform series of grey shades running between
|
||||
* black and white but not including either on grounds of
|
||||
* redundancy).
|
||||
* - 256 is default foreground
|
||||
* - 257 is default bold foreground
|
||||
* - 258 is default background
|
||||
* - 259 is default bold background
|
||||
* - 260 is cursor foreground
|
||||
* - 261 is cursor background
|
||||
*/
|
||||
|
||||
#define ATTR_DEFFG (256 << ATTR_FGSHIFT)
|
||||
#define ATTR_DEFBG (258 << ATTR_BGSHIFT)
|
||||
#define ATTR_DEFFG (OSC4_COLOUR_fg << ATTR_FGSHIFT)
|
||||
#define ATTR_DEFBG (OSC4_COLOUR_bg << ATTR_BGSHIFT)
|
||||
#define ATTR_DEFAULT (ATTR_DEFFG | ATTR_DEFBG)
|
||||
|
||||
struct sesslist {
|
||||
@ -1142,8 +1268,9 @@ struct TermWinVtable {
|
||||
void (*move)(TermWin *, int x, int y);
|
||||
void (*set_zorder)(TermWin *, bool top);
|
||||
|
||||
bool (*palette_get)(TermWin *, int n, int *r, int *g, int *b);
|
||||
void (*palette_set)(TermWin *, int n, int r, int g, int b);
|
||||
/* Palette-handling functions. Palette indices are in OSC 4 encoding. */
|
||||
bool (*palette_get)(TermWin *, unsigned n, int *r, int *g, int *b);
|
||||
void (*palette_set)(TermWin *, unsigned n, int r, int g, int b);
|
||||
void (*palette_reset)(TermWin *);
|
||||
|
||||
void (*get_pos)(TermWin *, int *x, int *y);
|
||||
@ -1198,10 +1325,10 @@ static inline void win_move(TermWin *win, int x, int y)
|
||||
{ win->vt->move(win, x, y); }
|
||||
static inline void win_set_zorder(TermWin *win, bool top)
|
||||
{ win->vt->set_zorder(win, top); }
|
||||
static inline bool win_palette_get(TermWin *win, int n, int *r, int *g, int *b)
|
||||
{ return win->vt->palette_get(win, n, r, g, b); }
|
||||
static inline void win_palette_set(TermWin *win, int n, int r, int g, int b)
|
||||
{ win->vt->palette_set(win, n, r, g, b); }
|
||||
static inline bool win_palette_get(TermWin *win, unsigned n,
|
||||
int *r, int *g, int *b) { return win->vt->palette_get(win, n, r, g, b); }
|
||||
static inline void win_palette_set(TermWin *win, unsigned n,
|
||||
int r, int g, int b) { win->vt->palette_set(win, n, r, g, b); }
|
||||
static inline void win_palette_reset(TermWin *win)
|
||||
{ win->vt->palette_reset(win); }
|
||||
static inline void win_get_pos(TermWin *win, int *x, int *y)
|
||||
@ -1390,7 +1517,7 @@ NORETURN void cleanup_exit(int);
|
||||
X(BOOL, NONE, system_colour) \
|
||||
X(BOOL, NONE, try_palette) \
|
||||
X(INT, NONE, bold_style) /* 1=font 2=colour (3=both) */ \
|
||||
X(INT, INT, colours) \
|
||||
X(INT, INT, colours) /* indexed by the CONF_COLOUR_* enum encoding */ \
|
||||
/* Selection options */ \
|
||||
X(INT, NONE, mouse_is_xterm) /* 0=compromise 1=xterm 2=Windows */ \
|
||||
X(BOOL, NONE, rect_select) \
|
||||
@ -1479,8 +1606,6 @@ NORETURN void cleanup_exit(int);
|
||||
enum config_primary_key { CONFIG_OPTIONS(CONF_ENUM_DEF) N_CONFIG_OPTIONS };
|
||||
#undef CONF_ENUM_DEF
|
||||
|
||||
#define NCFGCOLOURS 22 /* number of colours in CONF_colours above */
|
||||
|
||||
/* Functions handling configuration structures. */
|
||||
Conf *conf_new(void); /* create an empty configuration */
|
||||
void conf_free(Conf *conf);
|
||||
|
25
terminal.c
25
terminal.c
@ -132,6 +132,24 @@ static void unlineptr(termline *line)
|
||||
freetermline(line);
|
||||
}
|
||||
|
||||
const int colour_indices_conf_to_oscp[CONF_NCOLOURS] = {
|
||||
#define COLOUR_ENTRY(id,name) OSCP_COLOUR_##id,
|
||||
CONF_COLOUR_LIST(COLOUR_ENTRY)
|
||||
#undef COLOUR_ENTRY
|
||||
};
|
||||
|
||||
const int colour_indices_conf_to_osc4[CONF_NCOLOURS] = {
|
||||
#define COLOUR_ENTRY(id,name) OSC4_COLOUR_##id,
|
||||
CONF_COLOUR_LIST(COLOUR_ENTRY)
|
||||
#undef COLOUR_ENTRY
|
||||
};
|
||||
|
||||
const int colour_indices_oscp_to_osc4[OSCP_NCOLOURS] = {
|
||||
#define COLOUR_ENTRY(id) OSC4_COLOUR_##id,
|
||||
OSCP_COLOUR_LIST(COLOUR_ENTRY)
|
||||
#undef COLOUR_ENTRY
|
||||
};
|
||||
|
||||
#ifdef TERM_CC_DIAGS
|
||||
/*
|
||||
* Diagnostic function: verify that a termline has a correct
|
||||
@ -4868,8 +4886,13 @@ static void term_out(Terminal *term)
|
||||
}
|
||||
term->osc_string[term->osc_strlen++] = val;
|
||||
if (term->osc_strlen >= 7) {
|
||||
unsigned oscp_index = term->osc_string[0];
|
||||
assert(oscp_index < OSCP_NCOLOURS);
|
||||
unsigned osc4_index =
|
||||
colour_indices_oscp_to_osc4[oscp_index];
|
||||
|
||||
win_palette_set(
|
||||
term->win, term->osc_string[0],
|
||||
term->win, osc4_index,
|
||||
term->osc_string[1] * 16 + term->osc_string[2],
|
||||
term->osc_string[3] * 16 + term->osc_string[4],
|
||||
term->osc_string[5] * 16 + term->osc_string[6]);
|
||||
|
@ -44,10 +44,6 @@
|
||||
|
||||
#include "x11misc.h"
|
||||
|
||||
/* Colours come in two flavours: configurable, and xterm-extended. */
|
||||
#define NEXTCOLOURS 240 /* 216 colour-cube plus 24 shades of grey */
|
||||
#define NALLCOLOURS (NCFGCOLOURS + NEXTCOLOURS)
|
||||
|
||||
GdkAtom compound_text_atom, utf8_string_atom;
|
||||
static GdkAtom clipboard_atom
|
||||
#if GTK_CHECK_VERSION(2,0,0) /* GTK1 will have to fill this in at startup */
|
||||
@ -137,7 +133,7 @@ struct GtkFrontend {
|
||||
int xpos, ypos, gravity;
|
||||
bool gotpos;
|
||||
GdkCursor *rawcursor, *textcursor, *blankcursor, *waitcursor, *currcursor;
|
||||
GdkColor cols[NALLCOLOURS];
|
||||
GdkColor cols[OSC4_NCOLOURS]; /* indexed by xterm colour indices */
|
||||
#if !GTK_CHECK_VERSION(3,0,0)
|
||||
GdkColormap *colmap;
|
||||
#endif
|
||||
@ -2522,7 +2518,8 @@ static void gtkwin_request_resize(TermWin *tw, int w, int h)
|
||||
|
||||
}
|
||||
|
||||
static void real_palette_set(GtkFrontend *inst, int n, int r, int g, int b)
|
||||
static void real_palette_set(GtkFrontend *inst, unsigned n,
|
||||
int r, int g, int b)
|
||||
{
|
||||
inst->cols[n].red = r * 0x0101;
|
||||
inst->cols[n].green = g * 0x0101;
|
||||
@ -2584,15 +2581,13 @@ void set_window_background(GtkFrontend *inst)
|
||||
set_gtk_widget_background(GTK_WIDGET(inst->window), &inst->cols[258]);
|
||||
}
|
||||
|
||||
static void gtkwin_palette_set(TermWin *tw, int n, int r, int g, int b)
|
||||
static void gtkwin_palette_set(TermWin *tw, unsigned n, int r, int g, int b)
|
||||
{
|
||||
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
|
||||
if (n >= 16)
|
||||
n += 256 - 16;
|
||||
if (n >= NALLCOLOURS)
|
||||
if (n >= OSC4_NCOLOURS)
|
||||
return;
|
||||
real_palette_set(inst, n, r, g, b);
|
||||
if (n == 258) {
|
||||
if (n == OSC4_COLOUR_bg) {
|
||||
/* Default Background changed. Ensure space between text area and
|
||||
* window border is redrawn */
|
||||
set_window_background(inst);
|
||||
@ -2601,10 +2596,10 @@ static void gtkwin_palette_set(TermWin *tw, int n, int r, int g, int b)
|
||||
}
|
||||
}
|
||||
|
||||
static bool gtkwin_palette_get(TermWin *tw, int n, int *r, int *g, int *b)
|
||||
static bool gtkwin_palette_get(TermWin *tw, unsigned n, int *r, int *g, int *b)
|
||||
{
|
||||
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
|
||||
if (n < 0 || n >= NALLCOLOURS)
|
||||
if (n >= OSC4_NCOLOURS)
|
||||
return false;
|
||||
*r = inst->cols[n].red >> 8;
|
||||
*g = inst->cols[n].green >> 8;
|
||||
@ -2615,53 +2610,44 @@ static bool gtkwin_palette_get(TermWin *tw, int n, int *r, int *g, int *b)
|
||||
static void gtkwin_palette_reset(TermWin *tw)
|
||||
{
|
||||
GtkFrontend *inst = container_of(tw, GtkFrontend, termwin);
|
||||
/* This maps colour indices in inst->conf to those used in inst->cols. */
|
||||
static const int ww[] = {
|
||||
256, 257, 258, 259, 260, 261,
|
||||
0, 8, 1, 9, 2, 10, 3, 11,
|
||||
4, 12, 5, 13, 6, 14, 7, 15
|
||||
};
|
||||
int i;
|
||||
|
||||
assert(lenof(ww) == NCFGCOLOURS);
|
||||
|
||||
#if !GTK_CHECK_VERSION(3,0,0)
|
||||
if (!inst->colmap) {
|
||||
inst->colmap = gdk_colormap_get_system();
|
||||
} else {
|
||||
gdk_colormap_free_colors(inst->colmap, inst->cols, NALLCOLOURS);
|
||||
gdk_colormap_free_colors(inst->colmap, inst->cols, OSC4_NCOLOURS);
|
||||
}
|
||||
#endif
|
||||
|
||||
for (i = 0; i < NCFGCOLOURS; i++) {
|
||||
inst->cols[ww[i]].red =
|
||||
for (i = 0; i < CONF_NCOLOURS; i++) {
|
||||
int w = colour_indices_conf_to_osc4[i];
|
||||
inst->cols[w].red =
|
||||
conf_get_int_int(inst->conf, CONF_colours, i*3+0) * 0x0101;
|
||||
inst->cols[ww[i]].green =
|
||||
inst->cols[w].green =
|
||||
conf_get_int_int(inst->conf, CONF_colours, i*3+1) * 0x0101;
|
||||
inst->cols[ww[i]].blue =
|
||||
inst->cols[w].blue =
|
||||
conf_get_int_int(inst->conf, CONF_colours, i*3+2) * 0x0101;
|
||||
}
|
||||
|
||||
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 ? r * 0x2828 + 0x3737 : 0;
|
||||
inst->cols[i+16].green = g ? g * 0x2828 + 0x3737 : 0;
|
||||
inst->cols[i+16].blue = b ? b * 0x2828 + 0x3737 : 0;
|
||||
} else {
|
||||
int shade = i - 216;
|
||||
shade = shade * 0x0a0a + 0x0808;
|
||||
inst->cols[i+16].red = inst->cols[i+16].green =
|
||||
inst->cols[i+16].blue = shade;
|
||||
}
|
||||
for (i = 0; i < 216; i++) {
|
||||
int r = i / 36, g = (i / 6) % 6, b = i % 6;
|
||||
inst->cols[i+16].red = r ? r * 0x2828 + 0x3737 : 0;
|
||||
inst->cols[i+16].green = g ? g * 0x2828 + 0x3737 : 0;
|
||||
inst->cols[i+16].blue = b ? b * 0x2828 + 0x3737 : 0;
|
||||
}
|
||||
for (i = 0; i < 24; i++) {
|
||||
int shade = i * 0x0a0a + 0x0808;
|
||||
inst->cols[i+232].red = inst->cols[i+232].green =
|
||||
inst->cols[i+232].blue = shade;
|
||||
}
|
||||
|
||||
#if !GTK_CHECK_VERSION(3,0,0)
|
||||
{
|
||||
gboolean success[NALLCOLOURS];
|
||||
gdk_colormap_alloc_colors(inst->colmap, inst->cols, NALLCOLOURS,
|
||||
gboolean success[OSC4_NCOLOURS];
|
||||
gdk_colormap_alloc_colors(inst->colmap, inst->cols, OSC4_NCOLOURS,
|
||||
false, true, success);
|
||||
for (i = 0; i < NALLCOLOURS; i++) {
|
||||
for (i = 0; i < OSC4_NCOLOURS; i++) {
|
||||
if (!success[i])
|
||||
g_error("%s: couldn't allocate colour %d (#%02x%02x%02x)\n",
|
||||
appname, i,
|
||||
@ -4626,12 +4612,6 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data)
|
||||
|
||||
static void after_change_settings_dialog(void *vctx, int retval)
|
||||
{
|
||||
/* This maps colour indices in inst->conf to those used in inst->cols. */
|
||||
static const int ww[] = {
|
||||
256, 257, 258, 259, 260, 261,
|
||||
0, 8, 1, 9, 2, 10, 3, 11,
|
||||
4, 12, 5, 13, 6, 14, 7, 15
|
||||
};
|
||||
struct after_change_settings_dialog_ctx ctx =
|
||||
*(struct after_change_settings_dialog_ctx *)vctx;
|
||||
GtkFrontend *inst = ctx.inst;
|
||||
@ -4641,8 +4621,6 @@ static void after_change_settings_dialog(void *vctx, int retval)
|
||||
|
||||
sfree(vctx); /* we've copied this already */
|
||||
|
||||
assert(lenof(ww) == NCFGCOLOURS);
|
||||
|
||||
unregister_dialog(&inst->seat, DIALOG_SLOT_RECONFIGURE);
|
||||
|
||||
if (retval > 0) {
|
||||
@ -4675,13 +4653,13 @@ static void after_change_settings_dialog(void *vctx, int retval)
|
||||
* to the new default, on the assumption that the user is
|
||||
* most likely to want an immediate update.
|
||||
*/
|
||||
for (i = 0; i < NCFGCOLOURS; i++) {
|
||||
for (i = 0; i < CONF_NCOLOURS; i++) {
|
||||
for (j = 0; j < 3; j++)
|
||||
if (conf_get_int_int(oldconf, CONF_colours, i*3+j) !=
|
||||
conf_get_int_int(newconf, CONF_colours, i*3+j))
|
||||
break;
|
||||
if (j < 3) {
|
||||
real_palette_set(inst, ww[i],
|
||||
real_palette_set(inst, colour_indices_conf_to_osc4[i],
|
||||
conf_get_int_int(newconf,CONF_colours,i*3+0),
|
||||
conf_get_int_int(newconf,CONF_colours,i*3+1),
|
||||
conf_get_int_int(newconf,CONF_colours,i*3+2));
|
||||
@ -4691,7 +4669,7 @@ static void after_change_settings_dialog(void *vctx, int retval)
|
||||
* repaint the space in between the window border
|
||||
* and the text area.
|
||||
*/
|
||||
if (ww[i] == 258) {
|
||||
if (i == CONF_COLOUR_bg) {
|
||||
set_window_background(inst);
|
||||
draw_backing_rect(inst);
|
||||
}
|
||||
|
@ -189,16 +189,13 @@ static enum {
|
||||
} und_mode;
|
||||
static int descent, font_strikethrough_y;
|
||||
|
||||
#define NCFGCOLOURS 22
|
||||
#define NEXTCOLOURS 240
|
||||
#define NALLCOLOURS (NCFGCOLOURS + NEXTCOLOURS)
|
||||
static COLORREF colours[NALLCOLOURS];
|
||||
static COLORREF colours[OSC4_NCOLOURS];
|
||||
static struct rgb {
|
||||
int r, g, b;
|
||||
} colours_rgb[NALLCOLOURS];
|
||||
} colours_rgb[OSC4_NCOLOURS];
|
||||
static HPALETTE pal;
|
||||
static LPLOGPALETTE logpal;
|
||||
static RGBTRIPLE defpal[NALLCOLOURS];
|
||||
static RGBTRIPLE defpal[OSC4_NCOLOURS];
|
||||
|
||||
static HBITMAP caretbm;
|
||||
|
||||
@ -247,8 +244,8 @@ static void wintw_set_minimised(TermWin *, bool minimised);
|
||||
static void wintw_set_maximised(TermWin *, bool maximised);
|
||||
static void wintw_move(TermWin *, int x, int y);
|
||||
static void wintw_set_zorder(TermWin *, bool top);
|
||||
static bool wintw_palette_get(TermWin *, int n, int *r, int *g, int *b);
|
||||
static void wintw_palette_set(TermWin *, int n, int r, int g, int b);
|
||||
static bool wintw_palette_get(TermWin *, unsigned n, int *r, int *g, int *b);
|
||||
static void wintw_palette_set(TermWin *, unsigned n, int r, int g, int b);
|
||||
static void wintw_palette_reset(TermWin *);
|
||||
static void wintw_get_pos(TermWin *, int *x, int *y);
|
||||
static void wintw_get_pixels(TermWin *, int *x, int *y);
|
||||
@ -1203,35 +1200,27 @@ static void wm_netevent_callback(void *vctx)
|
||||
|
||||
/*
|
||||
* Copy the colour palette from the configuration data into defpal.
|
||||
* This is non-trivial because the colour indices are different.
|
||||
*/
|
||||
static void conftopalette(void)
|
||||
{
|
||||
int i;
|
||||
static const int ww[] = {
|
||||
256, 257, 258, 259, 260, 261,
|
||||
0, 8, 1, 9, 2, 10, 3, 11,
|
||||
4, 12, 5, 13, 6, 14, 7, 15
|
||||
};
|
||||
|
||||
for (i = 0; i < 22; i++) {
|
||||
int w = ww[i];
|
||||
int w = colour_indices_conf_to_osc4[i];
|
||||
defpal[w].rgbtRed = conf_get_int_int(conf, CONF_colours, i*3+0);
|
||||
defpal[w].rgbtGreen = conf_get_int_int(conf, CONF_colours, i*3+1);
|
||||
defpal[w].rgbtBlue = conf_get_int_int(conf, CONF_colours, i*3+2);
|
||||
}
|
||||
for (i = 0; i < NEXTCOLOURS; i++) {
|
||||
if (i < 216) {
|
||||
int r = i / 36, g = (i / 6) % 6, b = i % 6;
|
||||
defpal[i+16].rgbtRed = r ? r * 40 + 55 : 0;
|
||||
defpal[i+16].rgbtGreen = g ? g * 40 + 55 : 0;
|
||||
defpal[i+16].rgbtBlue = b ? b * 40 + 55 : 0;
|
||||
} else {
|
||||
int shade = i - 216;
|
||||
shade = shade * 10 + 8;
|
||||
defpal[i+16].rgbtRed = defpal[i+16].rgbtGreen =
|
||||
defpal[i+16].rgbtBlue = shade;
|
||||
}
|
||||
for (i = 0; i < 216; i++) {
|
||||
int r = i / 36, g = (i / 6) % 6, b = i % 6;
|
||||
defpal[i+16].rgbtRed = r ? r * 40 + 55 : 0;
|
||||
defpal[i+16].rgbtGreen = g ? g * 40 + 55 : 0;
|
||||
defpal[i+16].rgbtBlue = b ? b * 40 + 55 : 0;
|
||||
}
|
||||
for (i = 0; i < 24; i++) {
|
||||
int shade = i * 10 + 8;
|
||||
defpal[i+232].rgbtRed = defpal[i+232].rgbtGreen =
|
||||
defpal[i+232].rgbtBlue = shade;
|
||||
}
|
||||
|
||||
/* Override with system colours if appropriate */
|
||||
@ -1250,10 +1239,10 @@ static void systopalette(void)
|
||||
int i;
|
||||
static const struct { int nIndex; int norm; int bold; } or[] =
|
||||
{
|
||||
{ COLOR_WINDOWTEXT, 256, 257 }, /* Default Foreground */
|
||||
{ COLOR_WINDOW, 258, 259 }, /* Default Background */
|
||||
{ COLOR_HIGHLIGHTTEXT, 260, 260 }, /* Cursor Text */
|
||||
{ COLOR_HIGHLIGHT, 261, 261 }, /* Cursor Colour */
|
||||
{ COLOR_WINDOWTEXT, OSC4_COLOUR_fg, OSC4_COLOUR_fg_bold },
|
||||
{ COLOR_WINDOW, OSC4_COLOUR_bg, OSC4_COLOUR_bg_bold },
|
||||
{ COLOR_HIGHLIGHTTEXT, OSC4_COLOUR_cursor_fg, OSC4_COLOUR_cursor_fg },
|
||||
{ COLOR_HIGHLIGHT, OSC4_COLOUR_cursor_bg, OSC4_COLOUR_cursor_bg },
|
||||
};
|
||||
|
||||
for (i = 0; i < (sizeof(or)/sizeof(or[0])); i++) {
|
||||
@ -1267,10 +1256,9 @@ static void systopalette(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void internal_set_colour(int i, int r, int g, int b)
|
||||
static void internal_set_colour(unsigned i, int r, int g, int b)
|
||||
{
|
||||
assert(i >= 0);
|
||||
assert(i < NALLCOLOURS);
|
||||
assert(i < OSC4_NCOLOURS);
|
||||
if (pal)
|
||||
colours[i] = PALETTERGB(r, g, b);
|
||||
else
|
||||
@ -1296,10 +1284,10 @@ static void init_palette(void)
|
||||
*/
|
||||
logpal = smalloc(sizeof(*logpal)
|
||||
- sizeof(logpal->palPalEntry)
|
||||
+ NALLCOLOURS * sizeof(PALETTEENTRY));
|
||||
+ OSC4_NCOLOURS * sizeof(PALETTEENTRY));
|
||||
logpal->palVersion = 0x300;
|
||||
logpal->palNumEntries = NALLCOLOURS;
|
||||
for (i = 0; i < NALLCOLOURS; i++) {
|
||||
logpal->palNumEntries = OSC4_NCOLOURS;
|
||||
for (i = 0; i < OSC4_NCOLOURS; i++) {
|
||||
logpal->palPalEntry[i].peRed = defpal[i].rgbtRed;
|
||||
logpal->palPalEntry[i].peGreen = defpal[i].rgbtGreen;
|
||||
logpal->palPalEntry[i].peBlue = defpal[i].rgbtBlue;
|
||||
@ -1314,7 +1302,7 @@ static void init_palette(void)
|
||||
}
|
||||
ReleaseDC(wgs.term_hwnd, hdc);
|
||||
}
|
||||
for (i = 0; i < NALLCOLOURS; i++)
|
||||
for (i = 0; i < OSC4_NCOLOURS; i++)
|
||||
internal_set_colour(i, defpal[i].rgbtRed,
|
||||
defpal[i].rgbtGreen, defpal[i].rgbtBlue);
|
||||
}
|
||||
@ -4758,7 +4746,7 @@ static void wintw_free_draw_ctx(TermWin *tw)
|
||||
wintw_hdc = NULL;
|
||||
}
|
||||
|
||||
static void real_palette_set(int n, int r, int g, int b)
|
||||
static void real_palette_set(unsigned n, int r, int g, int b)
|
||||
{
|
||||
internal_set_colour(n, r, g, b);
|
||||
if (pal) {
|
||||
@ -4766,13 +4754,13 @@ static void real_palette_set(int n, int r, int g, int b)
|
||||
logpal->palPalEntry[n].peGreen = g;
|
||||
logpal->palPalEntry[n].peBlue = b;
|
||||
logpal->palPalEntry[n].peFlags = PC_NOCOLLAPSE;
|
||||
SetPaletteEntries(pal, 0, NALLCOLOURS, logpal->palPalEntry);
|
||||
SetPaletteEntries(pal, 0, OSC4_NCOLOURS, logpal->palPalEntry);
|
||||
}
|
||||
}
|
||||
|
||||
static bool wintw_palette_get(TermWin *tw, int n, int *r, int *g, int *b)
|
||||
static bool wintw_palette_get(TermWin *tw, unsigned n, int *r, int *g, int *b)
|
||||
{
|
||||
if (n < 0 || n >= NALLCOLOURS)
|
||||
if (n >= OSC4_NCOLOURS)
|
||||
return false;
|
||||
*r = colours_rgb[n].r;
|
||||
*g = colours_rgb[n].g;
|
||||
@ -4780,11 +4768,9 @@ static bool wintw_palette_get(TermWin *tw, int n, int *r, int *g, int *b)
|
||||
return true;
|
||||
}
|
||||
|
||||
static void wintw_palette_set(TermWin *tw, int n, int r, int g, int b)
|
||||
static void wintw_palette_set(TermWin *tw, unsigned n, int r, int g, int b)
|
||||
{
|
||||
if (n >= 16)
|
||||
n += 256 - 16;
|
||||
if (n >= NALLCOLOURS)
|
||||
if (n >= OSC4_NCOLOURS)
|
||||
return;
|
||||
real_palette_set(n, r, g, b);
|
||||
if (pal) {
|
||||
@ -4793,7 +4779,7 @@ static void wintw_palette_set(TermWin *tw, int n, int r, int g, int b)
|
||||
RealizePalette(hdc);
|
||||
free_hdc(hdc);
|
||||
} else {
|
||||
if (n == (ATTR_DEFBG>>ATTR_BGSHIFT))
|
||||
if (n == OSC4_COLOUR_bg)
|
||||
/* If Default Background changes, we need to ensure any
|
||||
* space between the text area and the window border is
|
||||
* redrawn. */
|
||||
@ -4803,10 +4789,8 @@ static void wintw_palette_set(TermWin *tw, int n, int r, int g, int b)
|
||||
|
||||
static void wintw_palette_reset(TermWin *tw)
|
||||
{
|
||||
int i;
|
||||
|
||||
/* And this */
|
||||
for (i = 0; i < NALLCOLOURS; i++) {
|
||||
for (unsigned i = 0; i < OSC4_NCOLOURS; i++) {
|
||||
internal_set_colour(i, defpal[i].rgbtRed,
|
||||
defpal[i].rgbtGreen, defpal[i].rgbtBlue);
|
||||
if (pal) {
|
||||
@ -4819,7 +4803,7 @@ static void wintw_palette_reset(TermWin *tw)
|
||||
|
||||
if (pal) {
|
||||
HDC hdc;
|
||||
SetPaletteEntries(pal, 0, NALLCOLOURS, logpal->palPalEntry);
|
||||
SetPaletteEntries(pal, 0, OSC4_NCOLOURS, logpal->palPalEntry);
|
||||
hdc = make_hdc();
|
||||
RealizePalette(hdc);
|
||||
free_hdc(hdc);
|
||||
@ -4930,7 +4914,7 @@ static void wintw_clip_write(
|
||||
COLORREF bg, lastbg = -1;
|
||||
int attrBold, lastAttrBold = 0;
|
||||
int attrUnder, lastAttrUnder = 0;
|
||||
int palette[NALLCOLOURS];
|
||||
int palette[OSC4_NCOLOURS];
|
||||
int numcolours;
|
||||
tree234 *rgbtree = NULL;
|
||||
FontSpec *font = conf_get_fontspec(conf, CONF_font);
|
||||
@ -5006,7 +4990,7 @@ static void wintw_clip_write(
|
||||
* Next - Create a reduced palette
|
||||
*/
|
||||
numcolours = 0;
|
||||
for (i = 0; i < NALLCOLOURS; i++) {
|
||||
for (i = 0; i < OSC4_NCOLOURS; i++) {
|
||||
if (palette[i] != 0)
|
||||
palette[i] = ++numcolours;
|
||||
}
|
||||
@ -5022,7 +5006,7 @@ static void wintw_clip_write(
|
||||
*/
|
||||
put_datapl(rtf, PTRLEN_LITERAL("{\\colortbl ;"));
|
||||
|
||||
for (i = 0; i < NALLCOLOURS; i++) {
|
||||
for (i = 0; i < OSC4_NCOLOURS; i++) {
|
||||
if (palette[i] != 0) {
|
||||
strbuf_catf(rtf, "\\red%d\\green%d\\blue%d;",
|
||||
defpal[i].rgbtRed, defpal[i].rgbtGreen,
|
||||
|
Loading…
Reference in New Issue
Block a user