commit fe95612

sewn  ·  2026-05-07 23:22:38 +0000 UTC
parent b880be4
free image upon configure
2 files changed,  +16, -4
M wawa.c
+8, -3
 1@@ -1,7 +1,8 @@
 2 # wawa
 3 
 4 A even simpler Wayland wallpaper setter utilizing `stb_image` that targets `wlr-layer-shell`
 5-supported compositors. It takes in a path and zooms it to each screen.
 6+supported compositors, with stretch, fit, fill, tile and a color, with less SLOC than your
 7+average wallpaper setter.
 8 
 9 ## Comparison
10 
11@@ -16,8 +17,12 @@ undesirable for 4:3 wallpapers or other monitors, which wbg doesn't even have
12 support for setting for each monitor, wawa zooms the image by default, and is
13 significantly simpler.
14 
15-It is reccomended you stick to [swaybg] for all intents and purposes. wawa aims
16-to be a simpler replacement for [swaybg] eventually.
17+In wawa, the image is loaded only for monitors that need it, and is immediately
18+freed when all monitors have been configured; this keeps the memory usage of
19+wawa extremely low (7x less than wbg, almost 24x less than swaybg), which may
20+be a performance hit if youre constantly resizing the monitor. Please open an
21+issue if this concerns you, in which case a specific flag can be added to keep
22+the image in memory, unless it is a design flaw.
23 
24 [swaybg]: https://github.com/swaywm/swaybg
25 [wbg]: https://codeberg.org/dnkl/wbg
M wawa.c
+8, -1
 1@@ -220,7 +220,7 @@ layer_surface_handle_configure(void *data, struct zwlr_layer_surface_v1 *layer_s
 2 	if (output->configured) return;
 3 
 4 	if (!image.data && image.fp) {
 5-		fputs("loaded image", stderr);
 6+		if (fseek(image.fp, 0, SEEK_SET) < 0) die("fseek:");
 7 		if (!(image.data = stbi_load_from_file(image.fp,
 8 		                       &image.width, &image.height, NULL, 4)))
 9 			die("failed to load image: %s", stbi_failure_reason());
10@@ -238,6 +238,13 @@ layer_surface_handle_configure(void *data, struct zwlr_layer_surface_v1 *layer_s
11 	wl_buffer_destroy(buffer);
12 
13 	output->configured = true;
14+
15+	if (!image.fp) return;
16+	wl_list_for_each(output, &outputs, link)
17+		if (!output->configured) return;
18+
19+	stbi_image_free(image.data);
20+	image.data = NULL;
21 }
22 
23 static void