shithub: asif

Download patch

ref: de7f8850194c4a7064291c160ff71cbaf5bd9903
parent: 165e0028e4533966f78eab011aa7fda3984fd90e
author: qwx <qwx@sciops.net>
date: Sat Mar 26 20:59:21 EDT 2022

mouse: don't switch between clearing and setting blocks

--- a/path/a∗.c
+++ b/path/a∗.c
@@ -138,12 +138,12 @@
 }
 
 int
-mouseinput(Node *n, Mouse m)
+mouseinput(Node *n, Mouse m, Node *old)
 {
 	switch(m.buttons & 7){
 	case 1: if(goal != n && !n->blocked) start = n; break;
 	case 2: if(start != n && !n->blocked) goal = n; break;
-	case 4: n->blocked ^= 1; return 0;
+	case 4: if(old == nil || n->blocked ^ old->blocked) n->blocked ^= 1; return 0;
 	}
 	if(start != nil && goal != nil)
 		return findpath();
--- a/path/bfs.c
+++ b/path/bfs.c
@@ -136,12 +136,12 @@
 }
 
 int
-mouseinput(Node *n, Mouse m)
+mouseinput(Node *n, Mouse m, Node *old)
 {
 	switch(m.buttons & 7){
 	case 1: if(goal != n && !n->blocked) start = n; break;
 	case 2: if(start != n && !n->blocked) goal = n; break;
-	case 4: n->blocked ^= 1; return 0;
+	case 4: if(old == nil || n->blocked ^ old->blocked) n->blocked ^= 1; return 0;
 	}
 	if(start != nil && goal != nil)
 		return findpath();
--- a/path/client.c
+++ b/path/client.c
@@ -10,7 +10,7 @@
 #include "fns.h"
 
 extern QLock drawlock;
-int	mouseinput(Node*, Mouse);
+int	mouseinput(Node*, Mouse, Node*);
 int	keyinput(Rune);
 Node*	scrselect(Point);
 void	updatedrw(void);
@@ -46,13 +46,15 @@
 			resetdrw();
 			break;
 		case Amouse:
-			if(mc->buttons == 0)
+			if(mc->buttons == 0){
+				p = nil;
 				break;
+			}
 			if((n = scrselect(m.xy)) != nil && p != n){
-				if(mouseinput(n, mc->Mouse) < 0)
+				if(mouseinput(n, mc->Mouse, p) < 0)
 					fprint(2, "%r\n");
+				p = n;
 			}
-			p = n;
 			updatedrw();
 			break;
 		case Akbd:
--- a/path/dijkstra.c
+++ b/path/dijkstra.c
@@ -135,12 +135,12 @@
 }
 
 int
-mouseinput(Node *n, Mouse m)
+mouseinput(Node *n, Mouse m, Node *old)
 {
 	switch(m.buttons & 7){
 	case 1: if(goal != n && !n->blocked) start = n; break;
 	case 2: if(start != n && !n->blocked) goal = n; break;
-	case 4: n->blocked ^= 1; return 0;
+	case 4: if(old == nil || n->blocked ^ old->blocked) n->blocked ^= 1; return 0;
 	}
 	if(start != nil && goal != nil)
 		return findpath();