diff --git a/src/btop.cpp b/src/btop.cpp index 02367d2..69bb96c 100644 --- a/src/btop.cpp +++ b/src/btop.cpp @@ -157,6 +157,11 @@ void argumentParser(const int& argc, char **argv) { //* Handler for SIGWINCH and general resizing events, does nothing if terminal hasn't been resized unless force=true void term_resize(bool force) { static atomic resizing (false); + if (Input::polling) { + Global::resized = true; + Input::interrupt = true; + return; + } atomic_lock lck(resizing, true); if (auto refreshed = Term::refresh(true); refreshed or force) { if (force and refreshed) force = false; @@ -182,8 +187,9 @@ void term_resize(bool force) { << Mv::to((Term::height / 2) + 1, (Term::width / 2) - 12) << Global::fg_white << "Needed for current config:" << Mv::to((Term::height / 2) + 2, (Term::width / 2) - 10) << "Width = " << min_size.at(0) << " Height = " << min_size.at(1) << flush; - while (not Term::refresh() and not Input::poll()) sleep_ms(10); - if (Input::poll()) { + bool got_key = false; + for (; not Term::refresh() and not got_key; got_key = Input::poll(10)); + if (got_key) { auto key = Input::get(); if (key == "q") clean_quit(0); @@ -899,7 +905,7 @@ int main(int argc, char **argv) { else if (Global::should_sleep) { Global::should_sleep = false; _sleep(); } //? Make sure terminal size hasn't changed (in case of SIGWINCH not working properly) - term_resize(); + term_resize(Global::resized); //? Trigger secondary thread to redraw if terminal has been resized if (Global::resized) { diff --git a/src/btop_input.cpp b/src/btop_input.cpp index 14cbbe3..0694340 100644 --- a/src/btop_input.cpp +++ b/src/btop_input.cpp @@ -74,6 +74,7 @@ namespace Input { }; std::atomic interrupt (false); + std::atomic polling (false); array mouse_pos; unordered_flat_map mouse_mappings; @@ -133,6 +134,7 @@ namespace Input { }; bool poll(int timeout) { + atomic_lock lck(polling); if (timeout < 1) return InputThr::instance().avail() > 0; while (timeout > 0) { if (interrupt) { diff --git a/src/btop_input.hpp b/src/btop_input.hpp index fdcf6e2..7342709 100644 --- a/src/btop_input.hpp +++ b/src/btop_input.hpp @@ -42,6 +42,7 @@ namespace Input { extern unordered_flat_map mouse_mappings; extern atomic interrupt; + extern atomic polling; //* Mouse column and line position extern array mouse_pos;