shithub: bar

Download patch

ref: fcdc01e594cd5f3b27c571303b6ef4efd72c1eeb
parent: 49cca4636e049d4b70c4cdca646d3e79228cf805
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Wed Jan 27 02:20:48 EST 2021

rewrite updateproc to a simple timerproc

--- a/bar.c
+++ b/bar.c
@@ -68,6 +68,8 @@
 	char t[61], *a[5];
 	static int ow, oh;
 
+	fprint(wctl, bottom ? "bottom" : "top");
+
 	if((fd = open("/dev/screen", OREAD)) < 0)
 		return;
 	n = read(fd, t, sizeof(t)-1);
@@ -178,31 +180,13 @@
 }
 
 static void
-updateproc(void *)
+timerproc(void *c)
 {
-	uvlong t1, t2, n;
-
-	t1 = nanosec();
-	t2 = t1;
+	threadsetname("timer");
 	for(;;){
-		sleep(250);
-		if(wctl < 0)
-			break;
-		fprint(wctl, bottom ? "bottom" : "top");
-
-		n = nanosec();
-
-		if(n - t1 >= 10000000000ULL){
-			readbattery();
-			t1 = n;
-		}
-		if(n - t2 >= 1000000000ULL){
-			redraw();
-			t2 = n;
-		}
+		sleep(990);
+		sendul(c, 0);
 	}
-
-	threadexits(nil);
 }
 
 static void
@@ -211,6 +195,7 @@
 	Biobuf b;
 	char *s;
 
+	threadsetname("aux");
 	Binit(&b, 0, OREAD);
 	for(;;){
 		s = Brdstr(&b, '\n', 1);
@@ -249,6 +234,7 @@
 {
 	Keyboardctl *kctl;
 	Mousectl *mctl;
+	uvlong t, oldt;
 	int oldbuttons;
 	char *s, *v[3];
 	u32int brgb;
@@ -260,6 +246,7 @@
 		Eresize,
 		Ekeyboard,
 		Eaux,
+		Etimer,
 		Eend,
 	};
 	Alt a[] = {
@@ -267,6 +254,7 @@
 		[Eresize] = { nil, nil, CHANRCV },
 		[Ekeyboard] = { nil, &key, CHANRCV },
 		[Eaux] = { nil, &s, CHANRCV },
+		[Etimer] = { nil, nil, CHANRCV },
 		[Eend] = { nil, nil, CHANEND },
 	};
 
@@ -326,14 +314,16 @@
 	a[Eresize].c = mctl->resizec;
 	a[Ekeyboard].c = kctl->c;
 	a[Eaux].c = chancreate(sizeof(s), 0);
+	a[Etimer].c = chancreate(sizeof(ulong), 0);
 
 	aux = strdup("");
 	readbattery();
 	redraw();
-	proccreate(updateproc, nil, 4096);
+	proccreate(timerproc, a[Etimer].c, 4096);
 	proccreate(auxproc, a[Eaux].c, 16384);
 
 	m.buttons = 0;
+	oldt = nanosec();
 	for(;;){
 		oldbuttons = m.buttons;
 
@@ -341,7 +331,6 @@
 		case Ekeyboard:
 			if(key == Kdel){
 				close(wctl);
-				wctl = -1;
 				threadexitsall(nil);
 			}
 			break;
@@ -361,10 +350,18 @@
 
 		if(0){
 		case Eaux:
-			if(wctl >= 0)
-				fprint(wctl, bottom ? "bottom" : "top");
 			free(aux);
 			aux = s;
+			/* wet floor */
+		}
+
+		if(0){
+		case Etimer:
+			t = nanosec();
+			if(t - oldt >= 10000000000ULL){
+				readbattery();
+				oldt = t;
+			}
 		}
 			redraw();
 			place();