diff options
author | Drew DeVault <sir@cmpwn.com> | 2018-04-05 22:53:21 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-05 22:53:21 -0400 |
commit | f63d9417cd4d25121fa1fd309acad14a7562a55c (patch) | |
tree | c46a070652793db69ec5d6c5258d0e6cf86c1231 /sway/desktop | |
parent | 268c68b41707a664e5059699c720f000f20e2276 (diff) | |
parent | 641807d920854fdecc1307bd809c198db1a7dff1 (diff) |
Merge pull request #1743 from emersion/subsurface-damage-tracking
Damage tracking for view children
Diffstat (limited to 'sway/desktop')
-rw-r--r-- | sway/desktop/desktop.c | 20 | ||||
-rw-r--r-- | sway/desktop/output.c | 25 | ||||
-rw-r--r-- | sway/desktop/wl_shell.c | 1 | ||||
-rw-r--r-- | sway/desktop/xdg_shell_v6.c | 73 | ||||
-rw-r--r-- | sway/desktop/xwayland.c | 132 |
5 files changed, 214 insertions, 37 deletions
diff --git a/sway/desktop/desktop.c b/sway/desktop/desktop.c new file mode 100644 index 00000000..3a13191f --- /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, + lx - cont->x, ly - cont->y, surface); + } + } +} + +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..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, }; @@ -335,12 +332,24 @@ 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_container(struct sway_output *output, + struct sway_container *con) { + // 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/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 7b9d5fb7..c66cc39a 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); @@ -86,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) { @@ -100,6 +162,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 +220,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/desktop/xwayland.c b/sway/desktop/xwayland.c index 384f4236..e3da1da7 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -2,42 +2,110 @@ #include <stdbool.h> #include <stdlib.h> #include <wayland-server.h> -#include <wlr/xwayland.h> #include <wlr/types/wlr_output_layout.h> #include <wlr/types/wlr_output.h> +#include <wlr/xwayland.h> +#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_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); +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 create_unmanaged(struct wlr_xwayland_surface *xsurface) { - struct sway_xwayland_unmanaged *sway_surface = - calloc(1, sizeof(struct sway_xwayland_unmanaged)); - if (!sway_assert(sway_surface, "Failed to allocate surface")) { - return; +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; + + 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); } +} - sway_surface->wlr_xwayland_surface = xsurface; - - wl_signal_add(&xsurface->events.destroy, &sway_surface->destroy); - sway_surface->destroy.notify = unmanaged_handle_destroy; +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, - &sway_surface->link); + &surface->link); + + wl_signal_add(&xsurface->surface->events.commit, &surface->commit); + surface->commit.notify = unmanaged_handle_commit; + + 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) { + 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) { + 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 struct sway_xwayland_unmanaged *create_unmanaged( + struct wlr_xwayland_surface *xsurface) { + struct sway_xwayland_unmanaged *surface = + calloc(1, sizeof(struct sway_xwayland_unmanaged)); + if (surface == NULL) { + wlr_log(L_ERROR, "Allocation failed"); + return NULL; + } + + 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); + surface->unmap.notify = unmanaged_handle_unmap; + wl_signal_add(&xsurface->events.destroy, &surface->destroy); + surface->destroy.notify = unmanaged_handle_destroy; + + unmanaged_handle_map(&surface->map, xsurface); + + return surface; } @@ -127,6 +195,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) { @@ -140,12 +209,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); @@ -169,6 +232,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); |