From cf713edc1052943ceaf33fd3b41242b5775fd924 Mon Sep 17 00:00:00 2001 From: emersion Date: Fri, 3 Nov 2017 14:49:15 +0100 Subject: Fix moving views when resizing below min size --- rootston/xwayland.c | 50 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 41 insertions(+), 9 deletions(-) (limited to 'rootston/xwayland.c') diff --git a/rootston/xwayland.c b/rootston/xwayland.c index 2d7fe946..e3fc1c84 100644 --- a/rootston/xwayland.c +++ b/rootston/xwayland.c @@ -15,38 +15,69 @@ static void activate(struct roots_view *view, bool active) { wlr_xwayland_surface_activate(xwayland, view->xwayland_surface, active); } -static void resize(struct roots_view *view, uint32_t width, uint32_t height) { +static void move(struct roots_view *view, double x, double y) { assert(view->type == ROOTS_XWAYLAND_VIEW); struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; + view->x = x; + view->y = y; + wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, + x, y, xwayland_surface->width, xwayland_surface->height); +} + +static void apply_size_constraints( + struct wlr_xwayland_surface *xwayland_surface, uint32_t width, + uint32_t height, uint32_t *dest_width, uint32_t *dest_height) { + *dest_width = width; + *dest_height = height; struct wlr_xwayland_surface_size_hints *size_hints = xwayland_surface->size_hints; if (size_hints != NULL) { if (width < (uint32_t)size_hints->min_width) { - width = size_hints->min_width; + *dest_width = size_hints->min_width; } else if (size_hints->max_width > 0 && width > (uint32_t)size_hints->max_width) { - width = size_hints->max_width; + *dest_width = size_hints->max_width; } if (height < (uint32_t)size_hints->min_height) { - height = size_hints->min_height; + *dest_height = size_hints->min_height; } else if (size_hints->max_height > 0 && height > (uint32_t)size_hints->max_height) { - height = size_hints->max_height; + *dest_height = size_hints->max_height; } } +} + +static void resize(struct roots_view *view, uint32_t width, uint32_t height) { + assert(view->type == ROOTS_XWAYLAND_VIEW); + struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; + + uint32_t contrained_width, contrained_height; + apply_size_constraints(xwayland_surface, width, height, &contrained_width, + &contrained_height); wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, - xwayland_surface->x, xwayland_surface->y, width, height); + xwayland_surface->x, xwayland_surface->y, contrained_width, + contrained_height); } -static void set_position(struct roots_view *view, double x, double y) { +static void move_resize(struct roots_view *view, double x, double y, + uint32_t width, uint32_t height) { assert(view->type == ROOTS_XWAYLAND_VIEW); struct wlr_xwayland_surface *xwayland_surface = view->xwayland_surface; + + uint32_t contrained_width, contrained_height; + apply_size_constraints(xwayland_surface, width, height, &contrained_width, + &contrained_height); + + x = x + width - contrained_width; + y = y + height - contrained_height; + view->x = x; view->y = y; + wlr_xwayland_surface_configure(view->desktop->xwayland, xwayland_surface, - x, y, xwayland_surface->width, xwayland_surface->height); + x, y, contrained_width, contrained_height); } static void close(struct roots_view *view) { @@ -204,7 +235,8 @@ void handle_xwayland_surface(struct wl_listener *listener, void *data) { view->desktop = desktop; view->activate = activate; view->resize = resize; - view->set_position = set_position; + view->move = move; + view->move_resize = move_resize; view->close = close; roots_surface->view = view; wlr_list_add(desktop->views, view); -- cgit v1.2.3