Change the method by which we determine our terminal size has changed to be less confusing and more responsive.

This commit is contained in:
casey langen 2020-12-31 14:28:09 -08:00
parent 585e996098
commit ce562a1d13

View File

@ -63,7 +63,6 @@ using namespace std::chrono;
static OverlayStack overlays; static OverlayStack overlays;
static bool disconnected = false; static bool disconnected = false;
static int64_t resizeAt = 0;
static App* instance = nullptr; static App* instance = nullptr;
@ -72,11 +71,6 @@ static void hangupHandler(int signal) {
disconnected = true; disconnected = true;
} }
static void resizedHandler(int signal) {
endwin(); /* required in *nix because? */
resizeAt = App::Now() + REDRAW_DEBOUNCE_MS;
}
static std::string getEnvironmentVariable(const std::string& name) { static std::string getEnvironmentVariable(const std::string& name) {
std::string result; std::string result;
const char* value = std::getenv(name.c_str()); const char* value = std::getenv(name.c_str());
@ -254,7 +248,6 @@ App::App(const std::string& title) {
win32::ConfigureDpiAwareness(); win32::ConfigureDpiAwareness();
#else #else
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
std::signal(SIGWINCH, resizedHandler);
std::signal(SIGHUP, hangupHandler); std::signal(SIGHUP, hangupHandler);
std::signal(SIGPIPE, SIG_IGN); std::signal(SIGPIPE, SIG_IGN);
this->colorMode = Colors::Palette; this->colorMode = Colors::Palette;
@ -506,6 +499,8 @@ void App::Run(ILayoutPtr layout) {
this->state.input = nullptr; this->state.input = nullptr;
this->state.keyHandler = nullptr; this->state.keyHandler = nullptr;
int lastWidth = Screen::GetWidth();
int lastHeight = Screen::GetHeight();
this->ChangeLayout(layout); this->ChangeLayout(layout);
@ -553,9 +548,6 @@ process:
else if (kn == this->quitKey) { /* ctrl+d quits */ else if (kn == this->quitKey) { /* ctrl+d quits */
this->quit = true; this->quit = true;
} }
else if (kn == "KEY_RESIZE") {
resizeAt = App::Now() + REDRAW_DEBOUNCE_MS;
}
else if (this->mouseEnabled && kn == "KEY_MOUSE") { else if (this->mouseEnabled && kn == "KEY_MOUSE") {
#ifdef WIN32 #ifdef WIN32
if (nc_getmouse(&rawMouseEvent) == 0) { if (nc_getmouse(&rawMouseEvent) == 0) {
@ -592,9 +584,10 @@ process:
} }
} }
/* KEY_RESIZE often gets called dozens of times, so we debounce the if (lastWidth != Screen::GetWidth() || lastHeight != Screen::GetHeight()) {
actual resize until its settled. */ lastWidth = Screen::GetWidth();
if (resizeAt && App::Now() > resizeAt) { lastHeight = Screen::GetHeight();
resize_term(0, 0); resize_term(0, 0);
Window::InvalidateScreen(); Window::InvalidateScreen();
@ -604,8 +597,6 @@ process:
} }
this->OnResized(); this->OnResized();
resizeAt = 0;
} }
this->CheckShowOverlay(); this->CheckShowOverlay();