Module Name:    src
Committed By:   roy
Date:           Thu Jan  5 21:25:18 UTC 2017

Modified Files:
        src/distrib/sets/lists/comp: mi
        src/lib/libcurses: Makefile curses.3 curses.h curses_screen.3 resize.c

Log Message:
Implement is_term_resized and resize_term(3) ncurses extensions.
resizeterm(3) is now a wrapper for resize_term(3).


To generate a diff of this commit:
cvs rdiff -u -r1.2096 -r1.2097 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.79 -r1.80 src/lib/libcurses/Makefile
cvs rdiff -u -r1.64 -r1.65 src/lib/libcurses/curses.3
cvs rdiff -u -r1.116 -r1.117 src/lib/libcurses/curses.h
cvs rdiff -u -r1.20 -r1.21 src/lib/libcurses/curses_screen.3 \
    src/lib/libcurses/resize.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.2096 src/distrib/sets/lists/comp/mi:1.2097
--- src/distrib/sets/lists/comp/mi:1.2096	Thu Jan  5 20:31:37 2017
+++ src/distrib/sets/lists/comp/mi	Thu Jan  5 21:25:18 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.2096 2017/01/05 20:31:37 roy Exp $
+#	$NetBSD: mi,v 1.2097 2017/01/05 21:25:18 roy Exp $
 #
 # Note: don't delete entries from here - mark them as "obsolete" instead.
 ./etc/mtree/set.comp				comp-sys-root
@@ -6878,6 +6878,7 @@
 ./usr/share/man/cat3/is_keypad.0		comp-c-catman		.cat
 ./usr/share/man/cat3/is_leaveok.0		comp-c-catman		.cat
 ./usr/share/man/cat3/is_linetouched.0		comp-c-catman		.cat
+./usr/share/man/cat3/is_term_resized.0		comp-c-catman		.cat
 ./usr/share/man/cat3/is_wintouched.0		comp-c-catman		.cat
 ./usr/share/man/cat3/isalnum.0			comp-c-catman		.cat
 ./usr/share/man/cat3/isalpha.0			comp-c-catman		.cat
@@ -8676,6 +8677,7 @@
 ./usr/share/man/cat3/reset_prog_mode.0		comp-c-catman		.cat
 ./usr/share/man/cat3/reset_shell_mode.0		comp-c-catman		.cat
 ./usr/share/man/cat3/resetty.0			comp-c-catman		.cat
+./usr/share/man/cat3/resize_term.0		comp-c-catman		.cat
 ./usr/share/man/cat3/resizeterm.0		comp-c-catman		.cat
 ./usr/share/man/cat3/resolver.0			comp-c-catman		.cat
 ./usr/share/man/cat3/rewind.0			comp-c-catman		.cat
@@ -14230,6 +14232,7 @@
 ./usr/share/man/html3/is_keypad.html		comp-c-htmlman		html
 ./usr/share/man/html3/is_leaveok.html		comp-c-htmlman		html
 ./usr/share/man/html3/is_linetouched.html	comp-c-htmlman		html
+./usr/share/man/html3/is_term_resized.html	comp-c-htmlman		html
 ./usr/share/man/html3/is_wintouched.html	comp-c-htmlman		html
 ./usr/share/man/html3/isalnum.html		comp-c-htmlman		html
 ./usr/share/man/html3/isalpha.html		comp-c-htmlman		html
@@ -15988,6 +15991,7 @@
 ./usr/share/man/html3/reset_prog_mode.html	comp-c-htmlman		html
 ./usr/share/man/html3/reset_shell_mode.html	comp-c-htmlman		html
 ./usr/share/man/html3/resetty.html		comp-c-htmlman		html
+./usr/share/man/html3/resize_term.html		comp-c-htmlman		html
 ./usr/share/man/html3/resizeterm.html		comp-c-htmlman		html
 ./usr/share/man/html3/resolver.html		comp-c-htmlman		html
 ./usr/share/man/html3/rewind.html		comp-c-htmlman		html
@@ -21499,6 +21503,7 @@
 ./usr/share/man/man3/is_keypad.3		comp-c-man		.man
 ./usr/share/man/man3/is_leaveok.3		comp-c-man		.man
 ./usr/share/man/man3/is_linetouched.3		comp-c-man		.man
+./usr/share/man/man3/is_term_resized.3		comp-c-man		.man
 ./usr/share/man/man3/is_wintouched.3		comp-c-man		.man
 ./usr/share/man/man3/isalnum.3			comp-c-man		.man
 ./usr/share/man/man3/isalpha.3			comp-c-man		.man
@@ -23297,6 +23302,7 @@
 ./usr/share/man/man3/reset_prog_mode.3		comp-c-man		.man
 ./usr/share/man/man3/reset_shell_mode.3		comp-c-man		.man
 ./usr/share/man/man3/resetty.3			comp-c-man		.man
