commit bc903f4

Michael Forney  ·  2020-01-28 06:04:39 +0000 UTC
parent 27d50e5
Add support for xdg-decoration protocol
7 files changed,  +115, -4
+2, -0
1@@ -6,6 +6,8 @@ protocol/swc-protocol.c
2 protocol/swc-server-protocol.h
3 protocol/wayland-drm-protocol.c
4 protocol/wayland-drm-server-protocol.h
5+protocol/xdg-decoration-unstable-v1-protocol.c
6+protocol/xdg-decoration-unstable-v1-server-protocol.h
7 protocol/xdg-shell-protocol.c
8 protocol/xdg-shell-server-protocol.h
9 protocol/linux-dmabuf-unstable-v1-server-protocol.h
+1, -0
1@@ -49,6 +49,7 @@ struct swc {
2 	struct wl_global *panel_manager;
3 	struct wl_global *shell;
4 	struct wl_global *subcompositor;
5+	struct wl_global *xdg_decoration_manager;
6 	struct wl_global *xdg_shell;
7 };
8 
+5, -2
 1@@ -53,11 +53,13 @@ SWC_SOURCES =                       \
 2     libswc/view.c                   \
 3     libswc/wayland_buffer.c         \
 4     libswc/window.c                 \
 5+    libswc/xdg_decoration.c         \
 6     libswc/xdg_shell.c              \
 7+    protocol/linux-dmabuf-unstable-v1-protocol.c \
 8     protocol/swc-protocol.c         \
 9     protocol/wayland-drm-protocol.c \
10-    protocol/xdg-shell-protocol.c   \
11-    protocol/linux-dmabuf-unstable-v1-protocol.c
12+    protocol/xdg-decoration-unstable-v1-protocol.c \
13+    protocol/xdg-shell-protocol.c
14 
15 ifeq ($(ENABLE_LIBUDEV),1)
16 $(dir)_CFLAGS += -DENABLE_LIBUDEV
17@@ -72,6 +74,7 @@ objects = $(foreach obj,$(1),$(dir)/$(obj).o $(dir)/$(obj).lo)
18 $(call objects,compositor panel_manager panel screen): protocol/swc-server-protocol.h
19 $(call objects,dmabuf): protocol/linux-dmabuf-unstable-v1-server-protocol.h
20 $(call objects,drm drm_buffer): protocol/wayland-drm-server-protocol.h
21+$(call objects,xdg_decoration): protocol/xdg-decoration-unstable-v1-server-protocol.h
22 $(call objects,xdg_shell): protocol/xdg-shell-server-protocol.h
23 $(call objects,pointer): cursor/cursor_data.h
24 
+11, -1
 1@@ -39,6 +39,7 @@
 2 #include "subcompositor.h"
 3 #include "util.h"
 4 #include "window.h"
 5+#include "xdg_decoration.h"
 6 #include "xdg_shell.h"
 7 
 8 extern struct swc_launch swc_launch;
 9@@ -167,16 +168,24 @@ swc_initialize(struct wl_display *display, struct wl_event_loop *event_loop, con
10 		goto error10;
11 	}
12 
13+	swc.xdg_decoration_manager = xdg_decoration_manager_create(display);
14+	if (!swc.xdg_decoration_manager) {
15+		ERROR("Could not initialize XDG decoration manager\n");
16+		goto error11;
17+	}
18+
19 	swc.panel_manager = panel_manager_create(display);
20 	if (!swc.panel_manager) {
21 		ERROR("Could not initialize panel manager\n");
22-		goto error11;
23+		goto error12;
24 	}
25 
26 	setup_compositor();
27 
28 	return true;
29 
30+error12:
31+	wl_global_destroy(swc.xdg_decoration_manager);
32 error11:
33 	wl_global_destroy(swc.xdg_shell);
34 error10:
35@@ -207,6 +216,7 @@ EXPORT void
36 swc_finalize(void)
37 {
38 	wl_global_destroy(swc.panel_manager);
39+	wl_global_destroy(swc.xdg_decoration_manager);
40 	wl_global_destroy(swc.xdg_shell);
41 	wl_global_destroy(swc.shell);
42 	seat_destroy(swc.seat);
+63, -0
 1@@ -0,0 +1,63 @@
 2+/* swc: libswc/xdg_decoration.c
 3+ *
 4+ * Copyright (c) 2020 Michael Forney
 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_decoration.h"
26+#include "util.h"
27+
28+#include <wayland-server.h>
29+#include "xdg-decoration-unstable-v1-server-protocol.h"
30+
31+static void
32+get_toplevel_decoration(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *toplevel_resource)
33+{
34+	struct wl_resource *decoration;
35+
36+	decoration = wl_resource_create(client, &zxdg_toplevel_decoration_v1_interface, wl_resource_get_version(resource), id);
37+	if (!decoration)
38+		wl_resource_post_no_memory(resource);
39+	zxdg_toplevel_decoration_v1_send_configure(decoration, ZXDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
40+}
41+
42+static const struct zxdg_decoration_manager_v1_interface decoration_manager_impl = {
43+	.destroy = destroy_resource,
44+	.get_toplevel_decoration = get_toplevel_decoration,
45+};
46+
47+static void
48+bind_decoration_manager(struct wl_client *client, void *data, uint32_t version, uint32_t id)
49+{
50+	struct wl_resource *resource;
51+
52+	resource = wl_resource_create(client, &zxdg_decoration_manager_v1_interface, version, id);
53+	if (!resource) {
54+		wl_client_post_no_memory(client);
55+		return;
56+	}
57+	wl_resource_set_implementation(resource, &decoration_manager_impl, NULL, NULL);
58+}
59+
60+struct wl_global *
61+xdg_decoration_manager_create(struct wl_display *display)
62+{
63+	return wl_global_create(display, &zxdg_decoration_manager_v1_interface, 1, NULL, &bind_decoration_manager);
64+}
+31, -0
 1@@ -0,0 +1,31 @@
 2+/* swc: libswc/xdg_decoration.h
 3+ *
 4+ * Copyright (c) 2020 Michael Forney
 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_DECORATION_H
26+#define SWC_XDG_DECORATION_H
27+
28+struct wl_display;
29+
30+struct wl_global *xdg_decoration_manager_create(struct wl_display *display);
31+
32+#endif
+2, -1
 1@@ -7,7 +7,8 @@ PROTOCOL_EXTENSIONS =           \
 2     $(dir)/swc.xml              \
 3     $(dir)/wayland-drm.xml      \
 4     $(wayland_protocols)/stable/xdg-shell/xdg-shell.xml \
 5-    $(wayland_protocols)/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml
 6+    $(wayland_protocols)/unstable/linux-dmabuf/linux-dmabuf-unstable-v1.xml \
 7+    $(wayland_protocols)/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml
 8 
 9 $(dir)_PACKAGES := wayland-server
10