From 700941dde8d270b7986bd592fcb42333e7626718 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 13 Jul 2018 21:53:56 +0100 Subject: [PATCH] Listen to server-decoration mode changes --- include/sway/decoration.h | 13 +++++++++++++ include/sway/server.h | 10 +++++++++- sway/decoration.c | 41 +++++++++++++++++++++++++++++++++++++++ sway/meson.build | 5 +++-- sway/server.c | 9 ++++++--- 5 files changed, 72 insertions(+), 6 deletions(-) create mode 100644 include/sway/decoration.h create mode 100644 sway/decoration.c diff --git a/include/sway/decoration.h b/include/sway/decoration.h new file mode 100644 index 000000000..c77c04c77 --- /dev/null +++ b/include/sway/decoration.h @@ -0,0 +1,13 @@ +#ifndef _SWAY_DECORATION_H +#define _SWAY_DECORATION_H + +#include + +struct sway_server_decoration { + struct wlr_server_decoration *wlr_server_decoration; + + struct wl_listener destroy; + struct wl_listener mode; +}; + +#endif diff --git a/include/sway/server.h b/include/sway/server.h index a3782f910..7e73fb4f7 100644 --- a/include/sway/server.h +++ b/include/sway/server.h @@ -4,12 +4,13 @@ #include #include #include +#include #include #include #include +#include #include #include -#include // TODO WLR: make Xwayland optional #include "list.h" #include "config.h" @@ -42,11 +43,16 @@ struct sway_server { struct wlr_xdg_shell *xdg_shell; struct wl_listener xdg_shell_surface; + #ifdef HAVE_XWAYLAND struct sway_xwayland xwayland; struct wl_listener xwayland_surface; struct wl_listener xwayland_ready; #endif + + struct wlr_server_decoration_manager *server_decoration_manager; + struct wl_listener server_decoration; + bool debug_txn_timings; list_t *transactions; @@ -71,4 +77,6 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data); #ifdef HAVE_XWAYLAND void handle_xwayland_surface(struct wl_listener *listener, void *data); #endif +void handle_server_decoration(struct wl_listener *listener, void *data); + #endif diff --git a/sway/decoration.c b/sway/decoration.c new file mode 100644 index 000000000..73b3f45d6 --- /dev/null +++ b/sway/decoration.c @@ -0,0 +1,41 @@ +#include +#include "sway/decoration.h" +#include "sway/server.h" +#include "sway/tree/view.h" +#include "log.h" + +static void server_decoration_handle_destroy(struct wl_listener *listener, + void *data) { + struct sway_server_decoration *deco = + wl_container_of(listener, deco, destroy); + wl_list_remove(&deco->destroy.link); + free(deco); +} + +static void server_decoration_handle_mode(struct wl_listener *listener, + void *data) { + struct sway_server_decoration *deco = + wl_container_of(listener, deco, mode); + struct sway_view *view = + view_from_wlr_surface(deco->wlr_server_decoration->surface); + + // TODO + wlr_log(WLR_ERROR, "%p %d", view, deco->wlr_server_decoration->mode); +} + +void handle_server_decoration(struct wl_listener *listener, void *data) { + struct wlr_server_decoration *wlr_deco = data; + + struct sway_server_decoration *deco = calloc(1, sizeof(*deco)); + if (deco == NULL) { + return; + } + + deco->wlr_server_decoration = wlr_deco; + + wl_signal_add(&wlr_deco->events.destroy, &deco->destroy); + deco->destroy.notify = server_decoration_handle_destroy; + + wl_signal_add(&wlr_deco->events.mode, &deco->mode); + deco->mode.notify = server_decoration_handle_mode; +} diff --git a/sway/meson.build b/sway/meson.build index c18fb6e23..2a4572708 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -1,13 +1,14 @@ sway_sources = files( - 'main.c', - 'server.c', 'commands.c', 'config.c', 'criteria.c', 'debug-tree.c', + 'decoration.c', 'ipc-json.c', 'ipc-server.c', + 'main.c', 'security.c', + 'server.c', 'swaynag.c', 'desktop/desktop.c', diff --git a/sway/server.c b/sway/server.c index e8755360c..bf6255bc0 100644 --- a/sway/server.c +++ b/sway/server.c @@ -109,11 +109,14 @@ bool server_init(struct sway_server *server) { } #endif - // TODO: Integration with sway borders - struct wlr_server_decoration_manager *deco_manager = + server->server_decoration_manager = wlr_server_decoration_manager_create(server->wl_display); wlr_server_decoration_manager_set_default_mode( - deco_manager, WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); + server->server_decoration_manager, + WLR_SERVER_DECORATION_MANAGER_MODE_SERVER); + wl_signal_add(&server->server_decoration_manager->events.new_decoration, + &server->server_decoration); + server->server_decoration.notify = handle_server_decoration; wlr_linux_dmabuf_v1_create(server->wl_display, renderer); wlr_export_dmabuf_manager_v1_create(server->wl_display);