diff options
author | John Ferguson <j-n-f@users.noreply.github.com> | 2021-04-25 13:39:52 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-25 19:39:52 +0200 |
commit | 71970fa73cdcf760499274fc9666611272cd62bf (patch) | |
tree | 264c9704ca86c827ace0c3dfa499034d0a22588d | |
parent | 295663fc1cbfe2be5c501f9f819bdb29208aed0a (diff) |
Fix overflow errors and allow small terminal sizes (#473)
* In #259 users request the ability to have ncmpcpp remain open when the
terminal has a small size. Previously ncmpcpp would exit when there
were less than 30 columns or 5 rows.
* After removing this constraint, ncmpcpp would freeze when terminal
sizes went below those thresholds.
* Upon debugging, it became clear that ncmpcpp wasn't frozen, it was
stuck in a very long for loop because it thought the display was
unreasonably large (resulting from integer overflow).
* Preventing that overflow allows ncmpcpp to handle small sizes
gracefully. No other changes to the rendering code were necessary.
Fixes #259
-rw-r--r-- | src/actions.cpp | 14 | ||||
-rw-r--r-- | src/curses/window.cpp | 9 |
2 files changed, 6 insertions, 17 deletions
diff --git a/src/actions.cpp b/src/actions.cpp index 70fb97ff..9bcb15ec 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -124,18 +124,6 @@ size_t HeaderHeight; size_t FooterHeight; size_t FooterStartY; -void validateScreenSize() -{ - using Global::MainHeight; - - if (COLS < 30 || MainHeight < 5) - { - NC::destroyScreen(); - std::cout << "Screen is too small to handle ncmpcpp correctly\n"; - exit(1); - } -} - void initializeScreens() { myHelp = new Help; @@ -221,8 +209,6 @@ void resizeScreen(bool reload_main_window) MainHeight = std::max(LINES-(Config.design == Design::Alternative ? 7 : 4), 0); - validateScreenSize(); - if (!Config.header_visibility) MainHeight += 2; if (!Config.statusbar_visibility) diff --git a/src/curses/window.cpp b/src/curses/window.cpp index 231e36a6..d3f9efd6 100644 --- a/src/curses/window.cpp +++ b/src/curses/window.cpp @@ -682,13 +682,16 @@ void Window::moveTo(size_t new_x, size_t new_y) void Window::adjustDimensions(size_t width, size_t height) { + // NOTE: when dimensions get small, integer overflow will cause calls to + // `Menu<T>::refresh()` to run for a very long time. + if (m_border) { - width -= 2; - height -= 2; + width -= width >= 2 ? 2 : 0; + height -= height >= 2 ? 2 : 0; } if (!m_title.empty()) - height -= 2; + height -= height >= 2 ? 2 : 0; m_height = height; m_width = width; } |