From 50205ade9d7b3d4c014fce5364db329c29acfa86 Mon Sep 17 00:00:00 2001 From: Kenny Levinsen Date: Mon, 8 Feb 2021 01:03:44 +0100 Subject: transaction: Move centering to view_center_surface This will allow us to reuse it for centering elsewhere. --- sway/tree/view.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'sway/tree/view.c') diff --git a/sway/tree/view.c b/sway/tree/view.c index 3b1e67ea..f4ae8171 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -887,6 +887,16 @@ void view_update_size(struct sway_view *view, int width, int height) { } } +void view_center_surface(struct sway_view *view) { + struct sway_container *con = view->container; + // We always center the current coordinates rather than the next, as the + // geometry immediately affects the currently active rendering. + con->surface_x = fmax(con->current.content_x, con->current.content_x + + (con->current.content_width - view->geometry.width) / 2); + con->surface_y = fmax(con->current.content_y, con->current.content_y + + (con->current.content_height - view->geometry.height) / 2); +} + static const struct sway_view_child_impl subsurface_impl; static void subsurface_get_root_coords(struct sway_view_child *child, -- cgit v1.2.3-54-g00ecf