From 71afa388906bf29dcd937aa92b65a97c8b320f60 Mon Sep 17 00:00:00 2001 From: Drew DeVault Date: Thu, 3 Dec 2015 08:35:22 -0500 Subject: Add swaylock protocol, add resource destructors This prevents sway crashing if swaybg or swaybar dies. --- common/libsway-common.a | Bin 0 -> 59254 bytes include/extensions.h | 11 ++++++++++- protocols/CMakeLists.txt | 11 +++++++++++ protocols/libsway-protocols.a | Bin 0 -> 31798 bytes protocols/swaylock.xml | 18 ++++++++++++++++++ sway/extensions.c | 29 +++++++++++++++++++++++++++++ wayland/libsway-wayland.a | Bin 0 -> 70060 bytes 7 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 common/libsway-common.a create mode 100644 protocols/libsway-protocols.a create mode 100644 protocols/swaylock.xml create mode 100644 wayland/libsway-wayland.a diff --git a/common/libsway-common.a b/common/libsway-common.a new file mode 100644 index 00000000..22267800 Binary files /dev/null and b/common/libsway-common.a differ diff --git a/include/extensions.h b/include/extensions.h index 1ef7d920..872fd3bd 100644 --- a/include/extensions.h +++ b/include/extensions.h @@ -1,18 +1,21 @@ #ifndef _SWAY_EXTENSIONS_H #define _SWAY_EXTENSIONS_H +#include +#include #include "wayland-desktop-shell-server-protocol.h" #include "list.h" -#include "wlc/wlc-wayland.h" struct background_config { wlc_handle output; wlc_resource surface; + struct wl_resource *resource; }; struct panel_config { wlc_handle output; wlc_resource surface; + struct wl_resource *resource; }; struct desktop_shell_state { @@ -22,6 +25,12 @@ struct desktop_shell_state { struct wlc_size panel_size; }; +struct swaylock_state { + bool active; + wlc_handle output; + wlc_resource surface; +}; + extern struct desktop_shell_state desktop_shell; void register_extensions(void); diff --git a/protocols/CMakeLists.txt b/protocols/CMakeLists.txt index 07becc36..d7516d0c 100644 --- a/protocols/CMakeLists.txt +++ b/protocols/CMakeLists.txt @@ -13,10 +13,21 @@ WAYLAND_ADD_PROTOCOL_SERVER(proto-server-desktop-shell desktop-shell ) +WAYLAND_ADD_PROTOCOL_CLIENT(proto-client-swaylock + swaylock.xml + swaylock +) +WAYLAND_ADD_PROTOCOL_SERVER(proto-server-swaylock + swaylock.xml + swaylock +) + add_library(sway-protocols ${proto-client-xdg-shell} ${proto-client-desktop-shell} ${proto-server-desktop-shell} + ${proto-client-swaylock} + ${proto-server-swaylock} ) set(PROTOCOLS_INCLUDE_DIRS ${CMAKE_BINARY_DIR}/protocols PARENT_SCOPE) diff --git a/protocols/libsway-protocols.a b/protocols/libsway-protocols.a new file mode 100644 index 00000000..284f46c2 Binary files /dev/null and b/protocols/libsway-protocols.a differ diff --git a/protocols/swaylock.xml b/protocols/swaylock.xml new file mode 100644 index 00000000..c7a102dd --- /dev/null +++ b/protocols/swaylock.xml @@ -0,0 +1,18 @@ + + + + + The Weston desktop-shell protocol's locking functionality depends more + on the behavior of the compositor than of a screen locking client, so + another protocol is necessary. + + + + + + + + + + + diff --git a/sway/extensions.c b/sway/extensions.c index 1f8e9a7c..18621015 100644 --- a/sway/extensions.c +++ b/sway/extensions.c @@ -8,6 +8,31 @@ struct desktop_shell_state desktop_shell; +void background_surface_destructor(struct wl_resource *resource) { + sway_log(L_DEBUG, "Background surface killed"); + int i; + for (i = 0; i < desktop_shell.backgrounds->length; ++i) { + struct background_config *config = desktop_shell.backgrounds->items[i]; + if (config->resource == resource) { + list_del(desktop_shell.backgrounds, i); + break; + } + } +} + +void panel_surface_destructor(struct wl_resource *resource) { + sway_log(L_DEBUG, "Panel surface killed"); + int i; + for (i = 0; i < desktop_shell.panels->length; ++i) { + struct panel_config *config = desktop_shell.panels->items[i]; + if (config->resource == resource) { + list_del(desktop_shell.panels, i); + arrange_windows(&root_container, -1, -1); + break; + } + } +} + static void set_background(struct wl_client *client, struct wl_resource *resource, struct wl_resource *_output, struct wl_resource *surface) { wlc_handle output = wlc_handle_from_wl_output_resource(_output); @@ -18,7 +43,9 @@ static void set_background(struct wl_client *client, struct wl_resource *resourc struct background_config *config = malloc(sizeof(struct background_config)); config->output = output; config->surface = wlc_resource_from_wl_surface_resource(surface); + config->resource = surface; list_add(desktop_shell.backgrounds, config); + wl_resource_set_destructor(surface, background_surface_destructor); } static void set_panel(struct wl_client *client, struct wl_resource *resource, @@ -31,7 +58,9 @@ static void set_panel(struct wl_client *client, struct wl_resource *resource, struct panel_config *config = malloc(sizeof(struct panel_config)); config->output = output; config->surface = wlc_resource_from_wl_surface_resource(surface); + config->resource = surface; list_add(desktop_shell.panels, config); + wl_resource_set_destructor(surface, panel_surface_destructor); desktop_shell.panel_size = *wlc_surface_get_size(config->surface); arrange_windows(&root_container, -1, -1); } diff --git a/wayland/libsway-wayland.a b/wayland/libsway-wayland.a new file mode 100644 index 00000000..ac0f682c Binary files /dev/null and b/wayland/libsway-wayland.a differ -- cgit v1.2.3