code: plan9front

Download patch

ref: 819bec22ccf01927c8d31e9bbcddca91b5ed41ee
parent: b68b3a6e19eb57c9f1c8b70b624f103254f4964a
author: Ori Bernstein <ori@eigenstate.org>
date: Sat Jun 26 13:39:13 EDT 2021

vt: allow scrolling with the mouse.

--- a/sys/src/cmd/vt/cons.h
+++ b/sys/src/cmd/vt/cons.h
@@ -54,7 +54,7 @@
 extern int	number(Rune *, int *);
 extern void	shift(int,int,int,int);
 extern void	scroll(int,int,int,int);
-extern int	backup(int);
+extern void	backup(int);
 extern void	sendnchars(int, char *);
 extern Point	pt(int, int);
 extern Point	pos(Point);
--- a/sys/src/cmd/vt/main.c
+++ b/sys/src/cmd/vt/main.c
@@ -134,9 +134,7 @@
 
 Rune	kbdchar;
 
-#define	button1()	((mc->buttons & 07)==1)
-#define	button2()	((mc->buttons & 07)==2)
-#define	button3()	((mc->buttons & 07)==4)
+#define	button(num)	(mc->buttons == (1<<((num)-1)))
 
 Mousectl	*mc;
 Keyboardctl	*kc;
@@ -835,10 +833,14 @@
 		flushimage(display, 1);
 	switch(alt(a)){
 	case AMOUSE:
-		if(button1() || chording)
+		if(button(1) || chording)
 			selecting();
-		else if(button2() || button3())
+		else if(button(2) || button(3))
 			readmenu();
+		else if(button(4))
+			backup(backc+1);
+		else if(button(5) && backc > 0)
+			backup(--backc);
 		else if(resize_flag == 0)
 			goto Next;
 		break;
@@ -1130,7 +1132,7 @@
 			select(p, q, mode);
 			drawscreen();
 			readmouse(mc);
-		} while(button1());
+		} while(button(1));
 	}
 	if(mc->buttons != chording){
 		switch(mc->buttons & 0x7){
@@ -1169,7 +1171,7 @@
 	Point p;
 
 	p = pos(mc->xy);
-	if(button3()) {
+	if(button(3)) {
 		menu3.item[1] = ttystate[cs->raw].crnl ? "cr" : "crnl";
 		menu3.item[2] = ttystate[cs->raw].nlcr ? "nl" : "nlcr";
 		menu3.item[3] = cs->raw ? "cooked" : "raw";
@@ -1203,8 +1205,7 @@
 
 	switch(menuhit(2, mc, &menu2, nil)) {
 	case Mbackup:		/* back up */
-		if(backup(backc+1))
-			backc++;
+		backup(backc+1);
 		return;
 
 	case Mforward:		/* move forward */
@@ -1239,7 +1240,7 @@
 	}
 }
 
-int
+void
 backup(int count)
 {
 	Rune *cp;
@@ -1272,7 +1273,8 @@
 	if(cp >= &hist[HISTSIZ])
 		cp = hist;
 	backp = cp;
-	return left;
+	if(left)
+		backc = count;
 }
 
 Point