aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/commands.h6
-rw-r--r--include/container.h2
-rw-r--r--sway/commands.c65
-rw-r--r--sway/config.c28
-rw-r--r--sway/container.c20
-rw-r--r--sway/layout.c30
6 files changed, 82 insertions, 69 deletions
diff --git a/include/commands.h b/include/commands.h
index 714d2db0..808e64eb 100644
--- a/include/commands.h
+++ b/include/commands.h
@@ -6,8 +6,14 @@
6struct cmd_handler { 6struct cmd_handler {
7 char *command; 7 char *command;
8 bool (*handle)(struct sway_config *config, int argc, char **argv); 8 bool (*handle)(struct sway_config *config, int argc, char **argv);
9 enum {
10 CMD_COMPOSITOR_READY,
11 CMD_KEYBIND,
12 CMD_ANYTIME
13 } config_type;
9}; 14};
10 15
16struct cmd_handler *find_handler(char *line);
11bool handle_command(struct sway_config *config, char *command); 17bool handle_command(struct sway_config *config, char *command);
12 18
13void remove_view_from_scratchpad(); 19void remove_view_from_scratchpad();
diff --git a/include/container.h b/include/container.h
index cfb2e868..f902950a 100644
--- a/include/container.h
+++ b/include/container.h
@@ -107,6 +107,8 @@ bool swayc_is_active(swayc_t *view);
107bool swayc_is_parent_of(swayc_t *parent, swayc_t *child); 107bool swayc_is_parent_of(swayc_t *parent, swayc_t *child);
108// Is `child` a child of `parent` 108// Is `child` a child of `parent`
109bool swayc_is_child_of(swayc_t *child, swayc_t *parent); 109bool swayc_is_child_of(swayc_t *child, swayc_t *parent);
110// Return gap of specified container
111int swayc_gap(swayc_t *container);
110 112
111// Mapping functions 113// Mapping functions
112 114
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) {
519 } 519 }
520 520
521 if (argc == 1) { 521 if (argc == 1) {
522 char *end; 522 int amount = (int)strtol(argv[0], NULL, 10);
523 int amount = (int)strtol(argv[0], &end, 10);
524 if (errno == ERANGE || amount == 0) { 523 if (errno == ERANGE || amount == 0) {
525 errno = 0; 524 errno = 0;
526 return false; 525 return false;
@@ -532,8 +531,7 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
532 config->gaps_outer = amount; 531 config->gaps_outer = amount;
533 } 532 }
534 } else if (argc == 2) { 533 } else if (argc == 2) {
535 char *end; 534 int amount = (int)strtol(argv[1], NULL, 10);
536 int amount = (int)strtol(argv[1], &end, 10);
537 if (errno == ERANGE || amount == 0) { 535 if (errno == ERANGE || amount == 0) {
538 errno = 0; 536 errno = 0;
539 return false; 537 return false;
@@ -548,6 +546,7 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) {
548 } else { 546 } else {
549 return false; 547 return false;
550 } 548 }
549 arrange_windows(&root_container, -1, -1);
551 return true; 550 return true;
552} 551}
553 552
@@ -861,31 +860,31 @@ static bool cmd_ws_auto_back_and_forth(struct sway_config *config, int argc, cha
861 860
862/* Keep alphabetized */ 861/* Keep alphabetized */
863static struct cmd_handler handlers[] = { 862static struct cmd_handler handlers[] = {
864 { "bindsym", cmd_bindsym }, 863 { "bindsym", cmd_bindsym, CMD_ANYTIME },
865 { "default_orientation", cmd_orientation }, 864 { "default_orientation", cmd_orientation, CMD_ANYTIME},
866 { "exec", cmd_exec }, 865 { "exec", cmd_exec, CMD_COMPOSITOR_READY },
867 { "exec_always", cmd_exec_always }, 866 { "exec_always", cmd_exec_always, CMD_COMPOSITOR_READY },
868 { "exit", cmd_exit }, 867 { "exit", cmd_exit, CMD_KEYBIND },
869 { "floating", cmd_floating }, 868 { "floating", cmd_floating, CMD_KEYBIND },
870 { "floating_modifier", cmd_floating_mod }, 869 { "floating_modifier", cmd_floating_mod, CMD_ANYTIME },
871 { "focus", cmd_focus }, 870 { "focus", cmd_focus, CMD_KEYBIND },
872 { "focus_follows_mouse", cmd_focus_follows_mouse }, 871 { "focus_follows_mouse", cmd_focus_follows_mouse, CMD_ANYTIME },
873 { "fullscreen", cmd_fullscreen }, 872 { "fullscreen", cmd_fullscreen, CMD_KEYBIND },
874 { "gaps", cmd_gaps }, 873 { "gaps", cmd_gaps, CMD_ANYTIME },
875 { "kill", cmd_kill }, 874 { "kill", cmd_kill, CMD_KEYBIND },
876 { "layout", cmd_layout }, 875 { "layout", cmd_layout, CMD_KEYBIND },
877 { "log_colors", cmd_log_colors }, 876 { "log_colors", cmd_log_colors, CMD_ANYTIME },
878 { "move", cmd_move}, 877 { "move", cmd_move, CMD_KEYBIND },
879 { "output", cmd_output}, 878 { "output", cmd_output, CMD_ANYTIME },
880 { "reload", cmd_reload }, 879 { "reload", cmd_reload, CMD_KEYBIND },
881 { "resize", cmd_resize }, 880 { "resize", cmd_resize, CMD_KEYBIND },
882 { "scratchpad", cmd_scratchpad }, 881 { "scratchpad", cmd_scratchpad, CMD_KEYBIND },
883 { "set", cmd_set }, 882 { "set", cmd_set, CMD_ANYTIME },
884 { "split", cmd_split }, 883 { "split", cmd_split, CMD_KEYBIND },
885 { "splith", cmd_splith }, 884 { "splith", cmd_splith, CMD_KEYBIND },
886 { "splitv", cmd_splitv }, 885 { "splitv", cmd_splitv, CMD_KEYBIND },
887 { "workspace", cmd_workspace }, 886 { "workspace", cmd_workspace, CMD_COMPOSITOR_READY },
888 { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth } 887 { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth, CMD_ANYTIME },
889}; 888};
890 889
891static char **split_directive(char *line, int *argc) { 890static char **split_directive(char *line, int *argc) {
@@ -946,9 +945,11 @@ static int handler_compare(const void *_a, const void *_b) {
946 return strcasecmp(a->command, b->command); 945 return strcasecmp(a->command, b->command);
947} 946}
948 947
949static struct cmd_handler *find_handler(struct cmd_handler handlers[], int l, char *line) { 948struct cmd_handler *find_handler(char *line) {
950 struct cmd_handler d = { .command=line }; 949 struct cmd_handler d = { .command=line };
951 struct cmd_handler *res = bsearch(&d, handlers, l, sizeof(struct cmd_handler), handler_compare); 950 struct cmd_handler *res = bsearch(&d, handlers,
951 sizeof(handlers) / sizeof(struct cmd_handler),
952 sizeof(struct cmd_handler), handler_compare);
952 return res; 953 return res;
953} 954}
954 955
@@ -965,7 +966,7 @@ bool handle_command(struct sway_config *config, char *exec) {
965 strncpy(cmd, exec, index); 966 strncpy(cmd, exec, index);
966 cmd[index] = '\0'; 967 cmd[index] = '\0';
967 } 968 }
968 struct cmd_handler *handler = find_handler(handlers, sizeof(handlers) / sizeof(struct cmd_handler), cmd); 969 struct cmd_handler *handler = find_handler(cmd);
969 if (handler == NULL) { 970 if (handler == NULL) {
970 sway_log(L_ERROR, "Unknown command '%s'", cmd); 971 sway_log(L_ERROR, "Unknown command '%s'", cmd);
971 exec_success = false; // TODO: return error, probably 972 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) {
218 // Any command which would require wlc to be initialized 218 // Any command which would require wlc to be initialized
219 // should be queued for later execution 219 // should be queued for later execution
220 list_t *args = split_string(line, " "); 220 list_t *args = split_string(line, " ");
221 if (!is_active && ( 221 struct cmd_handler *handler;
222 strcmp("exec", args->items[0]) == 0 || 222 if ((handler = find_handler(args->items[0]))) {
223 strcmp("exec_always", args->items[0]) == 0 )) { 223 if (handler->config_type == CMD_KEYBIND) {
224 sway_log(L_DEBUG, "Deferring command %s", line); 224 sway_log(L_ERROR, "Invalid command during config ``%s''", line);
225 225 } else if (handler->config_type == CMD_COMPOSITOR_READY && !is_active) {
226 char *cmd = malloc(strlen(line) + 1); 226 sway_log(L_DEBUG, "Deferring command ``%s''", line);
227 strcpy(cmd, line); 227 char *cmd = malloc(strlen(line) + 1);
228 list_add(temp_config->cmd_queue, cmd); 228 strcpy(cmd, line);
229 } else if (!temp_depth && !handle_command(temp_config, line)) { 229 list_add(temp_config->cmd_queue, cmd);
230 sway_log(L_DEBUG, "Config load failed for line %s", line); 230 } else if (!temp_depth && !handle_command(temp_config, line)) {
231 success = false; 231 sway_log(L_DEBUG, "Config load failed for line ``%s''", line);
232 temp_config->failed = true; 232 success = false;
233 temp_config->failed = true;
234 }
235 } else {
236 sway_log(L_ERROR, "Invalid command ``%s''", line);
233 } 237 }
234 free_flat_list(args); 238 free_flat_list(args);
235 239
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 @@
14static swayc_t *new_swayc(enum swayc_types type) { 14static swayc_t *new_swayc(enum swayc_types type) {
15 swayc_t *c = calloc(1, sizeof(swayc_t)); 15 swayc_t *c = calloc(1, sizeof(swayc_t));
16 c->handle = -1; 16 c->handle = -1;
17 c->gaps = -1;
17 c->layout = L_NONE; 18 c->layout = L_NONE;
18 c->type = type; 19 c->type = type;
19 if (type != C_VIEW) { 20 if (type != C_VIEW) {
@@ -96,7 +97,6 @@ swayc_t *new_output(wlc_handle handle) {
96 } 97 }
97 output->handle = handle; 98 output->handle = handle;
98 output->name = name ? strdup(name) : NULL; 99 output->name = name ? strdup(name) : NULL;
99 output->gaps = config->gaps_outer;
100 100
101 // Find position for it 101 // Find position for it
102 if (oc && oc->x != -1 && oc->y != -1) { 102 if (oc && oc->x != -1 && oc->y != -1) {
@@ -244,8 +244,6 @@ swayc_t *new_view(swayc_t *sibling, wlc_handle handle) {
244 view->desired_width = geometry->size.w; 244 view->desired_width = geometry->size.w;
245 view->desired_height = geometry->size.h; 245 view->desired_height = geometry->size.h;
246 246
247 view->gaps = config->gaps_inner;
248
249 view->is_floating = false; 247 view->is_floating = false;
250 248
251 if (sibling->type == C_WORKSPACE) { 249 if (sibling->type == C_WORKSPACE) {
@@ -556,6 +554,16 @@ bool swayc_is_child_of(swayc_t *child, swayc_t *parent) {
556 return swayc_is_parent_of(parent, child); 554 return swayc_is_parent_of(parent, child);
557} 555}
558 556
557int swayc_gap(swayc_t *container) {
558 if (container->type == C_VIEW) {
559 return container->gaps >= 0 ? container->gaps : config->gaps_inner;
560 } else if (container->type == C_WORKSPACE) {
561 return container->gaps >= 0 ? container->gaps : config->gaps_outer;
562 } else {
563 return 0;
564 }
565}
566
559// Mapping 567// Mapping
560 568
561void container_map(swayc_t *container, void (*f)(swayc_t *view, void *data), void *data) { 569void 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) {
650 if (!ASSERT_NONNULL(view)) { 658 if (!ASSERT_NONNULL(view)) {
651 return; 659 return;
652 } 660 }
653 if (view->type == C_OUTPUT) { 661 if (view->type == C_WORKSPACE) {
654 view->gaps = config->gaps_outer; 662 view->gaps = -1;
655 } 663 }
656 if (view->type == C_VIEW) { 664 if (view->type == C_VIEW) {
657 view->gaps = config->gaps_inner; 665 view->gaps = -1;
658 } 666 }
659} 667}
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) {
319 if (container->type != C_VIEW) { 319 if (container->type != C_VIEW) {
320 return; 320 return;
321 } 321 }
322 int gap = swayc_gap(container);
322 struct wlc_geometry geometry = { 323 struct wlc_geometry geometry = {
323 .origin = { 324 .origin = {
324 .x = container->x + (container->is_floating ? 0 : container->gaps / 2), 325 .x = container->x + (container->is_floating ? 0 : gap / 2),
325 .y = container->y + (container->is_floating ? 0 : container->gaps / 2) 326 .y = container->y + (container->is_floating ? 0 : gap / 2)
326 }, 327 },
327 .size = { 328 .size = {
328 .w = container->width - (container->is_floating ? 0 : container->gaps), 329 .w = container->width - (container->is_floating ? 0 : gap),
329 .h = container->height - (container->is_floating ? 0 : container->gaps) 330 .h = container->height - (container->is_floating ? 0 : gap)
330 } 331 }
331 }; 332 };
332 if (swayc_is_fullscreen(container)) { 333 if (swayc_is_fullscreen(container)) {
@@ -364,10 +365,11 @@ void arrange_windows(swayc_t *container, double width, double height) {
364 x = 0, y = 0; 365 x = 0, y = 0;
365 for (i = 0; i < container->children->length; ++i) { 366 for (i = 0; i < container->children->length; ++i) {
366 swayc_t *child = container->children->items[i]; 367 swayc_t *child = container->children->items[i];
367 child->x = x + container->gaps; 368 int gap = swayc_gap(child);
368 child->y = y + container->gaps; 369 child->x = x + gap;
369 child->width = width - container->gaps * 2; 370 child->y = y + gap;
370 child->height = height - container->gaps * 2; 371 child->width = width - gap * 2;
372 child->height = height - gap * 2;
371 sway_log(L_DEBUG, "Arranging workspace #%d at %f, %f", i, child->x, child->y); 373 sway_log(L_DEBUG, "Arranging workspace #%d at %f, %f", i, child->x, child->y);
372 arrange_windows(child, -1, -1); 374 arrange_windows(child, -1, -1);
373 } 375 }
@@ -582,17 +584,7 @@ void recursive_resize(swayc_t *container, double amount, enum wlc_resize_edge ed
582 layout_match = container->layout == L_VERT; 584 layout_match = container->layout == L_VERT;
583 } 585 }
584 if (container->type == C_VIEW) { 586 if (container->type == C_VIEW) {
585 struct wlc_geometry geometry = { 587 update_geometry(container);
586 .origin = {
587 .x = container->x + container->gaps / 2,
588 .y = container->y + container->gaps / 2
589 },
590 .size = {
591 .w = container->width - container->gaps,
592 .h = container->height - container->gaps
593 }
594 };
595 wlc_view_set_geometry(container->handle, edge, &geometry);
596 return; 588 return;
597 } 589 }
598 if (layout_match) { 590 if (layout_match) {