From b2c2ee693b6f1cdaeb204a1469c0fa1b775a498c Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 17:49:40 -0400 Subject: Introduce common functions to create, map, unmap, destroy views --- sway/tree/view.c | 125 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 101 insertions(+), 24 deletions(-) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index b7d1a41b..2950812a 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -1,3 +1,4 @@ +#include #include #include #include "log.h" @@ -6,6 +7,31 @@ #include "sway/tree/layout.h" #include "sway/tree/view.h" +struct sway_view *view_create(enum sway_view_type type) { + struct sway_view *view = calloc(1, sizeof(struct sway_view)); + if (view == NULL) { + return NULL; + } + view->type = type; + wl_list_init(&view->unmanaged_view_link); + return view; +} + +void view_destroy(struct sway_view *view) { + if (view == NULL) { + return; + } + + if (view->surface != NULL) { + view_unmap(view); + } + if (view->swayc != NULL) { + container_view_destroy(view->swayc); + } + + free(view); +} + const char *view_get_title(struct sway_view *view) { if (view->iface.get_prop) { return view->iface.get_prop(view, VIEW_PROP_TITLE); @@ -34,6 +60,31 @@ const char *view_get_instance(struct sway_view *view) { return NULL; } +static void view_update_outputs(struct sway_view *view, + const struct wlr_box *before) { + struct wlr_output_layout *output_layout = + root_container.sway_root->output_layout; + struct wlr_box box = { + .x = view->swayc->x, + .y = view->swayc->y, + .width = view->width, + .height = view->height, + }; + struct wlr_output_layout_output *layout_output; + wl_list_for_each(layout_output, &output_layout->outputs, link) { + bool intersected = before != NULL && wlr_output_layout_intersects( + output_layout, layout_output->output, before); + bool intersects = wlr_output_layout_intersects(output_layout, + layout_output->output, &box); + if (intersected && !intersects) { + wlr_surface_send_leave(view->surface, layout_output->output); + } + if (!intersected && intersects) { + wlr_surface_send_enter(view->surface, layout_output->output); + } + } +} + void view_set_size(struct sway_view *view, int width, int height) { if (view->iface.set_size) { struct wlr_box box = { @@ -73,30 +124,6 @@ void view_close(struct sway_view *view) { } } -void view_update_outputs(struct sway_view *view, const struct wlr_box *before) { - struct wlr_output_layout *output_layout = - root_container.sway_root->output_layout; - struct wlr_box box = { - .x = view->swayc->x, - .y = view->swayc->y, - .width = view->width, - .height = view->height, - }; - struct wlr_output_layout_output *layout_output; - wl_list_for_each(layout_output, &output_layout->outputs, link) { - bool intersected = before != NULL && wlr_output_layout_intersects( - output_layout, layout_output->output, before); - bool intersects = wlr_output_layout_intersects(output_layout, - layout_output->output, &box); - if (intersected && !intersects) { - wlr_surface_send_leave(view->surface, layout_output->output); - } - if (!intersected && intersects) { - wlr_surface_send_enter(view->surface, layout_output->output); - } - } -} - struct sway_container *container_view_destroy(struct sway_container *view) { if (!view) { return NULL; @@ -107,6 +134,56 @@ struct sway_container *container_view_destroy(struct sway_container *view) { return parent; } +void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { + if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { + return; + } + + struct sway_seat *seat = input_manager_current_seat(input_manager); + struct sway_container *focus = sway_seat_get_focus_inactive(seat, + &root_container); + struct sway_container *cont = container_view_create(focus, view); + + view->surface = wlr_surface; + view->swayc = cont; + + arrange_windows(cont->parent, -1, -1); + sway_input_manager_set_focus(input_manager, cont); + + view_damage_whole(view); +} + +void view_map_unmanaged(struct sway_view *view, + struct wlr_surface *wlr_surface) { + if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { + return; + } + + view->surface = wlr_surface; + view->swayc = NULL; + + wl_list_insert(&root_container.sway_root->unmanaged_views, + &view->unmanaged_view_link); + + view_damage_whole(view); +} + +void view_unmap(struct sway_view *view) { + if (!sway_assert(view->surface != NULL, "cannot unmap unmapped view")) { + return; + } + + view_damage_whole(view); + + wl_list_remove(&view->unmanaged_view_link); + wl_list_init(&view->unmanaged_view_link); + + container_view_destroy(view->swayc); + + view->swayc = NULL; + view->surface = NULL; +} + void view_damage_whole(struct sway_view *view) { struct sway_container *cont = NULL; for (int i = 0; i < root_container.children->length; ++i) { -- cgit v1.2.3 From 1d68f9ecca8870f2f2a6823072c77657436b123a Mon Sep 17 00:00:00 2001 From: emersion Date: Sat, 31 Mar 2018 18:07:44 -0400 Subject: Add sway_view_impl --- include/sway/tree/view.h | 31 +++++++++++++++++-------------- sway/desktop/wl_shell.c | 18 ++++++++---------- sway/desktop/xdg_shell_v6.c | 15 +++++++++------ sway/desktop/xwayland.c | 17 ++++++++++------- sway/tree/view.c | 36 +++++++++++++++++++----------------- 5 files changed, 63 insertions(+), 54 deletions(-) (limited to 'sway/tree/view.c') diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 82a5541b..c68739d6 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -66,10 +66,23 @@ enum sway_view_prop { VIEW_PROP_INSTANCE, }; +struct sway_view_impl { + const char *(*get_prop)(struct sway_view *view, + enum sway_view_prop prop); + void (*set_size)(struct sway_view *view, + int width, int height); + void (*set_position)(struct sway_view *view, + double ox, double oy); + void (*set_activated)(struct sway_view *view, bool activated); + void (*close)(struct sway_view *view); +}; + struct sway_view { enum sway_view_type type; - struct sway_container *swayc; - struct wlr_surface *surface; + const struct sway_view_impl *impl; + + struct sway_container *swayc; // NULL for unmanaged views + struct wlr_surface *surface; // NULL for unmapped views int width, height; union { @@ -84,22 +97,12 @@ struct sway_view { struct sway_wl_shell_surface *sway_wl_shell_surface; }; - struct { - const char *(*get_prop)(struct sway_view *view, - enum sway_view_prop prop); - void (*set_size)(struct sway_view *view, - int width, int height); - void (*set_position)(struct sway_view *view, - double ox, double oy); - void (*set_activated)(struct sway_view *view, bool activated); - void (*close)(struct sway_view *view); - } iface; - // only used for unmanaged views (shell specific) struct wl_list unmanaged_view_link; // sway_root::unmanaged_views }; -struct sway_view *view_create(enum sway_view_type type); +struct sway_view *view_create(enum sway_view_type type, + const struct sway_view_impl *impl); void view_destroy(struct sway_view *view); diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index ab969b17..e0909a03 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c @@ -47,10 +47,6 @@ static void set_position(struct sway_view *view, double ox, double oy) { view->swayc->y = oy; } -static void set_activated(struct sway_view *view, bool activated) { - // no way to activate wl_shell -} - static void close(struct sway_view *view) { if (!assert_wl_shell(view)) { return; @@ -59,6 +55,13 @@ static void close(struct sway_view *view) { wl_client_destroy(view->wlr_wl_shell_surface->client); } +static const struct sway_view_impl view_impl = { + .get_prop = get_prop, + .set_size = set_size, + .set_position = set_position, + .close = close, +}; + static void handle_commit(struct wl_listener *listener, void *data) { struct sway_wl_shell_surface *sway_surface = wl_container_of(listener, sway_surface, commit); @@ -101,15 +104,10 @@ void handle_wl_shell_surface(struct wl_listener *listener, void *data) { return; } - struct sway_view *view = view_create(SWAY_WL_SHELL_VIEW); + struct sway_view *view = view_create(SWAY_WL_SHELL_VIEW, &view_impl); if (!sway_assert(view, "Failed to allocate view")) { return; } - view->iface.get_prop = get_prop; - view->iface.set_size = set_size; - view->iface.set_position = set_position; - view->iface.set_activated = set_activated; - view->iface.close = close; view->wlr_wl_shell_surface = shell_surface; view->sway_wl_shell_surface = sway_surface; sway_surface->view = view; diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index 77a35b13..c1adc7fe 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -67,6 +67,14 @@ static void close(struct sway_view *view) { } } +static const struct sway_view_impl view_impl = { + .get_prop = get_prop, + .set_size = set_size, + .set_position = set_position, + .set_activated = set_activated, + .close = close, +}; + static void handle_commit(struct wl_listener *listener, void *data) { struct sway_xdg_surface_v6 *sway_surface = wl_container_of(listener, sway_surface, commit); @@ -124,15 +132,10 @@ void handle_xdg_shell_v6_surface(struct wl_listener *listener, void *data) { return; } - struct sway_view *view = view_create(SWAY_XDG_SHELL_V6_VIEW); + struct sway_view *view = view_create(SWAY_XDG_SHELL_V6_VIEW, &view_impl); if (!sway_assert(view, "Failed to allocate view")) { return; } - view->iface.get_prop = get_prop; - view->iface.set_size = set_size; - view->iface.set_position = set_position; - view->iface.set_activated = set_activated; - view->iface.close = close; view->wlr_xdg_surface_v6 = xdg_surface; view->sway_xdg_surface_v6 = sway_surface; sway_surface->view = view; diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index e1c2ad08..93c78228 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -81,13 +81,21 @@ static void set_activated(struct sway_view *view, bool activated) { wlr_xwayland_surface_activate(surface, activated); } -static void close_view(struct sway_view *view) { +static void _close(struct sway_view *view) { if (!assert_xwayland(view)) { return; } wlr_xwayland_surface_close(view->wlr_xwayland_surface); } +static const struct sway_view_impl view_impl = { + .get_prop = get_prop, + .set_size = set_size, + .set_position = set_position, + .set_activated = set_activated, + .close = _close, +}; + static void handle_commit(struct wl_listener *listener, void *data) { struct sway_xwayland_surface *sway_surface = wl_container_of(listener, sway_surface, commit); @@ -159,15 +167,10 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { return; } - struct sway_view *view = view_create(SWAY_XWAYLAND_VIEW); + struct sway_view *view = view_create(SWAY_XWAYLAND_VIEW, &view_impl); if (!sway_assert(view, "Failed to allocate view")) { return; } - view->iface.get_prop = get_prop; - view->iface.set_size = set_size; - view->iface.set_position = set_position; - view->iface.set_activated = set_activated; - view->iface.close = close_view; view->wlr_xwayland_surface = xsurface; view->sway_xwayland_surface = sway_surface; sway_surface->view = view; diff --git a/sway/tree/view.c b/sway/tree/view.c index 2950812a..d7a52e19 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -7,12 +7,14 @@ #include "sway/tree/layout.h" #include "sway/tree/view.h" -struct sway_view *view_create(enum sway_view_type type) { +struct sway_view *view_create(enum sway_view_type type, + const struct sway_view_impl *impl) { struct sway_view *view = calloc(1, sizeof(struct sway_view)); if (view == NULL) { return NULL; } view->type = type; + view->impl = impl; wl_list_init(&view->unmanaged_view_link); return view; } @@ -33,29 +35,29 @@ void view_destroy(struct sway_view *view) { } const char *view_get_title(struct sway_view *view) { - if (view->iface.get_prop) { - return view->iface.get_prop(view, VIEW_PROP_TITLE); + if (view->impl->get_prop) { + return view->impl->get_prop(view, VIEW_PROP_TITLE); } return NULL; } const char *view_get_app_id(struct sway_view *view) { - if (view->iface.get_prop) { - return view->iface.get_prop(view, VIEW_PROP_APP_ID); + if (view->impl->get_prop) { + return view->impl->get_prop(view, VIEW_PROP_APP_ID); } return NULL; } const char *view_get_class(struct sway_view *view) { - if (view->iface.get_prop) { - return view->iface.get_prop(view, VIEW_PROP_CLASS); + if (view->impl->get_prop) { + return view->impl->get_prop(view, VIEW_PROP_CLASS); } return NULL; } const char *view_get_instance(struct sway_view *view) { - if (view->iface.get_prop) { - return view->iface.get_prop(view, VIEW_PROP_INSTANCE); + if (view->impl->get_prop) { + return view->impl->get_prop(view, VIEW_PROP_INSTANCE); } return NULL; } @@ -86,41 +88,41 @@ static void view_update_outputs(struct sway_view *view, } void view_set_size(struct sway_view *view, int width, int height) { - if (view->iface.set_size) { + if (view->impl->set_size) { struct wlr_box box = { .x = view->swayc->x, .y = view->swayc->y, .width = view->width, .height = view->height, }; - view->iface.set_size(view, width, height); + view->impl->set_size(view, width, height); view_update_outputs(view, &box); } } // TODO make view coordinates in layout coordinates void view_set_position(struct sway_view *view, double ox, double oy) { - if (view->iface.set_position) { + if (view->impl->set_position) { struct wlr_box box = { .x = view->swayc->x, .y = view->swayc->y, .width = view->width, .height = view->height, }; - view->iface.set_position(view, ox, oy); + view->impl->set_position(view, ox, oy); view_update_outputs(view, &box); } } void view_set_activated(struct sway_view *view, bool activated) { - if (view->iface.set_activated) { - view->iface.set_activated(view, activated); + if (view->impl->set_activated) { + view->impl->set_activated(view, activated); } } void view_close(struct sway_view *view) { - if (view->iface.close) { - view->iface.close(view); + if (view->impl->close) { + view->impl->close(view); } } -- cgit v1.2.3 From 61fabede14bb3a8fe9ee5a249352cd405fd1b9bf Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 2 Apr 2018 10:57:45 -0400 Subject: Address review comments --- include/sway/tree/view.h | 21 ++++--- sway/desktop/wl_shell.c | 23 +++----- sway/desktop/xdg_shell_v6.c | 24 +++----- sway/desktop/xwayland.c | 31 ++++------ sway/tree/layout.c | 8 ++- sway/tree/output.c | 1 + sway/tree/view.c | 137 +++++++++++++++++++++++++------------------- 7 files changed, 124 insertions(+), 121 deletions(-) (limited to 'sway/tree/view.c') diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index c68739d6..4e753b2a 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -69,10 +69,8 @@ enum sway_view_prop { struct sway_view_impl { const char *(*get_prop)(struct sway_view *view, enum sway_view_prop prop); - void (*set_size)(struct sway_view *view, - int width, int height); - void (*set_position)(struct sway_view *view, - double ox, double oy); + void (*configure)(struct sway_view *view, double ox, double oy, int width, + int height); void (*set_activated)(struct sway_view *view, bool activated); void (*close)(struct sway_view *view); }; @@ -114,14 +112,19 @@ const char *view_get_class(struct sway_view *view); const char *view_get_instance(struct sway_view *view); -void view_set_size(struct sway_view *view, int width, int height); - -void view_set_position(struct sway_view *view, double ox, double oy); +void view_configure(struct sway_view *view, double ox, double oy, int width, + int height); void view_set_activated(struct sway_view *view, bool activated); void view_close(struct sway_view *view); +void view_damage_whole(struct sway_view *view); + +void view_damage_from(struct sway_view *view); + +// view implementation + void view_map(struct sway_view *view, struct wlr_surface *wlr_surface); void view_map_unmanaged(struct sway_view *view, @@ -129,8 +132,8 @@ void view_map_unmanaged(struct sway_view *view, void view_unmap(struct sway_view *view); -void view_damage_whole(struct sway_view *view); +void view_update_position(struct sway_view *view, double ox, double oy); -void view_damage_from(struct sway_view *view); +void view_update_size(struct sway_view *view, int width, int height); #endif diff --git a/sway/desktop/wl_shell.c b/sway/desktop/wl_shell.c index e0909a03..6528a397 100644 --- a/sway/desktop/wl_shell.c +++ b/sway/desktop/wl_shell.c @@ -30,24 +30,18 @@ static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) { } } -static void set_size(struct sway_view *view, int width, int height) { +static void configure(struct sway_view *view, double ox, double oy, int width, + int height) { if (!assert_wl_shell(view)) { return; } + view_update_position(view, ox, oy); view->sway_wl_shell_surface->pending_width = width; view->sway_wl_shell_surface->pending_height = height; wlr_wl_shell_surface_configure(view->wlr_wl_shell_surface, 0, width, height); } -static void set_position(struct sway_view *view, double ox, double oy) { - if (!assert_wl_shell(view)) { - return; - } - view->swayc->x = ox; - view->swayc->y = oy; -} - -static void close(struct sway_view *view) { +static void _close(struct sway_view *view) { if (!assert_wl_shell(view)) { return; } @@ -57,9 +51,8 @@ static void close(struct sway_view *view) { static const struct sway_view_impl view_impl = { .get_prop = get_prop, - .set_size = set_size, - .set_position = set_position, - .close = close, + .configure = configure, + .close = _close, }; static void handle_commit(struct wl_listener *listener, void *data) { @@ -68,8 +61,8 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct sway_view *view = sway_surface->view; // NOTE: We intentionally discard the view's desired width here // TODO: Let floating views do whatever - view->width = sway_surface->pending_width; - view->height = sway_surface->pending_height; + view_update_size(view, sway_surface->pending_width, + sway_surface->pending_height); view_damage_from(view); } diff --git a/sway/desktop/xdg_shell_v6.c b/sway/desktop/xdg_shell_v6.c index c1adc7fe..49305b39 100644 --- a/sway/desktop/xdg_shell_v6.c +++ b/sway/desktop/xdg_shell_v6.c @@ -30,23 +30,18 @@ static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) { } } -static void set_size(struct sway_view *view, int width, int height) { +static void configure(struct sway_view *view, double ox, double oy, int width, + int height) { if (!assert_xdg(view)) { return; } + + view_update_position(view, ox, oy); view->sway_xdg_surface_v6->pending_width = width; view->sway_xdg_surface_v6->pending_height = height; wlr_xdg_toplevel_v6_set_size(view->wlr_xdg_surface_v6, width, height); } -static void set_position(struct sway_view *view, double ox, double oy) { - if (!assert_xdg(view)) { - return; - } - view->swayc->x = ox; - view->swayc->y = oy; -} - static void set_activated(struct sway_view *view, bool activated) { if (!assert_xdg(view)) { return; @@ -57,7 +52,7 @@ static void set_activated(struct sway_view *view, bool activated) { } } -static void close(struct sway_view *view) { +static void _close(struct sway_view *view) { if (!assert_xdg(view)) { return; } @@ -69,10 +64,9 @@ static void close(struct sway_view *view) { static const struct sway_view_impl view_impl = { .get_prop = get_prop, - .set_size = set_size, - .set_position = set_position, + .configure = configure, .set_activated = set_activated, - .close = close, + .close = _close, }; static void handle_commit(struct wl_listener *listener, void *data) { @@ -82,8 +76,8 @@ static void handle_commit(struct wl_listener *listener, void *data) { // NOTE: We intentionally discard the view's desired width here // TODO: Store this for restoration when moving to floating plane // TODO: Let floating views do whatever - view->width = sway_surface->pending_width; - view->height = sway_surface->pending_height; + view_update_size(view, sway_surface->pending_width, + sway_surface->pending_height); view_damage_from(view); } diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 93c78228..39076fab 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -33,22 +33,13 @@ static const char *get_prop(struct sway_view *view, enum sway_view_prop prop) { } } -static void set_size(struct sway_view *view, int width, int height) { +static void configure(struct sway_view *view, double ox, double oy, int width, + int height) { if (!assert_xwayland(view)) { return; } - view->sway_xwayland_surface->pending_width = width; - view->sway_xwayland_surface->pending_height = height; - struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; - wlr_xwayland_surface_configure(xsurface, xsurface->x, xsurface->y, - width, height); -} -static void set_position(struct sway_view *view, double ox, double oy) { - if (!assert_xwayland(view)) { - return; - } struct sway_container *output = container_parent(view->swayc, C_OUTPUT); if (!sway_assert(output, "view must be within tree to set position")) { return; @@ -64,13 +55,12 @@ static void set_position(struct sway_view *view, double ox, double oy) { return; } - view->swayc->x = ox; - view->swayc->y = oy; + view_update_position(view, ox, oy); - wlr_xwayland_surface_configure(view->wlr_xwayland_surface, - ox + loutput->x, oy + loutput->y, - view->wlr_xwayland_surface->width, - view->wlr_xwayland_surface->height); + view->sway_xwayland_surface->pending_width = width; + view->sway_xwayland_surface->pending_height = height; + wlr_xwayland_surface_configure(xsurface, ox + loutput->x, oy + loutput->y, + width, height); } static void set_activated(struct sway_view *view, bool activated) { @@ -90,8 +80,7 @@ static void _close(struct sway_view *view) { static const struct sway_view_impl view_impl = { .get_prop = get_prop, - .set_size = set_size, - .set_position = set_position, + .configure = configure, .set_activated = set_activated, .close = _close, }; @@ -102,8 +91,8 @@ static void handle_commit(struct wl_listener *listener, void *data) { struct sway_view *view = sway_surface->view; // NOTE: We intentionally discard the view's desired width here // TODO: Let floating views do whatever - view->width = sway_surface->pending_width; - view->height = sway_surface->pending_height; + view_update_size(view, sway_surface->pending_width, + sway_surface->pending_height); view_damage_from(view); } diff --git a/sway/tree/layout.c b/sway/tree/layout.c index ce0682dc..3fec02a1 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -261,7 +261,7 @@ void arrange_windows(struct sway_container *container, { container->width = width; container->height = height; - view_set_size(container->sway_view, + view_configure(container->sway_view, container->x, container->y, container->width, container->height); wlr_log(L_DEBUG, "Set view to %.f x %.f @ %.f, %.f", container->width, container->height, @@ -322,7 +322,8 @@ static void apply_horiz_layout(struct sway_container *container, wlr_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, width, scale); - view_set_position(child->sway_view, child_x, y); + view_configure(child->sway_view, child_x, y, child->width, + child->height); if (i == end - 1) { double remaining_width = x + width - child_x; @@ -373,7 +374,8 @@ void apply_vert_layout(struct sway_container *container, wlr_log(L_DEBUG, "Calculating arrangement for %p:%d (will scale %f by %f)", child, child->type, height, scale); - view_set_position(child->sway_view, x, child_y); + view_configure(child->sway_view, x, child_y, child->width, + child->height); if (i == end - 1) { double remaining_height = y + height - child_y; diff --git a/sway/tree/output.c b/sway/tree/output.c index 7248fd00..80a36ac7 100644 --- a/sway/tree/output.c +++ b/sway/tree/output.c @@ -29,6 +29,7 @@ struct sway_container *container_output_destroy(struct sway_container *output) { wl_list_remove(&output->sway_output->destroy.link); wl_list_remove(&output->sway_output->mode.link); wl_list_remove(&output->sway_output->transform.link); + wl_list_remove(&output->sway_output->scale.link); wl_list_remove(&output->sway_output->damage_destroy.link); wl_list_remove(&output->sway_output->damage_frame.link); diff --git a/sway/tree/view.c b/sway/tree/view.c index d7a52e19..73e3d445 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -62,55 +62,10 @@ const char *view_get_instance(struct sway_view *view) { return NULL; } -static void view_update_outputs(struct sway_view *view, - const struct wlr_box *before) { - struct wlr_output_layout *output_layout = - root_container.sway_root->output_layout; - struct wlr_box box = { - .x = view->swayc->x, - .y = view->swayc->y, - .width = view->width, - .height = view->height, - }; - struct wlr_output_layout_output *layout_output; - wl_list_for_each(layout_output, &output_layout->outputs, link) { - bool intersected = before != NULL && wlr_output_layout_intersects( - output_layout, layout_output->output, before); - bool intersects = wlr_output_layout_intersects(output_layout, - layout_output->output, &box); - if (intersected && !intersects) { - wlr_surface_send_leave(view->surface, layout_output->output); - } - if (!intersected && intersects) { - wlr_surface_send_enter(view->surface, layout_output->output); - } - } -} - -void view_set_size(struct sway_view *view, int width, int height) { - if (view->impl->set_size) { - struct wlr_box box = { - .x = view->swayc->x, - .y = view->swayc->y, - .width = view->width, - .height = view->height, - }; - view->impl->set_size(view, width, height); - view_update_outputs(view, &box); - } -} - -// TODO make view coordinates in layout coordinates -void view_set_position(struct sway_view *view, double ox, double oy) { - if (view->impl->set_position) { - struct wlr_box box = { - .x = view->swayc->x, - .y = view->swayc->y, - .width = view->width, - .height = view->height, - }; - view->impl->set_position(view, ox, oy); - view_update_outputs(view, &box); +void view_configure(struct sway_view *view, double ox, double oy, int width, + int height) { + if (view->impl->configure) { + view->impl->configure(view, ox, oy, width, height); } } @@ -136,6 +91,56 @@ struct sway_container *container_view_destroy(struct sway_container *view) { return parent; } +void view_damage_whole(struct sway_view *view) { + 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_view(cont->sway_output, view); + } + } +} + +void view_damage_from(struct sway_view *view) { + // TODO + view_damage_whole(view); +} + +static void view_get_layout_box(struct sway_view *view, struct wlr_box *box) { + struct sway_container *cont = container_parent(view->swayc, C_OUTPUT); + + struct wlr_output_layout *output_layout = + root_container.sway_root->output_layout; + struct wlr_box *output_box = wlr_output_layout_get_box(output_layout, + cont->sway_output->wlr_output); + + box->x = output_box->x + view->swayc->x; + box->y = output_box->y + view->swayc->y; + box->width = view->width; + box->height = view->height; +} + +static void view_update_outputs(struct sway_view *view, + const struct wlr_box *before) { + struct wlr_box box; + view_get_layout_box(view, &box); + + struct wlr_output_layout *output_layout = + root_container.sway_root->output_layout; + struct wlr_output_layout_output *layout_output; + wl_list_for_each(layout_output, &output_layout->outputs, link) { + bool intersected = before != NULL && wlr_output_layout_intersects( + output_layout, layout_output->output, before); + bool intersects = wlr_output_layout_intersects(output_layout, + layout_output->output, &box); + if (intersected && !intersects) { + wlr_surface_send_leave(view->surface, layout_output->output); + } + if (!intersected && intersects) { + wlr_surface_send_enter(view->surface, layout_output->output); + } + } +} + void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { return; @@ -153,6 +158,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { sway_input_manager_set_focus(input_manager, cont); view_damage_whole(view); + view_update_outputs(view, NULL); } void view_map_unmanaged(struct sway_view *view, @@ -168,6 +174,8 @@ void view_map_unmanaged(struct sway_view *view, &view->unmanaged_view_link); view_damage_whole(view); + // TODO: make this work for unmanaged views + //view_update_outputs(view, NULL); } void view_unmap(struct sway_view *view) { @@ -186,17 +194,30 @@ void view_unmap(struct sway_view *view) { view->surface = NULL; } -void view_damage_whole(struct sway_view *view) { - struct sway_container *cont = NULL; - for (int i = 0; i < root_container.children->length; ++i) { - cont = root_container.children->items[i]; - if (cont->type == C_OUTPUT) { - output_damage_whole_view(cont->sway_output, view); - } +void view_update_position(struct sway_view *view, double ox, double oy) { + if (view->swayc->x == ox && view->swayc->y == oy) { + return; } + + struct wlr_box box; + view_get_layout_box(view, &box); + view_damage_whole(view); + view->swayc->x = ox; + view->swayc->y = oy; + view_update_outputs(view, &box); + view_damage_whole(view); } -void view_damage_from(struct sway_view *view) { - // TODO +void view_update_size(struct sway_view *view, int width, int height) { + if (view->width == width && view->height == height) { + return; + } + + struct wlr_box box; + view_get_layout_box(view, &box); + view_damage_whole(view); + view->width = width; + view->height = height; + view_update_outputs(view, &box); view_damage_whole(view); } -- cgit v1.2.3 From 2f64ce86c47efb2ee4c0e3a3c2b31307d21404d9 Mon Sep 17 00:00:00 2001 From: emersion Date: Mon, 2 Apr 2018 14:35:43 -0400 Subject: Xwayland unmanaged views aren't views anymore --- include/sway/tree/container.h | 4 +++- include/sway/tree/layout.h | 2 +- include/sway/tree/view.h | 10 ++++++--- sway/desktop/output.c | 14 ++++++------- sway/desktop/xwayland.c | 47 ++++++++++++++++++++++++++++++++++--------- sway/input/cursor.c | 11 +++++----- sway/tree/layout.c | 2 +- sway/tree/view.c | 36 ++++----------------------------- 8 files changed, 67 insertions(+), 59 deletions(-) (limited to 'sway/tree/view.c') diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index d707df17..423c0a22 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -70,7 +70,9 @@ struct sway_container { enum sway_container_layout prev_layout; enum sway_container_layout workspace_layout; - // in output-local coordinates + // For C_ROOT, this has no meaning + // For C_OUTPUT, this is the output position in layout coordinates + // For other types, this is the position in output-local coordinates double x, y; // does not include borders or gaps. double width, height; diff --git a/include/sway/tree/layout.h b/include/sway/tree/layout.h index 0a904c4b..fecf1582 100644 --- a/include/sway/tree/layout.h +++ b/include/sway/tree/layout.h @@ -23,7 +23,7 @@ struct sway_root { struct wl_listener output_layout_change; - struct wl_list unmanaged_views; // sway_view::unmanaged_view_link + struct wl_list xwayland_unmanaged; // sway_xwayland_unmanaged::link struct { struct wl_signal new_container; diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 4e753b2a..4b84205e 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -39,6 +39,13 @@ struct sway_xwayland_surface { int pending_width, pending_height; }; +struct sway_xwayland_unmanaged { + struct wlr_xwayland_surface *wlr_xwayland_surface; + struct wl_list link; + + struct wl_listener destroy; +}; + struct sway_wl_shell_surface { struct sway_view *view; @@ -127,9 +134,6 @@ void view_damage_from(struct sway_view *view); void view_map(struct sway_view *view, struct wlr_surface *wlr_surface); -void view_map_unmanaged(struct sway_view *view, - struct wlr_surface *wlr_surface); - void view_unmap(struct sway_view *view); void view_update_position(struct sway_view *view, double ox, double oy); diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 6c97ac37..352f4af3 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -257,15 +257,15 @@ static void render_output(struct sway_output *output, struct timespec *when, container_descendants(workspace, C_VIEW, render_view, &rdata); // render unmanaged views on top - struct sway_view *view; - wl_list_for_each(view, &root_container.sway_root->unmanaged_views, - unmanaged_view_link) { - if (view->type != SWAY_XWAYLAND_VIEW) { + 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 wlr_xwayland_surface *xsurface = + sway_surface->wlr_xwayland_surface; + if (xsurface->surface == NULL) { continue; } - struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; - const struct wlr_box view_box = { .x = xsurface->x, .y = xsurface->y, @@ -277,7 +277,7 @@ static void render_output(struct sway_output *output, struct timespec *when, continue; } - render_surface(view->surface, wlr_output, &output->last_frame, + render_surface(xsurface->surface, wlr_output, &output->last_frame, view_box.x - output_box->x, view_box.y - output_box->y, 0); } diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 39076fab..bfef68cf 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -14,6 +14,33 @@ #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 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; + } + + sway_surface->wlr_xwayland_surface = xsurface; + + wl_signal_add(&xsurface->events.destroy, &sway_surface->destroy); + sway_surface->destroy.notify = unmanaged_handle_destroy; + + wl_list_insert(&root_container.sway_root->xwayland_unmanaged, + &sway_surface->link); + + // TODO: damage tracking +} + + static bool assert_xwayland(struct sway_view *view) { return sway_assert(view->type == SWAY_XWAYLAND_VIEW, "Expected xwayland view!"); @@ -121,13 +148,8 @@ static void handle_map(struct wl_listener *listener, void *data) { struct sway_view *view = sway_surface->view; // put it back into the tree - if (wlr_xwayland_surface_is_unmanaged(xsurface) || - xsurface->override_redirect) { - view_map_unmanaged(view, xsurface->surface); - } else { - wlr_xwayland_surface_set_maximized(xsurface, true); - view_map(view, xsurface->surface); - } + wlr_xwayland_surface_set_maximized(xsurface, true); + view_map(view, xsurface->surface); } static void handle_request_configure(struct wl_listener *listener, void *data) { @@ -147,12 +169,19 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { listener, server, xwayland_surface); struct wlr_xwayland_surface *xsurface = data; + if (wlr_xwayland_surface_is_unmanaged(xsurface) || + xsurface->override_redirect) { + wlr_log(L_DEBUG, "New xwayland unmanaged surface"); + create_unmanaged(xsurface); + return; + } + wlr_log(L_DEBUG, "New xwayland surface title='%s' class='%s'", - xsurface->title, xsurface->class); + xsurface->title, xsurface->class); struct sway_xwayland_surface *sway_surface = calloc(1, sizeof(struct sway_xwayland_surface)); - if (!sway_assert(sway_surface, "Failed to allocate surface!")) { + if (!sway_assert(sway_surface, "Failed to allocate surface")) { return; } diff --git a/sway/input/cursor.c b/sway/input/cursor.c index d608a9cf..77ab9e31 100644 --- a/sway/input/cursor.c +++ b/sway/input/cursor.c @@ -47,14 +47,15 @@ static struct wlr_surface *layer_surface_at(struct sway_output *output, 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->unmanaged_views; - struct sway_view *view; - wl_list_for_each_reverse(view, unmanaged, unmanaged_view_link) { - if (view->type != SWAY_XWAYLAND_VIEW) { + 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 wlr_xwayland_surface *xsurface = + sway_surface->wlr_xwayland_surface; + if (xsurface->surface == NULL) { continue; } - struct wlr_xwayland_surface *xsurface = view->wlr_xwayland_surface; struct wlr_box box = { .x = xsurface->x, .y = xsurface->y, diff --git a/sway/tree/layout.c b/sway/tree/layout.c index 3fec02a1..122ea494 100644 --- a/sway/tree/layout.c +++ b/sway/tree/layout.c @@ -57,7 +57,7 @@ void layout_init(void) { root_container.sway_root = calloc(1, sizeof(*root_container.sway_root)); root_container.sway_root->output_layout = wlr_output_layout_create(); - wl_list_init(&root_container.sway_root->unmanaged_views); + wl_list_init(&root_container.sway_root->xwayland_unmanaged); wl_signal_init(&root_container.sway_root->events.new_container); root_container.sway_root->output_layout_change.notify = diff --git a/sway/tree/view.c b/sway/tree/view.c index 73e3d445..8f044621 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -15,7 +15,6 @@ struct sway_view *view_create(enum sway_view_type type, } view->type = type; view->impl = impl; - wl_list_init(&view->unmanaged_view_link); return view; } @@ -27,10 +26,8 @@ void view_destroy(struct sway_view *view) { if (view->surface != NULL) { view_unmap(view); } - if (view->swayc != NULL) { - container_view_destroy(view->swayc); - } + container_view_destroy(view->swayc); free(view); } @@ -106,15 +103,10 @@ void view_damage_from(struct sway_view *view) { } static void view_get_layout_box(struct sway_view *view, struct wlr_box *box) { - struct sway_container *cont = container_parent(view->swayc, C_OUTPUT); - - struct wlr_output_layout *output_layout = - root_container.sway_root->output_layout; - struct wlr_box *output_box = wlr_output_layout_get_box(output_layout, - cont->sway_output->wlr_output); + struct sway_container *output = container_parent(view->swayc, C_OUTPUT); - box->x = output_box->x + view->swayc->x; - box->y = output_box->y + view->swayc->y; + box->x = output->x + view->swayc->x; + box->y = output->y + view->swayc->y; box->width = view->width; box->height = view->height; } @@ -161,23 +153,6 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface) { view_update_outputs(view, NULL); } -void view_map_unmanaged(struct sway_view *view, - struct wlr_surface *wlr_surface) { - if (!sway_assert(view->surface == NULL, "cannot map mapped view")) { - return; - } - - view->surface = wlr_surface; - view->swayc = NULL; - - wl_list_insert(&root_container.sway_root->unmanaged_views, - &view->unmanaged_view_link); - - view_damage_whole(view); - // TODO: make this work for unmanaged views - //view_update_outputs(view, NULL); -} - void view_unmap(struct sway_view *view) { if (!sway_assert(view->surface != NULL, "cannot unmap unmapped view")) { return; @@ -185,9 +160,6 @@ void view_unmap(struct sway_view *view) { view_damage_whole(view); - wl_list_remove(&view->unmanaged_view_link); - wl_list_init(&view->unmanaged_view_link); - container_view_destroy(view->swayc); view->swayc = NULL; -- cgit v1.2.3