From 728aca615570a041321921f1e109da1880ce2513 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Thu, 11 Feb 2021 01:34:04 +0100 Subject: [PATCH] xdg_shell: Move floating window with attach point The buffer attach point was previously just used as an offset used during buffer rendering, while the purpose of the attach point is to move the window itself by the delta value. Use the delta to move floating containers, ignore it for tiling containers, and remove it as a variable in rendering. Closes: https://github.com/swaywm/sway/issues/6020 --- include/sway/tree/view.h | 2 +- sway/desktop/output.c | 4 ++-- sway/desktop/xdg_shell.c | 9 +++++++-- sway/desktop/xwayland.c | 2 +- sway/tree/view.c | 5 ++++- 5 files changed, 15 insertions(+), 7 deletions(-) diff --git a/include/sway/tree/view.h b/include/sway/tree/view.h index 86bd981c3..4507a750d 100644 --- a/include/sway/tree/view.h +++ b/include/sway/tree/view.h @@ -316,7 +316,7 @@ void view_map(struct sway_view *view, struct wlr_surface *wlr_surface, void view_unmap(struct sway_view *view); -void view_update_size(struct sway_view *view); +void view_update_size(struct sway_view *view, int dx, int dy); void view_center_surface(struct sway_view *view); void view_child_init(struct sway_view_child *child, diff --git a/sway/desktop/output.c b/sway/desktop/output.c index 691a285d2..7f12b28a9 100644 --- a/sway/desktop/output.c +++ b/sway/desktop/output.c @@ -99,8 +99,8 @@ static bool get_surface_box(struct surface_iterator_data *data, int sw = surface->current.width; int sh = surface->current.height; - double _sx = sx + surface->sx; - double _sy = sy + surface->sy; + double _sx = sx; + double _sy = sy; rotate_child_position(&_sx, &_sy, sw, sh, data->width, data->height, data->rotation); diff --git a/sway/desktop/xdg_shell.c b/sway/desktop/xdg_shell.c index 14880dcd3..3e99240e5 100644 --- a/sway/desktop/xdg_shell.c +++ b/sway/desktop/xdg_shell.c @@ -284,20 +284,25 @@ static void handle_commit(struct wl_listener *listener, void *data) { wl_container_of(listener, xdg_shell_view, commit); struct sway_view *view = &xdg_shell_view->view; struct wlr_xdg_surface *xdg_surface = view->wlr_xdg_surface; + struct wlr_surface *surface = xdg_surface->surface; struct wlr_box new_geo; wlr_xdg_surface_get_geometry(xdg_surface, &new_geo); bool new_size = new_geo.width != view->geometry.width || new_geo.height != view->geometry.height || new_geo.x != view->geometry.x || - new_geo.y != view->geometry.y; + new_geo.y != view->geometry.y || + surface->sx != 0 || + surface->sy != 0; if (new_size) { // The view has unexpectedly sent a new size desktop_damage_view(view); memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box)); if (container_is_floating(view->container)) { - view_update_size(view); + view_update_size(view, xdg_surface->surface->sx, xdg_surface->surface->sy); + xdg_surface->surface->sx = 0; + xdg_surface->surface->sy = 0; transaction_commit_dirty(); transaction_notify_view_ready_immediately(view); } else { diff --git a/sway/desktop/xwayland.c b/sway/desktop/xwayland.c index 4cd5f9d01..58f2a92e9 100644 --- a/sway/desktop/xwayland.c +++ b/sway/desktop/xwayland.c @@ -412,7 +412,7 @@ static void handle_commit(struct wl_listener *listener, void *data) { desktop_damage_view(view); memcpy(&view->geometry, &new_geo, sizeof(struct wlr_box)); if (container_is_floating(view->container)) { - view_update_size(view); + view_update_size(view, 0, 0); transaction_commit_dirty(); } else { view_center_surface(view); diff --git a/sway/tree/view.c b/sway/tree/view.c index e62fd018c..a255bbb36 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -872,10 +872,13 @@ void view_unmap(struct sway_view *view) { view->surface = NULL; } -void view_update_size(struct sway_view *view) { +void view_update_size(struct sway_view *view, int dx, int dy) { struct sway_container *con = view->container; + con->content_x += dx; + con->content_y += dy; con->content_width = view->geometry.width; con->content_height = view->geometry.height; + container_set_geometry_from_content(con); }