[hackers] [st] Check alternative screen before drawing box selection || "Roberto E. Vargas Caballero"

From: <hg_AT_suckless.org>
Date: Tue, 4 Sep 2012 20:35:16 +0200 (CEST)

changeset: 269:660b176e15e7
tag: tip
user: "Roberto E. Vargas Caballero" <k0ga_AT_shike2.com>
date: Tue Sep 04 20:33:01 2012 +0200
files: st.c
description:
Check alternative screen before drawing box selection
Some programs use the alternative screen (vi, less, ...), whose
content is different of the main screen. If you select text in one of
the screen, you don't wait the box selection is painted in the other
screen, so it is necessary check if the selection was done in the same
screen we are going to paint. Before to this commit, you could do
something like:

        $ LESS="" ls | less
        (select some code)
        q

and selection box remains drawing in the main screen, but the content
of selection keeps text of the alternate screen.
---
 st.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
diff -r b9ded6b6069e -r 660b176e15e7 st.c
--- a/st.c	Tue Sep 04 20:31:21 2012 +0200
+++ b/st.c	Tue Sep 04 20:33:01 2012 +0200
_AT_@ -221,6 +221,7 @@
 	struct {int x, y;} b, e;
 	char *clip;
 	Atom xtarget;
+	bool alt;
 	struct timeval tclick1;
 	struct timeval tclick2;
 } Selection;
_AT_@ -579,6 +580,7 @@
 		}
 		*ptr = 0;
 	}
+	sel.alt = IS_SET(MODE_ALTSCREEN);
 	xsetsel(str);
 }
 
_AT_@ -2076,7 +2078,10 @@
 	int ic, ib, x, y, ox, sl;
 	Glyph base, new;
 	char buf[DRAW_BUF_SIZ];
+	bool ena_sel = sel.bx != -1, alt = IS_SET(MODE_ALTSCREEN);
 
+	if((sel.alt && !alt) || (!sel.alt && alt))
+		ena_sel = 0;
 	if(!(xw.state & WIN_VISIBLE))
 		return;
 
_AT_@ -2089,7 +2094,7 @@
 		ic = ib = ox = 0;
 		for(x = x1; x < x2; x++) {
 			new = term.line[y][x];
-			if(sel.bx != -1 && *(new.c) && selected(x, y))
+			if(ena_sel && *(new.c) && selected(x, y))
 				new.mode ^= ATTR_REVERSE;
 			if(ib > 0 && (!(new.state & GLYPH_SET) || ATTRCMP(base, new) ||
 						  ib >= DRAW_BUF_SIZ-UTF_SIZ)) {
Received on Tue Sep 04 2012 - 20:35:16 CEST

This archive was generated by hypermail 2.3.0 : Tue Sep 04 2012 - 20:36:08 CEST