Module Name: src Committed By: martin Date: Thu Oct 4 10:20:13 UTC 2018
Modified Files: src/lib/libcurses [netbsd-8]: curses_private.h curses_screen.3 fileio.c initscr.c newwin.c resize.c ripoffline.c screen.c setterm.c Log Message: Pull up following revision(s) (requested by roy in ticket #1047): lib/libcurses/curses_private.h: revision 1.64 lib/libcurses/curses_private.h: revision 1.65 lib/libcurses/initscr.c: revision 1.33 lib/libcurses/curses_screen.3: revision 1.24 lib/libcurses/curses_screen.3: revision 1.25 lib/libcurses/newwin.c: revision 1.52 lib/libcurses/fileio.c: revision 1.6 lib/libcurses/ripoffline.c: revision 1.4 lib/libcurses/resize.c: revision 1.28 lib/libcurses/ripoffline.c: revision 1.5 lib/libcurses/resize.c: revision 1.29 lib/libcurses/screen.c: revision 1.34 lib/libcurses/setterm.c: revision 1.67 curses: fix ripoffline When creating stdscr, ensure it's placed and sized in accordance with lines ripped off. LINES is no longer adjusted for lines ripped off. POSIX makes no mention that it should be adjusted. Bottom lines are now placed correctly. Lines ripped off are now displayed after calling initscr. ok kamil@ Fixes PR #53635 - curses: resize ripped off windows The application must still redraw them though. - Fix typos in curses_screen.3 Fn -> Ft in the resize_term(3) prototype funcion -> function To generate a diff of this commit: cvs rdiff -u -r1.62.4.1 -r1.62.4.2 src/lib/libcurses/curses_private.h cvs rdiff -u -r1.23 -r1.23.4.1 src/lib/libcurses/curses_screen.3 cvs rdiff -u -r1.5 -r1.5.6.1 src/lib/libcurses/fileio.c cvs rdiff -u -r1.32 -r1.32.6.1 src/lib/libcurses/initscr.c cvs rdiff -u -r1.50 -r1.50.6.1 src/lib/libcurses/newwin.c cvs rdiff -u -r1.26.4.1 -r1.26.4.2 src/lib/libcurses/resize.c cvs rdiff -u -r1.3 -r1.3.6.1 src/lib/libcurses/ripoffline.c cvs rdiff -u -r1.33 -r1.33.4.1 src/lib/libcurses/screen.c cvs rdiff -u -r1.66 -r1.66.4.1 src/lib/libcurses/setterm.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libcurses/curses_private.h diff -u src/lib/libcurses/curses_private.h:1.62.4.1 src/lib/libcurses/curses_private.h:1.62.4.2 --- src/lib/libcurses/curses_private.h:1.62.4.1 Thu Sep 27 15:12:15 2018 +++ src/lib/libcurses/curses_private.h Thu Oct 4 10:20:12 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: curses_private.h,v 1.62.4.1 2018/09/27 15:12:15 martin Exp $ */ +/* $NetBSD: curses_private.h,v 1.62.4.2 2018/10/04 10:20:12 martin Exp $ */ /*- * Copyright (c) 1998-2000 Brett Lymn @@ -368,7 +368,7 @@ void __cursesi_chtype_to_cchar(chtype, c int __fgetc_resize(FILE *); int __unget(wint_t); int __mvcur(int, int, int, int, int); -WINDOW *__newwin(SCREEN *, int, int, int, int, int); +WINDOW *__newwin(SCREEN *, int, int, int, int, int, int); int __nodelay(void); int __notimeout(void); void __restartwin(void); @@ -378,9 +378,10 @@ void __restore_meta_state(void); void __restore_termios(void); void __restore_stophandler(void); void __restore_winchhandler(void); -int __ripoffscreen(SCREEN *, int *); -void __ripoffresize(SCREEN *); -int __rippedlines(const SCREEN *); +int __ripoffscreen(SCREEN *); +int __ripoffresize(SCREEN *); +void __ripofftouch(SCREEN *); +int __rippedlines(const SCREEN *, int); void __save_termios(void); void __set_color(WINDOW *win, attr_t attr); void __set_stophandler(void); Index: src/lib/libcurses/curses_screen.3 diff -u src/lib/libcurses/curses_screen.3:1.23 src/lib/libcurses/curses_screen.3:1.23.4.1 --- src/lib/libcurses/curses_screen.3:1.23 Tue Jan 24 16:45:41 2017 +++ src/lib/libcurses/curses_screen.3 Thu Oct 4 10:20:12 2018 @@ -1,4 +1,4 @@ -.\" $NetBSD: curses_screen.3,v 1.23 2017/01/24 16:45:41 roy Exp $ +.\" $NetBSD: curses_screen.3,v 1.23.4.1 2018/10/04 10:20:12 martin Exp $ .\" .\" Copyright (c) 2002 .\" Brett Lymn (bl...@netbsd.org, brett_l...@yahoo.com.au) @@ -30,7 +30,7 @@ .\" SUCH DAMAGE. .\" .\" -.Dd January 24, 2017 +.Dd October 2, 2018 .Dt CURSES_SCREEN 3 .Os .Sh NAME @@ -74,7 +74,7 @@ .Fn isendwin "void" .Ft bool .Fn is_term_resized "int lines" "int cols" -.Fn int +.Ft int .Fn resize_term "int lines" "int cols" .Ft int .Fn resizeterm "int lines" "int cols" @@ -216,7 +216,7 @@ Set lines equal to 1. .Pp The .Fn ripoffline -funcion will rip a line from +function will rip a line from .Dv stdscr at the top if .Fa line @@ -239,8 +239,6 @@ or .Xr doupdate 3 , but may call .Xr wnoutrefresh 3 . -.Dv LINES -will be reduced by the total number of lines ripped off. .Fn ripoffline can be called up to five times. .Pp Index: src/lib/libcurses/fileio.c diff -u src/lib/libcurses/fileio.c:1.5 src/lib/libcurses/fileio.c:1.5.6.1 --- src/lib/libcurses/fileio.c:1.5 Sat Oct 22 21:55:06 2016 +++ src/lib/libcurses/fileio.c Thu Oct 4 10:20:12 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: fileio.c,v 1.5 2016/10/22 21:55:06 christos Exp $ */ +/* $NetBSD: fileio.c,v 1.5.6.1 2018/10/04 10:20:12 martin Exp $ */ /*- * Copyright (c) 2008 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: fileio.c,v 1.5 2016/10/22 21:55:06 christos Exp $"); +__RCSID("$NetBSD: fileio.c,v 1.5.6.1 2018/10/04 10:20:12 martin Exp $"); #endif /* not lint */ #include "curses.h" @@ -195,7 +195,7 @@ getwin(FILE *fp) if (fread(wtmp, sizeof(WINDOW), 1, fp) != 1) goto error0; win = __newwin(_cursesi_screen, wtmp->maxy, wtmp->maxx, - wtmp->begy, wtmp->begx, FALSE); + wtmp->begy, wtmp->begx, FALSE, FALSE); if (win == NULL) goto error0; win->cury = wtmp->cury; Index: src/lib/libcurses/initscr.c diff -u src/lib/libcurses/initscr.c:1.32 src/lib/libcurses/initscr.c:1.32.6.1 --- src/lib/libcurses/initscr.c:1.32 Wed Jan 11 17:15:27 2017 +++ src/lib/libcurses/initscr.c Thu Oct 4 10:20:12 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: initscr.c,v 1.32 2017/01/11 17:15:27 roy Exp $ */ +/* $NetBSD: initscr.c,v 1.32.6.1 2018/10/04 10:20:12 martin Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)initscr.c 8.2 (Berkeley) 5/4/94"; #else -__RCSID("$NetBSD: initscr.c,v 1.32 2017/01/11 17:15:27 roy Exp $"); +__RCSID("$NetBSD: initscr.c,v 1.32.6.1 2018/10/04 10:20:12 martin Exp $"); #endif #endif /* not lint */ @@ -70,6 +70,7 @@ initscr(void) set_term(_cursesi_screen); wrefresh(curscr); + __ripofftouch(_cursesi_screen); return stdscr; } Index: src/lib/libcurses/newwin.c diff -u src/lib/libcurses/newwin.c:1.50 src/lib/libcurses/newwin.c:1.50.6.1 --- src/lib/libcurses/newwin.c:1.50 Fri Jan 6 13:53:18 2017 +++ src/lib/libcurses/newwin.c Thu Oct 4 10:20:12 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: newwin.c,v 1.50 2017/01/06 13:53:18 roy Exp $ */ +/* $NetBSD: newwin.c,v 1.50.6.1 2018/10/04 10:20:12 martin Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)newwin.c 8.3 (Berkeley) 7/27/94"; #else -__RCSID("$NetBSD: newwin.c,v 1.50 2017/01/06 13:53:18 roy Exp $"); +__RCSID("$NetBSD: newwin.c,v 1.50.6.1 2018/10/04 10:20:12 martin Exp $"); #endif #endif /* not lint */ @@ -85,7 +85,8 @@ dupwin(WINDOW *win) WINDOW *new_one; if ((new_one = __newwin(_cursesi_screen, win->maxy, win->maxx, - win->begy, win->begx, FALSE)) == NULL) + win->begy, win->begx, FALSE, + win == stdscr ? TRUE : FALSE)) == NULL) return NULL; overwrite(win, new_one); @@ -100,7 +101,7 @@ WINDOW * newwin(int nlines, int ncols, int by, int bx) { - return __newwin(_cursesi_screen, nlines, ncols, by, bx, FALSE); + return __newwin(_cursesi_screen, nlines, ncols, by, bx, FALSE, FALSE); } /* @@ -113,22 +114,29 @@ newpad(int nlines, int ncols) if (nlines < 1 || ncols < 1) return NULL; - return __newwin(_cursesi_screen, nlines, ncols, 0, 0, TRUE); + return __newwin(_cursesi_screen, nlines, ncols, 0, 0, TRUE, FALSE); } WINDOW * -__newwin(SCREEN *screen, int nlines, int ncols, int by, int bx, int ispad) +__newwin(SCREEN *screen, int nlines, int ncols, int by, int bx, int ispad, + int isstdscr) { WINDOW *win; __LINE *lp; int i, j; - int maxy, maxx; + int ry, maxy, maxx; __LDATA *sp; if (by < 0 || bx < 0) return NULL; - maxy = nlines > 0 ? nlines : LINES - by + nlines; + if (isstdscr) { + ry = __rippedlines(screen, -1); + by += __rippedlines(screen, 1); + } else + ry = 0; + + maxy = nlines > 0 ? nlines : LINES - by - ry + nlines; maxx = ncols > 0 ? ncols : COLS - bx + ncols; if ((win = __makenew(screen, maxy, maxx, by, bx, 0, ispad)) == NULL) Index: src/lib/libcurses/resize.c diff -u src/lib/libcurses/resize.c:1.26.4.1 src/lib/libcurses/resize.c:1.26.4.2 --- src/lib/libcurses/resize.c:1.26.4.1 Wed Oct 3 17:49:06 2018 +++ src/lib/libcurses/resize.c Thu Oct 4 10:20:12 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: resize.c,v 1.26.4.1 2018/10/03 17:49:06 martin Exp $ */ +/* $NetBSD: resize.c,v 1.26.4.2 2018/10/04 10:20:12 martin Exp $ */ /* * Copyright (c) 2001 @@ -40,7 +40,7 @@ #if 0 static char sccsid[] = "@(#)resize.c blymn 2001/08/26"; #else -__RCSID("$NetBSD: resize.c,v 1.26.4.1 2018/10/03 17:49:06 martin Exp $"); +__RCSID("$NetBSD: resize.c,v 1.26.4.2 2018/10/04 10:20:12 martin Exp $"); #endif #endif /* not lint */ @@ -176,10 +176,7 @@ resizeterm(int nlines, int ncols) clearok(curscr, TRUE); if (result == OK) { - /* We know how to repaint the ripoffs */ - __ripoffresize(_cursesi_screen); - - /* We do need to reposition our slks. */ + /* Redraw the soft label keys to the new size. */ __slk_resize(_cursesi_screen, ncols); __slk_noutrefresh(_cursesi_screen); } @@ -209,21 +206,16 @@ resize_term(int nlines, int ncols) return ERR; if (__resizeterm(__virtscr, nlines, ncols) == ERR) return ERR; - rlines = nlines - __rippedlines(_cursesi_screen); + rlines = nlines - __rippedlines(_cursesi_screen, 0); if (__resizeterm(stdscr, rlines, ncols) == ERR) return ERR; _cursesi_screen->LINES = nlines; _cursesi_screen->COLS = ncols; - LINES = rlines; + LINES = nlines; COLS = ncols; - if (_cursesi_screen->slk_window != NULL && - __resizewin(_cursesi_screen->slk_window, - _cursesi_screen->slk_window->reqy, ncols) == ERR) - return ERR; - - /* tweak the flags now that we have updated the LINES and COLS */ + /* tweak the flags now that we have updated the LINES and COLS */ for (list = _cursesi_screen->winlistp; list != NULL; list = list->nextp) { win = list->winp; @@ -231,6 +223,10 @@ resize_term(int nlines, int ncols) __swflags(win); } + /* Resize and re-position the ripped off windows. */ + if (__ripoffresize(_cursesi_screen) == ERR) + return ERR; + return OK; } Index: src/lib/libcurses/ripoffline.c diff -u src/lib/libcurses/ripoffline.c:1.3 src/lib/libcurses/ripoffline.c:1.3.6.1 --- src/lib/libcurses/ripoffline.c:1.3 Tue Jan 24 17:27:30 2017 +++ src/lib/libcurses/ripoffline.c Thu Oct 4 10:20:12 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: ripoffline.c,v 1.3 2017/01/24 17:27:30 roy Exp $ */ +/* $NetBSD: ripoffline.c,v 1.3.6.1 2018/10/04 10:20:12 martin Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -31,7 +31,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: ripoffline.c,v 1.3 2017/01/24 17:27:30 roy Exp $"); +__RCSID("$NetBSD: ripoffline.c,v 1.3.6.1 2018/10/04 10:20:12 martin Exp $"); #endif /* not lint */ #include "curses.h" @@ -54,7 +54,7 @@ ripoffline(int line, int (*init)(WINDOW { #ifdef DEBUG - __CTRACE(__CTRACE_SCREEN, "ripoffline: %d\n", line); + __CTRACE(__CTRACE_WINDOW, "ripoffline: %d\n", line); #endif if (nrips >= MAX_RIPS || init == NULL) @@ -71,16 +71,16 @@ ripoffline(int line, int (*init)(WINDOW * Returns the number of ripped lines from the screen. */ int -__rippedlines(const SCREEN *screen) +__rippedlines(const SCREEN *screen, int line) { const struct __ripoff *rip; int i, n; n = 0; for (i = 0, rip = screen->ripped; i < screen->nripped; i++, rip++) { - if (rip->nlines < 0) + if (line < 1 && rip->nlines < 0) n += -rip->nlines; - else + else if (line > 0 && rip->nlines > 0) n += rip->nlines; } return n; @@ -93,38 +93,40 @@ __rippedlines(const SCREEN *screen) * this implemenation allows for N lines if needed. */ int -__ripoffscreen(SCREEN *screen, int *rtop) +__ripoffscreen(SCREEN *screen) { - int i, nlines; + int i, nlines, rbot, rtop; const struct ripoff *srip; struct __ripoff *rip; WINDOW *w; - *rtop = 0; rip = screen->ripped; + rbot = LINES; + rtop = 0; for (i = 0, srip = ripoffs; i < nrips; i++, srip++) { if (srip->nlines == 0) continue; nlines = srip->nlines < 0 ? -srip->nlines : srip->nlines; w = __newwin(screen, nlines, 0, - srip->nlines < 0 ? LINES - nlines : *rtop, - 0, FALSE); + srip->nlines < 0 ? rbot - nlines : rtop, + 0, FALSE, FALSE); if (w != NULL) { rip->win = w; rip->nlines = srip->nlines; rip++; screen->nripped++; - if (rip->nlines > 0) - (*rtop) += rip->nlines; - LINES -= nlines; + if (srip->nlines > 0) + rtop += nlines; + else + rbot -= nlines; } if (srip->init(w, COLS) == ERR) return ERR; #ifdef DEBUG if (w != NULL) - __CTRACE(__CTRACE_SCREEN, - "newterm: ripped %d lines from the %s\n", - nlines, srip->nlines < 0 ? "bottom" : "top"); + __CTRACE(__CTRACE_WINDOW, + "newterm: %p ripped %d line(s) from the %s\n", + w, nlines, srip->nlines < 0 ? "bottom" : "top"); #endif } nrips = 0; /* Reset the stack. */ @@ -136,20 +138,42 @@ __ripoffscreen(SCREEN *screen, int *rtop * Called from resizeterm to ensure the ripped off lines are correctly * placed and refreshed. */ -void +int __ripoffresize(SCREEN *screen) { - int rbot = screen->LINES, i; + int rbot = screen->LINES, i, nlines, ret = OK; struct __ripoff *rip; for (i = 0, rip = screen->ripped; i < screen->nripped; i++, rip++) { - if (rip->nlines > 0) - touchwin(rip->win); - else { + if (rip->nlines == 0) + continue; + nlines = rip->nlines < 0 ? -rip->nlines : rip->nlines; + if (wresize(rip->win, nlines, screen->COLS) == ERR) + ret = ERR; + if (rip->nlines < 0) { /* Reposition the lower windows. */ - mvwin(rip->win, rbot + rip->nlines, 0); - rbot += rip->nlines; + if (mvwin(rip->win, rbot + rip->nlines, 0) == ERR) + ret = ERR; + else + rbot += rip->nlines; } + } + + return ret; +} + +/* + * __ripofftouch -- + * Displays the ripped off lines from initscr. + */ +void +__ripofftouch(SCREEN *screen) +{ + int i; + struct __ripoff *rip; + + for (i = 0, rip = screen->ripped; i < screen->nripped; i++, rip++) { + touchwin(rip->win); wnoutrefresh(rip->win); } } Index: src/lib/libcurses/screen.c diff -u src/lib/libcurses/screen.c:1.33 src/lib/libcurses/screen.c:1.33.4.1 --- src/lib/libcurses/screen.c:1.33 Mon Mar 20 10:20:16 2017 +++ src/lib/libcurses/screen.c Thu Oct 4 10:20:12 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: screen.c,v 1.33 2017/03/20 10:20:16 roy Exp $ */ +/* $NetBSD: screen.c,v 1.33.4.1 2018/10/04 10:20:12 martin 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.33 2017/03/20 10:20:16 roy Exp $"); +__RCSID("$NetBSD: screen.c,v 1.33.4.1 2018/10/04 10:20:12 martin Exp $"); #endif #endif /* not lint */ @@ -74,7 +74,7 @@ set_term(SCREEN *new) old_screen->rawmode = __rawmode; old_screen->noqch = __noqch; old_screen->COLS = COLS; - old_screen->LINES = LINES + __rippedlines(old_screen); + old_screen->LINES = LINES; old_screen->ESCDELAY = ESCDELAY; old_screen->TABSIZE = TABSIZE; old_screen->COLORS = COLORS; @@ -91,7 +91,7 @@ set_term(SCREEN *new) __rawmode = new->rawmode; __noqch = new->noqch; COLS = new->COLS; - LINES = new->LINES - __rippedlines(new); + LINES = new->LINES; ESCDELAY = new->ESCDELAY; TABSIZE = new->TABSIZE; COLORS = new->COLORS; @@ -130,7 +130,6 @@ newterm(char *type, FILE *outfd, FILE *i { SCREEN *new_screen; char *sp; - int rtop; sp = type; if (type == NULL && (sp = getenv("TERM")) == NULL) @@ -193,21 +192,21 @@ newterm(char *type, FILE *outfd, FILE *i new_screen->winlistp = NULL; if ((new_screen->curscr = __newwin(new_screen, 0, - 0, 0, 0, FALSE)) == NULL) + 0, 0, 0, FALSE, FALSE)) == NULL) goto error_exit; if ((new_screen->__virtscr = __newwin(new_screen, 0, - 0, 0, 0, FALSE)) == NULL) + 0, 0, 0, FALSE, FALSE)) == NULL) goto error_exit; /* If Soft Label Keys are setup, they will ripoffline. */ if (__slk_init(new_screen) == ERR) goto error_exit; - if (__ripoffscreen(new_screen, &rtop) == ERR) + if (__ripoffscreen(new_screen) == ERR) goto error_exit; - new_screen->stdscr = __newwin(new_screen, LINES, 0, rtop, 0, FALSE); + new_screen->stdscr = __newwin(new_screen, 0, 0, 0, 0, FALSE, TRUE); if (new_screen->stdscr == NULL) goto error_exit; Index: src/lib/libcurses/setterm.c diff -u src/lib/libcurses/setterm.c:1.66 src/lib/libcurses/setterm.c:1.66.4.1 --- src/lib/libcurses/setterm.c:1.66 Thu Mar 23 00:55:39 2017 +++ src/lib/libcurses/setterm.c Thu Oct 4 10:20:12 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: setterm.c,v 1.66 2017/03/23 00:55:39 roy Exp $ */ +/* $NetBSD: setterm.c,v 1.66.4.1 2018/10/04 10:20:12 martin Exp $ */ /* * Copyright (c) 1981, 1993, 1994 @@ -34,7 +34,7 @@ #if 0 static char sccsid[] = "@(#)setterm.c 8.8 (Berkeley) 10/25/94"; #else -__RCSID("$NetBSD: setterm.c,v 1.66 2017/03/23 00:55:39 roy Exp $"); +__RCSID("$NetBSD: setterm.c,v 1.66.4.1 2018/10/04 10:20:12 martin Exp $"); #endif #endif /* not lint */ @@ -122,7 +122,7 @@ _cursesi_setterm(char *type, SCREEN *scr if (screen->COLS <= 4) return ERR; - LINES = screen->LINES - __rippedlines(screen); + LINES = screen->LINES; COLS = screen->COLS; ESCDELAY = screen->ESCDELAY; TABSIZE = screen->TABSIZE; @@ -248,7 +248,7 @@ void _cursesi_resetterm(SCREEN *screen) { - LINES = screen->LINES - __rippedlines(screen); + LINES = screen->LINES; COLS = screen->COLS; ESCDELAY = screen->ESCDELAY; TABSIZE = screen->TABSIZE;