commit 0f683bf

sewn  ·  2026-03-14 08:49:42 +0000 UTC
parent 502f272
Add support for xdg-output-manager protocol
7 files changed,  +123, -1
+1, -1
1@@ -13,4 +13,4 @@ launch/swc-launch
2 
3 # Generated from convert_font.c and cursor.pcf
4 cursor/convert_font
5-cursor/cursor_data.h
6+cursor/cursor_data.h
+1, -0
1@@ -54,6 +54,7 @@ struct swc {
2 	struct wl_global *subcompositor;
3 	struct wl_global *wallpaper_manager;
4 	struct wl_global *xdg_decoration_manager;
5+	struct wl_global *xdg_output_manager;
6 	struct wl_global *xdg_shell;
7 
8 #ifdef ENABLE_XWAYLAND
+1, -0
1@@ -31,6 +31,7 @@ bind_output(struct wl_client *client, void *data, uint32_t version, uint32_t id)
2 		return;
3 	}
4 
5+	output->resource = resource;
6 	wl_resource_set_implementation(resource, &output_impl, output,
7 	                               &remove_resource);
8 	wl_list_insert(&output->resources, wl_resource_get_link(resource));
+1, -0
1@@ -9,6 +9,7 @@
2 struct wl_display;
3 
4 struct output {
5+	struct wl_resource *resource;
6 	struct screen *screen;
7 
8 	char name[24];
+9, -0
 1@@ -44,6 +44,7 @@
 2 #include "wallpaper.h"
 3 #include "window.h"
 4 #include "xdg_decoration.h"
 5+#include "xdg_output.h"
 6 #include "xdg_shell.h"
 7 #ifdef ENABLE_XWAYLAND
 8 #include "xserver.h"
 9@@ -258,6 +259,12 @@ swc_initialize(struct wl_display *display, struct wl_event_loop *event_loop,
10 		goto error17;
11 	}
12 
13+	swc.xdg_output_manager = xdg_output_manager_create(display);
14+	if (!swc.xdg_output_manager) {
15+		ERROR("Could not initialize XDG output manager\n");
16+		goto error17;
17+	}
18+
19 	setup_compositor();
20 
21 	return true;
22@@ -308,8 +315,10 @@ swc_finalize(void)
23 #ifdef ENABLE_XWAYLAND
24 	xserver_finalize();
25 #endif
26+	wl_global_destroy(swc.xdg_output_manager);
27 	wl_global_destroy(swc.wallpaper_manager);
28 	wl_global_destroy(swc.snap_manager);
29+	wl_global_destroy(swc.select_manager);
30 	wl_global_destroy(swc.panel_manager);
31 	wl_global_destroy(swc.xdg_decoration_manager);
32 	wl_global_destroy(swc.xdg_shell);
+77, -0
 1@@ -0,0 +1,77 @@
 2+/* swc: libswc/xdg_output.c
 3+ *
 4+ * Copyright (c) 2026 sewn <sewn@disroot.org>
 5+ *
 6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
 7+ * of this software and associated documentation files (the "Software"), to deal
 8+ * in the Software without restriction, including without limitation the rights
 9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+#include "xdg_output.h"
26+#include "output.h"
27+#include "screen.h"
28+#include "util.h"
29+
30+#include "xdg-output-unstable-v1-server-protocol.h"
31+
32+static const struct zxdg_output_v1_interface output_impl = {
33+	.destroy = destroy_resource,
34+};
35+
36+static void
37+get_output(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *output_resource)
38+{
39+	struct output *output =
40+	    wl_resource_get_user_data(output_resource);
41+	struct swc_rectangle *geom = &output->screen->base.geometry;
42+
43+	resource = wl_resource_create(client, &zxdg_output_v1_interface, wl_resource_get_version(resource), id);
44+	if (!resource) {
45+		wl_client_post_no_memory(client);
46+		return;
47+	}
48+
49+	wl_resource_set_implementation(resource, &output_impl, NULL, NULL);
50+	zxdg_output_v1_send_logical_position(resource, geom->x, geom->y);
51+	zxdg_output_v1_send_logical_size(resource, geom->width, geom->height);
52+	zxdg_output_v1_send_name(resource, output->name);
53+	wl_output_send_done(output->resource);
54+}
55+
56+static const struct zxdg_output_manager_v1_interface output_manager_impl = {
57+	.destroy = destroy_resource,
58+	.get_xdg_output = get_output,
59+};
60+
61+static void
62+bind_output_manager(struct wl_client *client, void *data, uint32_t version, uint32_t id)
63+{
64+	struct wl_resource *resource;
65+
66+	resource = wl_resource_create(client, &zxdg_output_manager_v1_interface, version, id);
67+	if (!resource) {
68+		wl_client_post_no_memory(client);
69+		return;
70+	}
71+	wl_resource_set_implementation(resource, &output_manager_impl, NULL, NULL);
72+}
73+
74+struct wl_global *
75+xdg_output_manager_create(struct wl_display *display)
76+{
77+	return wl_global_create(display, &zxdg_output_manager_v1_interface, 3, NULL, &bind_output_manager);
78+}
+33, -0
 1@@ -0,0 +1,33 @@
 2+/* swc: libswc/xdg_output.h
 3+ *
 4+ * Copyright (c) 2026 sewn <sewn@disroot.org>
 5+ *
 6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
 7+ * of this software and associated documentation files (the "Software"), to deal
 8+ * in the Software without restriction, including without limitation the rights
 9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+ * SOFTWARE.
23+ */
24+
25+#ifndef SWC_XDG_OUTPUT_H
26+#define SWC_XDG_OUTPUT_H
27+
28+struct wl_display;
29+struct wl_global;
30+
31+struct wl_global *
32+xdg_output_manager_create(struct wl_display *display);
33+
34+#endif