From 9502fcea80045ad3cb2d867673d7425d7c10c597 Mon Sep 17 00:00:00 2001 From: nick black Date: Tue, 5 Oct 2021 05:44:39 -0400 Subject: [PATCH] [tcache] always track most recent cell geometry #2233 --- src/lib/notcurses.c | 32 +++++++++++++------------------- src/lib/termdesc.c | 4 ++++ src/lib/termdesc.h | 8 ++++++++ 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/lib/notcurses.c b/src/lib/notcurses.c index 707d396ed..6e247aa9e 100644 --- a/src/lib/notcurses.c +++ b/src/lib/notcurses.c @@ -259,19 +259,20 @@ int update_term_dimensions(int* rows, int* cols, tinfo* tcache, int margin_b){ } return 0; } + int rowsafe, colsafe; + if(rows == NULL){ + rows = &rowsafe; + } + if(cols == NULL){ + cols = &colsafe; + } #ifndef __MINGW64__ struct winsize ws; if(tiocgwinsz(tcache->ttyfd, &ws)){ return -1; } - int rowsafe; - if(rows == NULL){ - rows = &rowsafe; - } *rows = ws.ws_row; - if(cols){ - *cols = ws.ws_col; - } + *cols = ws.ws_col; if(tcache){ #ifdef __linux__ if(tcache->linux_fb_fd >= 0){ @@ -296,21 +297,14 @@ int update_term_dimensions(int* rows, int* cols, tinfo* tcache, int margin_b){ #else CONSOLE_SCREEN_BUFFER_INFO csbi; if(GetConsoleScreenBufferInfo(tcache->outhandle, &csbi)){ - if(cols){ - *cols = csbi.srWindow.Right - csbi.srWindow.Left + 1; - } - if(rows){ - *rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; - } + *cols = csbi.srWindow.Right - csbi.srWindow.Left + 1; + *rows = csbi.srWindow.Bottom - csbi.srWindow.Top + 1; }else{ - if(rows){ - *rows = tcache->default_rows; - } - if(cols){ - *cols = tcache->default_cols; - } + *rows = tcache->default_rows; + *cols = tcache->default_cols; } #endif + update_tinfo_geometry(tcache, *rows, *cols); if(tcache->sixel_maxy_pristine){ int sixelrows = *rows - 1; // if the bottom margin is at least one row, we can draw into the last diff --git a/src/lib/termdesc.c b/src/lib/termdesc.c index 1b30e14dd..2c0f3d7b7 100644 --- a/src/lib/termdesc.c +++ b/src/lib/termdesc.c @@ -41,6 +41,8 @@ get_default_geometry(tinfo* ti){ loginfo("Default geometry: %d row%s, %d column%s\n", ti->default_rows, ti->default_rows != 1 ? "s" : "", ti->default_cols, ti->default_cols != 1 ? "s" : ""); + ti->dimy = ti->default_rows; + ti->dimx = ti->default_cols; } // we found Sixel support -- set up its API. invert80 refers to whether the @@ -943,6 +945,8 @@ int interrogate_terminfo(tinfo* ti, const char* termtype, FILE* out, unsigned ut // random transient measurement? ti->default_rows = iresp->dimy; ti->default_cols = iresp->dimx; + ti->dimy = iresp->dimy; + ti->dimx = iresp->dimx; } if(iresp->pixy && iresp->pixx){ ti->pixy = iresp->pixy; diff --git a/src/lib/termdesc.h b/src/lib/termdesc.h index 686d3d2f6..f5b47b658 100644 --- a/src/lib/termdesc.h +++ b/src/lib/termdesc.h @@ -106,6 +106,7 @@ typedef struct tinfo { // be acquired on all terminals with pixel support. int cellpixy; // cell pixel height, might be 0 int cellpixx; // cell pixel width, might be 0 + int dimy, dimx; // most recent cell geometry unsigned supported_styles; // bitmask over NCSTYLE_* driven via sgr/ncv @@ -189,6 +190,13 @@ typedef struct tinfo { bool in_alt_screen; // are we in the alternate screen? } tinfo; +static inline void +update_tinfo_geometry(tinfo* ti, int dimy, int dimx){ + // FIXME probably need a lock on this! + ti->dimy = dimy; + ti->dimx = dimx; +} + // retrieve the terminfo(5)-style escape 'e' from tdesc (NULL if undefined). static inline __attribute__ ((pure)) const char* get_escape(const tinfo* tdesc, escape_e e){