diff options
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 65 | ||||
-rw-r--r-- | sway/config.c | 28 | ||||
-rw-r--r-- | sway/container.c | 20 | ||||
-rw-r--r-- | sway/layout.c | 30 |
4 files changed, 74 insertions, 69 deletions
diff --git a/sway/commands.c b/sway/commands.c index 6e74a442..0fc98538 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -519,8 +519,7 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { } if (argc == 1) { - char *end; - int amount = (int)strtol(argv[0], &end, 10); + int amount = (int)strtol(argv[0], NULL, 10); if (errno == ERANGE || amount == 0) { errno = 0; return false; @@ -532,8 +531,7 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { config->gaps_outer = amount; } } else if (argc == 2) { - char *end; - int amount = (int)strtol(argv[1], &end, 10); + int amount = (int)strtol(argv[1], NULL, 10); if (errno == ERANGE || amount == 0) { errno = 0; return false; @@ -548,6 +546,7 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { } else { return false; } + arrange_windows(&root_container, -1, -1); return true; } @@ -861,31 +860,31 @@ static bool cmd_ws_auto_back_and_forth(struct sway_config *config, int argc, cha /* Keep alphabetized */ static struct cmd_handler handlers[] = { - { "bindsym", cmd_bindsym }, - { "default_orientation", cmd_orientation }, - { "exec", cmd_exec }, - { "exec_always", cmd_exec_always }, - { "exit", cmd_exit }, - { "floating", cmd_floating }, - { "floating_modifier", cmd_floating_mod }, - { "focus", cmd_focus }, - { "focus_follows_mouse", cmd_focus_follows_mouse }, - { "fullscreen", cmd_fullscreen }, - { "gaps", cmd_gaps }, - { "kill", cmd_kill }, - { "layout", cmd_layout }, - { "log_colors", cmd_log_colors }, - { "move", cmd_move}, - { "output", cmd_output}, - { "reload", cmd_reload }, - { "resize", cmd_resize }, - { "scratchpad", cmd_scratchpad }, - { "set", cmd_set }, - { "split", cmd_split }, - { "splith", cmd_splith }, - { "splitv", cmd_splitv }, - { "workspace", cmd_workspace }, - { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth } + { "bindsym", cmd_bindsym, CMD_ANYTIME }, + { "default_orientation", cmd_orientation, CMD_ANYTIME}, + { "exec", cmd_exec, CMD_COMPOSITOR_READY }, + { "exec_always", cmd_exec_always, CMD_COMPOSITOR_READY }, + { "exit", cmd_exit, CMD_KEYBIND }, + { "floating", cmd_floating, CMD_KEYBIND }, + { "floating_modifier", cmd_floating_mod, CMD_ANYTIME }, + { "focus", cmd_focus, CMD_KEYBIND }, + { "focus_follows_mouse", cmd_focus_follows_mouse, CMD_ANYTIME }, + { "fullscreen", cmd_fullscreen, CMD_KEYBIND }, + { "gaps", cmd_gaps, CMD_ANYTIME }, + { "kill", cmd_kill, CMD_KEYBIND }, + { "layout", cmd_layout, CMD_KEYBIND }, + { "log_colors", cmd_log_colors, CMD_ANYTIME }, + { "move", cmd_move, CMD_KEYBIND }, + { "output", cmd_output, CMD_ANYTIME }, + { "reload", cmd_reload, CMD_KEYBIND }, + { "resize", cmd_resize, CMD_KEYBIND }, + { "scratchpad", cmd_scratchpad, CMD_KEYBIND }, + { "set", cmd_set, CMD_ANYTIME }, + { "split", cmd_split, CMD_KEYBIND }, + { "splith", cmd_splith, CMD_KEYBIND }, + { "splitv", cmd_splitv, CMD_KEYBIND }, + { "workspace", cmd_workspace, CMD_COMPOSITOR_READY }, + { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth, CMD_ANYTIME }, }; static char **split_directive(char *line, int *argc) { @@ -946,9 +945,11 @@ static int handler_compare(const void *_a, const void *_b) { return strcasecmp(a->command, b->command); } -static struct cmd_handler *find_handler(struct cmd_handler handlers[], int l, char *line) { +struct cmd_handler *find_handler(char *line) { struct cmd_handler d = { .command=line }; - struct cmd_handler *res = bsearch(&d, handlers, l, sizeof(struct cmd_handler), handler_compare); + struct cmd_handler *res = bsearch(&d, handlers, + sizeof(handlers) / sizeof(struct cmd_handler), + sizeof(struct cmd_handler), handler_compare); return res; } @@ -965,7 +966,7 @@ bool handle_command(struct sway_config *config, char *exec) { strncpy(cmd, exec, index); cmd[index] = '\0'; } - struct cmd_handler *handler = find_handler(handlers, sizeof(handlers) / sizeof(struct cmd_handler), cmd); + struct cmd_handler *handler = find_handler(cmd); if (handler == NULL) { sway_log(L_ERROR, "Unknown command '%s'", cmd); exec_success = false; // TODO: return error, probably diff --git a/sway/config.c b/sway/config.c index 2d7e241d..90f6529a 100644 --- a/sway/config.c +++ b/sway/config.c @@ -218,18 +218,22 @@ bool read_config(FILE *file, bool is_active) { // Any command which would require wlc to be initialized // should be queued for later execution list_t *args = split_string(line, " "); - if (!is_active && ( - strcmp("exec", args->items[0]) == 0 || - strcmp("exec_always", args->items[0]) == 0 )) { - sway_log(L_DEBUG, "Deferring command %s", line); - - char *cmd = malloc(strlen(line) + 1); - strcpy(cmd, line); - list_add(temp_config->cmd_queue, cmd); - } else if (!temp_depth && !handle_command(temp_config, line)) { - sway_log(L_DEBUG, "Config load failed for line %s", line); - success = false; - temp_config->failed = true; + struct cmd_handler *handler; + if ((handler = find_handler(args->items[0]))) { + if (handler->config_type == CMD_KEYBIND) { + sway_log(L_ERROR, "Invalid command during config ``%s''", line); + } else if (handler->config_type == CMD_COMPOSITOR_READY && !is_active) { + sway_log(L_DEBUG, "Deferring command ``%s''", line); + char *cmd = malloc(strlen(line) + 1); + strcpy(cmd, line); + list_add(temp_config->cmd_queue, cmd); + } else if (!temp_depth && !handle_command(temp_config, line)) { + sway_log(L_DEBUG, "Config load failed for line ``%s''", line); + success = false; + temp_config->failed = true; + } + } else { + sway_log(L_ERROR, "Invalid command ``%s''", line); } free_flat_list(args); diff --git a/sway/container.c b/sway/container.c index 442266ec..c922a6e6 100644 --- a/sway/container.c +++ b/sway/container.c @@ -14,6 +14,7 @@ static swayc_t *new_swayc(enum swayc_types type) { swayc_t *c = calloc(1, sizeof(swayc_t)); c->handle = -1; + c->gaps = -1; c->layout = L_NONE; c->type = type; if (type != C_VIEW) { @@ -96,7 +97,6 @@ swayc_t *new_output(wlc_handle handle) { } output->handle = handle; output->name = name ? strdup(name) : NULL; - output->gaps = config->gaps_outer; // Find position for it if (oc && oc->x != -1 && oc->y != -1) { @@ -244,8 +244,6 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) { view->desired_width = geometry->size.w; view->desired_height = geometry->size.h; - view->gaps = config->gaps_inner; - view->is_floating = false; if (sibling->type == C_WORKSPACE) { @@ -556,6 +554,16 @@ bool swayc_is_child_of(swayc_t *child, swayc_t *parent) { return swayc_is_parent_of(parent, child); } +int swayc_gap(swayc_t *container) { + if (container->type == C_VIEW) { + return container->gaps >= 0 ? container->gaps : config->gaps_inner; + } else if (container->type == C_WORKSPACE) { + return container->gaps >= 0 ? container->gaps : config->gaps_outer; + } else { + return 0; + } +} + // Mapping void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { @@ -650,10 +658,10 @@ void reset_gaps(swayc_t *view, void *data) { if (!ASSERT_NONNULL(view)) { return; } - if (view->type == C_OUTPUT) { - view->gaps = config->gaps_outer; + if (view->type == C_WORKSPACE) { + view->gaps = -1; } if (view->type == C_VIEW) { - view->gaps = config->gaps_inner; + view->gaps = -1; } } diff --git a/sway/layout.c b/sway/layout.c index daef332a..18202cf2 100644 --- a/sway/layout.c +++ b/sway/layout.c @@ -319,14 +319,15 @@ void update_geometry(swayc_t *container) { if (container->type != C_VIEW) { return; } + int gap = swayc_gap(container); struct wlc_geometry geometry = { .origin = { - .x = container->x + (container->is_floating ? 0 : container->gaps / 2), - .y = container->y + (container->is_floating ? 0 : container->gaps / 2) + .x = container->x + (container->is_floating ? 0 : gap / 2), + .y = container->y + (container->is_floating ? 0 : gap / 2) }, .size = { - .w = container->width - (container->is_floating ? 0 : container->gaps), - .h = container->height - (container->is_floating ? 0 : container->gaps) + .w = container->width - (container->is_floating ? 0 : gap), + .h = container->height - (container->is_floating ? 0 : gap) } }; if (swayc_is_fullscreen(container)) { @@ -364,10 +365,11 @@ void arrange_windows(swayc_t *container, double width, double height) { x = 0, y = 0; for (i = 0; i < container->children->length; ++i) { swayc_t *child = container->children->items[i]; - child->x = x + container->gaps; - child->y = y + container->gaps; - child->width = width - container->gaps * 2; - child->height = height - container->gaps * 2; + int gap = swayc_gap(child); + child->x = x + gap; + child->y = y + gap; + child->width = width - gap * 2; + child->height = height - gap * 2; sway_log(L_DEBUG, "Arranging workspace #%d at %f, %f", i, child->x, child->y); arrange_windows(child, -1, -1); } @@ -582,17 +584,7 @@ void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge ed layout_match = container->layout == L_VERT; } if (container->type == C_VIEW) { - struct wlc_geometry geometry = { - .origin = { - .x = container->x + container->gaps / 2, - .y = container->y + container->gaps / 2 - }, - .size = { - .w = container->width - container->gaps, - .h = container->height - container->gaps - } - }; - wlc_view_set_geometry(container->handle, edge, &geometry); + update_geometry(container); return; } if (layout_match) { |