From e283eadffc2fbc7023a7e8ddc1f991ccc0a677a0 Mon Sep 17 00:00:00 2001 From: millert Date: Wed, 10 Mar 2021 20:16:08 +0000 Subject: [PATCH] Don't return ERR if resize didn't change size This is a backport of the ncurses 5.9 20120707 patch. Previously, getch() would return ERR if SIGWINCH was received but the window didn't actually change size. This can happen, for example, when the xterm font is changed. OK tb@ --- lib/libcurses/base/lib_set_term.c | 5 +++-- lib/libcurses/base/resizeterm.c | 8 +++++--- lib/libcurses/curs_getch.3 | 12 ++++++------ lib/libcurses/curses.priv.h | 5 +++-- lib/libcurses/resizeterm.3 | 6 ++---- lib/libcurses/tinfo/lib_setup.c | 9 ++++++--- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/lib/libcurses/base/lib_set_term.c b/lib/libcurses/base/lib_set_term.c index 0c4af8a2673..0c821fdb98d 100644 --- a/lib/libcurses/base/lib_set_term.c +++ b/lib/libcurses/base/lib_set_term.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_set_term.c,v 1.13 2010/01/12 23:22:06 nicm Exp $ */ +/* $OpenBSD: lib_set_term.c,v 1.14 2021/03/10 20:16:08 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * @@ -46,7 +46,7 @@ #include /* cur_term */ #include -MODULE_ID("$Id: lib_set_term.c,v 1.13 2010/01/12 23:22:06 nicm Exp $") +MODULE_ID("$Id: lib_set_term.c,v 1.14 2021/03/10 20:16:08 millert Exp $") NCURSES_EXPORT(SCREEN *) set_term(SCREEN *screenp) @@ -549,6 +549,7 @@ _nc_setupscreen(int slines GCC_UNUSED, #endif #if USE_SIZECHANGE SP->_resize = resizeterm; + SP->_ungetch = _nc_ungetch; #endif newscr->_clear = TRUE; diff --git a/lib/libcurses/base/resizeterm.c b/lib/libcurses/base/resizeterm.c index 8f8c7131b83..ac84a951b0d 100644 --- a/lib/libcurses/base/resizeterm.c +++ b/lib/libcurses/base/resizeterm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: resizeterm.c,v 1.3 2010/01/12 23:22:06 nicm Exp $ */ +/* $OpenBSD: resizeterm.c,v 1.4 2021/03/10 20:16:08 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * @@ -43,7 +43,7 @@ #include #include -MODULE_ID("$Id: resizeterm.c,v 1.3 2010/01/12 23:22:06 nicm Exp $") +MODULE_ID("$Id: resizeterm.c,v 1.4 2021/03/10 20:16:08 millert Exp $") #define stolen_lines (screen_lines - SP->_lines_avail) @@ -420,7 +420,6 @@ resizeterm(int ToLines, int ToCols) result = resize_term(ToLines, ToCols); #if USE_SIGWINCH - _nc_ungetch(SP, KEY_RESIZE); /* so application can know this */ clearok(curscr, TRUE); /* screen contents are unknown */ /* ripped-off lines are a special case: if we did not lengthen @@ -451,6 +450,9 @@ resizeterm(int ToLines, int ToCols) } #endif } +#if USE_SIGWINCH + _nc_ungetch(SP, KEY_RESIZE); /* so application can know this */ +#endif } returnCode(result); diff --git a/lib/libcurses/curs_getch.3 b/lib/libcurses/curs_getch.3 index 136bb73cf85..3d07208b35f 100644 --- a/lib/libcurses/curs_getch.3 +++ b/lib/libcurses/curs_getch.3 @@ -1,5 +1,5 @@ '\" t -.\" $OpenBSD: curs_getch.3,v 1.4 2019/02/13 07:18:57 nicm Exp $ +.\" $OpenBSD: curs_getch.3,v 1.5 2021/03/10 20:16:08 millert Exp $ .\" .\"*************************************************************************** .\" Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * @@ -29,7 +29,7 @@ .\" authorization. * .\"*************************************************************************** .\" -.\" $Id: curs_getch.3,v 1.4 2019/02/13 07:18:57 nicm Exp $ +.\" $Id: curs_getch.3,v 1.5 2021/03/10 20:16:08 millert Exp $ .TH curs_getch 3 "" .na .hy 0 @@ -236,14 +236,14 @@ See \fBresizeterm\fR(3) for more details about \fBKEY_RESIZE\fP, and All routines return the integer \fBERR\fR upon failure and an integer value other than \fBERR\fR (\fBOK\fR in the case of ungetch()) upon successful completion. -.RS +.RS 3 .TP 5 \fBungetch\fP -returns an error +returns ERR if there is no more room in the FIFO. -.TP 5 +.TP \fBwgetch\fP -returns an error +returns ERR if the window pointer is null, or if its timeout expires without having any data. .RE diff --git a/lib/libcurses/curses.priv.h b/lib/libcurses/curses.priv.h index 334bbe0cf37..95c1b9a8837 100644 --- a/lib/libcurses/curses.priv.h +++ b/lib/libcurses/curses.priv.h @@ -1,4 +1,4 @@ -/* $OpenBSD: curses.priv.h,v 1.34 2010/09/06 17:26:17 nicm Exp $ */ +/* $OpenBSD: curses.priv.h,v 1.35 2021/03/10 20:16:08 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * @@ -36,7 +36,7 @@ /* - * $Id: curses.priv.h,v 1.34 2010/09/06 17:26:17 nicm Exp $ + * $Id: curses.priv.h,v 1.35 2021/03/10 20:16:08 millert Exp $ * * curses.priv.h * @@ -895,6 +895,7 @@ struct screen { */ #if USE_SIZECHANGE int (*_resize)(int,int); + int (*_ungetch)(SCREEN *, int); #endif /* diff --git a/lib/libcurses/resizeterm.3 b/lib/libcurses/resizeterm.3 index 7b500cc8695..6d2bd228694 100644 --- a/lib/libcurses/resizeterm.3 +++ b/lib/libcurses/resizeterm.3 @@ -1,4 +1,4 @@ -.\" $OpenBSD: resizeterm.3,v 1.5 2010/01/12 23:21:59 nicm Exp $ +.\" $OpenBSD: resizeterm.3,v 1.6 2021/03/10 20:16:08 millert Exp $ .\" .\"*************************************************************************** .\" Copyright (c) 1998-2003,2005 Free Software Foundation, Inc. * @@ -30,7 +30,7 @@ .\" .\" Author: Thomas E. Dickey 1996-2005 .\" -.\" $Id: resizeterm.3,v 1.5 2010/01/12 23:21:59 nicm Exp $ +.\" $Id: resizeterm.3,v 1.6 2021/03/10 20:16:08 millert Exp $ .TH resizeterm 3 "" .SH NAME \fBis_term_resized\fR, @@ -88,8 +88,6 @@ this overrides the library's use of the window size obtained from the operating system. Thus, even if a SIGWINCH is received, no screen size change may be recorded. -In that case, no \fBKEY_RESIZE\fP is queued for the next call to \fBgetch\fP; -an \fBERR\fP will be returned instead. .SH SEE ALSO \fBwresize\fR(3). .SH AUTHOR diff --git a/lib/libcurses/tinfo/lib_setup.c b/lib/libcurses/tinfo/lib_setup.c index 63643848a29..e6552263a44 100644 --- a/lib/libcurses/tinfo/lib_setup.c +++ b/lib/libcurses/tinfo/lib_setup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lib_setup.c,v 1.12 2010/01/12 23:22:06 nicm Exp $ */ +/* $OpenBSD: lib_setup.c,v 1.13 2021/03/10 20:16:08 millert Exp $ */ /**************************************************************************** * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. * @@ -55,7 +55,7 @@ #include /* lines, columns, cur_term */ -MODULE_ID("$Id: lib_setup.c,v 1.12 2010/01/12 23:22:06 nicm Exp $") +MODULE_ID("$Id: lib_setup.c,v 1.13 2021/03/10 20:16:08 millert Exp $") /**************************************************************************** * @@ -321,8 +321,11 @@ _nc_update_screensize(SCREEN *sp) */ if (sp != 0 && sp->_resize != 0) { - if ((new_lines != old_lines) || (new_cols != old_cols)) + if ((new_lines != old_lines) || (new_cols != old_cols)) { sp->_resize(new_lines, new_cols); + } else if (sp->_sig_winch && (sp->_ungetch != 0)) { + sp->_ungetch(SP, KEY_RESIZE); /* so application can know this */ + } sp->_sig_winch = FALSE; } } -- 2.20.1