From 694a0c133f6fb3bc5c92966a30c6f75af77fad82 Mon Sep 17 00:00:00 2001 From: nick black Date: Thu, 8 Apr 2021 01:15:18 -0400 Subject: [PATCH] [terminfo] only interrogate for sixel when pixel geometry is defined #1511 #1506 --- src/lib/debug.c | 2 +- src/lib/terminfo.c | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/src/lib/debug.c b/src/lib/debug.c index 64e64de3e..667444e66 100644 --- a/src/lib/debug.c +++ b/src/lib/debug.c @@ -20,7 +20,7 @@ tinfo_debug_caps(const tinfo* ti, FILE* debugfp, int rows, int cols, indent, capyn(ti->sgr), capyn(ti->sgr0)); fprintf(debugfp, "%sop: %c fgop: %c bgop: %c\n", indent, capyn(ti->op), capyn(ti->fgop), capyn(ti->bgop)); - fprintf(debugfp, "%srows: %u cols: %u rpix: %u cpix: %u (%dx%d)\n", + fprintf(debugfp, "%srows: %u cols: %u rpx: %u cpx: %u (%dx%d)\n", indent, rows, cols, ti->cellpixy, ti->cellpixx, rows * ti->cellpixy, cols * ti->cellpixx); if(!ti->pixel_query_done){ fprintf(debugfp, "%sno bitmap graphics information yet\n", indent); diff --git a/src/lib/terminfo.c b/src/lib/terminfo.c index 02039edc4..14b1e8ab7 100644 --- a/src/lib/terminfo.c +++ b/src/lib/terminfo.c @@ -372,6 +372,9 @@ query_sixel(tinfo* ti, int fd){ } // fd must be a real terminal. uses the query lock of |ti| to only act once. +// we ought already have performed a TIOCGWINSZ ioctl() to verify that the +// terminal reports cell area in pixels, as that's necessary for our use of +// sixel (or any other bitmap protocol). int query_term(tinfo* ti, int fd){ if(fd < 0){ return -1; @@ -383,16 +386,22 @@ int query_term(tinfo* ti, int fd){ int ret = 0; pthread_mutex_lock(&ti->pixel_query); if(!ti->pixel_query_done){ - if(flags & O_NONBLOCK){ - fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); - } - ret = query_sixel(ti, fd); - ti->pixel_query_done = true; - if(ti->sixel_supported){ - ti->pixel_init(fd); - } - if(flags & O_NONBLOCK){ - fcntl(fd, F_SETFL, flags); + // if the terminal reported 0 pixels for cell dimensions, bypass any + // interrogation, and assume no bitmap support. + if(!ti->cellpixx || !ti->cellpixy){ + ti->pixel_query_done = true; + }else{ + if(flags & O_NONBLOCK){ + fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); + } + ret = query_sixel(ti, fd); + ti->pixel_query_done = true; + if(ti->sixel_supported){ + ti->pixel_init(fd); + } + if(flags & O_NONBLOCK){ + fcntl(fd, F_SETFL, flags); + } } } pthread_mutex_unlock(&ti->pixel_query);