rain(6): Update the "rainable area" upon SIGWINCH

This makes sure rain falls to fill the entire window even if the window
grows in size.
This commit is contained in:
charlotte 2024-02-28 23:24:52 +00:00
parent 433cbeabe6
commit 3b25eeee74
1 changed files with 19 additions and 7 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: rain.c,v 1.23 2024/02/28 23:14:37 charlotte Exp $ */ /* $NetBSD: rain.c,v 1.24 2024/02/28 23:24:52 charlotte Exp $ */
/* /*
* Copyright (c) 1980, 1993 * Copyright (c) 1980, 1993
@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 1993\
#if 0 #if 0
static char sccsid[] = "@(#)rain.c 8.1 (Berkeley) 5/31/93"; static char sccsid[] = "@(#)rain.c 8.1 (Berkeley) 5/31/93";
#else #else
__RCSID("$NetBSD: rain.c,v 1.23 2024/02/28 23:14:37 charlotte Exp $"); __RCSID("$NetBSD: rain.c,v 1.24 2024/02/28 23:24:52 charlotte Exp $");
#endif #endif
#endif /* not lint */ #endif /* not lint */
@ -59,8 +59,11 @@ __RCSID("$NetBSD: rain.c,v 1.23 2024/02/28 23:14:37 charlotte Exp $");
#include <limits.h> #include <limits.h>
static volatile sig_atomic_t sig_caught = 0; static volatile sig_atomic_t sig_caught = 0;
static long cols;
static long lines;
int main(int, char **); int main(int, char **);
static void winupdate(void);
static void onsig(int); static void onsig(int);
@ -68,7 +71,6 @@ int
main(int argc, char **argv) main(int argc, char **argv)
{ {
int x, y, j; int x, y, j;
long cols, lines;
unsigned int delay = 120000; unsigned int delay = 120000;
unsigned long val = 0; unsigned long val = 0;
int ch; int ch;
@ -95,10 +97,7 @@ main(int argc, char **argv)
if (!initscr()) if (!initscr())
errx(0, "couldn't initialize screen"); errx(0, "couldn't initialize screen");
cols = COLS - 4; winupdate();
lines = LINES - 4;
if (cols == 0) cols++;
if (lines == 0) lines++;
(void)signal(SIGHUP, onsig); (void)signal(SIGHUP, onsig);
(void)signal(SIGINT, onsig); (void)signal(SIGINT, onsig);
@ -114,6 +113,10 @@ main(int argc, char **argv)
(void)endwin(); (void)endwin();
exit(0); exit(0);
} }
if (is_term_resized(LINES, COLS)) {
resizeterm(LINES, COLS);
winupdate();
}
x = random() % cols + 2; x = random() % cols + 2;
y = random() % lines + 2; y = random() % lines + 2;
(void)mvaddch(y, x, '.'); (void)mvaddch(y, x, '.');
@ -147,6 +150,15 @@ main(int argc, char **argv)
} }
} }
static void
winupdate(void)
{
cols = COLS - 4;
lines = LINES - 4;
if (cols == 0) cols++;
if (lines == 0) lines++;
}
/* ARGSUSED */ /* ARGSUSED */
static void static void
onsig(int dummy __unused) onsig(int dummy __unused)