From 45f93e165096ed04c4d1152523502ae5fc760632 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 5 Apr 2018 14:46:02 -0400 Subject: Accumulate damage from subsurfaces --- include/sway/tree/view.h | 33 ++++++++++++++ sway/tree/view.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 145 insertions(+) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index d4dace4a..f8e41652 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -45,6 +45,12 @@ struct sway_view { struct wlr_xwayland_surface *wlr_xwayland_surface; struct wlr_wl_shell_surface *wlr_wl_shell_surface; }; + + struct { + struct wl_signal unmap; + } events; + + struct wl_listener surface_new_subsurface; }; struct sway_xdg_shell_v6_view { @@ -95,6 +101,27 @@ struct sway_wl_shell_view { int pending_width, pending_height; }; +struct sway_view_child; + +struct sway_view_child_impl { + void (*destroy)(struct sway_view_child *child); +}; + +/** + * A view child is a surface in the view tree, such as a subsurface or a popup. + */ +struct sway_view_child { + const struct sway_view_child_impl *impl; + + struct sway_view *view; + struct wlr_surface *surface; + + struct wl_listener surface_commit; + struct wl_listener surface_new_subsurface; + struct wl_listener surface_destroy; + struct wl_listener view_unmap; +}; + const char *view_get_title(struct sway_view *view); const char *view_get_app_id(struct sway_view *view); @@ -129,4 +156,10 @@ void view_update_position(struct sway_view *view, double ox, double oy); void view_update_size(struct sway_view *view, int width, int height); +void view_child_init(struct sway_view_child *child, + const struct sway_view_child_impl *impl, struct sway_view *view, + struct wlr_surface *surface); + +void view_child_destroy(struct sway_view_child *child); + #endif diff --git a/sway/tree/view.c b/sway/tree/view.c index 3927c195..85fd3093 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -11,6 +11,7 @@ void view_init(struct sway_view *view, enum sway_view_type type, const struct sway_view_impl *impl) { view->type = type; view->impl = impl; + wl_signal_init(&view->events.unmap); } void view_destroy(struct sway_view *view) { @@ -123,6 +124,20 @@ static void view_update_outputs(struct sway_view *view, } } +static void view_subsurface_create(struct sway_view *view, + struct wlr_subsurface *subsurface); + +static void view_init_subsurfaces(struct sway_view *view, + struct wlr_surface *surface); + +static void view_handle_surface_new_subsurface(struct wl_listener *listener, + void *data) { + struct sway_view *view = + wl_container_of(listener, view, surface_new_subsurface); + struct wlr_subsurface *subsurface = data; + view_subsurface_create(view, subsurface); +} + void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { return; @@ -136,11 +151,18 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { view->surface = wlr_surface; view->swayc = cont; + view_init_subsurfaces(view, wlr_surface); + wl_signal_add(&wlr_surface->events.new_subsurface, + &view->surface_new_subsurface); + view->surface_new_subsurface.notify = view_handle_surface_new_subsurface; + arrange_windows(cont->parent, -1, -1); input_manager_set_focus(input_manager, cont); view_damage_whole(view); view_update_outputs(view, NULL); + + // TODO: create view children for subsurfaces } void view_unmap(struct sway_view *view) { @@ -148,6 +170,8 @@ void view_unmap(struct sway_view *view) { return; } + wl_signal_emit(&view->events.unmap, view); + view_damage_whole(view); struct sway_container *parent = container_destroy(view->swayc); @@ -185,3 +209,91 @@ void view_update_size(struct sway_view *view, int width, int height) { view_update_outputs(view, &box); view_damage_whole(view); } + + +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)); + if (child == NULL) { + wlr_log(L_ERROR, "Allocation failed"); + return; + } + view_child_init(child, NULL, view, subsurface->surface); +} + +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); +} + +static void view_child_handle_surface_new_subsurface( + struct wl_listener *listener, void *data) { + struct sway_view_child *child = + wl_container_of(listener, child, surface_new_subsurface); + struct wlr_subsurface *subsurface = data; + view_subsurface_create(child->view, subsurface); +} + +static void view_child_handle_surface_destroy(struct wl_listener *listener, + void *data) { + struct sway_view_child *child = + wl_container_of(listener, child, surface_destroy); + view_child_destroy(child); +} + +static void view_child_handle_view_unmap(struct wl_listener *listener, + void *data) { + struct sway_view_child *child = + wl_container_of(listener, child, view_unmap); + view_child_destroy(child); +} + +static void view_init_subsurfaces(struct sway_view *view, + struct wlr_surface *surface) { + struct wlr_subsurface *subsurface; + wl_list_for_each(subsurface, &surface->subsurface_list, parent_link) { + view_subsurface_create(view, subsurface); + } +} + +void view_child_init(struct sway_view_child *child, + const struct sway_view_child_impl *impl, struct sway_view *view, + struct wlr_surface *surface) { + child->impl = impl; + child->view = view; + child->surface = surface; + + wl_signal_add(&surface->events.commit, &child->surface_commit); + child->surface_commit.notify = view_child_handle_surface_commit; + wl_signal_add(&surface->events.new_subsurface, + &child->surface_new_subsurface); + child->surface_new_subsurface.notify = + view_child_handle_surface_new_subsurface; + wl_signal_add(&surface->events.destroy, &child->surface_destroy); + child->surface_destroy.notify = view_child_handle_surface_destroy; + wl_signal_add(&view->events.unmap, &child->view_unmap); + child->view_unmap.notify = view_child_handle_view_unmap; + + view_init_subsurfaces(child->view, surface); + + // TODO: only damage the whole child + view_damage_whole(child->view); +} + +void view_child_destroy(struct sway_view_child *child) { + // TODO: only damage the whole child + view_damage_whole(child->view); + + wl_list_remove(&child->surface_commit.link); + wl_list_remove(&child->surface_destroy.link); + wl_list_remove(&child->view_unmap.link); + + if (child->impl && child->impl->destroy) { + child->impl->destroy(child); + } else { + free(child); + } +} -- cgit v1.2.3-54-g00ecf From f5e5b1819bf88841f6f42fdfe416fa588abbeeb5 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 5 Apr 2018 16:48:11 -0400 Subject: Track damage of xdg-shell-v6 popups --- include/sway/tree/view.h | 11 +++++++ sway/desktop/xdg_shell_v6.c | 72 +++++++++++++++++++++++++++++++++++++++++++++ sway/tree/view.c | 2 ++ 3 files changed, 85 insertions(+) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index f8e41652..2eca7a3e 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -60,6 +60,7 @@ struct sway_xdg_shell_v6_view { struct wl_listener request_move; struct wl_listener request_resize; struct wl_listener request_maximize; + struct wl_listener new_popup; struct wl_listener map; struct wl_listener unmap; struct wl_listener destroy; @@ -122,6 +123,16 @@ struct sway_view_child { struct wl_listener view_unmap; }; +struct sway_xdg_popup_v6 { + struct sway_view_child child; + + struct wlr_xdg_surface_v6 *wlr_xdg_surface_v6; + + struct wl_listener new_popup; + struct wl_listener unmap; + struct wl_listener destroy; +}; + const char *view_get_title(struct sway_view *view); const char *view_get_app_id(struct sway_view *view); diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 7b9d5fb7..baf07a1e 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -11,6 +11,66 @@ #include "sway/input/input-manager.h" #include "log.h" +static const struct sway_view_child_impl popup_impl; + +static void popup_destroy(struct sway_view_child *child) { + if (!sway_assert(child->impl == &popup_impl, + "Expected an xdg_shell_v6 popup")) { + return; + } + struct sway_xdg_popup_v6 *popup = (struct sway_xdg_popup_v6 *)child; + wl_list_remove(&popup->new_popup.link); + wl_list_remove(&popup->unmap.link); + wl_list_remove(&popup->destroy.link); + free(popup); +} + +static const struct sway_view_child_impl popup_impl = { + .destroy = popup_destroy, +}; + +static struct sway_xdg_popup_v6 *popup_create( + struct wlr_xdg_popup_v6 *wlr_popup, struct sway_view *view); + +static void popup_handle_new_popup(struct wl_listener *listener, void *data) { + struct sway_xdg_popup_v6 *popup = + wl_container_of(listener, popup, new_popup); + struct wlr_xdg_popup_v6 *wlr_popup = data; + popup_create(wlr_popup, popup->child.view); +} + +static void popup_handle_unmap(struct wl_listener *listener, void *data) { + struct sway_xdg_popup_v6 *popup = wl_container_of(listener, popup, unmap); + view_child_destroy(&popup->child); +} + +static void popup_handle_destroy(struct wl_listener *listener, void *data) { + struct sway_xdg_popup_v6 *popup = wl_container_of(listener, popup, destroy); + view_child_destroy(&popup->child); +} + +static struct sway_xdg_popup_v6 *popup_create( + struct wlr_xdg_popup_v6 *wlr_popup, struct sway_view *view) { + struct wlr_xdg_surface_v6 *xdg_surface = wlr_popup->base; + + struct sway_xdg_popup_v6 *popup = + calloc(1, sizeof(struct sway_xdg_popup_v6)); + if (popup == NULL) { + return NULL; + } + view_child_init(&popup->child, &popup_impl, view, xdg_surface->surface); + + wl_signal_add(&xdg_surface->events.new_popup, &popup->new_popup); + popup->new_popup.notify = popup_handle_new_popup; + wl_signal_add(&xdg_surface->events.unmap, &popup->unmap); + popup->unmap.notify = popup_handle_unmap; + wl_signal_add(&xdg_surface->events.destroy, &popup->destroy); + popup->destroy.notify = popup_handle_destroy; + + return popup; +} + + static struct sway_xdg_shell_v6_view *xdg_shell_v6_view_from_view( struct sway_view *view) { if (!sway_assert(view->type == SWAY_VIEW_XDG_SHELL_V6, @@ -76,6 +136,7 @@ static void destroy(struct sway_view *view) { } wl_list_remove(&xdg_shell_v6_view->commit.link); wl_list_remove(&xdg_shell_v6_view->destroy.link); + wl_list_remove(&xdg_shell_v6_view->new_popup.link); wl_list_remove(&xdg_shell_v6_view->map.link); wl_list_remove(&xdg_shell_v6_view->unmap.link); free(xdg_shell_v6_view); @@ -100,6 +161,13 @@ static void handle_commit(struct wl_listener *listener, void *data) { view_damage_from(view); } +static void handle_new_popup(struct wl_listener *listener, void *data) { + struct sway_xdg_shell_v6_view *xdg_shell_v6_view = + wl_container_of(listener, xdg_shell_v6_view, new_popup); + struct wlr_xdg_popup_v6 *wlr_popup = data; + popup_create(wlr_popup, &xdg_shell_v6_view->view); +} + static void handle_unmap(struct wl_listener *listener, void *data) { struct sway_xdg_shell_v6_view *xdg_shell_v6_view = wl_container_of(listener, xdg_shell_v6_view, unmap); @@ -151,6 +219,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { wl_signal_add(&xdg_surface->surface->events.commit, &xdg_shell_v6_view->commit); + xdg_shell_v6_view->new_popup.notify = handle_new_popup; + wl_signal_add(&xdg_surface->events.new_popup, + &xdg_shell_v6_view->new_popup); + xdg_shell_v6_view->map.notify = handle_map; wl_signal_add(&xdg_surface->events.map, &xdg_shell_v6_view->map); diff --git a/sway/tree/view.c b/sway/tree/view.c index 85fd3093..293edc95 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -176,6 +176,8 @@ void view_unmap(struct sway_view *view) { struct sway_container *parent = container_destroy(view->swayc); + wl_list_remove(&view->surface_new_subsurface.link); + view->swayc = NULL; view->surface = NULL; -- cgit v1.2.3-54-g00ecf From 7ce1038478de99f9328beaa289503826f107ac83 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 5 Apr 2018 17:08:30 -0400 Subject: Fix xwayland unmanaged surfaces --- include/sway/tree/view.h | 3 +++ sway/desktop/wl_shell.c | 1 + sway/desktop/xdg_shell_v6.c | 1 + sway/desktop/xwayland.c | 66 ++++++++++++++++++++++++++++++++++----------- 4 files changed, 56 insertions(+), 15 deletions(-) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 2eca7a3e..e52bee66 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -87,6 +87,9 @@ struct sway_xwayland_unmanaged { struct wlr_xwayland_surface *wlr_xwayland_surface; struct wl_list link; + struct wl_listener commit; + struct wl_listener map; + struct wl_listener unmap; struct wl_listener destroy; }; diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index 5955fa9d..fff31da8 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c @@ -68,6 +68,7 @@ static const struct sway_view_impl view_impl = { .get_prop = get_prop, .configure = configure, .close = _close, + .destroy = destroy, }; static void handle_commit(struct wl_listener *listener, void *data) { diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index baf07a1e..c66cc39a 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -147,6 +147,7 @@ static const struct sway_view_impl view_impl = { .configure = configure, .set_activated = set_activated, .close = _close, + .destroy = destroy, }; static void handle_commit(struct wl_listener *listener, void *data) { diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 384f4236..543c914e 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -14,30 +14,65 @@ #include "sway/input/input-manager.h" #include "log.h" +static void unmanaged_handle_commit(struct wl_listener *listener, void *data) { + struct sway_xwayland_unmanaged *surface = + wl_container_of(listener, surface, commit); + // TODO: damage tracking +} + +static void unmanaged_handle_map(struct wl_listener *listener, void *data) { + struct sway_xwayland_unmanaged *surface = + wl_container_of(listener, surface, map); + struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; + wl_list_insert(&root_container.sway_root->xwayland_unmanaged, + &surface->link); + wl_signal_add(&xsurface->surface->events.commit, &surface->commit); + surface->commit.notify = unmanaged_handle_commit; + // TODO: damage tracking +} + +static void unmanaged_handle_unmap(struct wl_listener *listener, void *data) { + struct sway_xwayland_unmanaged *surface = + wl_container_of(listener, surface, unmap); + wl_list_remove(&surface->link); + wl_list_remove(&surface->commit.link); + // TODO: damage tracking +} + static void unmanaged_handle_destroy(struct wl_listener *listener, void *data) { - struct sway_xwayland_unmanaged *sway_surface = - wl_container_of(listener, sway_surface, destroy); - wl_list_remove(&sway_surface->destroy.link); - wl_list_remove(&sway_surface->link); - free(sway_surface); + struct sway_xwayland_unmanaged *surface = + wl_container_of(listener, surface, destroy); + struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; + if (xsurface->mapped) { + unmanaged_handle_unmap(&surface->unmap, xsurface); + } + wl_list_remove(&surface->map.link); + wl_list_remove(&surface->unmap.link); + wl_list_remove(&surface->destroy.link); + free(surface); } -static void create_unmanaged(struct wlr_xwayland_surface *xsurface) { - struct sway_xwayland_unmanaged *sway_surface = +static struct sway_xwayland_unmanaged *create_unmanaged( + struct wlr_xwayland_surface *xsurface) { + struct sway_xwayland_unmanaged *surface = calloc(1, sizeof(struct sway_xwayland_unmanaged)); - if (!sway_assert(sway_surface, "Failed to allocate surface")) { - return; + if (surface == NULL) { + wlr_log(L_ERROR, "Allocation failed"); + return NULL; } - sway_surface->wlr_xwayland_surface = xsurface; + surface->wlr_xwayland_surface = xsurface; - wl_signal_add(&xsurface->events.destroy, &sway_surface->destroy); - sway_surface->destroy.notify = unmanaged_handle_destroy; + wl_signal_add(&xsurface->events.map, &surface->map); + surface->map.notify = unmanaged_handle_map; + wl_signal_add(&xsurface->events.unmap, &surface->unmap); + surface->unmap.notify = unmanaged_handle_unmap; + wl_signal_add(&xsurface->events.destroy, &surface->destroy); + surface->destroy.notify = unmanaged_handle_destroy; - wl_list_insert(&root_container.sway_root->xwayland_unmanaged, - &sway_surface->link); + unmanaged_handle_map(&surface->map, xsurface); - // TODO: damage tracking + return surface; } @@ -127,6 +162,7 @@ static const struct sway_view_impl view_impl = { .configure = configure, .set_activated = set_activated, .close = _close, + .destroy = destroy, }; static void handle_commit(struct wl_listener *listener, void *data) { -- cgit v1.2.3-54-g00ecf From a528aea2ee87a211edd3e6df83f2d408656430ab Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 5 Apr 2018 17:11:46 -0400 Subject: Make xwayland surface destroy more foolproof --- sway/desktop/xwayland.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 543c914e..0a70b680 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -176,12 +176,6 @@ static void handle_commit(struct wl_listener *listener, void *data) { view_damage_from(view); } -static void handle_destroy(struct wl_listener *listener, void *data) { - struct sway_xwayland_view *xwayland_view = - wl_container_of(listener, xwayland_view, destroy); - view_destroy(&xwayland_view->view); -} - static void handle_unmap(struct wl_listener *listener, void *data) { struct sway_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view, unmap); @@ -205,6 +199,17 @@ static void handle_map(struct wl_listener *listener, void *data) { view_map(view, xsurface->surface); } +static void handle_destroy(struct wl_listener *listener, void *data) { + struct sway_xwayland_view *xwayland_view = + wl_container_of(listener, xwayland_view, destroy); + struct sway_view *view = &xwayland_view->view; + struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; + if (xsurface->mapped) { + handle_unmap(&xwayland_view->unmap, xsurface); + } + view_destroy(&xwayland_view->view); +} + static void handle_request_configure(struct wl_listener *listener, void *data) { struct sway_xwayland_view *xwayland_view = wl_container_of(listener, xwayland_view, request_configure); -- cgit v1.2.3-54-g00ecf From 07f3bb3ad126e48247207126b977688a77e03928 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 5 Apr 2018 17:22:39 -0400 Subject: Handle xwayland configure requests for unmanaged surfaces --- include/sway/tree/view.h | 1 + sway/desktop/xwayland.c | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index e52bee66..faf38bdf 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -87,6 +87,7 @@ struct sway_xwayland_unmanaged { struct wlr_xwayland_surface *wlr_xwayland_surface; struct wl_list link; + struct wl_listener request_configure; struct wl_listener commit; struct wl_listener map; struct wl_listener unmap; diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 0a70b680..3842c2c8 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -14,6 +14,16 @@ #include "sway/input/input-manager.h" #include "log.h" +static void unmanaged_handle_request_configure(struct wl_listener *listener, + void *data) { + struct sway_xwayland_unmanaged *surface = + wl_container_of(listener, surface, request_configure); + struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; + struct wlr_xwayland_surface_configure_event *ev = data; + wlr_xwayland_surface_configure(xsurface, ev->x, ev->y, + ev->width, ev->height); +} + static void unmanaged_handle_commit(struct wl_listener *listener, void *data) { struct sway_xwayland_unmanaged *surface = wl_container_of(listener, surface, commit); @@ -63,6 +73,9 @@ static struct sway_xwayland_unmanaged *create_unmanaged( surface->wlr_xwayland_surface = xsurface; + wl_signal_add(&xsurface->events.request_configure, + &surface->request_configure); + surface->request_configure.notify = unmanaged_handle_request_configure; wl_signal_add(&xsurface->events.map, &surface->map); surface->map.notify = unmanaged_handle_map; wl_signal_add(&xsurface->events.unmap, &surface->unmap); -- cgit v1.2.3-54-g00ecf From 1c91d0c10ffbed14cafaba79276a14f55172b7eb Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 5 Apr 2018 17:37:24 -0400 Subject: Add damage tracking for xwayland unmanaged surfaces --- include/sway/desktop.h | 7 +++++++ include/sway/output.h | 3 +++ sway/desktop/desktop.c | 20 ++++++++++++++++++++ sway/desktop/output.c | 6 ++++++ sway/desktop/xwayland.c | 22 +++++++++++++--------- sway/meson.build | 1 + 6 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 include/sway/desktop.h create mode 100644 sway/desktop/desktop.c diff --git a/include/sway/desktop.h b/include/sway/desktop.h new file mode 100644 index 00000000..96bdc94c --- /dev/null +++ b/include/sway/desktop.h @@ -0,0 +1,7 @@ +#include + +void desktop_damage_whole_surface(struct wlr_surface *surface, double lx, + double ly); + +void desktop_damage_from_surface(struct wlr_surface *surface, double lx, + double ly); diff --git a/include/sway/output.h b/include/sway/output.h index 98d0f83f..9964a484 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -37,6 +37,9 @@ void output_damage_whole(struct sway_output *output); void output_damage_whole_view(struct sway_output *output, struct sway_view *view); +void output_damage_whole_surface(struct sway_output *output, + struct wlr_surface *surface, double ox, double oy); + struct sway_container *output_by_name(const char *name); #endif diff --git a/sway/desktop/desktop.c b/sway/desktop/desktop.c new file mode 100644 index 00000000..78a2d49f --- /dev/null +++ b/sway/desktop/desktop.c @@ -0,0 +1,20 @@ +#include "sway/tree/container.h" +#include "sway/desktop.h" +#include "sway/output.h" + +void desktop_damage_whole_surface(struct wlr_surface *surface, double lx, + double ly) { + for (int i = 0; i < root_container.children->length; ++i) { + struct sway_container *cont = root_container.children->items[i]; + if (cont->type == C_OUTPUT) { + output_damage_whole_surface(cont->sway_output, surface, + lx - cont->x, ly - cont->y); + } + } +} + +void desktop_damage_from_surface(struct wlr_surface *surface, double lx, + double ly) { + // TODO + desktop_damage_whole_surface(surface, lx, ly); +} diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 0e8a9485..0ae5e782 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -341,6 +341,12 @@ void output_damage_whole_view(struct sway_output *output, output_damage_whole(output); } +void output_damage_whole_surface(struct sway_output *output, + struct wlr_surface *surface, double ox, double oy) { + // TODO + output_damage_whole(output); +} + static void damage_handle_destroy(struct wl_listener *listener, void *data) { struct sway_output *output = wl_container_of(listener, output, damage_destroy); diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 3842c2c8..4797b801 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -2,17 +2,18 @@ #include #include #include -#include #include #include +#include +#include "log.h" +#include "sway/desktop.h" +#include "sway/input/input-manager.h" +#include "sway/input/seat.h" +#include "sway/output.h" +#include "sway/server.h" #include "sway/tree/container.h" #include "sway/tree/layout.h" -#include "sway/server.h" #include "sway/tree/view.h" -#include "sway/output.h" -#include "sway/input/seat.h" -#include "sway/input/input-manager.h" -#include "log.h" static void unmanaged_handle_request_configure(struct wl_listener *listener, void *data) { @@ -27,7 +28,9 @@ static void unmanaged_handle_request_configure(struct wl_listener *listener, static void unmanaged_handle_commit(struct wl_listener *listener, void *data) { struct sway_xwayland_unmanaged *surface = wl_container_of(listener, surface, commit); - // TODO: damage tracking + struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; + desktop_damage_from_surface(xsurface->surface, xsurface->x, xsurface->y); + // TODO: handle window motion } static void unmanaged_handle_map(struct wl_listener *listener, void *data) { @@ -38,15 +41,16 @@ static void unmanaged_handle_map(struct wl_listener *listener, void *data) { &surface->link); wl_signal_add(&xsurface->surface->events.commit, &surface->commit); surface->commit.notify = unmanaged_handle_commit; - // TODO: damage tracking + desktop_damage_whole_surface(xsurface->surface, xsurface->x, xsurface->y); } static void unmanaged_handle_unmap(struct wl_listener *listener, void *data) { struct sway_xwayland_unmanaged *surface = wl_container_of(listener, surface, unmap); + struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; + desktop_damage_whole_surface(xsurface->surface, xsurface->x, xsurface->y); wl_list_remove(&surface->link); wl_list_remove(&surface->commit.link); - // TODO: damage tracking } static void unmanaged_handle_destroy(struct wl_listener *listener, void *data) { diff --git a/sway/meson.build b/sway/meson.build index ec7b4c42..29aaa7b7 100644 --- a/sway/meson.build +++ b/sway/meson.build @@ -8,6 +8,7 @@ sway_sources = files( 'ipc-server.c', 'security.c', + 'desktop/desktop.c', 'desktop/output.c', 'desktop/layer_shell.c', 'desktop/wl_shell.c', -- cgit v1.2.3-54-g00ecf From 076bedb85eface4a6c41a0e99059c89186bdb275 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 5 Apr 2018 18:31:19 -0400 Subject: Add container_damage_whole --- include/sway/output.h | 4 ++-- include/sway/tree/container.h | 8 +++++--- sway/desktop/desktop.c | 5 +++-- sway/desktop/output.c | 4 ++-- sway/tree/container.c | 13 +++++++++++-- 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/include/sway/output.h b/include/sway/output.h index 9964a484..8945dde4 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -37,8 +37,8 @@ void output_damage_whole(struct sway_output *output); void output_damage_whole_view(struct sway_output *output, struct sway_view *view); -void output_damage_whole_surface(struct sway_output *output, - struct wlr_surface *surface, double ox, double oy); +void output_damage_whole_rect(struct sway_output *output, double ox, double oy, + int width, int height); struct sway_container *output_by_name(const char *name); diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index 3a3a9429..7acb607b 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -97,8 +97,7 @@ struct sway_container *container_create(enum sway_container_type type); const char *container_type_to_str(enum sway_container_type type); -struct sway_container *output_create( - struct sway_output *sway_output); +struct sway_container *output_create(struct sway_output *sway_output); /** * Create a new container container. A container container can be a a child of @@ -116,7 +115,8 @@ struct sway_container *output_create(struct sway_output *sway_output); * Create a new workspace container. Workspaces are children of an output * container and are ordered alphabetically by name. */ -struct sway_container *workspace_create(struct sway_container *output, const char *name); +struct sway_container *workspace_create(struct sway_container *output, + const char *name); /* * Create a new view container. A view can be a child of a workspace container @@ -182,4 +182,6 @@ bool container_has_child(struct sway_container *con, void container_create_notify(struct sway_container *container); +void container_damage_whole(struct sway_container *container); + #endif diff --git a/sway/desktop/desktop.c b/sway/desktop/desktop.c index 78a2d49f..c23d988c 100644 --- a/sway/desktop/desktop.c +++ b/sway/desktop/desktop.c @@ -7,8 +7,9 @@ void desktop_damage_whole_surface(struct wlr_surface *surface, double lx, for (int i = 0; i < root_container.children->length; ++i) { struct sway_container *cont = root_container.children->items[i]; if (cont->type == C_OUTPUT) { - output_damage_whole_surface(cont->sway_output, surface, - lx - cont->x, ly - cont->y); + output_damage_whole_rect(cont->sway_output, + lx - cont->x, ly - cont->y, + surface->current->width, surface->current->height); } } } diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 0ae5e782..09244460 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -341,8 +341,8 @@ void output_damage_whole_view(struct sway_output *output, output_damage_whole(output); } -void output_damage_whole_surface(struct sway_output *output, - struct wlr_surface *surface, double ox, double oy) { +void output_damage_whole_rect(struct sway_output *output, + double ox, double oy, int width, int height) { // TODO output_damage_whole(output); } diff --git a/sway/tree/container.c b/sway/tree/container.c index 8fc9e3e8..1450db6d 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -512,9 +512,18 @@ static bool find_child_func(struct sway_container *con, void *data) { bool container_has_child(struct sway_container *con, struct sway_container *child) { - if (con == NULL || con->type == C_VIEW || - con->children->length == 0) { + if (con == NULL || con->type == C_VIEW || con->children->length == 0) { return false; } return container_find(con, find_child_func, child); } + +void container_damage_whole(struct sway_container *con) { + struct sway_container *output = con; + if (output->type != C_OUTPUT) { + output = container_parent(output, C_OUTPUT); + } + + output_damage_whole_rect(output->sway_output, con->x, con->y, con->width, + con->height); +} -- cgit v1.2.3-54-g00ecf From 6b9b03f09ffae8c8a9d7150d1ec68845c9e0ebf0 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 5 Apr 2018 18:33:13 -0400 Subject: Remove outdated TODO --- sway/tree/view.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/sway/tree/view.c b/sway/tree/view.c index 293edc95..d3e3186c 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -161,8 +161,6 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { view_damage_whole(view); view_update_outputs(view, NULL); - - // TODO: create view children for subsurfaces } void view_unmap(struct sway_view *view) { -- cgit v1.2.3-54-g00ecf From d65d001aa55c71f67a35c8ce78d3cb3f7f5fd65e Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 5 Apr 2018 18:38:50 -0400 Subject: Fix desktop_damage_whole_surface --- include/sway/output.h | 7 +++++-- sway/desktop/desktop.c | 5 ++--- sway/desktop/output.c | 10 ++++++++-- sway/tree/container.c | 4 +--- 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/include/sway/output.h b/include/sway/output.h index 8945dde4..4bffa2b7 100644 --- a/include/sway/output.h +++ b/include/sway/output.h @@ -34,11 +34,14 @@ struct sway_output { void output_damage_whole(struct sway_output *output); +void output_damage_whole_surface(struct sway_output *output, + double ox, double oy, struct wlr_surface *surface); + void output_damage_whole_view(struct sway_output *output, struct sway_view *view); -void output_damage_whole_rect(struct sway_output *output, double ox, double oy, - int width, int height); +void output_damage_whole_container(struct sway_output *output, + struct sway_container *con); struct sway_container *output_by_name(const char *name); diff --git a/sway/desktop/desktop.c b/sway/desktop/desktop.c index c23d988c..3a13191f 100644 --- a/sway/desktop/desktop.c +++ b/sway/desktop/desktop.c @@ -7,9 +7,8 @@ void desktop_damage_whole_surface(struct wlr_surface *surface, double lx, for (int i = 0; i < root_container.children->length; ++i) { struct sway_container *cont = root_container.children->items[i]; if (cont->type == C_OUTPUT) { - output_damage_whole_rect(cont->sway_output, - lx - cont->x, ly - cont->y, - surface->current->width, surface->current->height); + output_damage_whole_surface(cont->sway_output, + lx - cont->x, ly - cont->y, surface); } } } diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 09244460..a7f40ef8 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -335,14 +335,20 @@ void output_damage_whole(struct sway_output *output) { wlr_output_damage_add_whole(output->damage); } +void output_damage_whole_surface(struct sway_output *output, + double ox, double oy, struct wlr_surface *surface) { + // TODO + output_damage_whole(output); +} + void output_damage_whole_view(struct sway_output *output, struct sway_view *view) { // TODO output_damage_whole(output); } -void output_damage_whole_rect(struct sway_output *output, - double ox, double oy, int width, int height) { +void output_damage_whole_container(struct sway_output *output, + struct sway_container *con) { // TODO output_damage_whole(output); } diff --git a/sway/tree/container.c b/sway/tree/container.c index 1450db6d..404d413f 100644 --- a/sway/tree/container.c +++ b/sway/tree/container.c @@ -523,7 +523,5 @@ void container_damage_whole(struct sway_container *con) { if (output->type != C_OUTPUT) { output = container_parent(output, C_OUTPUT); } - - output_damage_whole_rect(output->sway_output, con->x, con->y, con->width, - con->height); + output_damage_whole_container(output->sway_output, con); } -- cgit v1.2.3-54-g00ecf From 641807d920854fdecc1307bd809c198db1a7dff1 Mon Sep 17 00:00:00 2001 From: emersion Date: Thu, 5 Apr 2018 18:48:35 -0400 Subject: Handle unmanaged surfaces motion --- include/sway/tree/view.h | 2 ++ sway/desktop/output.c | 13 +++++-------- sway/desktop/xwayland.c | 22 +++++++++++++++++++--- sway/input/cursor.c | 14 +++++--------- 4 files changed, 31 insertions(+), 20 deletions(-) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index faf38bdf..03d27ceb 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -87,6 +87,8 @@ struct sway_xwayland_unmanaged { struct wlr_xwayland_surface *wlr_xwayland_surface; struct wl_list link; + int lx, ly; + struct wl_listener request_configure; struct wl_listener commit; struct wl_listener map; diff --git a/sway/desktop/output.c b/sway/desktop/output.c index a7f40ef8..aa18f1b8 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -267,17 +267,14 @@ static void render_output(struct sway_output *output, struct timespec *when, // render unmanaged views on top struct wl_list *unmanaged = &root_container.sway_root->xwayland_unmanaged; - struct sway_xwayland_unmanaged *sway_surface; - wl_list_for_each(sway_surface, unmanaged, link) { + struct sway_xwayland_unmanaged *unmanaged_surface; + wl_list_for_each(unmanaged_surface, unmanaged, link) { struct wlr_xwayland_surface *xsurface = - sway_surface->wlr_xwayland_surface; - if (xsurface->surface == NULL) { - continue; - } + unmanaged_surface->wlr_xwayland_surface; const struct wlr_box view_box = { - .x = xsurface->x, - .y = xsurface->y, + .x = unmanaged_surface->lx, + .y = unmanaged_surface->ly, .width = xsurface->width, .height = xsurface->height, }; diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 4797b801..e3da1da7 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -29,19 +29,35 @@ static void unmanaged_handle_commit(struct wl_listener *listener, void *data) { struct sway_xwayland_unmanaged *surface = wl_container_of(listener, surface, commit); struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; - desktop_damage_from_surface(xsurface->surface, xsurface->x, xsurface->y); - // TODO: handle window motion + + if (xsurface->x != surface->lx || xsurface->y != surface->ly) { + // Surface has moved + desktop_damage_whole_surface(xsurface->surface, + surface->lx, surface->ly); + surface->lx = xsurface->x; + surface->ly = xsurface->y; + desktop_damage_whole_surface(xsurface->surface, + surface->lx, surface->ly); + } else { + desktop_damage_from_surface(xsurface->surface, + xsurface->x, xsurface->y); + } } static void unmanaged_handle_map(struct wl_listener *listener, void *data) { struct sway_xwayland_unmanaged *surface = wl_container_of(listener, surface, map); struct wlr_xwayland_surface *xsurface = surface->wlr_xwayland_surface; + wl_list_insert(&root_container.sway_root->xwayland_unmanaged, &surface->link); + wl_signal_add(&xsurface->surface->events.commit, &surface->commit); surface->commit.notify = unmanaged_handle_commit; - desktop_damage_whole_surface(xsurface->surface, xsurface->x, xsurface->y); + + surface->lx = xsurface->x; + surface->ly = xsurface->y; + desktop_damage_whole_surface(xsurface->surface, surface->lx, surface->ly); } static void unmanaged_handle_unmap(struct wl_listener *listener, void *data) { diff --git a/sway/input/cursor.c b/sway/input/cursor.c index 195ddce9..b83bc9fe 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -48,17 +48,13 @@ static struct sway_container *container_at_cursor(struct sway_cursor *cursor, struct wlr_surface **surface, double *sx, double *sy) { // check for unmanaged views first struct wl_list *unmanaged = &root_container.sway_root->xwayland_unmanaged; - struct sway_xwayland_unmanaged *sway_surface; - wl_list_for_each_reverse(sway_surface, unmanaged, link) { + struct sway_xwayland_unmanaged *unmanaged_surface; + wl_list_for_each_reverse(unmanaged_surface, unmanaged, link) { struct wlr_xwayland_surface *xsurface = - sway_surface->wlr_xwayland_surface; - if (xsurface->surface == NULL) { - continue; - } - + unmanaged_surface->wlr_xwayland_surface; struct wlr_box box = { - .x = xsurface->x, - .y = xsurface->y, + .x = unmanaged_surface->lx, + .y = unmanaged_surface->ly, .width = xsurface->width, .height = xsurface->height, }; -- cgit v1.2.3-54-g00ecf