aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Drew DeVault <sir@cmpwn.com>2017-04-28 20:32:05 -0400
committerLibravatar Drew DeVault <sir@cmpwn.com>2017-04-28 20:32:05 -0400
commita5c07dde6aba87584ddb6c6a2769472a6003623a (patch)
tree45dd827f6c8f49ca003caefb8aa990b2f368e8f5
parentUpdate .build.yml (diff)
downloadsway-a5c07dde6aba87584ddb6c6a2769472a6003623a.tar.gz
sway-a5c07dde6aba87584ddb6c6a2769472a6003623a.tar.zst
sway-a5c07dde6aba87584ddb6c6a2769472a6003623a.zip
Implement KDE's server-side decoration protocol
-rw-r--r--include/sway/extensions.h7
-rw-r--r--protocols/CMakeLists.txt6
-rw-r--r--protocols/server-decoration.xml94
-rw-r--r--sway/extensions.c87
-rw-r--r--sway/handlers.c10
5 files changed, 198 insertions, 6 deletions
diff --git a/include/sway/extensions.h b/include/sway/extensions.h
index f6b0c00e..5212eb3a 100644
--- a/include/sway/extensions.h
+++ b/include/sway/extensions.h
@@ -42,8 +42,15 @@ struct swaylock_state {
42 wlc_resource surface; 42 wlc_resource surface;
43}; 43};
44 44
45struct decoration_state {
46 list_t *csd_resources;
47};
48
45extern struct desktop_shell_state desktop_shell; 49extern struct desktop_shell_state desktop_shell;
50extern struct decoration_state decoration_state;
46 51
47void register_extensions(void); 52void register_extensions(void);
48 53
54void server_decoration_enable_csd(wlc_handle handle);
55
49#endif 56#endif
diff --git a/protocols/CMakeLists.txt b/protocols/CMakeLists.txt
index a9b459ab..8d8e58ad 100644
--- a/protocols/CMakeLists.txt
+++ b/protocols/CMakeLists.txt
@@ -27,6 +27,11 @@ WAYLAND_ADD_PROTOCOL_SERVER(proto-server-gamma-control
27 gamma-control 27 gamma-control
28) 28)
29 29
30WAYLAND_ADD_PROTOCOL_SERVER(proto-server-server-decoration
31 server-decoration.xml
32 server-decoration
33)
34
30add_library(sway-protocols STATIC 35add_library(sway-protocols STATIC
31 ${proto-client-xdg-shell} 36 ${proto-client-xdg-shell}
32 ${proto-client-desktop-shell} 37 ${proto-client-desktop-shell}
@@ -34,6 +39,7 @@ add_library(sway-protocols STATIC
34 ${proto-client-swaylock} 39 ${proto-client-swaylock}
35 ${proto-server-swaylock} 40 ${proto-server-swaylock}
36 ${proto-server-gamma-control} 41 ${proto-server-gamma-control}
42 ${proto-server-server-decoration}
37 ) 43 )
38 44
39set(PROTOCOLS_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/protocols PARENT_SCOPE) 45set(PROTOCOLS_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/protocols PARENT_SCOPE)
diff --git a/protocols/server-decoration.xml b/protocols/server-decoration.xml
new file mode 100644
index 00000000..8bc106c7
--- /dev/null
+++ b/protocols/server-decoration.xml
@@ -0,0 +1,94 @@
1<?xml version="1.0" encoding="UTF-8"?>
2<protocol name="server_decoration">
3 <copyright><![CDATA[
4 Copyright (C) 2015 Martin Gräßlin
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation, either version 2.1 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
15
16 You should have received a copy of the GNU Lesser General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18 ]]></copyright>
19 <interface name="org_kde_kwin_server_decoration_manager" version="1">
20 <description summary="Server side window decoration manager">
21 This interface allows to coordinate whether the server should create
22 a server-side window decoration around a wl_surface representing a
23 shell surface (wl_shell_surface or similar). By announcing support
24 for this interface the server indicates that it supports server
25 side decorations.
26 </description>
27 <request name="create">
28 <description summary="Create a server-side decoration object for a given surface">
29 When a client creates a server-side decoration object it indicates
30 that it supports the protocol. The client is supposed to tell the
31 server whether it wants server-side decorations or will provide
32 client-side decorations.
33
34 If the client does not create a server-side decoration object for
35 a surface the server interprets this as lack of support for this
36 protocol and considers it as client-side decorated. Nevertheless a
37 client-side decorated surface should use this protocol to indicate
38 to the server that it does not want a server-side deco.
39 </description>
40 <arg name="id" type="new_id" interface="org_kde_kwin_server_decoration"/>
41 <arg name="surface" type="object" interface="wl_surface"/>
42 </request>
43 <enum name="mode">
44 <description summary="Possible values to use in request_mode and the event mode."/>
45 <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."/>
46 <entry name="Client" value="1" summary="Client-side decoration: The decoration is part of the surface and the client."/>
47 <entry name="Server" value="2" summary="Server-side decoration: The server embeds the surface into a decoration frame."/>
48 </enum>
49 <event name="default_mode">
50 <description summary="The default mode used on the server">
51 This event is emitted directly after binding the interface. It contains
52 the default mode for the decoration. When a new server decoration object
53 is created this new object will be in the default mode until the first
54 request_mode is requested.
55
56 The server may change the default mode at any time.
57 </description>
58 <arg name="mode" type="uint" summary="The default decoration mode applied to newly created server decorations."/>
59 </event>
60 </interface>
61 <interface name="org_kde_kwin_server_decoration" version="1">
62 <request name="release" type="destructor">
63 <description summary="release the server decoration object"/>
64 </request>
65 <enum name="mode">
66 <description summary="Possible values to use in request_mode and the event mode."/>
67 <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."/>
68 <entry name="Client" value="1" summary="Client-side decoration: The decoration is part of the surface and the client."/>
69 <entry name="Server" value="2" summary="Server-side decoration: The server embeds the surface into a decoration frame."/>
70 </enum>
71 <request name="request_mode">
72 <description summary="The decoration mode the surface wants to use."/>
73 <arg name="mode" type="uint" summary="The mode this surface wants to use."/>
74 </request>
75 <event name="mode">
76 <description summary="The new decoration mode applied by the server">
77 This event is emitted directly after the decoration is created and
78 represents the base decoration policy by the server. E.g. a server
79 which wants all surfaces to be client-side decorated will send Client,
80 a server which wants server-side decoration will send Server.
81
82 The client can request a different mode through the decoration request.
83 The server will acknowledge this by another event with the same mode. So
84 even if a server prefers server-side decoration it's possible to force a
85 client-side decoration.
86
87 The server may emit this event at any time. In this case the client can
88 again request a different mode. It's the responsibility of the server to
89 prevent a feedback loop.
90 </description>
91 <arg name="mode" type="uint" summary="The decoration mode applied to the surface by the server."/>
92 </event>
93 </interface>
94</protocol>
diff --git a/sway/extensions.c b/sway/extensions.c
index 96957dbf..91746561 100644
--- a/sway/extensions.c
+++ b/sway/extensions.c
@@ -5,6 +5,7 @@
5#include "wayland-desktop-shell-server-protocol.h" 5#include "wayland-desktop-shell-server-protocol.h"
6#include "wayland-swaylock-server-protocol.h" 6#include "wayland-swaylock-server-protocol.h"
7#include "wayland-gamma-control-server-protocol.h" 7#include "wayland-gamma-control-server-protocol.h"
8#include "wayland-server-decoration-server-protocol.h"
8#include "sway/layout.h" 9#include "sway/layout.h"
9#include "sway/input_state.h" 10#include "sway/input_state.h"
10#include "sway/extensions.h" 11#include "sway/extensions.h"
@@ -13,6 +14,7 @@
13#include "log.h" 14#include "log.h"
14 15
15struct desktop_shell_state desktop_shell; 16struct desktop_shell_state desktop_shell;
17struct decoration_state decoration_state;
16 18
17static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) { 19static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) {
18 for (int i = 0; i < desktop_shell.panels->length; i++) { 20 for (int i = 0; i < desktop_shell.panels->length; i++) {
@@ -173,7 +175,7 @@ static struct desktop_shell_interface desktop_shell_implementation = {
173}; 175};
174 176
175static void desktop_shell_bind(struct wl_client *client, void *data, 177static void desktop_shell_bind(struct wl_client *client, void *data,
176 unsigned int version, unsigned int id) { 178 uint32_t version, uint32_t id) {
177 if (version > 3) { 179 if (version > 3) {
178 // Unsupported version 180 // Unsupported version
179 return; 181 return;
@@ -232,7 +234,7 @@ static struct lock_interface swaylock_implementation = {
232}; 234};
233 235
234static void swaylock_bind(struct wl_client *client, void *data, 236static void swaylock_bind(struct wl_client *client, void *data,
235 unsigned int version, unsigned int id) { 237 uint32_t version, uint32_t id) {
236 if (version > 1) { 238 if (version > 1) {
237 // Unsupported version 239 // Unsupported version
238 return; 240 return;
@@ -305,28 +307,101 @@ static struct gamma_control_manager_interface gamma_manager_implementation = {
305}; 307};
306 308
307static void gamma_control_manager_bind(struct wl_client *client, void *data, 309static void gamma_control_manager_bind(struct wl_client *client, void *data,
308 unsigned int version, unsigned int fd) { 310 uint32_t version, uint32_t id) {
309 if (version > 1) { 311 if (version > 1) {
310 // Unsupported version 312 // Unsupported version
311 return; 313 return;
312 } 314 }
313
314 struct wl_resource *resource = wl_resource_create(client, 315 struct wl_resource *resource = wl_resource_create(client,
315 &gamma_control_manager_interface, version, fd); 316 &gamma_control_manager_interface, version, id);
316 if (!resource) { 317 if (!resource) {
317 wl_client_post_no_memory(client); 318 wl_client_post_no_memory(client);
318 } 319 }
319
320 wl_resource_set_implementation(resource, &gamma_manager_implementation, NULL, NULL); 320 wl_resource_set_implementation(resource, &gamma_manager_implementation, NULL, NULL);
321} 321}
322 322
323static void server_decoration_release(struct wl_client *client,
324 struct wl_resource *resource) {
325 wl_resource_destroy(resource);
326}
327
328void server_decoration_enable_csd(wlc_handle handle) {
329 swayc_t *view = swayc_by_handle(handle);
330 if (!view) {
331 sway_log(L_DEBUG, "view invalid");
332 return;
333 }
334 sway_log(L_DEBUG, "%s requested client side decorations", view->name);
335 view->border_type = B_NONE;
336 update_geometry(view);
337}
338
339static void server_decoration_request_mode(struct wl_client *client,
340 struct wl_resource *resource, uint32_t mode) {
341 sway_log(L_DEBUG, "Client requested server decoration mode %d", mode);
342 if (mode == ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER) {
343 return;
344 }
345 struct wl_resource *surface = wl_resource_get_user_data(resource);
346 if (!surface) {
347 sway_log(L_DEBUG, "surface invalid");
348 return;
349 }
350 wlc_handle handle = wlc_handle_from_wl_surface_resource(surface);
351 if (!handle) {
352 list_add(decoration_state.csd_resources, surface);
353 return;
354 }
355 server_decoration_enable_csd(handle);
356}
357
358static struct org_kde_kwin_server_decoration_interface server_decoration_implementation = {
359 .release = server_decoration_release,
360 .request_mode = server_decoration_request_mode,
361};
362
363static void server_decoration_manager_create(struct wl_client *client,
364 struct wl_resource *resource, uint32_t id, struct wl_resource *surface) {
365 sway_log(L_DEBUG, "Client requested server decoration manager");
366 struct wl_resource *manager = wl_resource_create(client,
367 &org_kde_kwin_server_decoration_interface, 1, id);
368 if (!manager) {
369 wl_client_post_no_memory(client);
370 }
371 wl_resource_set_implementation(manager, &server_decoration_implementation, surface, NULL);
372}
373
374// Jesus christ KDE, these names are whack as hell
375static struct org_kde_kwin_server_decoration_manager_interface server_decoration_manager_implementation = {
376 .create = server_decoration_manager_create,
377};
378
379static void server_decoration_manager_bind(struct wl_client *client, void *data,
380 uint32_t version, uint32_t id) {
381 if (version > 1) {
382 // Unsupported version
383 return;
384 }
385 struct wl_resource *resource = wl_resource_create(client,
386 &org_kde_kwin_server_decoration_manager_interface, version, id);
387 if (!resource) {
388 wl_client_post_no_memory(client);
389 }
390 wl_resource_set_implementation(resource, &server_decoration_manager_implementation, NULL, NULL);
391 org_kde_kwin_server_decoration_manager_send_default_mode(resource,
392 ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER);
393}
394
323void register_extensions(void) { 395void register_extensions(void) {
324 wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind); 396 wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind);
325 desktop_shell.backgrounds = create_list(); 397 desktop_shell.backgrounds = create_list();
326 desktop_shell.panels = create_list(); 398 desktop_shell.panels = create_list();
327 desktop_shell.lock_surfaces = create_list(); 399 desktop_shell.lock_surfaces = create_list();
328 desktop_shell.is_locked = false; 400 desktop_shell.is_locked = false;
401 decoration_state.csd_resources = create_list();
329 wl_global_create(wlc_get_wl_display(), &lock_interface, 1, NULL, swaylock_bind); 402 wl_global_create(wlc_get_wl_display(), &lock_interface, 1, NULL, swaylock_bind);
330 wl_global_create(wlc_get_wl_display(), &gamma_control_manager_interface, 1, 403 wl_global_create(wlc_get_wl_display(), &gamma_control_manager_interface, 1,
331 NULL, gamma_control_manager_bind); 404 NULL, gamma_control_manager_bind);
405 wl_global_create(wlc_get_wl_display(), &org_kde_kwin_server_decoration_manager_interface ,
406 1, NULL, server_decoration_manager_bind);
332} 407}
diff --git a/sway/handlers.c b/sway/handlers.c
index da765d6d..0aa35c26 100644
--- a/sway/handlers.c
+++ b/sway/handlers.c
@@ -345,6 +345,8 @@ static bool handle_view_created(wlc_handle handle) {
345 swayc_t *current_ws = swayc_active_workspace(); 345 swayc_t *current_ws = swayc_active_workspace();
346 bool return_to_workspace = false; 346 bool return_to_workspace = false;
347 struct wl_client *client = wlc_view_get_wl_client(handle); 347 struct wl_client *client = wlc_view_get_wl_client(handle);
348 struct wl_resource *resource = wlc_surface_get_wl_resource(
349 wlc_view_get_surface(handle));
348 pid_t pid; 350 pid_t pid;
349 struct panel_config *panel_config = NULL; 351 struct panel_config *panel_config = NULL;
350 struct background_config *background_config = NULL; 352 struct background_config *background_config = NULL;
@@ -483,6 +485,14 @@ static bool handle_view_created(wlc_handle handle) {
483 if (workspace && workspace->fullscreen) { 485 if (workspace && workspace->fullscreen) {
484 set_focused_container(workspace->fullscreen); 486 set_focused_container(workspace->fullscreen);
485 } 487 }
488 for (int i = 0; i < decoration_state.csd_resources->length; ++i) {
489 struct wl_resource *res = decoration_state.csd_resources->items[i];
490 if (res == resource) {
491 list_del(decoration_state.csd_resources, i);
492 server_decoration_enable_csd(handle);
493 break;
494 }
495 }
486 } else { 496 } else {
487 swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT); 497 swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT);
488 wlc_handle *h = malloc(sizeof(wlc_handle)); 498 wlc_handle *h = malloc(sizeof(wlc_handle));