diff options
Diffstat (limited to 'sway/commands.c')
-rw-r--r-- | sway/commands.c | 202 |
1 files changed, 81 insertions, 121 deletions
diff --git a/sway/commands.c b/sway/commands.c index 5c782e99..e7ddfa71 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -96,7 +96,7 @@ static int bindsym_sort(const void *_lbind, const void *_rbind) { | |||
96 | return (rbind->keys->length + rmod) - (lbind->keys->length + lmod); | 96 | return (rbind->keys->length + rmod) - (lbind->keys->length + lmod); |
97 | } | 97 | } |
98 | 98 | ||
99 | static bool cmd_bindsym(struct sway_config *config, int argc, char **argv) { | 99 | static bool cmd_bindsym(int argc, char **argv) { |
100 | if (!checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1)) { | 100 | if (!checkarg(argc, "bindsym", EXPECTED_MORE_THAN, 1)) { |
101 | return false; | 101 | return false; |
102 | }; | 102 | }; |
@@ -146,7 +146,7 @@ static bool cmd_bindsym(struct sway_config *config, int argc, char **argv) { | |||
146 | return true; | 146 | return true; |
147 | } | 147 | } |
148 | 148 | ||
149 | static bool cmd_exec_always(struct sway_config *config, int argc, char **argv) { | 149 | static bool cmd_exec_always(int argc, char **argv) { |
150 | if (!checkarg(argc, "exec_always", EXPECTED_MORE_THAN, 0)) { | 150 | if (!checkarg(argc, "exec_always", EXPECTED_MORE_THAN, 0)) { |
151 | return false; | 151 | return false; |
152 | } | 152 | } |
@@ -171,14 +171,14 @@ static bool cmd_exec_always(struct sway_config *config, int argc, char **argv) { | |||
171 | return true; | 171 | return true; |
172 | } | 172 | } |
173 | 173 | ||
174 | static bool cmd_exec(struct sway_config *config, int argc, char **argv) { | 174 | static bool cmd_exec(int argc, char **argv) { |
175 | if (config->reloading) { | 175 | if (config->reloading) { |
176 | char *args = join_args(argv, argc); | 176 | char *args = join_args(argv, argc); |
177 | sway_log(L_DEBUG, "Ignoring exec %s due to reload", args); | 177 | sway_log(L_DEBUG, "Ignoring exec %s due to reload", args); |
178 | free(args); | 178 | free(args); |
179 | return true; | 179 | return true; |
180 | } | 180 | } |
181 | return cmd_exec_always(config, argc, argv); | 181 | return cmd_exec_always(argc, argv); |
182 | } | 182 | } |
183 | 183 | ||
184 | static void kill_views(swayc_t *container, void *data) { | 184 | static void kill_views(swayc_t *container, void *data) { |
@@ -187,7 +187,7 @@ static void kill_views(swayc_t *container, void *data) { | |||
187 | } | 187 | } |
188 | } | 188 | } |
189 | 189 | ||
190 | static bool cmd_exit(struct sway_config *config, int argc, char **argv) { | 190 | static bool cmd_exit(int argc, char **argv) { |
191 | if (!checkarg(argc, "exit", EXPECTED_EQUAL_TO, 0)) { | 191 | if (!checkarg(argc, "exit", EXPECTED_EQUAL_TO, 0)) { |
192 | return false; | 192 | return false; |
193 | } | 193 | } |
@@ -197,7 +197,7 @@ static bool cmd_exit(struct sway_config *config, int argc, char **argv) { | |||
197 | return true; | 197 | return true; |
198 | } | 198 | } |
199 | 199 | ||
200 | static bool cmd_floating(struct sway_config *config, int argc, char **argv) { | 200 | static bool cmd_floating(int argc, char **argv) { |
201 | if (!checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1)) { | 201 | if (!checkarg(argc, "floating", EXPECTED_EQUAL_TO, 1)) { |
202 | return false; | 202 | return false; |
203 | } | 203 | } |
@@ -258,7 +258,7 @@ static bool cmd_floating(struct sway_config *config, int argc, char **argv) { | |||
258 | return true; | 258 | return true; |
259 | } | 259 | } |
260 | 260 | ||
261 | static bool cmd_floating_mod(struct sway_config *config, int argc, char **argv) { | 261 | static bool cmd_floating_mod(int argc, char **argv) { |
262 | if (!checkarg(argc, "floating_modifier", EXPECTED_EQUAL_TO, 1)) { | 262 | if (!checkarg(argc, "floating_modifier", EXPECTED_EQUAL_TO, 1)) { |
263 | return false; | 263 | return false; |
264 | } | 264 | } |
@@ -282,7 +282,7 @@ static bool cmd_floating_mod(struct sway_config *config, int argc, char **argv) | |||
282 | return true; | 282 | return true; |
283 | } | 283 | } |
284 | 284 | ||
285 | static bool cmd_focus(struct sway_config *config, int argc, char **argv) { | 285 | static bool cmd_focus(int argc, char **argv) { |
286 | static int floating_toggled_index = 0; | 286 | static int floating_toggled_index = 0; |
287 | static int tiled_toggled_index = 0; | 287 | static int tiled_toggled_index = 0; |
288 | if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) { | 288 | if (!checkarg(argc, "focus", EXPECTED_EQUAL_TO, 1)) { |
@@ -340,7 +340,7 @@ static bool cmd_focus(struct sway_config *config, int argc, char **argv) { | |||
340 | return true; | 340 | return true; |
341 | } | 341 | } |
342 | 342 | ||
343 | static bool cmd_focus_follows_mouse(struct sway_config *config, int argc, char **argv) { | 343 | static bool cmd_focus_follows_mouse(int argc, char **argv) { |
344 | if (!checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1)) { | 344 | if (!checkarg(argc, "focus_follows_mouse", EXPECTED_EQUAL_TO, 1)) { |
345 | return false; | 345 | return false; |
346 | } | 346 | } |
@@ -365,7 +365,39 @@ static void hide_view_in_scratchpad(swayc_t *sp_view) { | |||
365 | set_focused_container(container_under_pointer()); | 365 | set_focused_container(container_under_pointer()); |
366 | } | 366 | } |
367 | 367 | ||
368 | static bool cmd_move(struct sway_config *config, int argc, char **argv) { | 368 | static bool cmd_mode(int argc, char **argv) { |
369 | if (!checkarg(argc, "move", EXPECTED_AT_LEAST, 1)) { | ||
370 | return false; | ||
371 | } | ||
372 | const char *mode_name = argv[0]; | ||
373 | struct sway_mode *mode = NULL; | ||
374 | // Find mode | ||
375 | int i, len = config->modes->length; | ||
376 | for (i = 0; i < len; ++i) { | ||
377 | struct sway_mode *find = config->modes->items[i]; | ||
378 | if (strcasecmp(find->name, mode_name)==0) { | ||
379 | mode = find; | ||
380 | break; | ||
381 | } | ||
382 | } | ||
383 | // Create mode if it doesnt exist | ||
384 | if (!mode && argc >= 2 && strncmp(argv[1],"{",1) == 0) { | ||
385 | mode = malloc(sizeof*mode); | ||
386 | mode->name = strdup(mode_name); | ||
387 | mode->bindings = create_list(); | ||
388 | list_add(config->modes, mode); | ||
389 | } | ||
390 | if (!mode) { | ||
391 | sway_log(L_ERROR, "Invalide mode `%s'", mode_name); | ||
392 | return false; | ||
393 | } | ||
394 | sway_log(L_DEBUG, "Switching to mode `%s'",mode->name); | ||
395 | // Set current mode | ||
396 | config->current_mode = mode; | ||
397 | return true; | ||
398 | } | ||
399 | |||
400 | static bool cmd_move(int argc, char **argv) { | ||
369 | if (!checkarg(argc, "move", EXPECTED_AT_LEAST, 1)) { | 401 | if (!checkarg(argc, "move", EXPECTED_AT_LEAST, 1)) { |
370 | return false; | 402 | return false; |
371 | } | 403 | } |
@@ -435,7 +467,7 @@ static bool cmd_move(struct sway_config *config, int argc, char **argv) { | |||
435 | return true; | 467 | return true; |
436 | } | 468 | } |
437 | 469 | ||
438 | static bool cmd_orientation(struct sway_config *config, int argc, char **argv) { | 470 | static bool cmd_orientation(int argc, char **argv) { |
439 | if (strcasecmp(argv[0], "horizontal") == 0) { | 471 | if (strcasecmp(argv[0], "horizontal") == 0) { |
440 | config->default_orientation = L_HORIZ; | 472 | config->default_orientation = L_HORIZ; |
441 | } else if (strcasecmp(argv[0], "vertical") == 0) { | 473 | } else if (strcasecmp(argv[0], "vertical") == 0) { |
@@ -448,7 +480,7 @@ static bool cmd_orientation(struct sway_config *config, int argc, char **argv) { | |||
448 | return true; | 480 | return true; |
449 | } | 481 | } |
450 | 482 | ||
451 | static bool cmd_output(struct sway_config *config, int argc, char **argv) { | 483 | static bool cmd_output(int argc, char **argv) { |
452 | if (!checkarg(argc, "output", EXPECTED_AT_LEAST, 1)) { | 484 | if (!checkarg(argc, "output", EXPECTED_AT_LEAST, 1)) { |
453 | return false; | 485 | return false; |
454 | } | 486 | } |
@@ -513,7 +545,7 @@ static bool cmd_output(struct sway_config *config, int argc, char **argv) { | |||
513 | return true; | 545 | return true; |
514 | } | 546 | } |
515 | 547 | ||
516 | static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { | 548 | static bool cmd_gaps(int argc, char **argv) { |
517 | if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { | 549 | if (!checkarg(argc, "gaps", EXPECTED_AT_LEAST, 1)) { |
518 | return false; | 550 | return false; |
519 | } | 551 | } |
@@ -655,13 +687,13 @@ static bool cmd_gaps(struct sway_config *config, int argc, char **argv) { | |||
655 | return true; | 687 | return true; |
656 | } | 688 | } |
657 | 689 | ||
658 | static bool cmd_kill(struct sway_config *config, int argc, char **argv) { | 690 | static bool cmd_kill(int argc, char **argv) { |
659 | swayc_t *view = get_focused_container(&root_container); | 691 | swayc_t *view = get_focused_container(&root_container); |
660 | wlc_view_close(view->handle); | 692 | wlc_view_close(view->handle); |
661 | return true; | 693 | return true; |
662 | } | 694 | } |
663 | 695 | ||
664 | static bool cmd_layout(struct sway_config *config, int argc, char **argv) { | 696 | static bool cmd_layout(int argc, char **argv) { |
665 | if (!checkarg(argc, "layout", EXPECTED_MORE_THAN, 0)) { | 697 | if (!checkarg(argc, "layout", EXPECTED_MORE_THAN, 0)) { |
666 | return false; | 698 | return false; |
667 | } | 699 | } |
@@ -686,7 +718,7 @@ static bool cmd_layout(struct sway_config *config, int argc, char **argv) { | |||
686 | return true; | 718 | return true; |
687 | } | 719 | } |
688 | 720 | ||
689 | static bool cmd_reload(struct sway_config *config, int argc, char **argv) { | 721 | static bool cmd_reload(int argc, char **argv) { |
690 | if (!checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0)) { | 722 | if (!checkarg(argc, "reload", EXPECTED_EQUAL_TO, 0)) { |
691 | return false; | 723 | return false; |
692 | } | 724 | } |
@@ -697,7 +729,7 @@ static bool cmd_reload(struct sway_config *config, int argc, char **argv) { | |||
697 | return true; | 729 | return true; |
698 | } | 730 | } |
699 | 731 | ||
700 | static bool cmd_resize(struct sway_config *config, int argc, char **argv) { | 732 | static bool cmd_resize(int argc, char **argv) { |
701 | if (!checkarg(argc, "resize", EXPECTED_AT_LEAST, 3)) { | 733 | if (!checkarg(argc, "resize", EXPECTED_AT_LEAST, 3)) { |
702 | return false; | 734 | return false; |
703 | } | 735 | } |
@@ -769,7 +801,7 @@ void remove_view_from_scratchpad(swayc_t *view) { | |||
769 | } | 801 | } |
770 | } | 802 | } |
771 | 803 | ||
772 | static bool cmd_scratchpad(struct sway_config *config, int argc, char **argv) { | 804 | static bool cmd_scratchpad(int argc, char **argv) { |
773 | if (!checkarg(argc, "scratchpad", EXPECTED_EQUAL_TO, 1)) { | 805 | if (!checkarg(argc, "scratchpad", EXPECTED_EQUAL_TO, 1)) { |
774 | return false; | 806 | return false; |
775 | } | 807 | } |
@@ -796,20 +828,18 @@ static bool cmd_scratchpad(struct sway_config *config, int argc, char **argv) { | |||
796 | } | 828 | } |
797 | } | 829 | } |
798 | 830 | ||
799 | static bool cmd_set(struct sway_config *config, int argc, char **argv) { | 831 | static bool cmd_set(int argc, char **argv) { |
800 | if (!checkarg(argc, "set", EXPECTED_EQUAL_TO, 2)) { | 832 | if (!checkarg(argc, "set", EXPECTED_EQUAL_TO, 2)) { |
801 | return false; | 833 | return false; |
802 | } | 834 | } |
803 | struct sway_variable *var = malloc(sizeof(struct sway_variable)); | 835 | struct sway_variable *var = malloc(sizeof(struct sway_variable)); |
804 | var->name = malloc(strlen(argv[0]) + 1); | 836 | var->name = strdup(argv[0]); |
805 | strcpy(var->name, argv[0]); | 837 | var->value = strdup(argv[1]); |
806 | var->value = malloc(strlen(argv[1]) + 1); | ||
807 | strcpy(var->value, argv[1]); | ||
808 | list_add(config->symbols, var); | 838 | list_add(config->symbols, var); |
809 | return true; | 839 | return true; |
810 | } | 840 | } |
811 | 841 | ||
812 | static bool _do_split(struct sway_config *config, int argc, char **argv, int layout) { | 842 | static bool _do_split(int argc, char **argv, int layout) { |
813 | char *name = layout == L_VERT ? "splitv" : | 843 | char *name = layout == L_VERT ? "splitv" : |
814 | layout == L_HORIZ ? "splith" : "split"; | 844 | layout == L_HORIZ ? "splith" : "split"; |
815 | if (!checkarg(argc, name, EXPECTED_EQUAL_TO, 0)) { | 845 | if (!checkarg(argc, name, EXPECTED_EQUAL_TO, 0)) { |
@@ -840,15 +870,15 @@ static bool _do_split(struct sway_config *config, int argc, char **argv, int lay | |||
840 | return true; | 870 | return true; |
841 | } | 871 | } |
842 | 872 | ||
843 | static bool cmd_split(struct sway_config *config, int argc, char **argv) { | 873 | static bool cmd_split(int argc, char **argv) { |
844 | if (!checkarg(argc, "split", EXPECTED_EQUAL_TO, 1)) { | 874 | if (!checkarg(argc, "split", EXPECTED_EQUAL_TO, 1)) { |
845 | return false; | 875 | return false; |
846 | } | 876 | } |
847 | 877 | ||
848 | if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { | 878 | if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) { |
849 | _do_split(config, argc - 1, argv + 1, L_VERT); | 879 | _do_split(argc - 1, argv + 1, L_VERT); |
850 | } else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) { | 880 | } else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) { |
851 | _do_split(config, argc - 1, argv + 1, L_HORIZ); | 881 | _do_split(argc - 1, argv + 1, L_HORIZ); |
852 | } else { | 882 | } else { |
853 | sway_log(L_ERROR, "Invalid split command (expected either horiziontal or vertical)."); | 883 | sway_log(L_ERROR, "Invalid split command (expected either horiziontal or vertical)."); |
854 | return false; | 884 | return false; |
@@ -857,15 +887,15 @@ static bool cmd_split(struct sway_config *config, int argc, char **argv) { | |||
857 | return true; | 887 | return true; |
858 | } | 888 | } |
859 | 889 | ||
860 | static bool cmd_splitv(struct sway_config *config, int argc, char **argv) { | 890 | static bool cmd_splitv(int argc, char **argv) { |
861 | return _do_split(config, argc, argv, L_VERT); | 891 | return _do_split(argc, argv, L_VERT); |
862 | } | 892 | } |
863 | 893 | ||
864 | static bool cmd_splith(struct sway_config *config, int argc, char **argv) { | 894 | static bool cmd_splith(int argc, char **argv) { |
865 | return _do_split(config, argc, argv, L_HORIZ); | 895 | return _do_split(argc, argv, L_HORIZ); |
866 | } | 896 | } |
867 | 897 | ||
868 | static bool cmd_log_colors(struct sway_config *config, int argc, char **argv) { | 898 | static bool cmd_log_colors(int argc, char **argv) { |
869 | if (!checkarg(argc, "log_colors", EXPECTED_EQUAL_TO, 1)) { | 899 | if (!checkarg(argc, "log_colors", EXPECTED_EQUAL_TO, 1)) { |
870 | return false; | 900 | return false; |
871 | } | 901 | } |
@@ -878,7 +908,7 @@ static bool cmd_log_colors(struct sway_config *config, int argc, char **argv) { | |||
878 | return true; | 908 | return true; |
879 | } | 909 | } |
880 | 910 | ||
881 | static bool cmd_fullscreen(struct sway_config *config, int argc, char **argv) { | 911 | static bool cmd_fullscreen(int argc, char **argv) { |
882 | if (!checkarg(argc, "fullscreen", EXPECTED_AT_LEAST, 0)) { | 912 | if (!checkarg(argc, "fullscreen", EXPECTED_AT_LEAST, 0)) { |
883 | return false; | 913 | return false; |
884 | } | 914 | } |
@@ -897,7 +927,7 @@ static bool cmd_fullscreen(struct sway_config *config, int argc, char **argv) { | |||
897 | return true; | 927 | return true; |
898 | } | 928 | } |
899 | 929 | ||
900 | static bool cmd_workspace(struct sway_config *config, int argc, char **argv) { | 930 | static bool cmd_workspace(int argc, char **argv) { |
901 | if (!checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1)) { | 931 | if (!checkarg(argc, "workspace", EXPECTED_AT_LEAST, 1)) { |
902 | return false; | 932 | return false; |
903 | } | 933 | } |
@@ -953,7 +983,7 @@ static bool cmd_workspace(struct sway_config *config, int argc, char **argv) { | |||
953 | return true; | 983 | return true; |
954 | } | 984 | } |
955 | 985 | ||
956 | static bool cmd_ws_auto_back_and_forth(struct sway_config *config, int argc, char **argv) { | 986 | static bool cmd_ws_auto_back_and_forth(int argc, char **argv) { |
957 | if (!checkarg(argc, "workspace_auto_back_and_forth", EXPECTED_EQUAL_TO, 1)) { | 987 | if (!checkarg(argc, "workspace_auto_back_and_forth", EXPECTED_EQUAL_TO, 1)) { |
958 | return false; | 988 | return false; |
959 | } | 989 | } |
@@ -979,6 +1009,7 @@ static struct cmd_handler handlers[] = { | |||
979 | { "kill", cmd_kill, CMD_KEYBIND }, | 1009 | { "kill", cmd_kill, CMD_KEYBIND }, |
980 | { "layout", cmd_layout, CMD_KEYBIND }, | 1010 | { "layout", cmd_layout, CMD_KEYBIND }, |
981 | { "log_colors", cmd_log_colors, CMD_ANYTIME }, | 1011 | { "log_colors", cmd_log_colors, CMD_ANYTIME }, |
1012 | { "mode", cmd_mode, CMD_ANYTIME }, | ||
982 | { "move", cmd_move, CMD_KEYBIND }, | 1013 | { "move", cmd_move, CMD_KEYBIND }, |
983 | { "output", cmd_output, CMD_ANYTIME }, | 1014 | { "output", cmd_output, CMD_ANYTIME }, |
984 | { "reload", cmd_reload, CMD_KEYBIND }, | 1015 | { "reload", cmd_reload, CMD_KEYBIND }, |
@@ -992,58 +1023,6 @@ static struct cmd_handler handlers[] = { | |||
992 | { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth, CMD_ANYTIME }, | 1023 | { "workspace_auto_back_and_forth", cmd_ws_auto_back_and_forth, CMD_ANYTIME }, |
993 | }; | 1024 | }; |
994 | 1025 | ||
995 | static char **split_directive(char *line, int *argc) { | ||
996 | const char *delimiters = " "; | ||
997 | *argc = 0; | ||
998 | while (isspace(*line) && *line) ++line; | ||
999 | |||
1000 | int capacity = 10; | ||
1001 | char **parts = malloc(sizeof(char *) * capacity); | ||
1002 | |||
1003 | if (!*line) return parts; | ||
1004 | |||
1005 | int in_string = 0, in_character = 0; | ||
1006 | int i, j, _; | ||
1007 | for (i = 0, j = 0; line[i]; ++i) { | ||
1008 | if (line[i] == '\\') { | ||
1009 | ++i; | ||
1010 | } else if (line[i] == '"' && !in_character) { | ||
1011 | in_string = !in_string; | ||
1012 | } else if (line[i] == '\'' && !in_string) { | ||
1013 | in_character = !in_character; | ||
1014 | } else if (!in_character && !in_string) { | ||
1015 | if (strchr(delimiters, line[i]) != NULL) { | ||
1016 | char *item = malloc(i - j + 1); | ||
1017 | strncpy(item, line + j, i - j); | ||
1018 | item[i - j] = '\0'; | ||
1019 | item = strip_whitespace(item, &_); | ||
1020 | if (item[0] == '\0') { | ||
1021 | free(item); | ||
1022 | } else { | ||
1023 | if (*argc == capacity) { | ||
1024 | capacity *= 2; | ||
1025 | parts = realloc(parts, sizeof(char *) * capacity); | ||
1026 | } | ||
1027 | parts[*argc] = item; | ||
1028 | j = i + 1; | ||
1029 | ++*argc; | ||
1030 | } | ||
1031 | } | ||
1032 | } | ||
1033 | } | ||
1034 | char *item = malloc(i - j + 1); | ||
1035 | strncpy(item, line + j, i - j); | ||
1036 | item[i - j] = '\0'; | ||
1037 | item = strip_whitespace(item, &_); | ||
1038 | if (*argc == capacity) { | ||
1039 | capacity++; | ||
1040 | parts = realloc(parts, sizeof(char *) * capacity); | ||
1041 | } | ||
1042 | parts[*argc] = item; | ||
1043 | ++*argc; | ||
1044 | return parts; | ||
1045 | } | ||
1046 | |||
1047 | static int handler_compare(const void *_a, const void *_b) { | 1026 | static int handler_compare(const void *_a, const void *_b) { |
1048 | const struct cmd_handler *a = _a; | 1027 | const struct cmd_handler *a = _a; |
1049 | const struct cmd_handler *b = _b; | 1028 | const struct cmd_handler *b = _b; |
@@ -1058,44 +1037,25 @@ struct cmd_handler *find_handler(char *line) { | |||
1058 | return res; | 1037 | return res; |
1059 | } | 1038 | } |
1060 | 1039 | ||
1061 | bool handle_command(struct sway_config *config, char *exec) { | 1040 | bool handle_command(char *exec) { |
1062 | sway_log(L_INFO, "Handling command '%s'", exec); | 1041 | sway_log(L_INFO, "Handling command '%s'", exec); |
1063 | char *ptr, *cmd; | 1042 | int argc; |
1064 | bool exec_success; | 1043 | char **argv = split_args(exec, &argc); |
1065 | 1044 | if (argc == 0) { | |
1066 | if ((ptr = strchr(exec, ' ')) == NULL) { | 1045 | return false; |
1067 | cmd = exec; | 1046 | } |
1068 | } else { | 1047 | struct cmd_handler *handler = find_handler(argv[0]); |
1069 | int index = ptr - exec; | 1048 | bool exec_success = false; |
1070 | cmd = malloc(index + 1); | 1049 | if (handler) { |
1071 | strncpy(cmd, exec, index); | ||
1072 | cmd[index] = '\0'; | ||
1073 | } | ||
1074 | struct cmd_handler *handler = find_handler(cmd); | ||
1075 | if (handler == NULL) { | ||
1076 | sway_log(L_ERROR, "Unknown command '%s'", cmd); | ||
1077 | exec_success = false; // TODO: return error, probably | ||
1078 | } else { | ||
1079 | int argc; | ||
1080 | char **argv = split_directive(exec + strlen(handler->command), &argc); | ||
1081 | int i; | 1050 | int i; |
1082 | 1051 | for (i = 1; i < argc; ++i) { | |
1083 | // Perform var subs on all parts of the command | 1052 | argv[i] = do_var_replacement(argv[i]); |
1084 | for (i = 0; i < argc; ++i) { | ||
1085 | argv[i] = do_var_replacement(config, argv[i]); | ||
1086 | } | ||
1087 | |||
1088 | exec_success = handler->handle(config, argc, argv); | ||
1089 | for (i = 0; i < argc; ++i) { | ||
1090 | free(argv[i]); | ||
1091 | } | ||
1092 | free(argv); | ||
1093 | if (!exec_success) { | ||
1094 | sway_log(L_ERROR, "Command failed: %s", cmd); | ||
1095 | } | 1053 | } |
1054 | exec_success = handler->handle(argc - 1, argv + 1); | ||
1096 | } | 1055 | } |
1097 | if (ptr) { | 1056 | if (exec_success == false) { |
1098 | free(cmd); | 1057 | sway_log(L_ERROR, "Command failed: %s", argv[0]); |
1099 | } | 1058 | } |
1059 | free_argv(argc, argv); | ||
1100 | return exec_success; | 1060 | return exec_success; |
1101 | } | 1061 | } |