From: Timo Korvola Date: Tue, 6 Feb 2018 22:25:46 +0000 (+0200) Subject: Better method for row shrinking. X-Git-Url: https://scope-eye.net/git/?a=commitdiff_plain;h=caa87d389822e85ea34abeb6940d36c40a9ec9f0;p=liskon_frotz.git Better method for row shrinking. Shrink the screen so that the cursor will normally be on the last row. #42: Handle terminal resizing --- 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);