commit 17d40aa

Michael Forney  ·  2020-01-28 06:22:51 +0000 UTC
parent bc903f4
Add support for KDE server-side decoration protocol

GTK still does not support xdg-decoration, so implement this for
now.
8 files changed,  +219, -1
+2, -0
1@@ -2,6 +2,8 @@
2 *.lo
3 .*.sw*
4 
5+protocol/server-decoration-protocol.c
6+protocol/server-decoration-server-protocol.h
7 protocol/swc-protocol.c
8 protocol/swc-server-protocol.h
9 protocol/wayland-drm-protocol.c
+1, -0
1@@ -46,6 +46,7 @@ struct swc {
2 	struct swc_shm *shm;
3 	struct swc_drm *const drm;
4 	struct wl_global *data_device_manager;
5+	struct wl_global *kde_decoration_manager;
6 	struct wl_global *panel_manager;
7 	struct wl_global *shell;
8 	struct wl_global *subcompositor;
+75, -0
 1@@ -0,0 +1,75 @@
 2+/* swc: libswc/kde_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 "kde_decoration.h"
26+
27+#include <wayland-server.h>
28+#include "server-decoration-server-protocol.h"
29+
30+static void
31+request_mode(struct wl_client *client, struct wl_resource *resource, uint32_t mode)
32+{
33+	/* Server is required to send back the mode requested by
34+	 * the client, we just don't plan to do anything with it. */
35+	org_kde_kwin_server_decoration_send_mode(resource, mode);
36+}
37+
38+static const struct org_kde_kwin_server_decoration_interface decoration_impl = {
39+	.request_mode = request_mode,
40+};
41+
42+static void
43+create(struct wl_client *client, struct wl_resource *resource, uint32_t id, struct wl_resource *toplevel_resource)
44+{
45+	struct wl_resource *decoration;
46+
47+	decoration = wl_resource_create(client, &org_kde_kwin_server_decoration_interface, wl_resource_get_version(resource), id);
48+	if (!decoration)
49+		wl_resource_post_no_memory(resource);
50+	wl_resource_set_implementation(decoration, &decoration_impl, NULL, NULL);
51+	org_kde_kwin_server_decoration_send_mode(decoration, ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_SERVER);
52+}
53+
54+static const struct org_kde_kwin_server_decoration_manager_interface decoration_manager_impl = {
55+	.create = create,
56+};
57+
58+static void
59+bind_decoration_manager(struct wl_client *client, void *data, uint32_t version, uint32_t id)
60+{
61+	struct wl_resource *resource;
62+
63+	resource = wl_resource_create(client, &org_kde_kwin_server_decoration_manager_interface, version, id);
64+	if (!resource) {
65+		wl_client_post_no_memory(client);
66+		return;
67+	}
68+	wl_resource_set_implementation(resource, &decoration_manager_impl, NULL, NULL);
69+	org_kde_kwin_server_decoration_manager_send_default_mode(resource, ORG_KDE_KWIN_SERVER_DECORATION_MANAGER_MODE_SERVER);
70+}
71+
72+struct wl_global *
73+kde_decoration_manager_create(struct wl_display *display)
74+{
75+	return wl_global_create(display, &org_kde_kwin_server_decoration_manager_interface, 1, NULL, &bind_decoration_manager);
76+}
+31, -0
 1@@ -0,0 +1,31 @@
 2+/* swc: libswc/kde_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_KDE_DECORATION_H
26+#define SWC_KDE_DECORATION_H
27+
28+struct wl_display;
29+
30+struct wl_global *kde_decoration_manager_create(struct wl_display *display);
31+
32+#endif
+3, -0
 1@@ -30,6 +30,7 @@ SWC_SOURCES =                       \
 2     libswc/dmabuf.c                 \
 3     libswc/drm.c                    \
 4     libswc/input.c                  \
 5+    libswc/kde_decoration.c         \
 6     libswc/keyboard.c               \
 7     libswc/launch.c                 \
 8     libswc/mode.c                   \
 9@@ -56,6 +57,7 @@ SWC_SOURCES =                       \
10     libswc/xdg_decoration.c         \
11     libswc/xdg_shell.c              \
12     protocol/linux-dmabuf-unstable-v1-protocol.c \
13+    protocol/server-decoration-protocol.c \
14     protocol/swc-protocol.c         \
15     protocol/wayland-drm-protocol.c \
16     protocol/xdg-decoration-unstable-v1-protocol.c \
17@@ -74,6 +76,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,kde_decoration): protocol/server-decoration-server-protocol.h
22 $(call objects,xdg_decoration): protocol/xdg-decoration-unstable-v1-server-protocol.h
23 $(call objects,xdg_shell): protocol/xdg-shell-server-protocol.h
24 $(call objects,pointer): cursor/cursor_data.h
+10, -1
 1@@ -29,6 +29,7 @@
 2 #include "event.h"
 3 #include "internal.h"
 4 #include "launch.h"
 5+#include "kde_decoration.h"
 6 #include "keyboard.h"
 7 #include "panel_manager.h"
 8 #include "pointer.h"
 9@@ -174,16 +175,24 @@ swc_initialize(struct wl_display *display, struct wl_event_loop *event_loop, con
10 		goto error11;
11 	}
12 
13+	swc.kde_decoration_manager = kde_decoration_manager_create(display);
14+	if (!swc.kde_decoration_manager) {
15+		ERROR("Could not initialize KDE decoration manager\n");
16+		goto error12;
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 error12;
23+		goto error13;
24 	}
25 
26 	setup_compositor();
27 
28 	return true;
29 
30+error13:
31+	wl_global_destroy(swc.kde_decoration_manager);
32 error12:
33 	wl_global_destroy(swc.xdg_decoration_manager);
34 error11:
+1, -0
1@@ -4,6 +4,7 @@ dir := protocol
2 wayland_protocols := $(call pkgconfig,wayland-protocols,variable=pkgdatadir,DATADIR)
3 
4 PROTOCOL_EXTENSIONS =           \
5+    $(dir)/server-decoration.xml\
6     $(dir)/swc.xml              \
7     $(dir)/wayland-drm.xml      \
8     $(wayland_protocols)/stable/xdg-shell/xdg-shell.xml \
+96, -0
 1@@ -0,0 +1,96 @@
 2+<?xml version="1.0" encoding="UTF-8"?>
 3+<protocol name="server_decoration">
 4+  <copyright><![CDATA[
 5+    Copyright (C) 2015 Martin Gräßlin
 6+
 7+    This program is free software: you can redistribute it and/or modify
 8+    it under the terms of the GNU Lesser General Public License as published by
 9+    the Free Software Foundation, either version 2.1 of the License, or
10+    (at your option) any later version.
11+
12+    This program is distributed in the hope that it will be useful,
13+    but WITHOUT ANY WARRANTY; without even the implied warranty of
14+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15+    GNU Lesser General Public License for more details.
16+
17+    You should have received a copy of the GNU Lesser General Public License
18+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19+  ]]></copyright>
20+  <interface  name="org_kde_kwin_server_decoration_manager" version="1">
21+      <description summary="Server side window decoration manager">
22+        This interface allows to coordinate whether the server should create
23+        a server-side window decoration around a wl_surface representing a
24+        shell surface (wl_shell_surface or similar). By announcing support
25+        for this interface the server indicates that it supports server
26+        side decorations.
27+
28+        Use in conjunction with zxdg_decoration_manager_v1 is undefined.
29+      </description>
30+      <request name="create">
31+        <description summary="Create a server-side decoration object for a given surface">
32+            When a client creates a server-side decoration object it indicates
33+            that it supports the protocol. The client is supposed to tell the
34+            server whether it wants server-side decorations or will provide
35+            client-side decorations.
36+
37+            If the client does not create a server-side decoration object for
38+            a surface the server interprets this as lack of support for this
39+            protocol and considers it as client-side decorated. Nevertheless a
40+            client-side decorated surface should use this protocol to indicate
41+            to the server that it does not want a server-side deco.
42+        </description>
43+        <arg name="id" type="new_id" interface="org_kde_kwin_server_decoration"/>
44+        <arg name="surface" type="object" interface="wl_surface"/>
45+      </request>
46+      <enum name="mode">
47+            <description summary="Possible values to use in request_mode and the event mode."/>
48+            <entry name="None" value="0" summary="Undecorated: The surface is not decorated at all, neither server nor client-side. An example is a popup surface which should not be decorated."/>
49+            <entry name="Client" value="1" summary="Client-side decoration: The decoration is part of the surface and the client."/>
50+            <entry name="Server" value="2" summary="Server-side decoration: The server embeds the surface into a decoration frame."/>
51+      </enum>
52+      <event name="default_mode">
53+          <description summary="The default mode used on the server">
54+              This event is emitted directly after binding the interface. It contains
55+              the default mode for the decoration. When a new server decoration object
56+              is created this new object will be in the default mode until the first
57+              request_mode is requested.
58+
59+              The server may change the default mode at any time.
60+          </description>
61+          <arg name="mode" type="uint" summary="The default decoration mode applied to newly created server decorations."/>
62+      </event>
63+  </interface>
64+  <interface name="org_kde_kwin_server_decoration" version="1">
65+      <request name="release" type="destructor">
66+        <description summary="release the server decoration object"/>
67+      </request>
68+      <enum name="mode">
69+            <description summary="Possible values to use in request_mode and the event mode."/>
70+            <entry name="None" value="0" summary="Undecorated: The surface is not decorated at all, neither server nor client-side. An example is a popup surface which should not be decorated."/>
71+            <entry name="Client" value="1" summary="Client-side decoration: The decoration is part of the surface and the client."/>
72+            <entry name="Server" value="2" summary="Server-side decoration: The server embeds the surface into a decoration frame."/>
73+      </enum>
74+      <request name="request_mode">
75+          <description summary="The decoration mode the surface wants to use."/>
76+          <arg name="mode" type="uint" summary="The mode this surface wants to use."/>
77+      </request>
78+      <event name="mode">
79+          <description summary="The new decoration mode applied by the server">
80+              This event is emitted directly after the decoration is created and
81+              represents the base decoration policy by the server. E.g. a server
82+              which wants all surfaces to be client-side decorated will send Client,
83+              a server which wants server-side decoration will send Server.
84+
85+              The client can request a different mode through the decoration request.
86+              The server will acknowledge this by another event with the same mode. So
87+              even if a server prefers server-side decoration it's possible to force a
88+              client-side decoration.
89+
90+              The server may emit this event at any time. In this case the client can
91+              again request a different mode. It's the responsibility of the server to
92+              prevent a feedback loop.
93+          </description>
94+          <arg name="mode" type="uint" summary="The decoration mode applied to the surface by the server."/>
95+      </event>
96+  </interface>
97+</protocol>