mirror of
https://git.jabber.space/devs/cproof.git
synced 2026-07-20 16:26:22 +00:00
fix(editor): prevent UI redraw conflicts during editor suspend/resume
Guard against re-entrant editor launches, abort editor on Ctrl-Z, and centralize suspend-aware redraws through prof_doupdate() to prevent terminal corruption when SIGTSTP is received while editor is active. Removes SIGUSR1 editor escape in favor of standard pkill <editor> recovery.
This commit is contained in:
@@ -327,7 +327,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
|
||||
cons_show_incoming_message(display_name, num, chatwin->unread, window);
|
||||
|
||||
if (prefs_get_boolean(PREF_FLASH)) {
|
||||
flash();
|
||||
ui_flash();
|
||||
}
|
||||
|
||||
chatwin->unread++;
|
||||
@@ -364,7 +364,7 @@ chatwin_incoming_msg(ProfChatWin* chatwin, ProfMessage* message, gboolean win_cr
|
||||
wins_add_quotes_ac(window, message->plain, FALSE);
|
||||
|
||||
if (prefs_get_boolean(PREF_BEEP)) {
|
||||
beep();
|
||||
ui_beep();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,14 @@ static Display* display;
|
||||
|
||||
static void _ui_draw_term_title(void);
|
||||
|
||||
// Fail-safe gate: authoritative flag (doesn't depend on isendwin staying
|
||||
// TRUE), plus the regular endwin check for shutdown.
|
||||
static gboolean
|
||||
_ui_redraw_suspended(void)
|
||||
{
|
||||
return ui_suspended || isendwin();
|
||||
}
|
||||
|
||||
static void
|
||||
_ui_close(void)
|
||||
{
|
||||
@@ -120,8 +129,7 @@ ui_sigwinch_handler(int sig)
|
||||
void
|
||||
ui_update(void)
|
||||
{
|
||||
// UI is suspended
|
||||
if (isendwin()) {
|
||||
if (_ui_redraw_suspended()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -138,7 +146,7 @@ ui_update(void)
|
||||
title_bar_update_virtual();
|
||||
status_bar_draw();
|
||||
inp_put_back();
|
||||
doupdate();
|
||||
prof_doupdate();
|
||||
|
||||
if (perform_resize) {
|
||||
perform_resize = FALSE;
|
||||
@@ -180,21 +188,49 @@ void
|
||||
ui_suspend(void)
|
||||
{
|
||||
inp_suspend();
|
||||
// Flush before flipping the flag (prof_doupdate skips while suspended).
|
||||
prof_doupdate();
|
||||
ui_suspended = TRUE;
|
||||
endwin();
|
||||
}
|
||||
|
||||
void
|
||||
ui_resume(void)
|
||||
{
|
||||
ui_suspended = FALSE;
|
||||
clearok(stdscr, TRUE); // ncurses can't see vim's screen clobber
|
||||
refresh();
|
||||
inp_resume();
|
||||
}
|
||||
|
||||
void
|
||||
ui_beep(void)
|
||||
{
|
||||
if (!isendwin()) {
|
||||
beep();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ui_flash(void)
|
||||
{
|
||||
if (!isendwin()) {
|
||||
flash();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
prof_doupdate(void)
|
||||
{
|
||||
if (!_ui_redraw_suspended()) {
|
||||
doupdate();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ui_resize(void)
|
||||
{
|
||||
// UI is suspended
|
||||
if (isendwin()) {
|
||||
if (_ui_redraw_suspended()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -216,8 +252,7 @@ ui_resize(void)
|
||||
void
|
||||
ui_redraw(void)
|
||||
{
|
||||
// UI is suspended
|
||||
if (isendwin()) {
|
||||
if (_ui_redraw_suspended()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -182,7 +182,11 @@ inp_readline(void)
|
||||
{
|
||||
// UI is suspended
|
||||
if (is_suspended || isendwin()) {
|
||||
// Mirror the normal-path unlock so workers aren't starved
|
||||
// for the whole editor session.
|
||||
pthread_mutex_unlock(&lock);
|
||||
g_usleep(100000); // 100ms
|
||||
pthread_mutex_lock(&lock);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -311,11 +315,13 @@ inp_get_line(void)
|
||||
werase(inp_win);
|
||||
wmove(inp_win, 0, 0);
|
||||
_inp_win_update_virtual();
|
||||
doupdate();
|
||||
prof_doupdate();
|
||||
char* line = NULL;
|
||||
while (!line) {
|
||||
line = inp_readline();
|
||||
ui_update();
|
||||
while (g_main_context_iteration(NULL, FALSE)) // non-blocking; bounded by ready sources
|
||||
;
|
||||
}
|
||||
status_bar_clear_prompt();
|
||||
return line;
|
||||
@@ -338,12 +344,14 @@ inp_get_password(void)
|
||||
werase(inp_win);
|
||||
wmove(inp_win, 0, 0);
|
||||
_inp_win_update_virtual();
|
||||
doupdate();
|
||||
prof_doupdate();
|
||||
char* password = NULL;
|
||||
get_password = TRUE;
|
||||
while (!password) {
|
||||
password = inp_readline();
|
||||
ui_update();
|
||||
while (g_main_context_iteration(NULL, FALSE)) // non-blocking; bounded by ready sources
|
||||
;
|
||||
}
|
||||
get_password = FALSE;
|
||||
status_bar_clear_prompt();
|
||||
@@ -459,7 +467,7 @@ _inp_write(char* line, int offset)
|
||||
_inp_win_handle_scroll();
|
||||
|
||||
_inp_win_update_virtual();
|
||||
doupdate();
|
||||
prof_doupdate();
|
||||
}
|
||||
|
||||
static int
|
||||
|
||||
@@ -57,7 +57,7 @@ privwin_incoming_msg(ProfPrivateWin* privatewin, ProfMessage* message)
|
||||
privatewin->unread++;
|
||||
|
||||
if (prefs_get_boolean(PREF_FLASH)) {
|
||||
flash();
|
||||
ui_flash();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ privwin_incoming_msg(ProfPrivateWin* privatewin, ProfMessage* message)
|
||||
wins_add_quotes_ac(window, message->plain, TRUE);
|
||||
|
||||
if (prefs_get_boolean(PREF_BEEP)) {
|
||||
beep();
|
||||
ui_beep();
|
||||
}
|
||||
|
||||
if (notify) {
|
||||
|
||||
@@ -43,6 +43,9 @@ void ui_load_colours(void);
|
||||
void ui_update(void);
|
||||
void ui_redraw(void);
|
||||
void ui_resize(void);
|
||||
// doupdate() wrapper that skips when the UI is suspended. Use this instead
|
||||
// of raw doupdate() to avoid the per-site whitelist class of bug.
|
||||
void prof_doupdate(void);
|
||||
void ui_focus_win(ProfWin* window);
|
||||
void ui_sigwinch_handler(int sig);
|
||||
void ui_handle_otr_error(const char* const barejid, const char* const message);
|
||||
@@ -84,6 +87,8 @@ void ui_handle_recipient_error(const char* const recipient, const char* const er
|
||||
void ui_handle_error(const char* const err_msg);
|
||||
void ui_clear_win_title(void);
|
||||
void ui_goodbye_title(void);
|
||||
void ui_beep(void);
|
||||
void ui_flash(void);
|
||||
void ui_handle_room_configuration_form_error(const char* const roomjid, const char* const message);
|
||||
void ui_handle_room_config_submit_result(const char* const roomjid);
|
||||
void ui_handle_room_config_submit_result_error(const char* const roomjid, const char* const message);
|
||||
|
||||
Reference in New Issue
Block a user