From d4a1ab7b8674646abe462f1dc3e40d03e62dd5fd Mon Sep 17 00:00:00 2001 From: mtvare6 Date: Thu, 31 Oct 2024 11:54:55 +0530 Subject: [PATCH] desktop/transaction: clamp vertical border length to 0 --- common/util.c | 4 ++++ include/util.h | 5 +++++ sway/desktop/transaction.c | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/common/util.c b/common/util.c index 7c492bcbf..f3fdff062 100644 --- a/common/util.c +++ b/common/util.c @@ -13,6 +13,10 @@ int wrap(int i, int max) { return ((i % max) + max) % max; } +int max(int a, int b){ + return a > b ? a : b; +} + bool parse_color(const char *color, uint32_t *result) { if (color[0] == '#') { ++color; diff --git a/include/util.h b/include/util.h index f887d4895..92749db3e 100644 --- a/include/util.h +++ b/include/util.h @@ -34,6 +34,11 @@ int parse_movement_amount(int argc, char **argv, */ int wrap(int i, int max); +/** + * Returns maximum of a and b + */ +int max(int a, int b); + /** * Given a string that represents an RGB(A) color, result will be set to a * uint32_t version of the color, as long as it is valid. If it is invalid, diff --git a/sway/desktop/transaction.c b/sway/desktop/transaction.c index 0cd5331cf..8a647e722 100644 --- a/sway/desktop/transaction.c +++ b/sway/desktop/transaction.c @@ -17,6 +17,7 @@ #include "sway/tree/workspace.h" #include "list.h" #include "log.h" +#include "util.h" struct sway_transaction { struct wl_event_source *timer; @@ -424,8 +425,7 @@ static void arrange_container(struct sway_container *con, int border_bottom = con->current.border_bottom ? border_width : 0; int border_left = con->current.border_left ? border_width : 0; int border_right = con->current.border_right ? border_width : 0; - int vert_border_height = (height - border_top - border_bottom) > 0 ? - (height- border_top - border_bottom) : 0; + int vert_border_height = max(0, height- border_top - border_bottom); wlr_scene_rect_set_size(con->border.top, width, border_top); wlr_scene_rect_set_size(con->border.bottom, width, border_bottom); wlr_scene_rect_set_size(con->border.left,