commit 6a95d3e

sewn  ·  2026-05-08 12:42:44 +0000 UTC
parent fe95612
remove unnecessary loc
1 files changed,  +18, -38
M wawa.c
M wawa.c
+18, -38
  1@@ -9,7 +9,6 @@
  2 #include <linux/memfd.h>
  3 
  4 #include "stbi_alloc.h"
  5-
  6 #define STB_IMAGE_IMPLEMENTATION
  7 #include "stb_image.h"
  8 #define STB_IMAGE_RESIZE_IMPLEMENTATION
  9@@ -18,8 +17,6 @@
 10 #include "wlr-layer-shell-unstable-v1-protocol.h"
 11 
 12 struct output {
 13-	uint32_t registry_name;
 14-
 15 	struct wl_output *wl;
 16 	struct wl_surface *surface;
 17 	struct zwlr_layer_surface_v1 *layer_surface;
 18@@ -32,6 +29,11 @@ struct output {
 19 	struct wl_list link;
 20 };
 21 
 22+struct rect {
 23+	int width, height;
 24+	int x, y;
 25+};
 26+
 27 static struct wl_display *display;
 28 static struct wl_registry *registry;
 29 static struct wl_compositor *compositor;
 30@@ -39,10 +41,6 @@ static struct wl_shm *shm;
 31 static struct zwlr_layer_shell_v1 *layer_shell;
 32 static struct wl_list outputs;
 33 
 34-/*
 35- * Must be valid when a single monitor is misconfigured
 36- * or during startup, after which the image is freed.
 37- */
 38 struct {
 39 	FILE *fp;
 40 	int width, height;
 41@@ -88,6 +86,7 @@ parse_color(const char *src)
 42 	if (len == 6)
 43 		color = (color << 8) | 0xFF;
 44 
 45+	/* for colorspace conversion in output_image_load */
 46 	color = bswap_32(color);
 47 }
 48 
 49@@ -109,10 +108,7 @@ image_stretch(unsigned char *dst, struct output *output)
 50 static void
 51 image_fit(unsigned char *dst, struct output *output)
 52 {
 53-	struct {
 54-		int width, height;
 55-		int x, y;
 56-	} crop;
 57+	struct rect crop;
 58 	double factor;
 59 
 60 	factor = fmin((double)output->width/image.width, (double)output->height/image.height);
 61@@ -123,17 +119,13 @@ image_fit(unsigned char *dst, struct output *output)
 62 	stbir_resize_uint8_linear(
 63 	  image.data, image.width, image.height, image.width * 4,
 64 		dst + (crop.y * output->stride) + (crop.x * 4),
 65-		crop.width, crop.height, output->stride,
 66-		4);
 67+		crop.width, crop.height, output->stride, 4);
 68 }
 69 
 70 static void
 71 image_fill(unsigned char *dst, struct output *output)
 72 {
 73-	struct {
 74-		int width, height;
 75-		int x, y;
 76-	} crop;
 77+	struct rect crop;
 78 	double factor;
 79 
 80 	factor = fmin((double)image.width/output->width, (double)image.height/output->height);
 81@@ -144,8 +136,7 @@ image_fill(unsigned char *dst, struct output *output)
 82 	stbir_resize_uint8_linear(
 83 	  image.data + (crop.y * image.width + crop.x) * 4,
 84 	  crop.width, crop.height, image.width * 4,
 85-		dst, output->width, output->height, output->stride,
 86-		4);
 87+		dst, output->width, output->height, output->stride, 4);
 88 }
 89 
 90 static void
 91@@ -221,9 +212,8 @@ layer_surface_handle_configure(void *data, struct zwlr_layer_surface_v1 *layer_s
 92 
 93 	if (!image.data && image.fp) {
 94 		if (fseek(image.fp, 0, SEEK_SET) < 0) die("fseek:");
 95-		if (!(image.data = stbi_load_from_file(image.fp,
 96-		                       &image.width, &image.height, NULL, 4)))
 97-			die("failed to load image: %s", stbi_failure_reason());
 98+		image.data = stbi_load_from_file(image.fp, &image.width, &image.height, NULL, 4);
 99+		if (!image.data) die("failed to load image: %s", stbi_failure_reason());
100 	}
101 
102 	output->width = width;
103@@ -233,7 +223,6 @@ layer_surface_handle_configure(void *data, struct zwlr_layer_surface_v1 *layer_s
104 
105 	buffer = output_load_image(output);
106 	wl_surface_attach(output->surface, buffer, 0, 0);
107-	wl_surface_damage_buffer(output->surface, 0, 0, INT32_MAX, INT32_MAX);
108 	wl_surface_commit(output->surface);
109 	wl_buffer_destroy(buffer);
110 
111@@ -251,8 +240,12 @@ static void
112 layer_surface_handle_closed(void *data, struct zwlr_layer_surface_v1 *surface)
113 {
114 	struct output *output = data;
115+
116 	zwlr_layer_surface_v1_destroy(output->layer_surface);
117 	wl_surface_destroy(output->surface);
118+	wl_output_destroy(output->wl);
119+	wl_list_remove(&output->link);
120+	free(output);
121 }
122 
123 static const struct zwlr_layer_surface_v1_listener layer_surface_listener = {
124@@ -292,7 +285,7 @@ registry_handle_global(void *data, struct wl_registry *registry,
125 	struct wl_callback *callback;
126 
127 	if (!strcmp(interface, wl_compositor_interface.name))
128-		compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 6);
129+		compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1);
130  	else if (!strcmp(interface, wl_shm_interface.name))
131 		shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
132 	else if (!strcmp(interface, zwlr_layer_shell_v1_interface.name))
133@@ -301,9 +294,8 @@ registry_handle_global(void *data, struct wl_registry *registry,
134 	else if (!strcmp(interface, wl_output_interface.name)) {
135 		struct output *output = calloc(1, sizeof(struct output));
136 		if (!output) die("calloc:");
137-		output->registry_name = name;
138 		output->wl = wl_registry_bind(registry, name,
139-			&wl_output_interface, 4);
140+			&wl_output_interface, 1);
141 		wl_list_insert(&outputs, &output->link);
142 		/*
143 		 * There is no gurantee of the registry order, ensure a callback is used
144@@ -318,16 +310,6 @@ registry_handle_global(void *data, struct wl_registry *registry,
145 static void
146 registry_handle_remove(void *data, struct wl_registry *registry, uint32_t name)
147 {
148-	struct output *output, *tmp;
149-	
150-	wl_list_for_each_safe(output, tmp, &outputs, link) {
151-		if (output->registry_name != name)
152-			continue;	
153-		wl_output_destroy(output->wl);
154-		wl_list_remove(&output->link);
155-		free(output);
156-		break;
157-	}
158 }
159 
160 static const struct wl_registry_listener registry_listener = {
161@@ -335,8 +317,6 @@ static const struct wl_registry_listener registry_listener = {
162 	.global_remove = registry_handle_remove,
163 };
164 
165-
166-
167 int
168 main(int argc, char *argv[])
169 {