general: simplify the detection of a SIGWINCH
There is no need for a counter, nor an old counter to compare it with.master
parent
2bcc6d7f66
commit
b77e6bd99d
|
@ -29,8 +29,8 @@
|
||||||
|
|
||||||
/* Global variables. */
|
/* Global variables. */
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
volatile sig_atomic_t sigwinch_counter = 0;
|
volatile sig_atomic_t the_window_resized = FALSE;
|
||||||
/* Is incremented by the handler whenever a SIGWINCH occurs. */
|
/* Set to TRUE by the handler whenever a SIGWINCH occurs. */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
|
@ -1289,7 +1289,7 @@ RETSIGTYPE do_continue(int signal)
|
||||||
RETSIGTYPE handle_sigwinch(int signal)
|
RETSIGTYPE handle_sigwinch(int signal)
|
||||||
{
|
{
|
||||||
/* Let the input routine know that a SIGWINCH has occurred. */
|
/* Let the input routine know that a SIGWINCH has occurred. */
|
||||||
sigwinch_counter++;
|
the_window_resized = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Reinitialize and redraw the screen completely. */
|
/* Reinitialize and redraw the screen completely. */
|
||||||
|
@ -1299,6 +1299,9 @@ void regenerate_screen(void)
|
||||||
int fd, result = 0;
|
int fd, result = 0;
|
||||||
struct winsize win;
|
struct winsize win;
|
||||||
|
|
||||||
|
/* Reset the trigger. */
|
||||||
|
the_window_resized = FALSE;
|
||||||
|
|
||||||
if (tty == NULL)
|
if (tty == NULL)
|
||||||
return;
|
return;
|
||||||
fd = open(tty, O_RDWR);
|
fd = open(tty, O_RDWR);
|
||||||
|
|
|
@ -26,7 +26,7 @@
|
||||||
|
|
||||||
/* All external variables. See global.c for their descriptions. */
|
/* All external variables. See global.c for their descriptions. */
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
extern volatile sig_atomic_t sigwinch_counter;
|
extern volatile sig_atomic_t the_window_resized;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
|
21
src/winio.c
21
src/winio.c
|
@ -55,21 +55,6 @@ static bool seen_wide = FALSE;
|
||||||
/* Whether we've seen a multicolumn character in the current line. */
|
/* Whether we've seen a multicolumn character in the current line. */
|
||||||
#endif
|
#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:
|
/* Control character compatibility:
|
||||||
*
|
*
|
||||||
* - Ctrl-H is Backspace under ASCII, ANSI, VT100, and VT220.
|
* - Ctrl-H is Backspace under ASCII, ANSI, VT100, and VT220.
|
||||||
|
@ -144,8 +129,9 @@ void get_key_buffer(WINDOW *win)
|
||||||
input = wgetch(win);
|
input = wgetch(win);
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (the_window_resized()) {
|
if (the_window_resized) {
|
||||||
ungetch(input);
|
ungetch(input);
|
||||||
|
regenerate_screen();
|
||||||
input = KEY_WINCH;
|
input = KEY_WINCH;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -162,7 +148,8 @@ void get_key_buffer(WINDOW *win)
|
||||||
handle_hupterm(0);
|
handle_hupterm(0);
|
||||||
|
|
||||||
#ifndef NANO_TINY
|
#ifndef NANO_TINY
|
||||||
if (the_window_resized()) {
|
if (the_window_resized) {
|
||||||
|
regenerate_screen();
|
||||||
input = KEY_WINCH;
|
input = KEY_WINCH;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue