From a5c07dde6aba87584ddb6c6a2769472a6003623a Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Fri, 28 Apr 2017 20:32:05 -0400 Subject: Implement KDE's server-side decoration protocol --- include/sway/extensions.h | 7 +++ protocols/CMakeLists.txt | 6 +++ protocols/server-decoration.xml | 94 +++++++++++++++++++++++++++++++++++++++++ sway/extensions.c | 87 +++++++++++++++++++++++++++++++++++--- sway/handlers.c | 10 +++++ 5 files changed, 198 insertions(+), 6 deletions(-) create mode 100644 protocols/server-decoration.xml 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 { wlc_resource surface; }; +struct decoration_state { + list_t *csd_resources; +}; + extern struct desktop_shell_state desktop_shell; +extern struct decoration_state decoration_state; void register_extensions(void); +void server_decoration_enable_csd(wlc_handle handle); + #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 gamma-control ) +WAYLAND_ADD_PROTOCOL_SERVER(proto-server-server-decoration + server-decoration.xml + server-decoration +) + add_library(sway-protocols STATIC ${proto-client-xdg-shell} ${proto-client-desktop-shell} @@ -34,6 +39,7 @@ add_library(sway-protocols STATIC ${proto-client-swaylock} ${proto-server-swaylock} ${proto-server-gamma-control} + ${proto-server-server-decoration} ) set(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 @@ + + + . + ]]> + + + This interface allows to coordinate whether the server should create + a server-side window decoration around a wl_surface representing a + shell surface (wl_shell_surface or similar). By announcing support + for this interface the server indicates that it supports server + side decorations. + + + + When a client creates a server-side decoration object it indicates + that it supports the protocol. The client is supposed to tell the + server whether it wants server-side decorations or will provide + client-side decorations. + + If the client does not create a server-side decoration object for + a surface the server interprets this as lack of support for this + protocol and considers it as client-side decorated. Nevertheless a + client-side decorated surface should use this protocol to indicate + to the server that it does not want a server-side deco. + + + + + + + + + + + + + This event is emitted directly after binding the interface. It contains + the default mode for the decoration. When a new server decoration object + is created this new object will be in the default mode until the first + request_mode is requested. + + The server may change the default mode at any time. + + + + + + + + + + + + + + + + + + + + + This event is emitted directly after the decoration is created and + represents the base decoration policy by the server. E.g. a server + which wants all surfaces to be client-side decorated will send Client, + a server which wants server-side decoration will send Server. + + The client can request a different mode through the decoration request. + The server will acknowledge this by another event with the same mode. So + even if a server prefers server-side decoration it's possible to force a + client-side decoration. + + The server may emit this event at any time. In this case the client can + again request a different mode. It's the responsibility of the server to + prevent a feedback loop. + + + + + 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 @@ #include "wayland-desktop-shell-server-protocol.h" #include "wayland-swaylock-server-protocol.h" #include "wayland-gamma-control-server-protocol.h" +#include "wayland-server-decoration-server-protocol.h" #include "sway/layout.h" #include "sway/input_state.h" #include "sway/extensions.h" @@ -13,6 +14,7 @@ #include "log.h" struct desktop_shell_state desktop_shell; +struct decoration_state decoration_state; static struct panel_config *find_or_create_panel_config(struct wl_resource *resource) { for (int i = 0; i < desktop_shell.panels->length; i++) { @@ -173,7 +175,7 @@ static struct desktop_shell_interface desktop_shell_implementation = { }; static void desktop_shell_bind(struct wl_client *client, void *data, - unsigned int version, unsigned int id) { + uint32_t version, uint32_t id) { if (version > 3) { // Unsupported version return; @@ -232,7 +234,7 @@ static struct lock_interface swaylock_implementation = { }; static void swaylock_bind(struct wl_client *client, void *data, - unsigned int version, unsigned int id) { + uint32_t version, uint32_t id) { if (version > 1) { // Unsupported version return; @@ -305,28 +307,101 @@ static struct gamma_control_manager_interface gamma_manager_implementation = { }; static void gamma_control_manager_bind(struct wl_client *client, void *data, - unsigned int version, unsigned int fd) { + uint32_t version, uint32_t id) { if (version > 1) { // Unsupported version return; } - struct wl_resource *resource = wl_resource_create(client, - &gamma_control_manager_interface, version, fd); + &gamma_control_manager_interface, version, id); if (!resource) { wl_client_post_no_memory(client); } - wl_resource_set_implementation(resource, &gamma_manager_implementation, NULL, NULL); } +static void server_decoration_release(struct wl_client *client, + struct wl_resource *resource) { + wl_resource_destroy(resource); +} + +void server_decoration_enable_csd(wlc_handle handle) { + swayc_t *view = swayc_by_handle(handle); + if (!view) { + sway_log(L_DEBUG, "view invalid"); + return; + } + sway_log(L_DEBUG, "%s requested client side decorations", view->name); + view->border_type = B_NONE; + update_geometry(view); +} + +static void server_decoration_request_mode(struct wl_client *client, + struct wl_resource *resource, uint32_t mode) { + sway_log(L_DEBUG, "Client requested server decoration mode %d", mode); + if (mode == ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER) { + return; + } + struct wl_resource *surface = wl_resource_get_user_data(resource); + if (!surface) { + sway_log(L_DEBUG, "surface invalid"); + return; + } + wlc_handle handle = wlc_handle_from_wl_surface_resource(surface); + if (!handle) { + list_add(decoration_state.csd_resources, surface); + return; + } + server_decoration_enable_csd(handle); +} + +static struct org_kde_kwin_server_decoration_interface server_decoration_implementation = { + .release = server_decoration_release, + .request_mode = server_decoration_request_mode, +}; + +static void server_decoration_manager_create(struct wl_client *client, + struct wl_resource *resource, uint32_t id, struct wl_resource *surface) { + sway_log(L_DEBUG, "Client requested server decoration manager"); + struct wl_resource *manager = wl_resource_create(client, + &org_kde_kwin_server_decoration_interface, 1, id); + if (!manager) { + wl_client_post_no_memory(client); + } + wl_resource_set_implementation(manager, &server_decoration_implementation, surface, NULL); +} + +// Jesus christ KDE, these names are whack as hell +static struct org_kde_kwin_server_decoration_manager_interface server_decoration_manager_implementation = { + .create = server_decoration_manager_create, +}; + +static void server_decoration_manager_bind(struct wl_client *client, void *data, + uint32_t version, uint32_t id) { + if (version > 1) { + // Unsupported version + return; + } + struct wl_resource *resource = wl_resource_create(client, + &org_kde_kwin_server_decoration_manager_interface, version, id); + if (!resource) { + wl_client_post_no_memory(client); + } + wl_resource_set_implementation(resource, &server_decoration_manager_implementation, NULL, NULL); + org_kde_kwin_server_decoration_manager_send_default_mode(resource, + ORG_KDE_KWIN_SERVER_DECORATION_MODE_SERVER); +} + void register_extensions(void) { wl_global_create(wlc_get_wl_display(), &desktop_shell_interface, 3, NULL, desktop_shell_bind); desktop_shell.backgrounds = create_list(); desktop_shell.panels = create_list(); desktop_shell.lock_surfaces = create_list(); desktop_shell.is_locked = false; + decoration_state.csd_resources = create_list(); wl_global_create(wlc_get_wl_display(), &lock_interface, 1, NULL, swaylock_bind); wl_global_create(wlc_get_wl_display(), &gamma_control_manager_interface, 1, NULL, gamma_control_manager_bind); + wl_global_create(wlc_get_wl_display(), &org_kde_kwin_server_decoration_manager_interface , + 1, NULL, server_decoration_manager_bind); } 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) { swayc_t *current_ws = swayc_active_workspace(); bool return_to_workspace = false; struct wl_client *client = wlc_view_get_wl_client(handle); + struct wl_resource *resource = wlc_surface_get_wl_resource( + wlc_view_get_surface(handle)); pid_t pid; struct panel_config *panel_config = NULL; struct background_config *background_config = NULL; @@ -483,6 +485,14 @@ static bool handle_view_created(wlc_handle handle) { if (workspace && workspace->fullscreen) { set_focused_container(workspace->fullscreen); } + for (int i = 0; i < decoration_state.csd_resources->length; ++i) { + struct wl_resource *res = decoration_state.csd_resources->items[i]; + if (res == resource) { + list_del(decoration_state.csd_resources, i); + server_decoration_enable_csd(handle); + break; + } + } } else { swayc_t *output = swayc_parent_by_type(focused, C_OUTPUT); wlc_handle *h = malloc(sizeof(wlc_handle)); -- cgit v1.2.3-54-g00ecf