From c69849ffb15a8c03b7c80d7785d4d965c4a24cea Mon Sep 17 00:00:00 2001 From: nick black Date: Mon, 4 Oct 2021 01:48:50 -0400 Subject: [PATCH] track unknown background color if we can't learn it #2226 --- src/info/main.c | 10 +++++++--- src/lib/render.c | 3 ++- src/lib/termdesc.c | 11 +++++++---- src/lib/termdesc.h | 3 ++- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/src/info/main.c b/src/info/main.c index 8771398bb..bab26c7cb 100644 --- a/src/info/main.c +++ b/src/info/main.c @@ -337,9 +337,13 @@ display_logo(struct ncplane* n, const char* path){ static void tinfo_debug_bitmaps(struct ncplane* n, const tinfo* ti, const char* indent){ - ncplane_printf(n, "%sdefbg 0x%06lx %sconsidered transparent", indent, - ti->bg_collides_default & 0xfffffful, - (ti->bg_collides_default & 0x01000000) ? "" : "not "); + if(!(ti->bg_collides_default & 0x80000000)){ + ncplane_printf(n, "%sdefbg 0x%06lx %sconsidered transparent", indent, + ti->bg_collides_default & 0xfffffful, + (ti->bg_collides_default & 0x01000000) ? "" : "not "); + }else{ + ncplane_printf(n, "couldn't detect default background"); + } finish_line(n); ncpixelimpl_e blit = notcurses_check_pixel_support(ncplane_notcurses(n)); switch(blit){ diff --git a/src/lib/render.c b/src/lib/render.c index 43888bc7c..4ae582854 100644 --- a/src/lib/render.c +++ b/src/lib/render.c @@ -146,6 +146,7 @@ static uint32_t highcontrast(const tinfo* ti, uint32_t bchannel){ unsigned r, g, b; if(ncchannel_default_p(bchannel)){ + // FIXME what if we couldn't identify the background color? r = ncchannel_r(ti->bg_collides_default); g = ncchannel_g(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. // If it doesn't work, eh, it doesn't work. Fuck the world; save yourself. if(ti->caps.rgb){ - if(ti->bg_collides_default){ + if((ti->bg_collides_default & 0xff000000) == 0x01000000){ if((r == (ti->bg_collides_default & 0xff0000lu)) && (g == (ti->bg_collides_default & 0xff00lu)) && (b == (ti->bg_collides_default & 0xfflu))){ diff --git a/src/lib/termdesc.c b/src/lib/termdesc.c index d6ed8a591..1b30e14dd 100644 --- a/src/lib/termdesc.c +++ b/src/lib/termdesc.c @@ -721,6 +721,7 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut } *cursor_x = *cursor_y = -1; memset(ti, 0, sizeof(*ti)); + ti->bg_collides_default = 0xfe000000; 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); @@ -951,7 +952,11 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut ti->cellpixy = ti->pixy / ti->default_rows; 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 if((kitty_graphics = iresp->kitty_graphics) == 0){ 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; } free(iresp); - } - if(nocbreak){ - if(ti->ttyfd >= 0){ + if(nocbreak){ // FIXME do this in input later, upon signaling completion? if(tcsetattr(ti->ttyfd, TCSANOW, ti->tpreserved)){ goto err; diff --git a/src/lib/termdesc.h b/src/lib/termdesc.h index 6119319f5..686d3d2f6 100644 --- a/src/lib/termdesc.h +++ b/src/lib/termdesc.h @@ -112,7 +112,8 @@ typedef struct tinfo { // kitty interprets an RGB background that matches the default background // color *as* the default background, meaning it'll be translucent if // 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; // bitmap support. if we support bitmaps, pixel_implementation will be a