From 5e572d3d5f2581d14c29bd0071c6be0d7fbdce5e Mon Sep 17 00:00:00 2001 From: PatR Date: Thu, 19 Sep 2024 01:41:24 -0700 Subject: [PATCH] fix part of github issue #1285 - cursed curses Issue reported by g-branden-robinson: vertical status panel ended up with an extra closing paren on the energy line, and sometimes popups left some text and/or border to the right of the map. I haven't been able to reproduce the energy anomaly. It is possible that it is dependent on the version of curses. This fixes the leftover popup traces that the base window catches (and hangs onto) when there is extra space to the right of the map. Erasing a popup prior to deleting it suffices to make base window forget it. I have a more elaborate fix that covers the space to the right of the map, when there is some, with an extra window and erases that window when refreshing the map. It works but adds a bunch of code that we can get by without. Issue #1285 is still open. --- doc/fixes3-7-0.txt | 3 +++ win/curses/curswins.c | 26 ++++++++++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/doc/fixes3-7-0.txt b/doc/fixes3-7-0.txt index 113b9875e..4a4615960 100644 --- a/doc/fixes3-7-0.txt +++ b/doc/fixes3-7-0.txt @@ -2192,6 +2192,9 @@ curses: allow changing default colors with the 'palette' config option curses: if messages have been issued during start-up (for instance, warnings about issues in run-time config file), prompt user to press so that they can be read before curses erases the screen +curses: when the map was narrower than the space set aside for it, wide popup + windows could write into the unused space and whatever was written + there would stick after the popup was removed documentation: when building plain text Guidebook.txt from Guidebook.mn, avoid attempting to use CR font; change doesn't affect building Guidebook.ps which utilizes CR to get various instances of fixed-width text diff --git a/win/curses/curswins.c b/win/curses/curswins.c index 0bc7507b6..381153cb9 100644 --- a/win/curses/curswins.c +++ b/win/curses/curswins.c @@ -199,6 +199,27 @@ curses_set_wid_colors(int wid, WINDOW *win) void curses_destroy_win(WINDOW *win) { + int mapwidth = 0, winwidth, dummyht; + + /* + * In case map is narrower than the space alloted for it, if we + * are destroying a popup window and it is wider than the map, + * erase the popup first. It probably has overwritten some of + * the next-to-map empty space. If we don't clear that now, the + * base window will remember it and redisplay it during refreshes. + * + * Note: since we almost never destroy non-popups, we don't really + * need to determine whether 'win' is one. Overhead for unnecessary + * erasure is negligible. + */ + getmaxyx(win, dummyht, winwidth); /* macro, assigns to its args */ + if (mapwin) + getmaxyx(mapwin, dummyht, mapwidth); + if (winwidth > mapwidth) { + werase(win); + wnoutrefresh(win); + } + delwin(win); if (win == activemenu) activemenu = NULL; @@ -329,8 +350,9 @@ curses_parse_wid_colors(int wid, char *fg, char *bg) /* Add curses window pointer and window info to list for given NetHack winid */ void -curses_add_nhwin(winid wid, int height, int width, int y, int x, - orient orientation, boolean border) +curses_add_nhwin( + winid wid, int height, int width, int y, int x, + orient orientation, boolean border) { WINDOW *win; int real_width = width;