track unknown background color if we can't learn it #2226

This commit is contained in:
nick black 2021-10-04 01:48:50 -04:00
parent e42a76a2d2
commit c69849ffb1
No known key found for this signature in database
GPG Key ID: 5F43400C21CBFACC
4 changed files with 18 additions and 9 deletions

View File

@ -337,9 +337,13 @@ display_logo(struct ncplane* n, const char* path){
static void static void
tinfo_debug_bitmaps(struct ncplane* n, const tinfo* ti, const char* indent){ tinfo_debug_bitmaps(struct ncplane* n, const tinfo* ti, const char* indent){
ncplane_printf(n, "%sdefbg 0x%06lx %sconsidered transparent", indent, if(!(ti->bg_collides_default & 0x80000000)){
ti->bg_collides_default & 0xfffffful, ncplane_printf(n, "%sdefbg 0x%06lx %sconsidered transparent", indent,
(ti->bg_collides_default & 0x01000000) ? "" : "not "); ti->bg_collides_default & 0xfffffful,
(ti->bg_collides_default & 0x01000000) ? "" : "not ");
}else{
ncplane_printf(n, "couldn't detect default background");
}
finish_line(n); finish_line(n);
ncpixelimpl_e blit = notcurses_check_pixel_support(ncplane_notcurses(n)); ncpixelimpl_e blit = notcurses_check_pixel_support(ncplane_notcurses(n));
switch(blit){ switch(blit){

View File

@ -146,6 +146,7 @@ static uint32_t
highcontrast(const tinfo* ti, uint32_t bchannel){ highcontrast(const tinfo* ti, uint32_t bchannel){
unsigned r, g, b; unsigned r, g, b;
if(ncchannel_default_p(bchannel)){ if(ncchannel_default_p(bchannel)){
// FIXME what if we couldn't identify the background color?
r = ncchannel_r(ti->bg_collides_default); r = ncchannel_r(ti->bg_collides_default);
g = ncchannel_g(ti->bg_collides_default); g = ncchannel_g(ti->bg_collides_default);
b = ncchannel_b(ti->bg_collides_default); b = ncchannel_b(ti->bg_collides_default);
@ -691,7 +692,7 @@ term_bg_rgb8(const tinfo* ti, fbuf* f, unsigned r, unsigned g, unsigned b){
// we're also in that case working with hopefully more robust terminals. // we're also in that case working with hopefully more robust terminals.
// If it doesn't work, eh, it doesn't work. Fuck the world; save yourself. // If it doesn't work, eh, it doesn't work. Fuck the world; save yourself.
if(ti->caps.rgb){ if(ti->caps.rgb){
if(ti->bg_collides_default){ if((ti->bg_collides_default & 0xff000000) == 0x01000000){
if((r == (ti->bg_collides_default & 0xff0000lu)) && if((r == (ti->bg_collides_default & 0xff0000lu)) &&
(g == (ti->bg_collides_default & 0xff00lu)) && (g == (ti->bg_collides_default & 0xff00lu)) &&
(b == (ti->bg_collides_default & 0xfflu))){ (b == (ti->bg_collides_default & 0xfflu))){

View File

@ -721,6 +721,7 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut
} }
*cursor_x = *cursor_y = -1; *cursor_x = *cursor_y = -1;
memset(ti, 0, sizeof(*ti)); memset(ti, 0, sizeof(*ti));
ti->bg_collides_default = 0xfe000000;
ti->qterm = TERMINAL_UNKNOWN; ti->qterm = TERMINAL_UNKNOWN;
// we don't need a controlling tty for everything we do; allow a failure here // we don't need a controlling tty for everything we do; allow a failure here
ti->ttyfd = get_tty_fd(out); ti->ttyfd = get_tty_fd(out);
@ -951,7 +952,11 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut
ti->cellpixy = ti->pixy / ti->default_rows; ti->cellpixy = ti->pixy / ti->default_rows;
ti->cellpixx = ti->pixx / ti->default_cols; ti->cellpixx = ti->pixx / ti->default_cols;
} }
ti->bg_collides_default = iresp->bg; if(iresp->got_bg){
// reset the 0xfe000000 we loaded during initialization. if we're
// kitty, we'll add the 0x01000000 in during heuristics.
ti->bg_collides_default = iresp->bg;
}
// kitty trumps sixel, when both are available // kitty trumps sixel, when both are available
if((kitty_graphics = iresp->kitty_graphics) == 0){ if((kitty_graphics = iresp->kitty_graphics) == 0){
ti->color_registers = iresp->color_registers; ti->color_registers = iresp->color_registers;
@ -959,9 +964,7 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut
ti->sixel_maxx = iresp->sixelx; ti->sixel_maxx = iresp->sixelx;
} }
free(iresp); free(iresp);
} if(nocbreak){
if(nocbreak){
if(ti->ttyfd >= 0){
// FIXME do this in input later, upon signaling completion? // FIXME do this in input later, upon signaling completion?
if(tcsetattr(ti->ttyfd, TCSANOW, ti->tpreserved)){ if(tcsetattr(ti->ttyfd, TCSANOW, ti->tpreserved)){
goto err; goto err;

View File

@ -112,7 +112,8 @@ typedef struct tinfo {
// kitty interprets an RGB background that matches the default background // kitty interprets an RGB background that matches the default background
// color *as* the default background, meaning it'll be translucent if // color *as* the default background, meaning it'll be translucent if
// background_opaque is in use. detect this, and avoid the default if so. // background_opaque is in use. detect this, and avoid the default if so.
// bg_collides_default is either 0x0000000 or (if in use) 0x1RRGGBB. // bg_collides_default is either:
// 0xfexxxxxxx (unknown), 0x00RRGGBB (no collide), or 0x01RRGGBB (collides).
uint32_t bg_collides_default; uint32_t bg_collides_default;
// bitmap support. if we support bitmaps, pixel_implementation will be a // bitmap support. if we support bitmaps, pixel_implementation will be a