From a31ce37701adfc627cc534062e9c897fc7b8892b Mon Sep 17 00:00:00 2001 From: Tomi Ollila Date: Sun, 14 May 2023 20:46:15 +0300 Subject: [PATCH] round_down_to_increment (wm_) size hints while resizing Previously, while resizing views with size_hints (some X11 windows), rounding was done to the nearest increment. This may have caused the window borders to advance beyond output dimensions. --- src/view.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/view.c b/src/view.c index 1d43fcfa..7a28b9f5 100644 --- a/src/view.c +++ b/src/view.c @@ -685,12 +685,12 @@ substitute_nonzero(int *a, int *b) } static int -round_to_increment(int val, int base, int inc) +round_down_to_increment(int val, int base, int inc) { if (base < 0 || inc <= 0) { return val; } - return base + (val - base + inc / 2) / inc * inc; + return base + (val - base) / inc * inc; } void @@ -712,8 +712,8 @@ view_adjust_size(struct view *view, int *w, int *h) * terminal is resized to a width/height evenly divisible by the * cell (character) size. */ - *w = round_to_increment(*w, hints.base_width, hints.width_inc); - *h = round_to_increment(*h, hints.base_height, hints.height_inc); + *w = round_down_to_increment(*w, hints.base_width, hints.width_inc); + *h = round_down_to_increment(*h, hints.base_height, hints.height_inc); /* If a minimum width/height was not set, then use default */ if (hints.min_width < 1) {