diff options
Diffstat (limited to 'sway/commands')
-rw-r--r-- | sway/commands/resize.c | 28 | ||||
-rw-r--r-- | sway/commands/title_align.c | 30 |
2 files changed, 48 insertions, 10 deletions
diff --git a/sway/commands/resize.c b/sway/commands/resize.c index a90d578e..cf5dea02 100644 --- a/sway/commands/resize.c +++ b/sway/commands/resize.c @@ -512,34 +512,42 @@ 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; + break; + case RESIZE_UNIT_INVALID: + sway_assert(false, "invalid width unit"); + 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; + break; + case RESIZE_UNIT_INVALID: + sway_assert(false, "invalid height unit"); + break; } } diff --git a/sway/commands/title_align.c b/sway/commands/title_align.c new file mode 100644 index 00000000..82578186 --- /dev/null +++ b/sway/commands/title_align.c @@ -0,0 +1,30 @@ +#include "sway/commands.h" +#include "sway/config.h" +#include "sway/output.h" +#include "sway/tree/container.h" +#include "sway/tree/root.h" + +struct cmd_results *cmd_title_align(int argc, char **argv) { + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "title_align", EXPECTED_AT_LEAST, 1))) { + return error; + } + + if (strcmp(argv[0], "left") == 0) { + config->title_align = ALIGN_LEFT; + } else if (strcmp(argv[0], "center") == 0) { + config->title_align = ALIGN_CENTER; + } else if (strcmp(argv[0], "right") == 0) { + config->title_align = ALIGN_RIGHT; + } else { + return cmd_results_new(CMD_INVALID, "title_align", + "Expected 'title_align left|center|right'"); + } + + for (int i = 0; i < root->outputs->length; ++i) { + struct sway_output *output = root->outputs->items[i]; + output_damage_whole(output); + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); +} |