From a7b9e63cbcacc5dd4629598734a231b9f830670d Mon Sep 17 00:00:00 2001 From: Konstantin Pospelov Date: Sun, 25 Nov 2018 12:03:04 +0300 Subject: resize set: fix units for floating containers This commit fixes the default size units for floating containers, so that pixels are used if the units are not specified. --- sway/commands/resize.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'sway/commands') diff --git a/sway/commands/resize.c b/sway/commands/resize.c index a90d578e..bafaea87 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -512,34 +512,38 @@ static struct cmd_results *resize_set_floating(struct sway_container *con, calculate_constraints(&min_width, &max_width, &min_height, &max_height); if (width->amount) { - if (width->unit == RESIZE_UNIT_PPT || - width->unit == RESIZE_UNIT_DEFAULT) { + switch (width->unit) { + case RESIZE_UNIT_PPT: // Convert to px width->amount = con->workspace->width * width->amount / 100; width->unit = RESIZE_UNIT_PX; - } - if (width->unit == RESIZE_UNIT_PX) { + // Falls through + case RESIZE_UNIT_PX: + case RESIZE_UNIT_DEFAULT: width->amount = fmax(min_width, fmin(width->amount, max_width)); grow_width = width->amount - con->width; - con->x -= grow_width / 2; con->width = width->amount; + case RESIZE_UNIT_INVALID: + break; } } if (height->amount) { - if (height->unit == RESIZE_UNIT_PPT || - height->unit == RESIZE_UNIT_DEFAULT) { + switch (height->unit) { + case RESIZE_UNIT_PPT: // Convert to px height->amount = con->workspace->height * height->amount / 100; height->unit = RESIZE_UNIT_PX; - } - if (height->unit == RESIZE_UNIT_PX) { + // Falls through + case RESIZE_UNIT_PX: + case RESIZE_UNIT_DEFAULT: height->amount = fmax(min_height, fmin(height->amount, max_height)); grow_height = height->amount - con->height; - con->y -= grow_height / 2; con->height = height->amount; + case RESIZE_UNIT_INVALID: + break; } } -- cgit v1.2.3 From f9bde0030dd12d1afd8dd6378f099944727561cf Mon Sep 17 00:00:00 2001 From: Konstantin Pospelov Date: Sun, 25 Nov 2018 15:16:45 +0300 Subject: resize set: add assertion for an invalid unit --- sway/commands/resize.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'sway/commands') diff --git a/sway/commands/resize.c b/sway/commands/resize.c index bafaea87..cf5dea02 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -524,7 +524,9 @@ static struct cmd_results *resize_set_floating(struct sway_container *con, grow_width = width->amount - con->width; con->x -= grow_width / 2; con->width = width->amount; + break; case RESIZE_UNIT_INVALID: + sway_assert(false, "invalid width unit"); break; } } @@ -542,7 +544,9 @@ static struct cmd_results *resize_set_floating(struct sway_container *con, grow_height = height->amount - con->height; con->y -= grow_height / 2; con->height = height->amount; + break; case RESIZE_UNIT_INVALID: + sway_assert(false, "invalid height unit"); break; } } -- cgit v1.2.3