+./usr/share/man/man3/resize_term.3		comp-c-man		.man
 ./usr/share/man/man3/resizeterm.3		comp-c-man		.man
 ./usr/share/man/man3/resolver.3			comp-c-man		.man
 ./usr/share/man/man3/rewind.3			comp-c-man		.man

Index: src/lib/libcurses/Makefile
diff -u src/lib/libcurses/Makefile:1.79 src/lib/libcurses/Makefile:1.80
--- src/lib/libcurses/Makefile:1.79	Thu Jan  5 20:31:37 2017
+++ src/lib/libcurses/Makefile	Thu Jan  5 21:25:17 2017
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile,v 1.79 2017/01/05 20:31:37 roy Exp $
+#	$NetBSD: Makefile,v 1.80 2017/01/05 21:25:17 roy Exp $
 #	@(#)Makefile	8.2 (Berkeley) 1/2/94
 
 .include <bsd.own.mk>
@@ -103,6 +103,7 @@ MLINKS+= curses_addch.3 addch.3 curses_a
 	 curses_tty.3 intrflush.3 \
 	 curses_pad.3 is_keypad.3 \
 	 curses_refresh.3 is_leaveok.3 curses_touch.3 is_linetouched.3 \
+	 curses_screen.3 is_term_resized.3 \
 	 curses_touch.3 is_wintouched.3 curses_screen.3 isendwin.3 \
 	 curses_keyname.3 keyname.3 \
 	 curses_input.3 keypad.3 curses_tty.3 killchar.3 \
@@ -140,7 +141,8 @@ MLINKS+= curses_addch.3 addch.3 curses_a
 	 curses_fileio.3 putwin.3 curses_tty.3 qiflush.3 \
 	 curses_tty.3 raw.3 curses_refresh.3 refresh.3 \
 	 curses_tty.3 reset_prog_mode.3 curses_tty.3 reset_shell_mode.3 \
-	 curses_tty.3 resetty.3 curses_screen.3 resizeterm.3 \
+	 curses_tty.3 resetty.3 \
+	 curses_screen.3 resizeterm.3 curses_screen.3 resize_term.3 \
 	 curses_tty.3 savetty.3 curses_scanw.3 scanw.3 \
 	 curses_scroll.3 scrl.3 curses_scroll.3 scroll.3 \
 	 curses_scroll.3 scrollok.3 curses_scroll.3 setscrreg.3 \

Index: src/lib/libcurses/curses.3
diff -u src/lib/libcurses/curses.3:1.64 src/lib/libcurses/curses.3:1.65
--- src/lib/libcurses/curses.3:1.64	Thu Jan  5 20:31:37 2017
+++ src/lib/libcurses/curses.3	Thu Jan  5 21:25:18 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: curses.3,v 1.64 2017/01/05 20:31:37 roy Exp $
+.\"	$NetBSD: curses.3,v 1.65 2017/01/05 21:25:18 roy Exp $
 .\"
 .\" Copyright (c) 1985, 1991, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -215,6 +215,7 @@ must be called before any of the other r
 .It reset_prog_mode Ta Xr curses_tty 3
 .It reset_shell_mode Ta Xr curses_tty 3
 .It resetty Ta Xr curses_tty 3
+.It resize_term Ta Xr curses_screen 3
 .It resizeterm Ta Xr curses_screen 3
 .It savetty Ta Xr curses_tty 3
 .It scanw Ta Xr curses_scanw 3

