[termdesc] copy only palette entries we actually read

pull/2460/head
nick black 3 years ago committed by nick black
parent ba1c79b66e
commit e106029c90

@ -1285,6 +1285,9 @@ palette_cb(inputctx* ictx){
logerror("empty palette string\n");
}else{
if(get_default_color(str, &ictx->initdata->palette.chans[idx]) == 0){
if((int)idx > ictx->initdata->maxpaletteread){
ictx->initdata->maxpaletteread = idx;
}
loginfo("index %u 0x%06x\n", idx, ictx->initdata->palette.chans[idx]);
}
free(str);
@ -1609,6 +1612,7 @@ create_inputctx(tinfo* ti, FILE* infp, int lmargin, int tmargin, int rmargin,
i->initdata->qterm = ti->qterm;
i->initdata->cursory = -1;
i->initdata->cursorx = -1;
i->initdata->maxpaletteread = -1;
i->iread = i->iwrite = i->ivalid = 0;
i->cread = i->cwrite = i->cvalid = 0;
i->initdata->kbdlevel = UINT_MAX;

@ -78,6 +78,7 @@ struct initial_responses {
char* version; // version string, heap-allocated
unsigned kbdlevel; // enabled kitty keyboard functions
ncpalette palette; // palette entries
int maxpaletteread; // maximum palette index read
};
// Blocking call. Waits until the input thread has processed all responses to

@ -998,6 +998,7 @@ int interrogate_terminfo(tinfo* ti, FILE* out, unsigned utf8,
ti->bg_collides_default = 0xfe000000;
ti->fg_default = 0xff000000;
ti->kbdlevel = UINT_MAX; // see comment in tinfo definition
ti->maxpaletteread = -1;
ti->qterm = TERMINAL_UNKNOWN;
// we don't need a controlling tty for everything we do; allow a failure here
ti->ttyfd = get_tty_fd(out);
@ -1233,7 +1234,11 @@ int interrogate_terminfo(tinfo* ti, FILE* out, unsigned utf8,
ti->dimy = iresp->dimy;
ti->dimx = iresp->dimx;
}
memcpy(&ti->originalpalette, &iresp->palette, sizeof(ti->originalpalette));
if(iresp->maxpaletteread >= 0){
memcpy(ti->originalpalette.chans, iresp->palette.chans,
sizeof(*ti->originalpalette.chans) * (iresp->maxpaletteread + 1));
ti->maxpaletteread = iresp->maxpaletteread;
}
if(iresp->rgb){
ti->caps.rgb = true;
}

@ -185,6 +185,7 @@ typedef struct tinfo {
int default_cols; // COLUMNS environment var / cols terminfo / 80
ncpalette originalpalette; // palette as read from initial queries
int maxpaletteread; // maximum palette entry read
pthread_t gpmthread; // thread handle for GPM watcher
int gpmfd; // connection to GPM daemon
char mouseproto; // DECSET level (100x, '0', '2', '3')

Loading…
Cancel
Save