commit b77e6bd99d1c7e9221fe8a4c34e187a4e1329a0a
parent 2bcc6d7f6696fcb6799ea64389b944d61fa0c3e4
Author: Benno Schulenberg <bensberg@justemail.net>
Date: Wed, 14 Dec 2016 20:37:03 +0100
general: simplify the detection of a SIGWINCH
There is no need for a counter, nor an old counter to compare it with.
Diffstat:
4 files changed, 11 insertions(+), 21 deletions(-)
diff --git 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
@@ -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
@@ -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
@@ -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;
}