From 9ea4cc13a0cf2d231c4e4c71aa674cd76831e6f9 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Sat, 30 Jun 2018 14:00:24 +0900 Subject: [PATCH] sway views: add helpers to get view and layer from wlr_surface --- include/sway/layers.h | 3 +++ include/sway/tree/view.h | 10 ++++++++++ sway/desktop/layer_shell.c | 5 +++++ sway/desktop/output.c | 4 ++++ sway/desktop/xdg_shell.c | 7 +++++++ sway/desktop/xdg_shell_v6.c | 7 +++++++ sway/desktop/xwayland.c | 7 +++++++ sway/tree/view.c | 30 ++++++++++++++++++++++++++++++ 8 files changed, 73 insertions(+) diff --git a/include/sway/layers.h b/include/sway/layers.h index ee47c5ad..96155eae 100644 --- a/include/sway/layers.h +++ b/include/sway/layers.h @@ -22,4 +22,7 @@ struct sway_layer_surface { struct sway_output; void arrange_layers(struct sway_output *output); +struct sway_layer_surface *layer_from_wlr_layer_surface( + struct wlr_layer_surface *layer_surface); + #endif diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index b99044d3..7dc8ac46 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -260,6 +260,16 @@ void view_child_init(struct sway_view_child *child, void view_child_destroy(struct sway_view_child *child); + +struct sway_view *view_from_wlr_xdg_surface( + struct wlr_xdg_surface *xdg_surface); +struct sway_view *view_from_wlr_xdg_surface_v6( + struct wlr_xdg_surface_v6 *xdg_surface_v6); +struct sway_view *view_from_wlr_xwayland_surface( + struct wlr_xwayland_surface *xsurface); + +struct sway_view *view_from_wlr_surface(struct wlr_surface *surface); + /** * Re-read the view's title property and update any relevant title bars. * The force argument makes it recreate the title bars even if the title hasn't diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index ff37bbf1..de1fe349 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c @@ -307,6 +307,11 @@ static void handle_unmap(struct wl_listener *listener, void *data) { unmap(sway_layer); } +struct sway_layer_surface *layer_from_wlr_layer_surface( + struct wlr_layer_surface *layer_surface) { + return layer_surface->data; +} + void handle_layer_shell_surface(struct wl_listener *listener, void *data) { struct wlr_layer_surface *layer_surface = data; struct sway_server *server = diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 541d765d..1e7494b3 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -1302,6 +1302,10 @@ static void handle_scale(struct wl_listener *listener, void *data) { arrange_and_commit(output->swayc); } +struct sway_output *output_from_wlr_output(struct wlr_output *wlr_output) { + return wlr_output->data; +} + void handle_new_output(struct wl_listener *listener, void *data) { struct sway_server *server = wl_container_of(listener, server, new_output); struct wlr_output *wlr_output = data; diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index da3a1cdd..5b40d903 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -289,6 +289,11 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data) arrange_and_commit(ws); } +struct sway_view *view_from_wlr_xdg_surface( + struct wlr_xdg_surface *xdg_surface) { + return xdg_surface->data; +} + void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { struct sway_server *server = wl_container_of(listener, server, xdg_shell_surface); @@ -327,4 +332,6 @@ void handle_xdg_shell_surface(struct wl_listener *listener, void *data) { xdg_shell_view->request_fullscreen.notify = handle_request_fullscreen; wl_signal_add(&xdg_surface->toplevel->events.request_fullscreen, &xdg_shell_view->request_fullscreen); + + xdg_surface->data = xdg_shell_view; } diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 69819280..c794e23a 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -280,6 +280,11 @@ static void handle_request_fullscreen(struct wl_listener *listener, void *data) arrange_and_commit(ws); } +struct sway_view *view_from_wlr_xdg_surface_v6( + struct wlr_xdg_surface_v6 *xdg_surface_v6) { + return xdg_surface_v6->data; +} + void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { struct sway_server *server = wl_container_of(listener, server, xdg_shell_v6_surface); @@ -318,4 +323,6 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { xdg_shell_v6_view->request_fullscreen.notify = handle_request_fullscreen; wl_signal_add(&xdg_surface->toplevel->events.request_fullscreen, &xdg_shell_v6_view->request_fullscreen); + + xdg_surface->data = xdg_shell_v6_view; } diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 6e63c505..4bb35f60 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -417,6 +417,11 @@ static void handle_set_window_type(struct wl_listener *listener, void *data) { view_execute_criteria(view); } +struct sway_view *view_from_wlr_xwayland_surface( + struct wlr_xwayland_surface *xsurface) { + return xsurface->data; +} + void handle_xwayland_surface(struct wl_listener *listener, void *data) { struct sway_server *server = wl_container_of(listener, server, xwayland_surface); @@ -470,6 +475,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { wl_signal_add(&xsurface->events.map, &xwayland_view->map); xwayland_view->map.notify = handle_map; + + xsurface->data = xwayland_view; } void handle_xwayland_ready(struct wl_listener *listener, void *data) { diff --git a/sway/tree/view.c b/sway/tree/view.c index 6263bfb0..06e9edc5 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -694,6 +694,36 @@ void view_child_destroy(struct sway_view_child *child) { } } +struct sway_view *view_from_wlr_surface(struct wlr_surface *wlr_surface) { + if (wlr_surface_is_xdg_surface(wlr_surface)) { + struct wlr_xdg_surface *xdg_surface = + wlr_xdg_surface_from_wlr_surface(wlr_surface); + return view_from_wlr_xdg_surface(xdg_surface); + } + if (wlr_surface_is_xdg_surface_v6(wlr_surface)) { + struct wlr_xdg_surface_v6 *xdg_surface_v6 = + wlr_xdg_surface_v6_from_wlr_surface(wlr_surface); + return view_from_wlr_xdg_surface_v6(xdg_surface_v6); + } + if (wlr_surface_is_xwayland_surface(wlr_surface)) { + struct wlr_xwayland_surface *xsurface = + wlr_xwayland_surface_from_wlr_surface(wlr_surface); + return view_from_wlr_xwayland_surface(xsurface); + } + if (wlr_surface_is_subsurface(wlr_surface)) { + struct wlr_subsurface *subsurface = + wlr_subsurface_from_wlr_surface(wlr_surface); + return view_from_wlr_surface(subsurface->parent); + } + if (wlr_surface_is_layer_surface(wlr_surface)) { + return NULL; + } + + wlr_log(L_DEBUG, "Surface of unknown type (role %s): %p", + wlr_surface->role, wlr_surface); + return NULL; +} + static size_t append_prop(char *buffer, const char *value) { if (!value) { return 0;