From b77e6bd99d1c7e9221fe8a4c34e187a4e1329a0a Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Wed, 14 Dec 2016 20:37:03 +0100 Subject: [PATCH] general: simplify the detection of a SIGWINCH There is no need for a counter, nor an old counter to compare it with. --- src/global.c | 4 ++-- src/nano.c | 5 ++++- src/proto.h | 2 +- src/winio.c | 21 ++++----------------- 4 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/global.c b/src/global.c index 77c8d842..a24c373f 100644 --- a/src/global.c +++ b/src/global.c @@ -29,8 +29,8 @@ /* Global variables. */ #ifndef NANO_TINY -volatile sig_atomic_t sigwinch_counter = 0; - /* Is incremented by the handler whenever a SIGWINCH occurs. */ +volatile sig_atomic_t the_window_resized = FALSE; + /* Set to TRUE by the handler whenever a SIGWINCH occurs. */ #endif #ifdef __linux__ diff --git a/src/nano.c b/src/nano.c index 02732238..efb43ea1 100644 --- a/src/nano.c +++ b/src/nano.c @@ -1289,7 +1289,7 @@ RETSIGTYPE do_continue(int signal) RETSIGTYPE handle_sigwinch(int signal) { /* Let the input routine know that a SIGWINCH has occurred. */ - sigwinch_counter++; + the_window_resized = TRUE; } /* Reinitialize and redraw the screen completely. */ @@ -1299,6 +1299,9 @@ void regenerate_screen(void) int fd, result = 0; struct winsize win; + /* Reset the trigger. */ + the_window_resized = FALSE; + if (tty == NULL) return; fd = open(tty, O_RDWR); diff --git a/src/proto.h b/src/proto.h index c4986810..a7fe3110 100644 --- a/src/proto.h +++ b/src/proto.h @@ -26,7 +26,7 @@ /* All external variables. See global.c for their descriptions. */ #ifndef NANO_TINY -extern volatile sig_atomic_t sigwinch_counter; +extern volatile sig_atomic_t the_window_resized; #endif #ifdef __linux__ diff --git a/src/winio.c b/src/winio.c index 5beec66d..7237b8ac 100644 --- a/src/winio.c +++ b/src/winio.c @@ -55,21 +55,6 @@ static bool seen_wide = FALSE; /* Whether we've seen a multicolumn character in the current line. */ #endif -#ifndef NANO_TINY -static sig_atomic_t last_sigwinch_counter = 0; - -/* Did we receive a SIGWINCH since we were last called? */ -bool the_window_resized(void) -{ - if (sigwinch_counter == last_sigwinch_counter) - return FALSE; - - last_sigwinch_counter = sigwinch_counter; - regenerate_screen(); - return TRUE; -} -#endif - /* Control character compatibility: * * - Ctrl-H is Backspace under ASCII, ANSI, VT100, and VT220. @@ -144,8 +129,9 @@ void get_key_buffer(WINDOW *win) input = wgetch(win); #ifndef NANO_TINY - if (the_window_resized()) { + if (the_window_resized) { ungetch(input); + regenerate_screen(); input = KEY_WINCH; } #endif @@ -162,7 +148,8 @@ void get_key_buffer(WINDOW *win) handle_hupterm(0); #ifndef NANO_TINY - if (the_window_resized()) { + if (the_window_resized) { + regenerate_screen(); input = KEY_WINCH; break; }