shithub: libnate

Download patch

ref: 794e2ee40b0345746539fbd41ad0eda122f8603e
parent: 8e9b3935e13faea2d4304b0f557754c43290a266
author: sirjofri <sirjofri@sirjofri.de>
date: Sun Feb 9 11:27:22 EST 2025

better debug output control, fixes box button input

--- a/n_box.c
+++ b/n_box.c
@@ -76,10 +76,30 @@
 {
 	NBox* b = (NBox*)nelem;
 	GUARD(b);
+	int b1 = m.buttons&1;
 	
-	if (b->hitfunc)
-		return b->hitfunc(m, b, b->hitaux);
-	return 0;
+	// TODO: behaviour when pressed down and releasing on another box?
+	// TODO:   drag-and-drop?
+	
+	if (b->ishit == b1) {
+		/* no state change */
+		return 0;
+	}
+	if (b->ishit && !b1) {
+		/* released */
+		b->ishit = 0;
+		return 0;
+	}
+	if (!b->ishit && b1) {
+		/* pressed */
+		b->ishit = 1;
+		if (b->hitfunc)
+			return b->hitfunc(m, b, b->hitaux);
+		return 0;
+	}
+	/* cannot happen */
+	assert(0);
+	return 1;
 }
 
 static void
--- a/n_box.h
+++ b/n_box.h
@@ -19,6 +19,7 @@
 	Image* bordercolor;
 	int (*hitfunc)(Mouse, Nelem*, void*);
 	void* hitaux;
+	int ishit;
 };
 
 NBox* New_Box(char*);
--- a/nate.c
+++ b/nate.c
@@ -6,6 +6,7 @@
 
 int nateborders = 0;
 int natetracehit = 0;
+int natetracedraw = 0;
 int natedebugfd = -1;
 
 static Nlist rootchain = { nil };
@@ -198,7 +199,7 @@
 	assert(nelem);
 	
 	if (nelem->funcs && nelem->funcs->draw) {
-		if (natedebugfd >= 0)
+		if (natetracedraw && natedebugfd >= 0)
 			fprint(natedebugfd, "DRAW: %s\n", nelem->type);
 		or = dst->clipr;
 		//replclipr(dst, 0, nelem->r);
@@ -212,8 +213,10 @@
 {
 	assert(nelem);
 	
-	nctracehit(nelem, !nelem->funcs->hit);
-	nctracehitlevel++;
+	if (natetracehit) {
+		nctracehit(nelem, !nelem->funcs->hit);
+		nctracehitlevel++;
+	}
 	if (nelem->funcs && nelem->funcs->checkhit) {
 		return nelem->funcs->checkhit(nelem, screen, m);
 	}
--- a/nate.h
+++ b/nate.h
@@ -36,6 +36,7 @@
 
 extern int nateborders;
 extern int natetracehit;
+extern int natetracedraw;
 extern int natedebugfd;
 
 struct {
--- a/test/ntest.c
+++ b/test/ntest.c
@@ -51,8 +51,20 @@
 	if (initdraw(nil, nil, "nate test") < 0)
 		sysfatal("initdraw: %r");
 	
+	/* send 2 output to /srv/ntest */
+	int p[2];
+	pipe(p);
+	dup(p[0], 2);
+	int fd = create("/srv/ntest", OWRITE|ORCLOSE, 0666);
+	if (fd < 0)
+		sysfatal("create: %r");
+	fprint(fd, "%d\n", p[1]);
+	close(p[1]);
+	
+	/* debug nate */
 	nateborders = 1;
-	natetracehit = 1;
+	//natetracehit = 1;
+	//natetracedraw = 1;
 	natedebugfd = 2;
 	
 	einit(Emouse);
@@ -114,24 +126,12 @@
 	
 	eresized(0);
 	
-	int p[2];
-	pipe(p);
-	dup(p[0], 2);
-	int fd = create("/srv/ntest", OWRITE|ORCLOSE, 0666);
-	if (fd < 0)
-		sysfatal("create: %r");
-	fprint(fd, "%d\n", p[1]);
-	close(p[1]);
-	
 	for (;;) {
 		e = event(&ev);
 		
 		switch (e) {
 		case Emouse:
-			if (ev.mouse.buttons & 4)
-				exits(nil);
-			if (ev.mouse.buttons & 1)
-				natemouseevent(ev.mouse);
+			natemouseevent(ev.mouse);
 			break;
 		default:
 			break;
--