shithub: pplay

Download patch

ref: d6e36b1d35d71d376d82c6a3260ac524885e4392
parent: c898b9cdb26ed6ac53982b945a548b746de783a2
author: qwx <qwx@sciops.net>
date: Sun Oct 29 02:11:18 EDT 2023

draw: adjustments to avoid any drawing artefacts

--- a/dat.h
+++ b/dat.h
@@ -42,6 +42,12 @@
 
 extern QLock lsync;
 
+enum{
+	Drawcur,
+	Drawrender,
+	Drawall,
+};
+
 extern int stereo;
 extern int debug, paused;
 extern int debugdraw;
--- a/draw.c
+++ b/draw.c
@@ -194,40 +194,39 @@
 }
 
 static void
-update(void)
-{
-	lockdisplay(display);
-	if(stalerender || working){
-		if(!working)
-			stalerender = 0;
-		render();
-		draw(screen, rectaddpt(view->r, screen->r.min), view, nil, ZP);
-	}else
-		erasemark(linepos);
-	renderpos(current->cur, col[Cline], 1);
-	linepos = current->cur;
-	drawstat();
-	flushimage(display, 1);
-	unlockdisplay(display);
-}
-
-static void
 drawproc(void*)
 {
+	int what;
+
 	threadsetname("drawer");
 	for(;;){
-		if(recv(drawc, nil) < 0){
+		if(recv(drawc, &what) < 0){
 			fprint(2, "drawproc: %r\n");
 			break;
 		}
-		update();
+		lockdisplay(display);
+		if(what == Drawcur)
+			erasemark(linepos);
+		else{
+			if(what == Drawrender || stalerender || working){
+				if(!working)
+					stalerender = 0;
+				render();
+			}
+			draw(screen, rectaddpt(view->r, screen->r.min), view, nil, ZP);
+		}
+		renderpos(current->cur, col[Cline], 1);
+		linepos = current->cur;
+		drawstat();
+		flushimage(display, 1);
+		unlockdisplay(display);
 	}
 }
 
 void
-refresh(void)
+refresh(int what)
 {
-	nbsend(drawc, nil);
+	nbsend(drawc, &what);
 }
 
 static void
@@ -304,7 +303,7 @@
 		working = 1;
 		stalerender = 1;
 		sample(d);
-		refresh();
+		refresh(Drawall);
 		working = 0;
 	}
 }
@@ -347,7 +346,7 @@
 		resetdraw();
 	unlockdisplay(display);
 	if(paused)
-		refresh();
+		refresh(Drawall);
 	/* FIXME: this overloading is stupid; just fork for each? have multiple
 	 * workers to begin with à la page? */
 	d = *current;
@@ -430,8 +429,7 @@
 		current->cur = from;
 	current->off = -1;
 	stalerender = 1;
-	if(paused)
-		refresh();
+	refresh(Drawrender);
 }
 
 int
@@ -444,8 +442,7 @@
 	}
 	current->off = current->cur = off;
 	stalerender = 1;
-	if(paused)
-		refresh();
+	refresh(Drawrender);
 	return 0;
 }
 
--- a/fns.h
+++ b/fns.h
@@ -10,7 +10,7 @@
 Chunk*	loadfile(int, Dot*);
 int	cmd(char*);
 int	initcmd(int);
-void	refresh(void);
+void	refresh(int);
 void	setzoom(int, int);
 int	zoominto(vlong, vlong);
 void	setrange(usize, usize);
--- a/pplay.c
+++ b/pplay.c
@@ -63,7 +63,7 @@
 			}
 			memcpy(bp, b, n);
 			advance(current, n);
-			refresh();
+			refresh(Drawcur);
 		}
 		if(write(afd, buf, sizeof buf) != sizeof buf){
 			fprint(2, "aproc write: %r\n");
@@ -90,7 +90,7 @@
 	chartorune(&q, buf);
 	if(q != r)
           snprint(buf, sizeof buf, "%C", r);
-	if(enter(nil, buf, sizeof(buf)-UTFmax, mc, kc, nil) < 0)
+	if(enter("cmd:", buf, sizeof(buf)-UTFmax, mc, kc, _screen) < 0)
 		return nil;
 	return buf;
 }
@@ -170,7 +170,7 @@
 			switch(r){
 			case Kdel:
 			case 'q': threadexitsall(nil);
-			case 'D': debug ^= 1; debugdraw ^= 1; break;
+			case 'D': debug ^= 1; debugdraw ^= 1; refresh(Drawrender); break;
 			case 'S': stereo ^= 1; redraw(1); break;
 			case ' ': toggleplay(); break;
 			case 'b': setjump(current->from); break;
@@ -184,11 +184,13 @@
 			case Kleft: setpage(-1); break;
 			case Kright: setpage(1); break;
 			default:
-				if((p = prompt(r)) == nil || strlen(p) == 0)
+				if((p = prompt(r)) == nil || strlen(p) == 0){
+					refresh(Drawrender);
 					break;
+				}
 				switch(cmd(p)){
 				case -1: fprint(2, "cmd \"%s\" failed: %r\n", p); break;
-				case 0: refresh(); break;
+				case 0: refresh(Drawall); break;
 				case 1: redraw(0); break;
 				case 2: redraw(1); break;
 				}