summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/commands.h3
-rw-r--r--sway/commands.c20
-rw-r--r--sway/config.c10
3 files changed, 11 insertions, 22 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index 5d45d78b..757cc817 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -31,7 +31,6 @@ enum cmd_status {
31 */ 31 */
32struct cmd_results { 32struct cmd_results {
33 enum cmd_status status; 33 enum cmd_status status;
34 char *input;
35 /** 34 /**
36 * Human friendly error message, or NULL on success 35 * Human friendly error message, or NULL on success
37 */ 36 */
@@ -63,7 +62,7 @@ list_t *execute_command(char *command, struct sway_seat *seat,
63 * 62 *
64 * Do not use this under normal conditions. 63 * Do not use this under normal conditions.
65 */ 64 */
66struct cmd_results *config_command(char *command); 65struct cmd_results *config_command(char *command, char **new_block);
67/** 66/**
68 * Parse and handle a sub command 67 * Parse and handle a sub command
69 */ 68 */
diff --git a/sway/commands.c b/sway/commands.c
index 1d190e0b..9fae6a35 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -316,7 +316,7 @@ cleanup:
316// be chained together) 316// be chained together)
317// 4) execute_command handles all state internally while config_command has 317// 4) execute_command handles all state internally while config_command has
318// some state handled outside (notably the block mode, in read_config) 318// some state handled outside (notably the block mode, in read_config)
319struct cmd_results *config_command(char *exec) { 319struct cmd_results *config_command(char *exec, char **new_block) {
320 struct cmd_results *results = NULL; 320 struct cmd_results *results = NULL;
321 int argc; 321 int argc;
322 char **argv = split_args(exec, &argc); 322 char **argv = split_args(exec, &argc);
@@ -329,9 +329,8 @@ struct cmd_results *config_command(char *exec) {
329 329
330 // Check for the start of a block 330 // Check for the start of a block
331 if (argc > 1 && strcmp(argv[argc - 1], "{") == 0) { 331 if (argc > 1 && strcmp(argv[argc - 1], "{") == 0) {
332 char *block = join_args(argv, argc - 1); 332 *new_block = join_args(argv, argc - 1);
333 results = cmd_results_new(CMD_BLOCK, block, NULL); 333 results = cmd_results_new(CMD_BLOCK, NULL, NULL);
334 free(block);
335 goto cleanup; 334 goto cleanup;
336 } 335 }
337 336
@@ -509,11 +508,7 @@ struct cmd_results *cmd_results_new(enum cmd_status status,
509 return NULL; 508 return NULL;
510 } 509 }
511 results->status = status; 510 results->status = status;
512 if (input) { 511 // NOTE: `input` argument is unused, remove
513 results->input = strdup(input); // input is the command name
514 } else {
515 results->input = NULL;
516 }
517 if (format) { 512 if (format) {
518 char *error = malloc(256); 513 char *error = malloc(256);
519 va_list args; 514 va_list args;
@@ -530,9 +525,6 @@ struct cmd_results *cmd_results_new(enum cmd_status status,
530} 525}
531 526
532void free_cmd_results(struct cmd_results *results) { 527void free_cmd_results(struct cmd_results *results) {
533 if (results->input) {
534 free(results->input);
535 }
536 if (results->error) { 528 if (results->error) {
537 free(results->error); 529 free(results->error);
538 } 530 }
@@ -552,10 +544,6 @@ char *cmd_results_to_json(list_t *res_list) {
552 json_object_object_add( 544 json_object_object_add(
553 root, "error", json_object_new_string(results->error)); 545 root, "error", json_object_new_string(results->error));
554 } 546 }
555 if (results->input) {
556 json_object_object_add(
557 root, "input", json_object_new_string(results->input));
558 }
559 json_object_array_add(result_array, root); 547 json_object_array_add(result_array, root);
560 } 548 }
561 const char *json = json_object_to_json_string(result_array); 549 const char *json = json_object_to_json_string(result_array);
diff --git a/sway/config.c b/sway/config.c
index 18fee404..d5d36306 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -710,11 +710,12 @@ bool read_config(FILE *file, struct sway_config *config,
710 config->current_config_line_number = line_number; 710 config->current_config_line_number = line_number;
711 config->current_config_line = line; 711 config->current_config_line = line;
712 struct cmd_results *res; 712 struct cmd_results *res;
713 char *new_block = NULL;
713 if (block && strcmp(block, "<commands>") == 0) { 714 if (block && strcmp(block, "<commands>") == 0) {
714 // Special case 715 // Special case
715 res = config_commands_command(expanded); 716 res = config_commands_command(expanded);
716 } else { 717 } else {
717 res = config_command(expanded); 718 res = config_command(expanded, &new_block);
718 } 719 }
719 switch(res->status) { 720 switch(res->status) {
720 case CMD_FAILURE: 721 case CMD_FAILURE:
@@ -740,9 +741,9 @@ bool read_config(FILE *file, struct sway_config *config,
740 break; 741 break;
741 742
742 case CMD_BLOCK: 743 case CMD_BLOCK:
743 wlr_log(WLR_DEBUG, "Entering block '%s'", res->input); 744 wlr_log(WLR_DEBUG, "Entering block '%s'", new_block);
744 list_insert(stack, 0, strdup(res->input)); 745 list_insert(stack, 0, strdup(new_block));
745 if (strcmp(res->input, "bar") == 0) { 746 if (strcmp(new_block, "bar") == 0) {
746 config->current_bar = NULL; 747 config->current_bar = NULL;
747 } 748 }
748 break; 749 break;
@@ -764,6 +765,7 @@ bool read_config(FILE *file, struct sway_config *config,
764 sizeof(config->handler_context)); 765 sizeof(config->handler_context));
765 default:; 766 default:;
766 } 767 }
768 free(new_block);
767 free(expanded); 769 free(expanded);
768 free_cmd_results(res); 770 free_cmd_results(res);
769 } 771 }