Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libcurses Move the ripoffline logic out of screen.c and ...
details: https://anonhg.NetBSD.org/src/rev/2f0e4feb595c
branches: trunk
changeset: 350447:2f0e4feb595c
user: roy <roy%NetBSD.org@localhost>
date: Wed Jan 11 20:43:03 2017 +0000
description:
Move the ripoffline logic out of screen.c and into ripoffline.c.
Store ripped off lines in the SCREEN structure so we can repaint then
when the terminal is resized.
Fix mvwin(3) so it can move windows in the ripped off area.
diffstat:
lib/libcurses/Makefile | 8 +-
lib/libcurses/curses_private.h | 16 +++-
lib/libcurses/mvwin.c | 11 +-
lib/libcurses/resize.c | 21 ++++-
lib/libcurses/ripoffline.c | 156 +++++++++++++++++++++++++++++++++++++++++
lib/libcurses/screen.c | 115 +++++++----------------------
lib/libcurses/setterm.c | 8 +-
7 files changed, 229 insertions(+), 106 deletions(-)
diffs (truncated from 557 to 300 lines):
diff -r 1ae398fa56d8 -r 2f0e4feb595c lib/libcurses/Makefile
--- a/lib/libcurses/Makefile Wed Jan 11 19:42:02 2017 +0000
+++ b/lib/libcurses/Makefile Wed Jan 11 20:43:03 2017 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.82 2017/01/10 10:13:24 roy Exp $
+# $NetBSD: Makefile,v 1.83 2017/01/11 20:43:03 roy Exp $
# @(#)Makefile 8.2 (Berkeley) 1/2/94
.include <bsd.own.mk>
@@ -22,9 +22,9 @@
idcok.c immedok.c inch.c inchstr.c initscr.c insch.c insdelln.c \
insertln.c instr.c keypad.c keyname.c leaveok.c line.c meta.c move.c \
mvwin.c newwin.c nodelay.c notimeout.c overlay.c overwrite.c pause.c \
- printw.c putchar.c refresh.c resize.c scanw.c screen.c scroll.c \
- scrollok.c setterm.c standout.c syncok.c timeout.c toucholap.c \
- touchwin.c tstp.c tty.c unctrl.c underscore.c
+ printw.c putchar.c refresh.c resize.c ripoffline.c scanw.c screen.c \
+ scroll.c scrollok.c setterm.c standout.c syncok.c timeout.c \
+ toucholap.c touchwin.c tstp.c tty.c unctrl.c underscore.c
MAN= curses.3 curses_addch.3 curses_addchstr.3 curses_addstr.3 \
curses_attributes.3 curses_background.3 curses_border.3 \
diff -r 1ae398fa56d8 -r 2f0e4feb595c lib/libcurses/curses_private.h
--- a/lib/libcurses/curses_private.h Wed Jan 11 19:42:02 2017 +0000
+++ b/lib/libcurses/curses_private.h Wed Jan 11 20:43:03 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: curses_private.h,v 1.58 2017/01/10 10:13:24 roy Exp $ */
+/* $NetBSD: curses_private.h,v 1.59 2017/01/11 20:43:03 roy Exp $ */
/*-
* Copyright (c) 1998-2000 Brett Lymn
@@ -189,6 +189,13 @@
typedef struct keymap keymap_t;
+
+#define MAX_RIPS 5
+struct __ripoff {
+ int nlines;
+ WINDOW *win;
+};
+
/* this is the encapsulation of the terminal definition, one for
* each terminal that curses talks to.
*/
@@ -201,8 +208,8 @@
int lx, ly; /* loop parameters for refresh */
int COLS; /* Columns on the screen. */
int LINES; /* Lines on the screen. */
- int ripped_top; /* Lines ripped from the top of the screen. */
- int ripped_bottom; /* Lines ripped from the bottom. */
+ int nripped; /* Number of ripofflines. */
+ struct __ripoff ripped[MAX_RIPS]; /* ripofflines. */
int ESCDELAY; /* Delay between keys in esc seq's. */
#define ESCDELAY_DEFAULT 300 /* milliseconds. */
int TABSIZE; /* Size of a tab. */
@@ -342,6 +349,9 @@
void __restore_termios(void);
void __restore_stophandler(void);
void __restore_winchhandler(void);
+int __ripoffscreen(SCREEN *, int *);
+void __ripoffresize(SCREEN *);
+int __rippedlines(const SCREEN *);
void __save_termios(void);
void __set_color(WINDOW *win, attr_t attr);
void __set_stophandler(void);
diff -r 1ae398fa56d8 -r 2f0e4feb595c lib/libcurses/mvwin.c
--- a/lib/libcurses/mvwin.c Wed Jan 11 19:42:02 2017 +0000
+++ b/lib/libcurses/mvwin.c Wed Jan 11 20:43:03 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mvwin.c,v 1.20 2017/01/06 13:53:18 roy Exp $ */
+/* $NetBSD: mvwin.c,v 1.21 2017/01/11 20:43:03 roy Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@@ -34,7 +34,7 @@
#if 0
static char sccsid[] = "@(#)mvwin.c 8.2 (Berkeley) 5/4/94";
#else
-__RCSID("$NetBSD: mvwin.c,v 1.20 2017/01/06 13:53:18 roy Exp $");
+__RCSID("$NetBSD: mvwin.c,v 1.21 2017/01/11 20:43:03 roy Exp $");
#endif
#endif /* not lint */
@@ -102,7 +102,8 @@
WINDOW *orig;
int dy, dx;
- if (by < 0 || by + win->maxy > LINES || bx < 0 || bx + win->maxx > COLS)
+ if (by < 0 || by + win->maxy > win->screen->LINES ||
+ bx < 0 || bx + win->maxx > win->screen->COLS)
return ERR;
dy = by - win->begy;
dx = bx - win->begx;
@@ -117,9 +118,9 @@
} while (win != orig);
} else {
if (by < orig->begy || win->maxy + dy > orig->maxy)
- return (ERR);
+ return ERR;
if (bx < orig->begx || win->maxx + dx > orig->maxx)
- return (ERR);
+ return ERR;
win->begy = by;
win->begx = bx;
__swflags(win);
diff -r 1ae398fa56d8 -r 2f0e4feb595c lib/libcurses/resize.c
--- a/lib/libcurses/resize.c Wed Jan 11 19:42:02 2017 +0000
+++ b/lib/libcurses/resize.c Wed Jan 11 20:43:03 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: resize.c,v 1.24 2017/01/10 23:28:45 roy Exp $ */
+/* $NetBSD: resize.c,v 1.25 2017/01/11 20:43:03 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.24 2017/01/10 23:28:45 roy Exp $");
+__RCSID("$NetBSD: resize.c,v 1.25 2017/01/11 20:43:03 roy Exp $");
#endif
#endif /* not lint */
@@ -163,11 +163,19 @@
__CTRACE(__CTRACE_WINDOW, "resizeterm: (%d, %d)\n", nlines, ncols);
#endif
+
if (!is_term_resized(nlines, ncols))
return OK;
result = resize_term(nlines, ncols);
+
+ /* Screen contents are unknown, libcurses is not libpanel, we don't
+ * know the correct draw order. */
clearok(curscr, TRUE);
+
+ /* We know how to repaint the ripoffs */
+ __ripoffresize(_cursesi_screen);
+
return result;
}
@@ -180,6 +188,7 @@
{
WINDOW *win;
struct __winlist *list;
+ int rlines;
#ifdef DEBUG
__CTRACE(__CTRACE_WINDOW, "resize_term: (%d, %d)\n", nlines, ncols);
@@ -192,11 +201,13 @@
return ERR;
if (__resizeterm(__virtscr, nlines, ncols) == ERR)
return ERR;
- nlines -= _cursesi_screen->ripped_top - _cursesi_screen->ripped_bottom;
- if (__resizeterm(stdscr, nlines, ncols) == ERR)
+ rlines = nlines - __rippedlines(_cursesi_screen);
+ if (__resizeterm(stdscr, rlines, ncols) == ERR)
return ERR;
- LINES = nlines;
+ _cursesi_screen->LINES = nlines;
+ _cursesi_screen->COLS = ncols;
+ LINES = rlines;
COLS = ncols;
/* tweak the flags now that we have updated the LINES and COLS */
diff -r 1ae398fa56d8 -r 2f0e4feb595c lib/libcurses/ripoffline.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libcurses/ripoffline.c Wed Jan 11 20:43:03 2017 +0000
@@ -0,0 +1,156 @@
+/* $NetBSD: ripoffline.c,v 1.1 2017/01/11 20:43:03 roy Exp $ */
+
+/*-
+ * Copyright (c) 2017 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Roy Marples.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: ripoffline.c,v 1.1 2017/01/11 20:43:03 roy Exp $");
+#endif /* not lint */
+
+#include "curses.h"
+#include "curses_private.h"
+
+/* List of ripoffline calls */
+static struct ripoff {
+ int nlines;
+ int (*init)(WINDOW *, int);
+} ripoffs[MAX_RIPS];
+static int nrips;
+
+/*
+ * ripoffline --
+ * Ripoff a line from the top of bottom of stdscr.
+ * Must be called before initscr or newterm.
+ */
+int
+ripoffline(int line, int (*init)(WINDOW *, int))
+{
+
+#ifdef DEBUG
+ __CTRACE(__CTRACE_SCREEN, "ripoffline: %d\n", line);
+#endif
+
+ if (nrips >= MAX_RIPS || init == NULL)
+ return ERR; /* This makes sense, but not standards compliant. */
+ if (line == 0)
+ return OK;
+ ripoffs[nrips].nlines = line < 0 ? -1 : 1;
+ ripoffs[nrips++].init = init;
+ return OK;
+}
+
+/*
+ * __rippedlines --
+ * Returns the number of ripped lines from the screen.
+ */
+int
+__rippedlines(const SCREEN *screen)
+{
+ const struct __ripoff *rip;
+ int i, n;
+
+ n = 0;
+ for (i = 0, rip = screen->ripped; i < screen->nripped; i++, rip++) {
+ if (rip->nlines < 0)
+ n += -rip->nlines;
+ else
+ n += rip->nlines;
+ }
+ return n;
+}
+
+/*
+ * __ripoffscreen --
+ * Rips lines from the screen by creating a WINDOW per ripoffline call.
+ * Although the POSIX API only allows for one line WINDOWS to be created,
+ * this implemenation allows for N lines if needed.
+ */
+int
+__ripoffscreen(SCREEN *screen, int *rtop)
+{
+ int i, nlines;
+ const struct ripoff *srip;
+ struct __ripoff *rip;
+ WINDOW *w;
+
+ *rtop = 0;
+ rip = screen->ripped;
+ for (i = 0, srip = ripoffs; i < nrips; i++, srip++) {
+ nlines = srip->nlines < 0 ? -srip->nlines : srip->nlines;
+ w = __newwin(screen, nlines, 0,
+ srip->nlines < 0 ? LINES - nlines : *rtop,
+ 0, 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->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");
+#endif
+ }
Home |
Main Index |
Thread Index |
Old Index