mirror of https://github.com/aristocratos/btop.git
Fixed: Terminal resize warning getting stuck
This commit is contained in:
parent
ec4bc6823f
commit
c77aee2211
12
src/btop.cpp
12
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
|
//* Handler for SIGWINCH and general resizing events, does nothing if terminal hasn't been resized unless force=true
|
||||||
void term_resize(bool force) {
|
void term_resize(bool force) {
|
||||||
static atomic<bool> resizing (false);
|
static atomic<bool> resizing (false);
|
||||||
|
if (Input::polling) {
|
||||||
|
Global::resized = true;
|
||||||
|
Input::interrupt = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
atomic_lock lck(resizing, true);
|
atomic_lock lck(resizing, true);
|
||||||
if (auto refreshed = Term::refresh(true); refreshed or force) {
|
if (auto refreshed = Term::refresh(true); refreshed or force) {
|
||||||
if (force and refreshed) force = false;
|
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
|
<< 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)
|
<< "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;
|
<< "Width = " << min_size.at(0) << " Height = " << min_size.at(1) << flush;
|
||||||
while (not Term::refresh() and not Input::poll()) sleep_ms(10);
|
bool got_key = false;
|
||||||
if (Input::poll()) {
|
for (; not Term::refresh() and not got_key; got_key = Input::poll(10));
|
||||||
|
if (got_key) {
|
||||||
auto key = Input::get();
|
auto key = Input::get();
|
||||||
if (key == "q")
|
if (key == "q")
|
||||||
clean_quit(0);
|
clean_quit(0);
|
||||||
|
@ -899,7 +905,7 @@ int main(int argc, char **argv) {
|
||||||
else if (Global::should_sleep) { Global::should_sleep = false; _sleep(); }
|
else if (Global::should_sleep) { Global::should_sleep = false; _sleep(); }
|
||||||
|
|
||||||
//? Make sure terminal size hasn't changed (in case of SIGWINCH not working properly)
|
//? 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
|
//? Trigger secondary thread to redraw if terminal has been resized
|
||||||
if (Global::resized) {
|
if (Global::resized) {
|
||||||
|
|
|
@ -74,6 +74,7 @@ namespace Input {
|
||||||
};
|
};
|
||||||
|
|
||||||
std::atomic<bool> interrupt (false);
|
std::atomic<bool> interrupt (false);
|
||||||
|
std::atomic<bool> polling (false);
|
||||||
array<int, 2> mouse_pos;
|
array<int, 2> mouse_pos;
|
||||||
unordered_flat_map<string, Mouse_loc> mouse_mappings;
|
unordered_flat_map<string, Mouse_loc> mouse_mappings;
|
||||||
|
|
||||||
|
@ -133,6 +134,7 @@ namespace Input {
|
||||||
};
|
};
|
||||||
|
|
||||||
bool poll(int timeout) {
|
bool poll(int timeout) {
|
||||||
|
atomic_lock lck(polling);
|
||||||
if (timeout < 1) return InputThr::instance().avail() > 0;
|
if (timeout < 1) return InputThr::instance().avail() > 0;
|
||||||
while (timeout > 0) {
|
while (timeout > 0) {
|
||||||
if (interrupt) {
|
if (interrupt) {
|
||||||
|
|
|
@ -42,6 +42,7 @@ namespace Input {
|
||||||
extern unordered_flat_map<string, Mouse_loc> mouse_mappings;
|
extern unordered_flat_map<string, Mouse_loc> mouse_mappings;
|
||||||
|
|
||||||
extern atomic<bool> interrupt;
|
extern atomic<bool> interrupt;
|
||||||
|
extern atomic<bool> polling;
|
||||||
|
|
||||||
//* Mouse column and line position
|
//* Mouse column and line position
|
||||||
extern array<int, 2> mouse_pos;
|
extern array<int, 2> mouse_pos;
|
||||||
|
|
Loading…
Reference in New Issue