shithub: drawterm

Download patch

ref: 44f57781df714328b2bda786131f7cfe76651aed
parent: 54f615f6c0090c7c0011f4121ecf54fcf1e07a6b
author: Jacob Moody <moody@posixcafe.org>
date: Fri Jun 24 22:43:55 EDT 2022

gui-wl: grab monitor size from compositor

Instead of harcoding at 1080p, just grab the largest connected
output and use that as the pool size. This allows us to be
a bit more stingy on reallocing.

--- a/gui-wl/wl-cb.c
+++ b/gui-wl/wl-cb.c
@@ -531,13 +531,39 @@
 };
 
 static void
+mode(void *data, struct wl_output*, uint, int x, int y, int)
+{
+	Wlwin *wl;
+
+	wl = data;
+	if(x >= wl->monx && y >= wl->mony){
+		wl->monx = x;
+		wl->mony = y;
+	}
+}
+static void done(void*, struct wl_output*){}
+static void scale(void*, struct wl_output*, int){}
+static void geometry(void*, struct wl_output*, int, int, int, int, int, const char*, const char*, int){}
+
+static const struct wl_output_listener output_listener = {
+	.geometry = geometry,
+	.mode = mode,
+	.done = done,
+	.scale = scale,
+};
+
+static void
 handle_global(void *data, struct wl_registry *registry, uint32_t name, const char *interface, uint32_t version)
 {
 	Wlwin *wl;
+	struct wl_output *out;
 
 	wl = data;
 	if(strcmp(interface, wl_shm_interface.name) == 0) {
 		wl->shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
+	} else if(strcmp(interface, wl_output_interface.name) == 0) {
+		out = wl_registry_bind(registry, name, &wl_output_interface, 2);
+		wl_output_add_listener(out, &output_listener, wl);
 	} else if(strcmp(interface, wl_seat_interface.name) == 0) {
 		//We don't support multiseat
 		if(wl->seat != nil)
--- a/gui-wl/wl-screen.c
+++ b/gui-wl/wl-screen.c
@@ -39,8 +39,8 @@
 		sysfatal("malloc Wlwin");
 	wl->dx = 1024;
 	wl->dy = 1024;
-	wl->monx = 1920;
-	wl->mony = 1080;
+	wl->monx = wl->dx;
+	wl->mony = wl->dy;
 	return wl;
 }
 
@@ -60,6 +60,8 @@
 	wl_surface_commit(wl->surface);
 }
 
+void  _screenresize(Rectangle);
+
 void
 wlresize(Wlwin *wl, int x, int y)
 {
@@ -73,11 +75,7 @@
 	r = Rect(0, 0, wl->dx, wl->dy);
 	gscreen = allocmemimage(r, XRGB32);
 	gscreen->clipr = ZR;
-	qunlock(&drawlock);
-
-	screenresize(r);
-
-	qlock(&drawlock);
+	_screenresize(r);
 	wl->dirty = 1;
 	wl->r = r;
 	wlflush(wl);
--- a/gui-wl/wl-util.c
+++ b/gui-wl/wl-util.c
@@ -50,7 +50,6 @@
 void
 wlallocpool(Wlwin *wl)
 {
-	int screenx, screeny;
 	int screensize, cursorsize;
 	int depth;
 	int fd;
@@ -59,9 +58,7 @@
 		wl_shm_pool_destroy(wl->pool);
 
 	depth = 4;
-	screenx = wl->dx > wl->monx ? wl->dx : wl->monx;
-	screeny = wl->dy > wl->mony ? wl->dy : wl->mony;
-	screensize = screenx * screeny * depth;
+	screensize = wl->monx * wl->mony * depth;
 	cursorsize = 16 * 16 * depth;
 
 	fd = wlcreateshm(screensize+cursorsize);
@@ -88,6 +85,8 @@
 	size = wl->dx * wl->dy * depth;
 	if(wl->pool == nil || size+(16*16*depth) > wl->poolsize)
 		wlallocpool(wl);
+
+	assert(size+(16*16*depth) <= wl->poolsize);
 
 	if(wl->screenbuffer != nil)
 		wl_buffer_destroy(wl->screenbuffer);