shithub: drawterm-fdroid

Download patch

ref: 74e47cdeb4f9b8d81766c24391bac05f87922115
parent: b5df2820e20709f48d2c4ce19fecb27e2f0d2105
author: cinap_lenrek <[email protected]>
date: Sat Nov 25 11:54:59 EST 2017

drawterm: debounce screen resize

--- a/gui-win32/screen.c
+++ b/gui-win32/screen.c
@@ -445,16 +445,7 @@
 	case WM_SIZE:
 		if(GetClientRect(hwnd, &winr) == 0)
 			break;
-		r = Rect(0, 0, winr.right - winr.left, winr.bottom - winr.top);
-		if(rectclip(&r, gscreen->r) == 0 || badrect(r))
-			break;
-		qlock(&drawlock);
-		gscreen->clipr = r;
-		qunlock(&drawlock);
-		screenwin();
-		deletescreenimage();
-		resetscreenimage();
-		mouseresize();
+		screenresize(Rect(0, 0, winr.right - winr.left, winr.bottom - winr.top));
 		break;
 
 	case WM_COMMAND:
--- a/gui-x11/x11.c
+++ b/gui-x11/x11.c
@@ -656,20 +656,9 @@
 static void
 xresize(XEvent *e)
 {
-	Rectangle r;
-
 	if(e->type != ConfigureNotify)
 		return;
-	r = Rect(0, 0, ((XConfigureEvent*)e)->width, ((XConfigureEvent*)e)->height);
-	if(rectclip(&r, gscreen->r) == 0 || badrect(r) || eqrect(r, gscreen->clipr))
-		return;
-	qlock(&drawlock);
-	gscreen->clipr = r;
-	qunlock(&drawlock);
-	screenwin();
-	deletescreenimage();
-	resetscreenimage();
-	mouseresize();
+	screenresize(Rect(0, 0, ((XConfigureEvent*)e)->width, ((XConfigureEvent*)e)->height));
 }
 
 static void
--- a/kern/screen.h
+++ b/kern/screen.h
@@ -58,7 +58,7 @@
 #define	ishwimage(i)	0
 
 void	terminit(void);
-void	screenwin(void);
+void	screenresize(Rectangle);
 
 void	mouseresize(void);
 void	mousetrack(int, int, int, ulong);
--- a/kern/term.c
+++ b/kern/term.c
@@ -47,7 +47,7 @@
 		combinerect(&flushr, r);
 }
 
-void
+static void
 screenwin(void)
 {
 	Point p;
@@ -86,7 +86,56 @@
 	qunlock(&drawlock);
 }
 
+static struct {
+	Rectangle	r;
+	Rendez		z;
+	int		f;
+} resize;
+
+static int
+isresized(void *arg)
+{
+	return resize.f != 0;
+}
+
+static void
+resizeproc(void *arg)
+{
+	USED(arg);
+	for(;;){
+		sleep(&resize.z, isresized, nil);
+		qlock(&drawlock);
+		resize.f = 0;
+		if(gscreen == nil
+		|| badrect(resize.r)
+		|| rectclip(&resize.r, gscreen->r) == 0
+		|| eqrect(resize.r, gscreen->clipr)){
+			qunlock(&drawlock);
+			continue;
+		}
+		gscreen->clipr = resize.r;
+		qunlock(&drawlock);
+
+		screenwin();
+		deletescreenimage();
+		resetscreenimage();
+		mouseresize();
+
+		osmsleep(1000);
+	}
+}
+
 void
+screenresize(Rectangle r)
+{
+	qlock(&drawlock);
+	resize.r = r;
+	resize.f = 1;
+	wakeup(&resize.z);
+	qunlock(&drawlock);
+}
+
+void
 terminit(void)
 {
 	memdefont = getmemdefont();
@@ -95,6 +144,7 @@
 	out.bwid = memdefont->info[' '].width;
 	screenwin();
 	screenputs = termscreenputs;
+	kproc("resize", resizeproc, nil);
 }
 
 static void