Module Name: src
Committed By: charlotte
Date: Wed Feb 28 23:24:52 UTC 2024
Modified Files:
src/games/rain: rain.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/games/rain/rain.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/games/rain/rain.c
diff -u src/games/rain/rain.c:1.23 src/games/rain/rain.c:1.24
--- src/games/rain/rain.c:1.23 Wed Feb 28 23:14:37 2024
+++ src/games/rain/rain.c Wed Feb 28 23:24:52 2024
@@ -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
@@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1980, 19
#if 0
static char sccsid[] = "@(#)rain.c 8.1 (Berkeley) 5/31/93";
#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 /* not lint */
@@ -59,8 +59,11 @@ __RCSID("$NetBSD: rain.c,v 1.23 2024/02/
#include <limits.h>
static volatile sig_atomic_t sig_caught = 0;
+static long cols;
+static long lines;
int main(int, char **);
+static void winupdate(void);
static void onsig(int);
@@ -68,7 +71,6 @@ int
main(int argc, char **argv)
{
int x, y, j;
- long cols, lines;
unsigned int delay = 120000;
unsigned long val = 0;
int ch;
@@ -95,10 +97,7 @@ main(int argc, char **argv)
if (!initscr())
errx(0, "couldn't initialize screen");
- cols = COLS - 4;
- lines = LINES - 4;
- if (cols == 0) cols++;
- if (lines == 0) lines++;
+ winupdate();
(void)signal(SIGHUP, onsig);
(void)signal(SIGINT, onsig);
@@ -114,6 +113,10 @@ main(int argc, char **argv)
(void)endwin();
exit(0);
}
+ if (is_term_resized(LINES, COLS)) {
+ resizeterm(LINES, COLS);
+ winupdate();
+ }
x = random() % cols + 2;
y = random() % lines + 2;
(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 */
static void
onsig(int dummy __unused)