Index: src/lib/libcurses/curses.h
diff -u src/lib/libcurses/curses.h:1.116 src/lib/libcurses/curses.h:1.117
--- src/lib/libcurses/curses.h:1.116	Thu Jan  5 20:31:37 2017
+++ src/lib/libcurses/curses.h	Thu Jan  5 21:25:18 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: curses.h,v 1.116 2017/01/05 20:31:37 roy Exp $	*/
+/*	$NetBSD: curses.h,v 1.117 2017/01/05 21:25:18 roy Exp $	*/
 
 /*
  * Copyright (c) 1981, 1993, 1994
@@ -695,6 +695,7 @@ int	 intrflush(WINDOW *, bool);
 bool	 isendwin(void);
 bool	 is_linetouched(WINDOW *, int);
 bool	 is_wintouched(WINDOW *);
+bool	 is_term_resized(int, int);
 int      keyok(int, bool);
 int	 keypad(WINDOW *, bool);
 char	*keyname(int);
@@ -744,6 +745,7 @@ int	 reset_prog_mode(void);
 int	 reset_shell_mode(void);
 int	 resetty(void);
 int      resizeterm(int, int);
+int	 resize_term(int, int);
 int	 savetty(void);
 int	 scanw(const char *, ...) __scanflike(1, 2);
 int	 scroll(WINDOW *);

Index: src/lib/libcurses/curses_screen.3
diff -u src/lib/libcurses/curses_screen.3:1.20 src/lib/libcurses/curses_screen.3:1.21
--- src/lib/libcurses/curses_screen.3:1.20	Thu Jan  5 20:31:37 2017
+++ src/lib/libcurses/curses_screen.3	Thu Jan  5 21:25:18 2017
@@ -1,4 +1,4 @@
-.\"	$NetBSD: curses_screen.3,v 1.20 2017/01/05 20:31:37 roy Exp $
+.\"	$NetBSD: curses_screen.3,v 1.21 2017/01/05 21:25:18 roy Exp $
 .\"
 .\" Copyright (c) 2002
 .\"	Brett Lymn (bl...@netbsd.org, brett_l...@yahoo.com.au)
@@ -43,6 +43,8 @@
 .Nm endwin ,
 .Nm initscr ,
 .Nm isendwin ,
+.Nm is_term_resized ,
+.Nm resize_term ,
 .Nm resizeterm ,
 .Nm setterm ,
 .Nm set_tabsize
@@ -67,6 +69,10 @@
 .Fn initscr "void"
 .Ft bool
 .Fn isendwin "void"
+.Ft bool
+.Fn is_term_resized "int lines" "int cols"
+.Fn int
+.Fn resize_term "int lines" "int cols"
 .Ft int
 .Fn resizeterm "int lines" "int cols"
 .Ft int
@@ -155,8 +161,8 @@ function can be used to determine whethe
 screen has occurred since the last call to
 .Fn endwin .
 .Pp
-The size of the screen may be changed  by calling
-.Fn resizeterm
+The size of the screen may be changed by calling
+.Fn resize_term
 with the updated number of lines and columns.
 This will resize the curses internal data structures to accommodate the
 changed terminal geometry.
@@ -167,7 +173,15 @@ and
 windows and any of their subwindows will be resized to fit the new
 screen size.
 The application must redraw the screen after a call to
-.Fn resizeterm .
+.Fn resize_term .
+The
+.Fn resizeterm
+function is a wrapper for
+.Fn resize_term
+and adjusts other structure data that handles window dimensions.
+The
+.Fn is_term_resized
+function tests if either of the above functions need to be called.
 .Pp
 The
 .Fn setterm
@@ -252,8 +266,11 @@ function is a
 extension to the Curses library and was added in
 .Nx 1.6 .
 The
+.Fn is_term_resized ,
+.Fn resize_term
+and
 .Fn set_tabsize
-function is a
+functions are
 .Em ncurses
 extension to the Curses library and was added in
 .Nx 8.0 .
Index: src/lib/libcurses/resize.c
diff -u src/lib/libcurses/resize.c:1.20 src/lib/libcurses/resize.c:1.21
--- src/lib/libcurses/resize.c:1.20	Wed Jul 22 16:57:15 2009
+++ src/lib/libcurses/resize.c	Thu Jan  5 21:25:18 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: resize.c,v 1.20 2009/07/22 16:57:15 roy Exp $	*/
+/*	$NetBSD: resize.c,v 1.21 2017/01/05 21:25:18 roy 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.20 2009/07/22 16:57:15 roy Exp $");
+__RCSID("$NetBSD: resize.c,v 1.21 2017/01/05 21:25:18 roy Exp $");
 #endif
 #endif				/* not lint */
 
@@ -136,19 +136,56 @@ wresize(WINDOW *win, int req_nlines, int
 }
 
 /*
+ * is_term_resized --
+ *	Return true if the given dimensions do not match the
+ *	internal structures.
+ */
+bool
+is_term_resized(int nlines, int ncols)
+{
+
+	return (nlines > 0 && ncols > 0 && (nlines != LINES || ncols != COLS));
+}
+
+/*
  * resizeterm --
  *	Resize the terminal window, resizing the dependent windows.
+ *	Handles internal book-keeping.
  */
 int
 resizeterm(int nlines, int ncols)
 {
+	int result;
+
+#ifdef	DEBUG
+	__CTRACE(__CTRACE_WINDOW, "resizeterm: (%d, %d)\n", nlines, ncols);
+#endif
+
+	if (!is_term_resized(nlines, ncols))
+		return OK;
+
+	result = resizeterm(nlines, ncols);
+	clearok(curscr, TRUE);
+	return result;
+}
+
+/*
+ * resize_term --
+ *	Resize the terminal window, resizing the dependent windows.
+ */
+int
+resize_term(int nlines, int ncols)
+{
 	WINDOW *win;
 	struct __winlist *list;
 
 #ifdef	DEBUG
-	__CTRACE(__CTRACE_WINDOW, "resizeterm: (%d, %d)\n", nlines, ncols);
+	__CTRACE(__CTRACE_WINDOW, "resize_term: (%d, %d)\n", nlines, ncols);
 #endif
 
+	if (!is_term_resized(nlines, ncols))
+		return OK;
+
 	if (__resizeterm(curscr, nlines, ncols) == ERR)
 		return ERR;
 	if (__resizeterm(__virtscr, nlines, ncols) == ERR)
@@ -167,7 +204,6 @@ resizeterm(int nlines, int ncols)
 			__swflags(win);
 	}
 
-	wrefresh(curscr);
 	return OK;
 }
 

Reply via email to