nano-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nano-devel] [PATCH] general: simplify the detection of a SIGWINCH


From: Benno Schulenberg
Subject: [Nano-devel] [PATCH] general: simplify the detection of a SIGWINCH
Date: Wed, 14 Dec 2016 21:16:07 +0100

---
 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 0727c61e..4fec8062 100644
--- a/src/nano.c
+++ b/src/nano.c
@@ -1300,7 +1300,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. */
@@ -1310,6 +1310,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 7dd423eb..be05cbab 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 80be167d..2f8e2a6d 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,7 +129,8 @@ void get_key_buffer(WINDOW *win)
     input = wgetch(win);
 
 #ifndef NANO_TINY
-    if (the_window_resized()) {
+    if (the_window_resized) {
+       regenerate_screen();
        ungetch(input);
        input = KEY_WINCH;
     }
@@ -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;
        }
-- 
2.11.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]