From 1059e173f4c0139e909c7d8b5d450f30c0adad0e Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 6 Oct 2018 14:49:33 +1000 Subject: [PATCH 1/3] Only damage popups when popups have damage The previous behaviour was to damage the entire view, which would recurse into each popup. This patch makes it damage only the popup's surface, and respect the surface damage given by the client. This adds listeners to the popup's map and unmap events rather than doing the damage in the create and destroy functions. To get the popup's position relative to the view, a new child_impl function get_root_coords has been introduced, which traverses up the parents. --- include/sway/tree/view.h | 3 +++ sway/desktop/xdg_shell.c | 17 +++++++++++++++++ sway/desktop/xdg_shell_v6.c | 17 +++++++++++++++++ sway/tree/view.c | 35 +++++++++++++++++++++++++++-------- 4 files changed, 64 insertions(+), 8 deletions(-) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 028be536..eed3d13d 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -206,6 +206,7 @@ struct sway_xwayland_unmanaged { struct sway_view_child; struct sway_view_child_impl { + void (*get_root_coords)(struct sway_view_child *child, int *sx, int *sy); void (*destroy)(struct sway_view_child *child); }; @@ -220,6 +221,8 @@ struct sway_view_child { struct wl_listener surface_commit; struct wl_listener surface_new_subsurface; + struct wl_listener surface_map; + struct wl_listener surface_unmap; struct wl_listener surface_destroy; struct wl_listener view_unmap; }; diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index a8b527a7..9036448b 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -20,6 +20,19 @@ static const struct sway_view_child_impl popup_impl; +static void popup_get_root_coords(struct sway_view_child *child, + int *root_sx, int *root_sy) { + struct sway_xdg_popup *popup = (struct sway_xdg_popup *)child; + struct wlr_xdg_surface *surface = popup->wlr_xdg_surface; + *root_sx = -surface->geometry.x; + *root_sy = -surface->geometry.y; + while (surface && surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { + *root_sx += surface->popup->geometry.x; + *root_sy += surface->popup->geometry.y; + surface = wlr_xdg_surface_from_wlr_surface(surface->popup->parent); + } +} + static void popup_destroy(struct sway_view_child *child) { if (!sway_assert(child->impl == &popup_impl, "Expected an xdg_shell popup")) { @@ -32,6 +45,7 @@ static void popup_destroy(struct sway_view_child *child) { } static const struct sway_view_child_impl popup_impl = { + .get_root_coords = popup_get_root_coords, .destroy = popup_destroy, }; @@ -85,6 +99,9 @@ static struct sway_xdg_popup *popup_create( wl_signal_add(&xdg_surface->events.destroy, &popup->destroy); popup->destroy.notify = popup_handle_destroy; + wl_signal_add(&xdg_surface->events.map, &popup->child.surface_map); + wl_signal_add(&xdg_surface->events.unmap, &popup->child.surface_unmap); + popup_unconstrain(popup); return popup; diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index a7838c0f..765a80b1 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -19,6 +19,19 @@ static const struct sway_view_child_impl popup_impl; +static void popup_get_root_coords(struct sway_view_child *child, + int *root_sx, int *root_sy) { + struct sway_xdg_popup_v6 *popup = (struct sway_xdg_popup_v6 *)child; + struct wlr_xdg_surface_v6 *surface = popup->wlr_xdg_surface_v6; + *root_sx = -surface->geometry.x; + *root_sy = -surface->geometry.y; + while (surface && surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) { + *root_sx += surface->popup->geometry.x; + *root_sy += surface->popup->geometry.y; + surface = surface->popup->parent; + } +} + static void popup_destroy(struct sway_view_child *child) { if (!sway_assert(child->impl == &popup_impl, "Expected an xdg_shell_v6 popup")) { @@ -31,6 +44,7 @@ static void popup_destroy(struct sway_view_child *child) { } static const struct sway_view_child_impl popup_impl = { + .get_root_coords = popup_get_root_coords, .destroy = popup_destroy, }; @@ -84,6 +98,9 @@ static struct sway_xdg_popup_v6 *popup_create( wl_signal_add(&xdg_surface->events.destroy, &popup->destroy); popup->destroy.notify = popup_handle_destroy; + wl_signal_add(&xdg_surface->events.map, &popup->child.surface_map); + wl_signal_add(&xdg_surface->events.unmap, &popup->child.surface_unmap); + popup_unconstrain(popup); return popup; diff --git a/sway/tree/view.c b/sway/tree/view.c index 73ce55ac..50d25c4f 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -15,6 +15,7 @@ #include "log.h" #include "sway/criteria.h" #include "sway/commands.h" +#include "sway/desktop.h" #include "sway/desktop/transaction.h" #include "sway/input/cursor.h" #include "sway/ipc-server.h" @@ -639,12 +640,18 @@ static void view_subsurface_create(struct sway_view *view, view_child_init(child, NULL, view, subsurface->surface); } +static void view_child_damage(struct sway_view_child *child, bool whole) { + int sx, sy; + child->impl->get_root_coords(child, &sx, &sy); + desktop_damage_surface(child->surface, + child->view->x + sx, child->view->y + sy, whole); +} + static void view_child_handle_surface_commit(struct wl_listener *listener, void *data) { struct sway_view_child *child = wl_container_of(listener, child, surface_commit); - // TODO: only accumulate damage from the child - view_damage_from(child->view); + view_child_damage(child, false); } static void view_child_handle_surface_new_subsurface( @@ -677,6 +684,20 @@ static void view_init_subsurfaces(struct sway_view *view, } } +static void view_child_handle_surface_map(struct wl_listener *listener, + void *data) { + struct sway_view_child *child = + wl_container_of(listener, child, surface_map); + view_child_damage(child, true); +} + +static void view_child_handle_surface_unmap(struct wl_listener *listener, + void *data) { + struct sway_view_child *child = + wl_container_of(listener, child, surface_unmap); + view_child_damage(child, true); +} + void view_child_init(struct sway_view_child *child, const struct sway_view_child_impl *impl, struct sway_view *view, struct wlr_surface *surface) { @@ -692,6 +713,10 @@ void view_child_init(struct sway_view_child *child, view_child_handle_surface_new_subsurface; wl_signal_add(&surface->events.destroy, &child->surface_destroy); child->surface_destroy.notify = view_child_handle_surface_destroy; + + child->surface_map.notify = view_child_handle_surface_map; + child->surface_unmap.notify = view_child_handle_surface_unmap; + wl_signal_add(&view->events.unmap, &child->view_unmap); child->view_unmap.notify = view_child_handle_view_unmap; @@ -699,15 +724,9 @@ void view_child_init(struct sway_view_child *child, wlr_surface_send_enter(child->surface, output->wlr_output); view_init_subsurfaces(child->view, surface); - - // TODO: only damage the whole child - container_damage_whole(child->view->container); } void view_child_destroy(struct sway_view_child *child) { - // TODO: only damage the whole child - container_damage_whole(child->view->container); - wl_list_remove(&child->surface_commit.link); wl_list_remove(&child->surface_destroy.link); wl_list_remove(&child->view_unmap.link); From 59ba528bd930e55263cbee03eb9dfb6bdee98caa Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sat, 6 Oct 2018 17:29:23 +1000 Subject: [PATCH 2/3] Use wlr_xdg_popup_get_toplevel_coords --- sway/desktop/xdg_shell.c | 12 +++++------- sway/desktop/xdg_shell_v6.c | 12 +++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 9036448b..2e2815c1 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -24,13 +24,11 @@ static void popup_get_root_coords(struct sway_view_child *child, int *root_sx, int *root_sy) { struct sway_xdg_popup *popup = (struct sway_xdg_popup *)child; struct wlr_xdg_surface *surface = popup->wlr_xdg_surface; - *root_sx = -surface->geometry.x; - *root_sy = -surface->geometry.y; - while (surface && surface->role == WLR_XDG_SURFACE_ROLE_POPUP) { - *root_sx += surface->popup->geometry.x; - *root_sy += surface->popup->geometry.y; - surface = wlr_xdg_surface_from_wlr_surface(surface->popup->parent); - } + + wlr_xdg_popup_get_toplevel_coords(surface->popup, + -surface->geometry.x + surface->popup->geometry.x, + -surface->geometry.y + surface->popup->geometry.y, + root_sx, root_sy); } static void popup_destroy(struct sway_view_child *child) { diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 765a80b1..e61bd652 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -23,13 +23,11 @@ static void popup_get_root_coords(struct sway_view_child *child, int *root_sx, int *root_sy) { struct sway_xdg_popup_v6 *popup = (struct sway_xdg_popup_v6 *)child; struct wlr_xdg_surface_v6 *surface = popup->wlr_xdg_surface_v6; - *root_sx = -surface->geometry.x; - *root_sy = -surface->geometry.y; - while (surface && surface->role == WLR_XDG_SURFACE_V6_ROLE_POPUP) { - *root_sx += surface->popup->geometry.x; - *root_sy += surface->popup->geometry.y; - surface = surface->popup->parent; - } + + wlr_xdg_popup_v6_get_toplevel_coords(surface->popup, + -surface->geometry.x + surface->popup->geometry.x, + -surface->geometry.y + surface->popup->geometry.y, + root_sx, root_sy); } static void popup_destroy(struct sway_view_child *child) { From caed15af8210abffe2dff7c9e0fffc36ab0fbdb5 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Sun, 7 Oct 2018 11:06:07 +1000 Subject: [PATCH 3/3] Handle subsurfaces in view_child_damage --- sway/tree/view.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/sway/tree/view.c b/sway/tree/view.c index 50d25c4f..ae73a687 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -630,6 +630,25 @@ void view_update_size(struct sway_view *view, int width, int height) { container_set_geometry_from_floating_view(view->container); } +static void subsurface_get_root_coords(struct sway_view_child *child, + int *root_sx, int *root_sy) { + struct wlr_surface *surface = child->surface; + *root_sx = -child->view->geometry.x; + *root_sy = -child->view->geometry.y; + + while (surface && wlr_surface_is_subsurface(surface)) { + struct wlr_subsurface *subsurface = + wlr_subsurface_from_wlr_surface(surface); + *root_sx += subsurface->current.x; + *root_sy += subsurface->current.y; + surface = subsurface->parent; + } +} + +static const struct sway_view_child_impl subsurface_impl = { + .get_root_coords = subsurface_get_root_coords, +}; + static void view_subsurface_create(struct sway_view *view, struct wlr_subsurface *subsurface) { struct sway_view_child *child = calloc(1, sizeof(struct sway_view_child)); @@ -637,7 +656,7 @@ static void view_subsurface_create(struct sway_view *view, wlr_log(WLR_ERROR, "Allocation failed"); return; } - view_child_init(child, NULL, view, subsurface->surface); + view_child_init(child, &subsurface_impl, view, subsurface->surface); } static void view_child_damage(struct sway_view_child *child, bool whole) {