diff options
-rw-r--r-- | include/container.h | 4 | ||||
-rw-r--r-- | sway/commands.c | 131 | ||||
-rw-r--r-- | sway/config.c | 1 | ||||
-rw-r--r-- | sway/container.c | 21 | ||||
-rw-r--r-- | sway/log.c | 5 |
5 files changed, 139 insertions, 23 deletions
diff --git a/include/container.h b/include/container.h index f902950a..a9b95229 100644 --- a/include/container.h +++ b/include/container.h @@ -116,7 +116,9 @@ void container_map(swayc_t *, void (*f)(swayc_t *, void *), void *); // Mappings void set_view_visibility(swayc_t *view, void *data); -void reset_gaps(swayc_t *view, void *data); +// Set or add to gaps +void set_gaps(swayc_t *view, void *amount); +void add_gaps(swayc_t *view, void *amount); void update_visibility(swayc_t *container); diff --git a/sway/commands.c b/sway/commands.c index 0fc98538..ffe7faa4 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -517,9 +517,10 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { return false; } - - if (argc == 1) { - int amount = (int)strtol(argv[0], NULL, 10); + const char *amount_str = argv[0]; + // gaps amount + if (argc >= 1 && isdigit(*amount_str)) { + int amount = (int)strtol(amount_str, NULL, 10); if (errno == ERANGE || amount == 0) { errno = 0; return false; @@ -530,23 +531,127 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { if (config->gaps_outer == 0) { config->gaps_outer = amount; } - } else if (argc == 2) { - int amount = (int)strtol(argv[1], NULL, 10); + return true; + } + // gaps inner|outer n + else if (argc >= 2 && isdigit((amount_str = argv[1])[0])) { + int amount = (int)strtol(amount_str, NULL, 10); if (errno == ERANGE || amount == 0) { errno = 0; return false; } - if (strcasecmp(argv[0], "inner") == 0) { + const char *target_str = argv[0]; + if (strcasecmp(target_str, "inner") == 0) { config->gaps_inner = amount; - } else if (strcasecmp(argv[0], "outer") == 0) { + } else if (strcasecmp(target_str, "outer") == 0) { config->gaps_outer = amount; + } + return true; + } + // gaps inner|outer current|all set|plus|minus n + if (argc < 4) { + return false; + } + // gaps inner|outer ... + const char *inout_str = argv[0]; + enum {INNER, OUTER} inout; + if (strcasecmp(inout_str, "inner") == 0) { + inout = INNER; + } else if (strcasecmp(inout_str, "outer") == 0) { + inout = OUTER; + } else { + return false; + } + + // gaps ... current|all ... + const char *target_str = argv[1]; + enum {CURRENT, WORKSPACE, ALL} target; + if (strcasecmp(target_str, "current") == 0) { + target = CURRENT; + } else if (strcasecmp(target_str, "all") == 0) { + target = ALL; + } else if (strcasecmp(target_str, "workspace") == 0){ + if (inout == OUTER) { + target = CURRENT; } else { - return false; + // Set gap for views in workspace + target = WORKSPACE; } } else { return false; } - arrange_windows(&root_container, -1, -1); + + // gaps ... n + amount_str = argv[3]; + int amount = (int)strtol(amount_str, NULL, 10); + if (errno == ERANGE || amount == 0) { + errno = 0; + return false; + } + + // gaps ... set|plus|minus ... + const char *method_str = argv[2]; + enum {SET, ADD} method; + if (strcasecmp(method_str, "set") == 0) { + method = SET; + } else if (strcasecmp(method_str, "plus") == 0) { + method = ADD; + } else if (strcasecmp(method_str, "minus") == 0) { + method = ADD; + amount *= -1; + } else { + return false; + } + + if (target == CURRENT) { + swayc_t *cont; + if (inout == OUTER) { + if ((cont = swayc_active_workspace()) == NULL) { + return false; + } + } else { + if ((cont = get_focused_view(&root_container))->type != C_VIEW) { + return false; + } + } + cont->gaps = swayc_gap(cont); + if (method == SET) { + cont->gaps = amount; + } else if ((cont->gaps += amount) < 0) { + cont->gaps = 0; + } + arrange_windows(cont->parent, -1, -1); + } else if (inout == OUTER) { + //resize all workspace. + int i,j; + for (i = 0; i < root_container.children->length; ++i) { + swayc_t *op = root_container.children->items[i]; + for (j = 0; j < op->children->length; ++j) { + swayc_t *ws = op->children->items[j]; + if (method == SET) { + ws->gaps = amount; + } else if ((ws->gaps += amount) < 0) { + ws->gaps = 0; + } + } + } + arrange_windows(&root_container, -1, -1); + } else { + // Resize gaps for all views in workspace + swayc_t *top; + if (target == WORKSPACE) { + if ((top = swayc_active_workspace()) == NULL) { + return false; + } + } else { + top = &root_container; + } + int top_gap = top->gaps; + container_map(top, method == SET ? set_gaps : add_gaps, &amount); + top->gaps = top_gap; + arrange_windows(top, -1, -1); + } + return true; } @@ -975,10 +1080,10 @@ bool handle_command(struct sway_config *config, char *exec) { char **argv = split_directive(exec + strlen(handler->command), &argc); int i; - // Perform var subs on all parts of the command - for (i = 0; i < argc; ++i) { - argv[i] = do_var_replacement(config, argv[i]); - } + // Perform var subs on all parts of the command + for (i = 0; i < argc; ++i) { + argv[i] = do_var_replacement(config, argv[i]); + } exec_success = handler->handle(config, argc, argv); for (i = 0; i < argc; ++i) { diff --git a/sway/config.c b/sway/config.c index 90f6529a..c9a9cc74 100644 --- a/sway/config.c +++ b/sway/config.c @@ -246,7 +246,6 @@ _continue: if (is_active) { temp_config->reloading = false; - container_map(&root_container, reset_gaps, NULL); arrange_windows(&root_container, -1, -1); } config = temp_config; diff --git a/sway/container.c b/sway/container.c index c922a6e6..ef0e6c55 100644 --- a/sway/container.c +++ b/sway/container.c @@ -653,15 +653,24 @@ void update_visibility(swayc_t *container) { } } -void reset_gaps(swayc_t *view, void *data) { - (void) data; +void set_gaps(swayc_t *view, void *_data) { + int *data = _data; if (!ASSERT_NONNULL(view)) { return; } - if (view->type == C_WORKSPACE) { - view->gaps = -1; + if (view->type == C_WORKSPACE || view->type == C_VIEW) { + view->gaps = *data; } - if (view->type == C_VIEW) { - view->gaps = -1; +} + +void add_gaps(swayc_t *view, void *_data) { + int *data = _data; + if (!ASSERT_NONNULL(view)) { + return; + } + if (view->type == C_WORKSPACE || view->type == C_VIEW) { + if ((view->gaps += *data) < 0) { + view->gaps = 0; + } } } @@ -159,8 +159,9 @@ static void container_log(const swayc_t *c) { c->layout == L_STACKED ? "Stacked|": c->layout == L_FLOATING ? "Floating|": "Unknown|"); - fprintf(stderr, "w:%f|h:%f|", c->width, c->height); - fprintf(stderr, "x:%f|y:%f|", c->x, c->y); + fprintf(stderr, "w:%.f|h:%.f|", c->width, c->height); + fprintf(stderr, "x:%.f|y:%.f|", c->x, c->y); + fprintf(stderr, "g:%d|",c->gaps); fprintf(stderr, "vis:%c|", c->visible?'t':'f'); fprintf(stderr, "name:%.16s|", c->name); fprintf(stderr, "children:%d\n",c->children?c->children->length:0); |