From 394df6d391046869da0e2c620c1a7edea2df1d52 Mon Sep 17 00:00:00 2001 From: "jabber.developer2" Date: Wed, 27 May 2026 22:00:18 +0300 Subject: [PATCH] fix(ui): add authoritative suspend flag gating redraws over the editor Builds on the upstream "guard terminal writes while suspended" fix. That fix keeps isendwin() a valid "suspended" signal by guarding stray writes (_inp_write, beep, flash) so the existing isendwin() checks in ui_update/ui_resize/ui_redraw hold. That is correct but fail-open: any future unguarded doupdate()/refresh() reachable during an editor session clears isendwin() and the ~10Hz ui_update() repaints over the editor again (the original bug class). Track suspension explicitly with a ui_suspended flag set in ui_suspend()/ui_resume() and gate the three redraw entry points on ui_suspended || isendwin() via _ui_redraw_suspended(). The flag is set exactly at the suspend/resume boundary, so the dominant repaint path fails safe regardless of isendwin() flapping. isendwin() is kept in the condition for the shutdown/closed-screen case. --- src/ui/core.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/ui/core.c b/src/ui/core.c index f67df803..93d240cd 100644 --- a/src/ui/core.c +++ b/src/ui/core.c @@ -54,6 +54,7 @@ static int inp_size; static gboolean perform_resize = FALSE; +static gboolean ui_suspended = FALSE; static GTimer* ui_idle_time; static WINDOW* main_scr; @@ -63,6 +64,16 @@ static Display* display; static void _ui_draw_term_title(void); +// Skip drawing while an external editor is active (ui_suspended) or after the +// screen has been closed (endwin). The flag is authoritative and does not rely +// on isendwin() staying TRUE, which a stray doupdate() during the session could +// otherwise clear. +static gboolean +_ui_redraw_suspended(void) +{ + return ui_suspended || isendwin(); +} + static void _ui_close(void) { @@ -120,8 +131,7 @@ ui_sigwinch_handler(int sig) void ui_update(void) { - // UI is suspended - if (isendwin()) { + if (_ui_redraw_suspended()) { return; } @@ -179,6 +189,7 @@ ui_reset_idle_time(void) void ui_suspend(void) { + ui_suspended = TRUE; inp_suspend(); doupdate(); endwin(); @@ -187,6 +198,7 @@ ui_suspend(void) void ui_resume(void) { + ui_suspended = FALSE; refresh(); inp_resume(); } @@ -210,8 +222,7 @@ ui_flash(void) void ui_resize(void) { - // UI is suspended - if (isendwin()) { + if (_ui_redraw_suspended()) { return; } @@ -233,8 +244,7 @@ ui_resize(void) void ui_redraw(void) { - // UI is suspended - if (isendwin()) { + if (_ui_redraw_suspended()) { return; }