shithub: drawterm

Download patch

ref: de6172c0abcbd9977dd1e39029248079f6f1e9c7
parent: c2a244ab69976103216b7ff9f3738a14b93bd546
author: Jacob Moody <moody@posixcafe.org>
date: Thu Apr 18 21:22:33 EDT 2024

gui-wl: fix more issues surfaced by cage

* We were calling wlresize() in the csd handler, this
was initially done to ensure that we draw the csd on
the first blit. This can instead be satisfied by doing
a roundtrip during initialization and being more careful
about the first blit in wlattach().

* Free the gscreen image on resize

* On cage since the "monitor" is the window,
we had a bug where x and y must both change
for us to consider the monitor to be larger.

* screenwin() should handle gscreen->clip where
r.min is not (0, 0).

* Refactor termscreenputs to avoid this canqlock
bussiness. When resizing this would cause an issue
where we would fail redraw the kmesg buffer.

--- a/gui-wl/wl-cb.c
+++ b/gui-wl/wl-cb.c
@@ -660,7 +660,6 @@
 	}
 
 	wl->client_side_deco = csd;
-	wlresize(wl, wl->dx, wl->dy);
 }
 
 static const struct zxdg_toplevel_decoration_v1_listener zxdg_toplevel_decoration_v1_listener = {
@@ -673,7 +672,7 @@
 	Wlwin *wl;
 
 	wl = data;
-	if(x >= wl->monx && y >= wl->mony){
+	if(x > wl->monx || y > wl->mony){
 		wl->monx = x;
 		wl->mony = y;
 	}
@@ -775,6 +774,7 @@
 		deco = zxdg_decoration_manager_v1_get_toplevel_decoration(wl->decoman, wl->xdg_toplevel);
 		zxdg_toplevel_decoration_v1_add_listener(deco, &zxdg_toplevel_decoration_v1_listener, wl);
 		zxdg_toplevel_decoration_v1_set_mode(deco, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
+		wl_display_roundtrip(wl->display);
 	}
 
 	xdg_toplevel_set_app_id(wl->xdg_toplevel, "drawterm");
--- a/gui-wl/wl-screen.c
+++ b/gui-wl/wl-screen.c
@@ -78,7 +78,7 @@
 	Point offset;
 	Rectangle button;
 
-	if(!wl->client_side_deco) {
+	if(!wl->client_side_deco){
 		memset(&wl->csd_rects, 0, sizeof wl->csd_rects);
 		return;
 	}
@@ -146,6 +146,8 @@
 	qlock(&drawlock);
 	wlallocbuffer(wl);
 	r = Rect(0, wl->csd_rects.bar.max.y, wl->dx, wl->dy);
+	if(gscreen != nil)
+		freememimage(gscreen);
 	gscreen = allocmemimage(r, XRGB32);
 	gscreen->clipr = ZR;
 	qunlock(&drawlock);
@@ -155,8 +157,8 @@
 	qlock(&drawlock);
 	wl->dirty = 1;
 	wl->r = r;
-	wlflush(wl);
 	wldrawcsd(wl);
+	wlflush(wl);
 	qunlock(&drawlock);
 }
 
@@ -190,15 +192,13 @@
 	r = Rect(0, wl->csd_rects.bar.max.y, wl->dx, wl->dy);
 	gscreen = allocmemimage(r, XRGB32);
 	gscreen->clipr = r;
-	gscreen->r = r;
-	rectclip(&(gscreen->clipr), gscreen->r);
 
 	wl->runing = 1;
 	kproc("wldispatch", dispatchproc, wl);
 	qlock(&drawlock);
+	wldrawcsd(wl);
 	terminit();
 	wlflush(wl);
-	wldrawcsd(wl);
 	qunlock(&drawlock);
 	return wl;
 }
--- a/kern/term.c
+++ b/kern/term.c
@@ -11,7 +11,6 @@
 extern Memimage		*gscreen;
 
 static Memsubfont	*memdefont;
-static Lock		screenlock;
 static Memimage		*conscol;
 static Memimage		*back;
 static Rectangle	flushr;
@@ -19,6 +18,7 @@
 static Point		curpos;
 static int		h;
 
+static void drawscreenputs(char*, int);
 static void termscreenputs(char*, int);
 
 static void
@@ -58,10 +58,10 @@
 	/* a lot of work to get a grey color */
 	grey = allocmemimage(Rect(0,0,1,1), CMAP8);
 	grey->flags |= Frepl;
-	grey->clipr = gscreen->r;
+	grey->clipr = gscreen->clipr;
 	memfillcolor(grey, 0xAAAAAAFF);
 	memimagedraw(gscreen, Rect(window.min.x, window.min.y,
-			window.max.x, window.min.y+h+5+6), grey, ZP, nil, ZP, S);
+			window.max.x, window.min.y+h+5+6), grey, gscreen->clipr.min, nil, ZP, S);
 	freememimage(grey);
 	window = insetrect(window, 5);
 
@@ -73,7 +73,8 @@
 	window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h;
 	flushmemscreen(gscreen->r);
 
-	termscreenputs(kmesg.buf, kmesg.n);
+	drawscreenputs(kmesg.buf, kmesg.n);
+	screenflush();
 }
 
 static struct {
@@ -216,7 +217,7 @@
 }
 
 static void
-termscreenputs(char *s, int n)
+drawscreenputs(char *s, int n)
 {
 	static char rb[UTFmax+1];
 	static int nrb;
@@ -223,8 +224,6 @@
 	int locked;
 	char *e;
 
-	lock(&screenlock);
-	locked = canqlock(&drawlock);
 	e = s + n;
 	while(s < e){
 		rb[nrb++] = *s++;
@@ -234,9 +233,13 @@
 			nrb = 0;
 		}
 	}
-	if(locked){
-		screenflush();
-		qunlock(&drawlock);
-	}
-	unlock(&screenlock);
+}
+
+static void
+termscreenputs(char *s, int n)
+{
+	qlock(&drawlock);
+	drawscreenputs(s, n);
+	screenflush();
+	qunlock(&drawlock);
 }