From 02599f640271f15690d0d0148c540d66690ca1bf Mon Sep 17 00:00:00 2001 From: Nate Symer Date: Sat, 26 May 2018 13:37:08 -0400 Subject: [PATCH] Fix tabbing --- include/sway/tree/container.h | 6 +- sway/commands/gaps.c | 238 +++++++++++++++++----------------- sway/commands/smart_gaps.c | 29 ++--- sway/config.c | 4 +- sway/tree/arrange.c | 22 ++-- 5 files changed, 149 insertions(+), 150 deletions(-) diff --git a/include/sway/tree/container.h b/include/sway/tree/container.h index ff16821f6..019fa441f 100644 --- a/include/sway/tree/container.h +++ b/include/sway/tree/container.h @@ -84,9 +84,9 @@ struct sway_container { double width, height; double saved_width, saved_height; - bool has_gaps; - double gaps_inner; - double gaps_outer; + bool has_gaps; + double gaps_inner; + double gaps_outer; list_t *children; diff --git a/sway/commands/gaps.c b/sway/commands/gaps.c index 329d784c0..0e23def0d 100644 --- a/sway/commands/gaps.c +++ b/sway/commands/gaps.c @@ -6,128 +6,128 @@ #include "stringop.h" int read_double(char *str, double *out) { - char *end; - double v = strtod(str, &end); - if (v == -HUGE_VAL || v == HUGE_VAL || strlen(end) > 0) { - *out = 0.0; - return 1; - } - *out = v; - return 0; + char *end; + double v = strtod(str, &end); + if (v == -HUGE_VAL || v == HUGE_VAL || strlen(end) > 0) { + *out = 0.0; + return 1; + } + *out = v; + return 0; } struct cmd_results *cmd_gaps(int argc, char **argv) { - struct cmd_results *error = NULL; - if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1))) { - return error; - } - - if (strcmp(argv[0], "edge_gaps") == 0) { - if (strcmp(argv[1], "on") == 0) { - config->edge_gaps = true; - arrange_root(); - } else if (strcmp(argv[1], "off") == 0) { - config->edge_gaps = false; - arrange_root(); - } else if (strcmp(argv[1], "toggle") == 0) { - if (config->active) { - config->edge_gaps = !(config->edge_gaps); - arrange_root(); - } else { - return cmd_results_new(CMD_INVALID, "gaps", "Cannot toggle gaps while not running."); - } - } else { - return cmd_results_new(CMD_INVALID, "gaps", ""); - } - } else { - int amount_idx = 0; - char op = '='; - char scope = 'a'; - bool inner = true; - - if (strcmp(argv[amount_idx], "inner") == 0) { - amount_idx++; - inner = true; - } else if (strcmp(argv[amount_idx], "outer") == 0) { - amount_idx++; - inner = false; - } - - if (amount_idx > 0) { - if (strcmp(argv[0], "all") == 0) { - amount_idx++; - scope = 'a'; - } else if (strcmp(argv[0], "workspace") == 0) { - amount_idx++; - scope = 'w'; - } else if (strcmp(argv[0], "current") == 0) { - amount_idx++; - scope = 'c'; - } - - if (strcmp(argv[amount_idx], "set") == 0) { - amount_idx++; - op = '='; - } else if (strcmp(argv[amount_idx], "plus") == 0) { - amount_idx++; - op = '+'; - } else if (strcmp(argv[amount_idx], "minus") == 0) { - amount_idx++; - op = '-'; - } - } - - double val; - if (read_double(argv[amount_idx], &val) == 0) { - if (amount_idx == 0) { - config->gaps_inner = val; - config->gaps_outer = val; - arrange_root(); - } else { - double total = val; - if (op == '-') { - total = (inner ? config->gaps_inner : config->gaps_outer) - val; - if (total < 0) { - total = 0; - } - } else if (op == '+') { - total = (inner ? config->gaps_inner : config->gaps_inner) + val; - } - - if (scope == 'a') { - if (inner) { - config->gaps_inner = total; - } else { - config->gaps_outer = total; - } - arrange_root(); - } else if (scope == 'w') { - struct sway_container *workspace = - config->handler_context.current_container; - if (workspace->type != C_WORKSPACE) { - workspace = container_parent(workspace, C_WORKSPACE); - } - workspace->has_gaps = true; - if (inner) { - workspace->gaps_inner = total; - } else { - workspace->gaps_outer = total; - } - arrange_workspace(workspace); - } else if (scope == 'c') { - struct sway_container *container = - config->handler_context.current_container; - container->has_gaps = true; - if (inner) { - container->gaps_inner = total; - } else { - container->gaps_outer = total; - } - arrange_workspace(container_parent(container, C_WORKSPACE)); - } + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1))) { + return error; } - } - } - return cmd_results_new(CMD_SUCCESS, NULL, NULL); + if (strcmp(argv[0], "edge_gaps") == 0) { + if (strcmp(argv[1], "on") == 0) { + config->edge_gaps = true; + arrange_root(); + } else if (strcmp(argv[1], "off") == 0) { + config->edge_gaps = false; + arrange_root(); + } else if (strcmp(argv[1], "toggle") == 0) { + if (config->active) { + config->edge_gaps = !(config->edge_gaps); + arrange_root(); + } else { + return cmd_results_new(CMD_INVALID, "gaps", "Cannot toggle gaps while not running."); + } + } else { + return cmd_results_new(CMD_INVALID, "gaps", ""); + } + } else { + int amount_idx = 0; + char op = '='; + char scope = 'a'; + bool inner = true; + + if (strcmp(argv[amount_idx], "inner") == 0) { + amount_idx++; + inner = true; + } else if (strcmp(argv[amount_idx], "outer") == 0) { + amount_idx++; + inner = false; + } + + if (amount_idx > 0) { + if (strcmp(argv[0], "all") == 0) { + amount_idx++; + scope = 'a'; + } else if (strcmp(argv[0], "workspace") == 0) { + amount_idx++; + scope = 'w'; + } else if (strcmp(argv[0], "current") == 0) { + amount_idx++; + scope = 'c'; + } + + if (strcmp(argv[amount_idx], "set") == 0) { + amount_idx++; + op = '='; + } else if (strcmp(argv[amount_idx], "plus") == 0) { + amount_idx++; + op = '+'; + } else if (strcmp(argv[amount_idx], "minus") == 0) { + amount_idx++; + op = '-'; + } + } + + double val; + if (read_double(argv[amount_idx], &val) == 0) { + if (amount_idx == 0) { + config->gaps_inner = val; + config->gaps_outer = val; + arrange_root(); + } else { + double total = val; + if (op == '-') { + total = (inner ? config->gaps_inner : config->gaps_outer) - val; + if (total < 0) { + total = 0; + } + } else if (op == '+') { + total = (inner ? config->gaps_inner : config->gaps_inner) + val; + } + + if (scope == 'a') { + if (inner) { + config->gaps_inner = total; + } else { + config->gaps_outer = total; + } + arrange_root(); + } else if (scope == 'w') { + struct sway_container *workspace = + config->handler_context.current_container; + if (workspace->type != C_WORKSPACE) { + workspace = container_parent(workspace, C_WORKSPACE); + } + workspace->has_gaps = true; + if (inner) { + workspace->gaps_inner = total; + } else { + workspace->gaps_outer = total; + } + arrange_workspace(workspace); + } else if (scope == 'c') { + struct sway_container *container = + config->handler_context.current_container; + container->has_gaps = true; + if (inner) { + container->gaps_inner = total; + } else { + container->gaps_outer = total; + } + arrange_workspace(container_parent(container, C_WORKSPACE)); + } + } + } + } + + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/commands/smart_gaps.c b/sway/commands/smart_gaps.c index 976b3f252..c38b3369c 100644 --- a/sway/commands/smart_gaps.c +++ b/sway/commands/smart_gaps.c @@ -8,21 +8,20 @@ #include "stringop.h" struct cmd_results *cmd_smart_gaps(int argc, char **argv) { - struct cmd_results *error = NULL; - if ((error = checkarg(argc, "smart_gaps", EXPECTED_AT_LEAST, 1))) { - return error; - } + struct cmd_results *error = NULL; + if ((error = checkarg(argc, "smart_gaps", EXPECTED_AT_LEAST, 1))) { + return error; + } - if (strcmp(argv[0], "on") == 0) { - config->smart_gaps = true; - arrange_root(); - } else if (strcmp(argv[0], "off") == 0) { - config->smart_gaps = false; - arrange_root(); - } else { - return cmd_results_new(CMD_INVALID, "smart_gaps", + if (strcmp(argv[0], "on") == 0) { + config->smart_gaps = true; + arrange_root(); + } else if (strcmp(argv[0], "off") == 0) { + config->smart_gaps = false; + arrange_root(); + } else { + return cmd_results_new(CMD_INVALID, "smart_gaps", "Expected 'smart_gaps ' "); - } - - return cmd_results_new(CMD_SUCCESS, NULL, NULL); + } + return cmd_results_new(CMD_SUCCESS, NULL, NULL); } diff --git a/sway/config.c b/sway/config.c index b524b7dcc..34c8a2802 100644 --- a/sway/config.c +++ b/sway/config.c @@ -193,8 +193,8 @@ static void config_defaults(struct sway_config *config) { config->edge_gaps = true; config->smart_gaps = false; - config->gaps_inner = 20;//0; - config->gaps_outer = 20;//0; + config->gaps_inner = 0; + config->gaps_outer = 0; if (!(config->active_bar_modifiers = create_list())) goto cleanup; diff --git a/sway/tree/arrange.c b/sway/tree/arrange.c index ab8b57df8..b595dcf7b 100644 --- a/sway/tree/arrange.c +++ b/sway/tree/arrange.c @@ -71,17 +71,17 @@ void arrange_workspace(struct sway_container *workspace) { struct wlr_box *area = &output->sway_output->usable_area; wlr_log(L_DEBUG, "Usable area for ws: %dx%d@%d,%d", area->width, area->height, area->x, area->y); - if (config->edge_gaps || (config->smart_gaps && workspace->children->length > 1)) { - double gaps = workspace->has_gaps ? workspace->gaps_outer : config->gaps_outer; - workspace->width = area->width - (2 * gaps); - workspace->height = area->height - (2 * gaps); - workspace->x = area->x + gaps; - workspace->y = area->y + gaps; - } else { - workspace->width = area->width; - workspace->height = area->height; - workspace->x = area->x; - workspace->y = area->y; + if (config->edge_gaps || (config->smart_gaps && workspace->children->length > 1)) { + double gaps = workspace->has_gaps ? workspace->gaps_outer : config->gaps_outer; + workspace->width = area->width - (2 * gaps); + workspace->height = area->height - (2 * gaps); + workspace->x = area->x + gaps; + workspace->y = area->y + gaps; + } else { + workspace->width = area->width; + workspace->height = area->height; + workspace->x = area->x; + workspace->y = area->y; } wlr_log(L_DEBUG, "Arranging workspace '%s' at %f, %f", workspace->name, workspace->x, workspace->y);