From e14c592f39dac97a5045f5f6ec1aa1ca0192532b Mon Sep 17 00:00:00 2001 From: Daniel Eklöf Date: Wed, 6 Jan 2021 11:17:29 +0100 Subject: config: add optional ‘center’ argument to ‘pad’ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When set, the grid contents is centered in the window. I.e. the left/right and top/bottom margins are equal (+- 1px). This causes the content to “jump” while doing an interactive resize, but may still be preferred in e.g. a tiling WM. Closes #273 --- render.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'render.c') diff --git a/render.c b/render.c index 6995a51b..354d7b99 100644 --- a/render.c +++ b/render.c @@ -2638,10 +2638,20 @@ maybe_resize(struct terminal *term, int width, int height, bool force) assert(new_rows >= 1); /* Margins */ - term->margins.left = pad_x; - term->margins.top = pad_y; - term->margins.right = term->width - new_cols * term->cell_width - term->margins.left; - term->margins.bottom = term->height - new_rows * term->cell_height - term->margins.top; + const int grid_width = new_cols * term->cell_width; + const int grid_height = new_rows * term->cell_height; + const int total_x_pad = term->width - grid_width; + const int total_y_pad = term->height - grid_height; + + if (term->conf->center) { + term->margins.left = total_x_pad / 2; + term->margins.top = total_y_pad / 2; + } else { + term->margins.left = pad_x; + term->margins.top = pad_y; + } + term->margins.right = total_x_pad - term->margins.left; + term->margins.bottom = total_y_pad - term->margins.top; assert(term->margins.left >= pad_x); assert(term->margins.right >= pad_x); -- cgit v1.3