From caa87d389822e85ea34abeb6940d36c40a9ec9f0 Mon Sep 17 00:00:00 2001 From: Timo Korvola Date: Wed, 7 Feb 2018 00:25:46 +0200 Subject: [PATCH] Better method for row shrinking. Shrink the screen so that the cursor will normally be on the last row. #42: Handle terminal resizing --- src/curses/ux_screen.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/curses/ux_screen.c b/src/curses/ux_screen.c index 35ef0cb..a469f35 100644 --- a/src/curses/ux_screen.c +++ b/src/curses/ux_screen.c @@ -211,20 +211,15 @@ void unix_resize_display(void) endwin(); refresh(); unix_get_terminal_size(); - if (lines > h_screen_rows) { - /* Lose some of the topmost lines that won't fit. */ - int lost = lines - h_screen_rows; - /* Don't lose the cursor position though, - drop some trailing lines instead. */ - if (y < lost) - lost = y; lines = h_screen_rows; - y -= lost; - pos += cols * lost; + if (y >= h_screen_rows) { + /* Lose some topmost lines to keep the cursor on screen. */ + int lost = y + 1 - h_screen_rows; + y = h_screen_rows - 1; + pos += cols * lost; + } } - if (y >= h_screen_rows) - y = h_screen_rows - 1; if (x >= h_screen_cols) x = h_screen_cols - 1; restore_screen(lines, cols, pos); -- 2.34.1