From 0a9ff774ad77d5c650c03c0ac3501983f3cb0d19 Mon Sep 17 00:00:00 2001 From: Ryan Dwyer Date: Mon, 28 Jan 2019 16:00:34 +1000 Subject: Center surface inside container when it's too small The goal here is to center fullscreen views when they are both too small for the output and refuse to resize to the output's dimensions. It has the side effect of also centering the view when it's too small for its container. Example clients that have this behaviour are emersion's hello-wayland and weston. It works by introducing surface_{x,y,width,height} properties to the container struct. The x and y represent layout-local coordinates where the surface will be rendered. The width and height are only used to track the surface's previous dimensions so we can detect when the client has resized it and recenter and apply damage accordingly. The new surface properties are calculated when a transaction is applied, as well as when a view resizes itself unexpectedly. The latter is done in view_update_size. This function was previously restricted to views which are floating, but can now be called for any views. For views which refuse to resize *smaller* than a particular size, such as gnome-calculator, the surface is still anchored to the top left as per the current behaviour. --- sway/tree/view.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 561c6ef1..9ccb2a31 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -673,15 +673,22 @@ void view_unmap(struct sway_view *view) { } void view_update_size(struct sway_view *view, int width, int height) { - if (!sway_assert(container_is_floating(view->container), - "Expected a floating container")) { - return; + struct sway_container *con = view->container; + + if (container_is_floating(con)) { + con->content_width = width; + con->content_height = height; + con->current.content_width = width; + con->current.content_height = height; + container_set_geometry_from_content(con); + } else { + con->surface_x = con->content_x + (con->content_width - width) / 2; + con->surface_y = con->content_y + (con->content_height - height) / 2; + con->surface_x = fmax(con->surface_x, con->content_x); + con->surface_y = fmax(con->surface_y, con->content_y); } - view->container->content_width = width; - view->container->content_height = height; - view->container->current.content_width = width; - view->container->current.content_height = height; - container_set_geometry_from_content(view->container); + con->surface_width = width; + con->surface_width = height; } static const struct sway_view_child_impl subsurface_impl; -- cgit v1.2.3-54-g00ecf