From 89f7d320b04423d8594fedf8bca66422240cc0a5 Mon Sep 17 00:00:00 2001 From: trilader Date: Wed, 2 Dec 2020 23:06:42 +0100 Subject: [PATCH] Add support for timeouts in tp_wait_for_event --- tui.cpp | 12 ++++++++++-- tui.h | 3 ++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/tui.cpp b/tui.cpp index 19e66b9..c70f010 100644 --- a/tui.cpp +++ b/tui.cpp @@ -41,6 +41,8 @@ static void convert_tp_event(void *, termpaint_event *tp_event) { } std::optional wait_for_event(termpaint_integration *integration, int timeout) { + const int cols = termpaint_surface_width(surface); + const int rows = termpaint_surface_height(surface); while (eventqueue.empty()) { bool ok = false; if(timeout > 0) @@ -49,8 +51,14 @@ std::optional wait_for_event(termpaint_integration *integration, int time ok = termpaintx_full_integration_do_iteration(integration); if (!ok) { return {}; // or some other error handling + } else if(cols != termpaint_surface_width(surface) || rows != termpaint_surface_height(surface)) { + Event e; + e.modifier = 0; + e.type = EV_RESIZE; + eventqueue.push_back(e); } else if(timeout == 0) { Event e; + e.modifier = 0; e.type = EV_TIMEOUT; eventqueue.push_back(e); } @@ -111,9 +119,9 @@ void tp_flush(const bool force) termpaint_terminal_flush(terminal, force); } -std::optional tp_wait_for_event() +std::optional tp_wait_for_event(int timeout) { - return wait_for_event(integration, 0); + return wait_for_event(integration, timeout); } static std::string repeated(const int n, const std::string &what) diff --git a/tui.h b/tui.h index 4d86f32..10d9c37 100644 --- a/tui.h +++ b/tui.h @@ -4,6 +4,7 @@ #include #define EV_TIMEOUT 0xffff #define EV_IGNORE 0xfffe +#define EV_RESIZE 0xfffd #include #include @@ -58,7 +59,7 @@ void tp_shutdown(); void tp_flush(const bool force=false); void tp_pause(); void tp_unpause(); -std::optional tp_wait_for_event(); +std::optional tp_wait_for_event(int timeout=0); struct action {