From owner-svn-src-stable@freebsd.org Wed Jul 19 13:28:26 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id BB6EDC7D4E0; Wed, 19 Jul 2017 13:28:26 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 8A9D47F2E3; Wed, 19 Jul 2017 13:28:26 +0000 (UTC) (envelope-from emaste@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v6JDSPO3044981; Wed, 19 Jul 2017 13:28:25 GMT (envelope-from emaste@FreeBSD.org) Received: (from emaste@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v6JDSPil044980; Wed, 19 Jul 2017 13:28:25 GMT (envelope-from emaste@FreeBSD.org) Message-Id: <201707191328.v6JDSPil044980@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: emaste set sender to emaste@FreeBSD.org using -f From: Ed Maste Date: Wed, 19 Jul 2017 13:28:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r321199 - stable/11/sys/dev/vt X-SVN-Group: stable-11 X-SVN-Commit-Author: emaste X-SVN-Commit-Paths: stable/11/sys/dev/vt X-SVN-Commit-Revision: 321199 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 19 Jul 2017 13:28:26 -0000 Author: emaste Date: Wed Jul 19 13:28:25 2017 New Revision: 321199 URL: https://svnweb.freebsd.org/changeset/base/321199 Log: MFC r313547, r313777: fix mouse selection when vt(4) scrolls r313547 (ray, submitted by hselasky): o Reset mouse selection when new lines reach selection lines. o Fix how selection handled on display. r313777 (rpokala): Un-break vt(4) for {powerpc,powerpc64,sparc64} LINT kernel builds The {powerpc,powerpc64,sparc64} LINT kernel builds fail with this error: sys/dev/vt/vt_buf.c:198: warning: 'vtbuf_htw' defined but not used Move vtbuf_htw() inside the '#if SC_NO_CUTPASTE' block where it belongs, and put it in the proper order. This fixes the immedate issue w/ vt(4), but all three then fail on different issues. PR: 211922 Relnotes: Yes Modified: stable/11/sys/dev/vt/vt_buf.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/dev/vt/vt_buf.c ============================================================================== --- stable/11/sys/dev/vt/vt_buf.c Wed Jul 19 13:11:35 2017 (r321198) +++ stable/11/sys/dev/vt/vt_buf.c Wed Jul 19 13:28:25 2017 (r321199) @@ -54,6 +54,11 @@ static MALLOC_DEFINE(M_VTBUF, "vtbuf", "vt buffer"); (d).tp_row = (s).tp_row; \ } while (0) +#ifndef SC_NO_CUTPASTE +static int vtbuf_htw(const struct vt_buf *vb, int row); +static int vtbuf_wth(const struct vt_buf *vb, int row); +static int vtbuf_in_this_range(int begin, int test, int end, int sz); +#endif /* * line4 @@ -122,6 +127,9 @@ vthistory_seek(struct vt_buf *vb, int offset, int when void vthistory_addlines(struct vt_buf *vb, int offset) { +#ifndef SC_NO_CUTPASTE + int cur, sz; +#endif vb->vb_curroffset += offset; if (vb->vb_curroffset < 0) @@ -132,6 +140,17 @@ vthistory_addlines(struct vt_buf *vb, int offset) if ((vb->vb_flags & VBF_SCROLL) == 0) { vb->vb_roffset = vb->vb_curroffset; } + +#ifndef SC_NO_CUTPASTE + sz = vb->vb_history_size; + cur = vb->vb_roffset + vb->vb_scr_size.tp_row + sz - 1; + if (vtbuf_in_this_range(cur, vb->vb_mark_start.tp_row, cur + offset, sz) || + vtbuf_in_this_range(cur, vb->vb_mark_end.tp_row, cur + offset, sz)) { + /* clear screen selection */ + vb->vb_mark_start.tp_row = vb->vb_mark_end.tp_row; + vb->vb_mark_start.tp_col = vb->vb_mark_end.tp_col; + } +#endif } void @@ -142,15 +161,6 @@ vthistory_getpos(const struct vt_buf *vb, unsigned int } #ifndef SC_NO_CUTPASTE /* Only mouse support use it now. */ -/* Translate current view row number to history row. */ -static int -vtbuf_wth(struct vt_buf *vb, int row) -{ - - return ((vb->vb_roffset + row) % vb->vb_history_size); -} -#endif - /* Translate history row to current view row number. */ static int vtbuf_htw(const struct vt_buf *vb, int row) @@ -166,36 +176,78 @@ vtbuf_htw(const struct vt_buf *vb, int row) vb->vb_history_size); } +/* Translate current view row number to history row. */ +static int +vtbuf_wth(const struct vt_buf *vb, int row) +{ + + return ((vb->vb_roffset + row) % vb->vb_history_size); +} + +/* + * Test if an index in a circular buffer is within a range. + * + * begin - start index + * end - end index + * test - test index + * sz - size of circular buffer when it turns over + */ +static int +vtbuf_in_this_range(int begin, int test, int end, int sz) +{ + + begin %= sz; + end %= sz; + + /* check for inversion */ + if (begin > end) + return (test >= begin || test < end); + else + return (test >= begin && test < end); +} +#endif + int vtbuf_iscursor(const struct vt_buf *vb, int row, int col) { - int sc, sr, ec, er, tmp; +#ifndef SC_NO_CUTPASTE + int sc, sr, sz, ec, er, tmp; +#endif if ((vb->vb_flags & (VBF_CURSOR|VBF_SCROLL)) == VBF_CURSOR && (vb->vb_cursor.tp_row == row) && (vb->vb_cursor.tp_col == col)) return (1); +#ifndef SC_NO_CUTPASTE /* Mark cut/paste region. */ + if (vb->vb_mark_start.tp_col == vb->vb_mark_end.tp_col && + vb->vb_mark_start.tp_row == vb->vb_mark_end.tp_row) + return (0); - /* - * Luckily screen view is not like circular buffer, so we will - * calculate in screen coordinates. Translate first. - */ sc = vb->vb_mark_start.tp_col; - sr = vtbuf_htw(vb, vb->vb_mark_start.tp_row); + sr = vb->vb_mark_start.tp_row; ec = vb->vb_mark_end.tp_col; - er = vtbuf_htw(vb, vb->vb_mark_end.tp_row); + er = vb->vb_mark_end.tp_row; + /* + * Information about if the selection was made bottom-top or + * top-bottom is lost due to modulo arithmetics and needs to + * be recovered: + */ + sz = vb->vb_history_size; + tmp = (sz + er - sr) % sz; + row = vtbuf_wth(vb, row); - /* Swap start and end if start > end. */ - if (POS_INDEX(sc, sr) > POS_INDEX(ec, er)) { + /* Swap start and end if start > end */ + if ((2 * tmp) > sz || (tmp == 0 && sc > ec)) { tmp = sc; sc = ec; ec = tmp; tmp = sr; sr = er; er = tmp; } - if ((POS_INDEX(sc, sr) <= POS_INDEX(col, row)) && - (POS_INDEX(col, row) < POS_INDEX(ec, er))) + if (vtbuf_in_this_range(POS_INDEX(sc, sr), POS_INDEX(col, row), + POS_INDEX(ec, er), POS_INDEX(0, sz))) return (1); +#endif return (0); } @@ -627,8 +679,8 @@ vtbuf_flush_mark(struct vt_buf *vb) int s, e; /* Notify renderer to update marked region. */ - if (vb->vb_mark_start.tp_col || vb->vb_mark_end.tp_col || - vb->vb_mark_start.tp_row || vb->vb_mark_end.tp_row) { + if ((vb->vb_mark_start.tp_col != vb->vb_mark_end.tp_col) || + (vb->vb_mark_start.tp_row != vb->vb_mark_end.tp_row)) { s = vtbuf_htw(vb, vb->vb_mark_start.tp_row); e = vtbuf_htw(vb, vb->vb_mark_end.tp_row);