commit d920d26

sewn  ·  2026-08-22 11:38:51 +0000 UTC
parent af41b95
handle negative output coordinates
2 files changed,  +34, -8
M wawa.c
+7, -1
 1@@ -13,7 +13,9 @@ CFLAGS  += -pedantic -Wall -Wno-strict-prototypes -D_GNU_SOURCE $(INCS)
 2 
 3 all: wawa
 4 
 5-PROTO = wlr-layer-shell-unstable-v1-protocol.h xdg-shell-protocol.h
 6+PROTO = xdg-shell-protocol.h xdg-output-unstable-v1-protocol.h \
 7+	wlr-layer-shell-unstable-v1-protocol.h
 8+	
 9 OBJ = wawa.o $(PROTO:.h=.o)
10 
11 wawa: $(OBJ)
12@@ -28,6 +30,10 @@ xdg-shell-protocol.h:
13 	$(WAYLAND_SCANNER) client-header $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@
14 xdg-shell-protocol.c:
15 	$(WAYLAND_SCANNER) private-code $(WAYLAND_PROTOCOLS)/stable/xdg-shell/xdg-shell.xml $@
16+xdg-output-unstable-v1-protocol.h:
17+	$(WAYLAND_SCANNER) client-header $(WAYLAND_PROTOCOLS)/unstable/xdg-output/xdg-output-unstable-v1.xml $@
18+xdg-output-unstable-v1-protocol.c:
19+	$(WAYLAND_SCANNER) private-code $(WAYLAND_PROTOCOLS)/unstable/xdg-output/xdg-output-unstable-v1.xml $@
20 wlr-layer-shell-unstable-v1-protocol.h:
21 	$(WAYLAND_SCANNER) client-header wlr-layer-shell-unstable-v1.xml $@
22 wlr-layer-shell-unstable-v1-protocol.c:
M wawa.c
+27, -7
 1@@ -19,6 +19,7 @@
 2 #define STB_IMAGE_RESIZE_IMPLEMENTATION
 3 #include "stb_image_resize2.h"
 4 
 5+#include "xdg-output-unstable-v1-protocol.h"
 6 #include "wlr-layer-shell-unstable-v1-protocol.h"
 7 
 8 #define MAX(A, B) ((A) > (B) ? (A) : (B))
 9@@ -48,6 +49,7 @@ static struct wl_registry *registry;
10 static struct wl_compositor *compositor;
11 static struct wl_shm *shm;
12 static struct zwlr_layer_shell_v1 *layer_shell;
13+static struct zxdg_output_manager_v1 *output_manager;
14 static struct wl_list outputs;
15 
16 struct {
17@@ -332,13 +334,33 @@ static const struct wl_output_listener output_listener = {
18 	.description = noop,
19 };
20 
21+
22+static void
23+output_handle_logical_position(void *data, struct zxdg_output_v1 *zxdg_output_v1,
24+	int32_t x, int32_t y)
25+{
26+	output_handle_geometry(data, NULL, x, y, 0, 0, 0, NULL, NULL, 0);
27+}
28+
29+static const struct zxdg_output_v1_listener xdg_output_listener = {
30+	.logical_position = &output_handle_logical_position,
31+	.logical_size = noop,
32+	.done = noop,
33+};
34+
35 static void
36 output_setup_callback(void *data, struct wl_callback *callback,
37 		uint32_t time)
38 {
39 	struct output *output = data;
40+	static struct zxdg_output_v1 *xdg;
41 
42 	output->surface = wl_compositor_create_surface(compositor);
43+
44+	if (output_manager) {
45+		xdg = zxdg_output_manager_v1_get_xdg_output(output_manager, output->wl);
46+		zxdg_output_v1_add_listener(xdg, &xdg_output_listener, output);
47+	}
48 	
49 	output->layer_surface = zwlr_layer_shell_v1_get_layer_surface(layer_shell,
50 				output->surface, output->wl, ZWLR_LAYER_SHELL_V1_LAYER_BACKGROUND, "wallpaper");
51@@ -365,11 +387,14 @@ registry_handle_global(void *data, struct wl_registry *registry,
52 
53 	if (!strcmp(interface, wl_compositor_interface.name))
54 		compositor = wl_registry_bind(registry, name, &wl_compositor_interface, 1);
55- 	else if (!strcmp(interface, wl_shm_interface.name))
56+	else if (!strcmp(interface, wl_shm_interface.name))
57 		shm = wl_registry_bind(registry, name, &wl_shm_interface, 1);
58 	else if (!strcmp(interface, zwlr_layer_shell_v1_interface.name))
59 		layer_shell = wl_registry_bind(registry, name,
60 			&zwlr_layer_shell_v1_interface, 1);
61+	else if (!strcmp(interface, zxdg_output_manager_v1_interface.name))
62+		output_manager = wl_registry_bind(registry, name,
63+		  &zxdg_output_manager_v1_interface, 1);
64 	else if (!strcmp(interface, wl_output_interface.name)) {
65 		struct output *output = calloc(1, sizeof(struct output));
66 		if (!output) die("calloc:");
67@@ -387,14 +412,9 @@ registry_handle_global(void *data, struct wl_registry *registry,
68 	}
69 }
70 
71-static void
72-registry_handle_remove(void *data, struct wl_registry *registry, uint32_t name)
73-{
74-}
75-
76 static const struct wl_registry_listener registry_listener = {
77 	.global = registry_handle_global,
78-	.global_remove = registry_handle_remove,
79+	.global_remove = noop, /* layer_surface_handle_closed */
80 };
81 
82 int