Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libcurses Add KEY_RESIZE support and a SIGWINCH handler.
details: https://anonhg.NetBSD.org/src/rev/98583c5b1947
branches: trunk
changeset: 559713:98583c5b1947
user: jdc <jdc%NetBSD.org@localhost>
date: Mon Mar 22 18:57:10 2004 +0000
description:
Add KEY_RESIZE support and a SIGWINCH handler.
Fixes PR bin/20032.
This requires a change to KEY_MAX, which affects libform and libmenu, so we
need to change libcurses major number.
diffstat:
lib/libcurses/curses_input.3 | 12 ++++-
lib/libcurses/curses_screen.3 | 21 ++++++++--
lib/libcurses/getch.c | 29 +++++++++++++-
lib/libcurses/screen.c | 6 ++-
lib/libcurses/tstp.c | 83 ++++++++++++++++++++++++++++++++++++++----
5 files changed, 131 insertions(+), 20 deletions(-)
diffs (truncated from 341 to 300 lines):
diff -r 1431aec5651d -r 98583c5b1947 lib/libcurses/curses_input.3
--- a/lib/libcurses/curses_input.3 Mon Mar 22 18:36:14 2004 +0000
+++ b/lib/libcurses/curses_input.3 Mon Mar 22 18:57:10 2004 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: curses_input.3,v 1.14 2004/03/16 19:25:05 snj Exp $
+.\" $NetBSD: curses_input.3,v 1.15 2004/03/22 18:57:10 jdc Exp $
.\"
.\" Copyright (c) 2002
.\" Brett Lymn (blymn%NetBSD.org@localhost, brett_lymn%yahoo.com.au@localhost)
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\"
-.Dd June 13, 2003
+.Dd February 24, 2004
.Dt CURSES_INPUT 3
.Os
.Sh NAME
@@ -112,6 +112,12 @@
then
.Fn getch
will assemble multi-character key sequences into key symbols,
+If the terminal is resized,
+.Fn getch
+will return
+.Dv KEY_RESIZE ,
+regardlesss of the setting of
+.Fn keypad .
Calling
.Fn getch
will cause an implicit
@@ -123,7 +129,7 @@
.Fn wgetch
function is the same as the
.Fn getch
-function, except that it reads from the input file descriptor associated
+function, excepting that it reads from the input file descriptor associated
with the window specified by
.Fa win .
.Pp
diff -r 1431aec5651d -r 98583c5b1947 lib/libcurses/curses_screen.3
--- a/lib/libcurses/curses_screen.3 Mon Mar 22 18:36:14 2004 +0000
+++ b/lib/libcurses/curses_screen.3 Mon Mar 22 18:57:10 2004 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: curses_screen.3,v 1.10 2004/03/16 19:26:18 snj Exp $
+.\" $NetBSD: curses_screen.3,v 1.11 2004/03/22 18:57:10 jdc Exp $
.\"
.\" Copyright (c) 2002
.\" Brett Lymn (blymn%NetBSD.org@localhost, brett_lymn%yahoo.com.au@localhost)
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\"
-.Dd April 8, 2003
+.Dd February 24, 2004
.Dt CURSES_SCREEN 3
.Os
.Sh NAME
@@ -111,7 +111,7 @@
which saves the current terminal state and sets up the terminal and
internal data structures to support the curses application.
This
-function call must be, with few exceptions, the first curses library
+function call must be, with few exceptions, the first Curses library
call made.
The exception to this rule is the
.Fn newterm
@@ -128,6 +128,18 @@
.Va COLS
are set, then these will be used instead.
.Pp
+When either
+.Fn newterm ,
+or
+.Fn initscr
+are called, the Curses library sets up signal handlers for
+.Dv SIGTSTP
+and
+.Dv SIGWINCH .
+If a signal handler is already installed for
+.Dv SIGWINCH ,
+this will also be called when the Curses library handler is called.
+.Pp
The
.Fn isendwin
function can be used to determine whether or not a refresh of the
@@ -168,7 +180,8 @@
.Sh SEE ALSO
.Xr curses_window 3 ,
.Xr tty 4 ,
-.Xr termcap 5
+.Xr termcap 5 ,
+.Xr signal 7
.Sh STANDARDS
The
.Nx
diff -r 1431aec5651d -r 98583c5b1947 lib/libcurses/getch.c
--- a/lib/libcurses/getch.c Mon Mar 22 18:36:14 2004 +0000
+++ b/lib/libcurses/getch.c Mon Mar 22 18:57:10 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getch.c,v 1.43 2004/03/16 07:44:31 jdc Exp $ */
+/* $NetBSD: getch.c,v 1.44 2004/03/22 18:57:10 jdc Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94";
#else
-__RCSID("$NetBSD: getch.c,v 1.43 2004/03/16 07:44:31 jdc Exp $");
+__RCSID("$NetBSD: getch.c,v 1.44 2004/03/22 18:57:10 jdc Exp $");
#endif
#endif /* not lint */
@@ -599,7 +599,15 @@
if (state == INKEY_NORM) {
if (delay && __timeout(delay) == ERR)
return ERR;
- if ((c = getchar()) == EOF) {
+ c = getchar();
+ if (_cursesi_screen->resized) {
+ if (c != -1)
+ ungetch(c);
+ _cursesi_screen->resized = 0;
+ clearerr(infd);
+ return KEY_RESIZE;
+ }
+ if (c == EOF) {
clearerr(infd);
return ERR;
}
@@ -640,6 +648,13 @@
}
c = getchar();
+ if (_cursesi_screen->resized) {
+ if (c != -1)
+ ungetch(c);
+ _cursesi_screen->resized = 0;
+ clearerr(infd);
+ return KEY_RESIZE;
+ }
if (ferror(infd)) {
clearerr(infd);
return ERR;
@@ -891,6 +906,14 @@
}
c = getchar();
+ if (_cursesi_screen->resized) {
+ if (c != -1)
+ ungetch(c);
+ _cursesi_screen->resized = 0;
+ clearerr(infd);
+ __restore_termios();
+ return KEY_RESIZE;
+ }
if (feof(infd)) {
clearerr(infd);
__restore_termios();
diff -r 1431aec5651d -r 98583c5b1947 lib/libcurses/screen.c
--- a/lib/libcurses/screen.c Mon Mar 22 18:36:14 2004 +0000
+++ b/lib/libcurses/screen.c Mon Mar 22 18:57:10 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: screen.c,v 1.15 2003/08/07 16:44:24 agc Exp $ */
+/* $NetBSD: screen.c,v 1.16 2004/03/22 18:57:10 jdc Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)screen.c 8.2 (blymn) 11/27/2001";
#else
-__RCSID("$NetBSD: screen.c,v 1.15 2003/08/07 16:44:24 agc Exp $");
+__RCSID("$NetBSD: screen.c,v 1.16 2004/03/22 18:57:10 jdc Exp $");
#endif
#endif /* not lint */
@@ -131,6 +131,7 @@
new_screen->curwin = 0;
new_screen->notty = FALSE;
new_screen->half_delay = FALSE;
+ new_screen->resized = 0;
if (_cursesi_gettmode(new_screen) == ERR)
goto error_exit;
@@ -168,6 +169,7 @@
__init_acs(new_screen);
__set_stophandler();
+ __set_winchhandler();
/*
* bleh - it seems that apps expect the first newterm to set
diff -r 1431aec5651d -r 98583c5b1947 lib/libcurses/tstp.c
--- a/lib/libcurses/tstp.c Mon Mar 22 18:36:14 2004 +0000
+++ b/lib/libcurses/tstp.c Mon Mar 22 18:57:10 2004 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: tstp.c,v 1.30 2003/08/07 16:44:25 agc Exp $ */
+/* $NetBSD: tstp.c,v 1.31 2004/03/22 18:57:10 jdc Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@@ -34,10 +34,12 @@
#if 0
static char sccsid[] = "@(#)tstp.c 8.3 (Berkeley) 5/4/94";
#else
-__RCSID("$NetBSD: tstp.c,v 1.30 2003/08/07 16:44:25 agc Exp $");
+__RCSID("$NetBSD: tstp.c,v 1.31 2004/03/22 18:57:10 jdc Exp $");
#endif
#endif /* not lint */
+#include <sys/ioctl.h>
+
#include <errno.h>
#include <signal.h>
#include <termios.h>
@@ -46,6 +48,8 @@
#include "curses.h"
#include "curses_private.h"
+static struct sigaction otsa, owsa;
+
/*
* stop_signal_handler --
* Handle stop signals.
@@ -87,16 +91,17 @@
(void) sigprocmask(SIG_SETMASK, &oset, NULL);
}
-static void (*otstpfn)
-__P((int)) = SIG_DFL;
-
/*
* Set the TSTP handler.
*/
void
__set_stophandler(void)
{
- otstpfn = signal(SIGTSTP, __stop_signal_handler);
+ struct sigaction sa;
+ sa.sa_handler = __stop_signal_handler;
+ sa.sa_flags = SA_RESTART;
+ sigemptyset(&sa.sa_mask);
+ sigaction(SIGTSTP, &sa, &otsa);
}
/*
@@ -105,9 +110,54 @@
void
__restore_stophandler(void)
{
- (void) signal(SIGTSTP, otstpfn);
+ sigaction(SIGTSTP, &otsa, NULL);
}
+/*
+ * winch_signal_handler --
+ * Handle winch signals by pushing KEY_RESIZE into the input stream.
+ */
+void
+__winch_signal_handler(/*ARGSUSED*/int signo)
+{
+ struct winsize win;
+
+ if (ioctl(fileno(_cursesi_screen->outfd), TIOCGWINSZ, &win) != -1 &&
+ win.ws_row != 0 && win.ws_col != 0) {
+ LINES = win.ws_row;
+ COLS = win.ws_col;
+ }
+ /*
+ * If there was a previous handler, call that,
+ * otherwise tell getch() to send KEY_RESIZE.
+ */
+ if (owsa.sa_handler != __winch_signal_handler)
+ owsa.sa_handler(signo);
+ else
+ _cursesi_screen->resized = 1;
+}
+
+/*
+ * Set the WINCH handler.
+ */
+void
+__set_winchhandler(void)
+{
+ struct sigaction sa;
+ sa.sa_handler = __winch_signal_handler;
+ sa.sa_flags = 0;
+ sigemptyset(&sa.sa_mask);
+ sigaction(SIGWINCH, &sa, &owsa);
+}
+
+/*
+ * Restore the TSTP handler.
+ */
+void
+__restore_winchhandler(void)
+{
+ sigaction(SIGTSTP, &owsa, NULL);
Home |
Main Index |
Thread Index |
Old Index