diff options
-rw-r--r-- | include/config.h | 1 | ||||
-rw-r--r-- | sway/commands.c | 36 | ||||
-rw-r--r-- | sway/config.c | 16 |
3 files changed, 31 insertions, 22 deletions
diff --git a/include/config.h b/include/config.h index 6b48063a..21fbb8f9 100644 --- a/include/config.h +++ b/include/config.h | |||
@@ -98,6 +98,7 @@ bool read_config(FILE *file, bool is_active); | |||
98 | * Does variable replacement for a string based on the config's currently loaded variables. | 98 | * Does variable replacement for a string based on the config's currently loaded variables. |
99 | */ | 99 | */ |
100 | char *do_var_replacement(char *str); | 100 | char *do_var_replacement(char *str); |
101 | int output_name_cmp(const void *item, const void *data);; | ||
101 | /** Sets up a WLC output handle based on a given output_config. | 102 | /** Sets up a WLC output handle based on a given output_config. |
102 | */ | 103 | */ |
103 | void apply_output_config(struct output_config *oc, swayc_t *output); | 104 | void apply_output_config(struct output_config *oc, swayc_t *output); |
diff --git a/sway/commands.c b/sway/commands.c index 42845f65..e00cc94d 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -716,20 +716,23 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
716 | if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) { | 716 | if ((error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1))) { |
717 | return error; | 717 | return error; |
718 | } | 718 | } |
719 | const char *name = argv[0]; | ||
720 | |||
719 | struct output_config *output = calloc(1, sizeof(struct output_config)); | 721 | struct output_config *output = calloc(1, sizeof(struct output_config)); |
720 | output->x = output->y = output->width = output->height = -1; | 722 | output->x = output->y = output->width = output->height = -1; |
721 | output->name = strdup(argv[0]); | 723 | output->name = strdup(name); |
722 | output->enabled = true; | 724 | output->enabled = true; |
723 | 725 | ||
724 | // TODO: atoi doesn't handle invalid numbers | 726 | // TODO: atoi doesn't handle invalid numbers |
725 | if (strcasecmp(argv[1], "disable") == 0) { | ||
726 | output->enabled = false; | ||
727 | } | ||
728 | // TODO: Check missing params after each sub-command | 727 | // TODO: Check missing params after each sub-command |
729 | 728 | ||
730 | int i; | 729 | int i; |
731 | for (i = 1; i < argc; ++i) { | 730 | for (i = 1; i < argc; ++i) { |
732 | if (strcasecmp(argv[i], "resolution") == 0 || strcasecmp(argv[i], "res") == 0) { | 731 | const char *command = argv[i]; |
732 | |||
733 | if (strcasecmp(command, "disable") == 0) { | ||
734 | output->enabled = false; | ||
735 | } else if (strcasecmp(command, "resolution") == 0 || strcasecmp(command, "res") == 0) { | ||
733 | char *res = argv[++i]; | 736 | char *res = argv[++i]; |
734 | char *x = strchr(res, 'x'); | 737 | char *x = strchr(res, 'x'); |
735 | int width = -1, height = -1; | 738 | int width = -1, height = -1; |
@@ -747,7 +750,7 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
747 | } | 750 | } |
748 | output->width = width; | 751 | output->width = width; |
749 | output->height = height; | 752 | output->height = height; |
750 | } else if (strcasecmp(argv[i], "position") == 0 || strcasecmp(argv[i], "pos") == 0) { | 753 | } else if (strcasecmp(command, "position") == 0 || strcasecmp(command, "pos") == 0) { |
751 | char *res = argv[++i]; | 754 | char *res = argv[++i]; |
752 | char *c = strchr(res, ','); | 755 | char *c = strchr(res, ','); |
753 | int x = -1, y = -1; | 756 | int x = -1, y = -1; |
@@ -765,7 +768,7 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
765 | } | 768 | } |
766 | output->x = x; | 769 | output->x = x; |
767 | output->y = y; | 770 | output->y = y; |
768 | } else if (strcasecmp(argv[i], "bg") == 0 || strcasecmp(argv[i], "background") == 0) { | 771 | } else if (strcasecmp(command, "background") == 0 || strcasecmp(command, "bg") == 0) { |
769 | wordexp_t p; | 772 | wordexp_t p; |
770 | if (++i >= argc) { | 773 | if (++i >= argc) { |
771 | return cmd_results_new(CMD_INVALID, "output", "Missing background file."); | 774 | return cmd_results_new(CMD_INVALID, "output", "Missing background file."); |
@@ -801,20 +804,19 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
801 | } | 804 | } |
802 | } | 805 | } |
803 | 806 | ||
804 | for (i = 0; i < config->output_configs->length; ++i) { | 807 | i = list_seq_find(config->output_configs, output_name_cmp, name); |
808 | if (i >= 0) { | ||
809 | // replace existing config | ||
805 | struct output_config *oc = config->output_configs->items[i]; | 810 | struct output_config *oc = config->output_configs->items[i]; |
806 | if (strcmp(oc->name, output->name) == 0) { | 811 | list_del(config->output_configs, i); |
807 | // replace existing config | 812 | free_output_config(oc); |
808 | list_del(config->output_configs, i); | ||
809 | free_output_config(oc); | ||
810 | break; | ||
811 | } | ||
812 | } | 813 | } |
813 | list_add(config->output_configs, output); | 814 | list_add(config->output_configs, output); |
814 | 815 | ||
815 | sway_log(L_DEBUG, "Config stored for output %s (%d x %d @ %d, %d) (bg %s %s)", | 816 | sway_log(L_DEBUG, "Config stored for output %s (%s) (%d x %d @ %d, %d) (bg %s %s)", |
816 | output->name, output->width, output->height, output->x, output->y, | 817 | output->name, output->enabled ? "enable" : "disable", output->width, |
817 | output->background, output->background_option); | 818 | output->height, output->x, output->y, output->background, |
819 | output->background_option); | ||
818 | 820 | ||
819 | if (output->name) { | 821 | if (output->name) { |
820 | // Try to find the output container and apply configuration now. If | 822 | // Try to find the output container and apply configuration now. If |
diff --git a/sway/config.c b/sway/config.c index e9785aba..dd466e5b 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -261,6 +261,14 @@ bool read_config(FILE *file, bool is_active) { | |||
261 | return success; | 261 | return success; |
262 | } | 262 | } |
263 | 263 | ||
264 | int output_name_cmp(const void *item, const void *data) | ||
265 | { | ||
266 | const struct output_config *output = item; | ||
267 | const char *name = data; | ||
268 | |||
269 | return strcmp(output->name, name); | ||
270 | } | ||
271 | |||
264 | void apply_output_config(struct output_config *oc, swayc_t *output) { | 272 | void apply_output_config(struct output_config *oc, swayc_t *output) { |
265 | if (oc && oc->width > 0 && oc->height > 0) { | 273 | if (oc && oc->width > 0 && oc->height > 0) { |
266 | output->width = oc->width; | 274 | output->width = oc->width; |
@@ -291,12 +299,10 @@ void apply_output_config(struct output_config *oc, swayc_t *output) { | |||
291 | 299 | ||
292 | if (!oc || !oc->background) { | 300 | if (!oc || !oc->background) { |
293 | // Look for a * config for background | 301 | // Look for a * config for background |
294 | int i; | 302 | int i = list_seq_find(config->output_configs, output_name_cmp, "*"); |
295 | for (i = 0; i < config->output_configs->length; ++i) { | 303 | if (i >= 0) { |
296 | oc = config->output_configs->items[i]; | 304 | oc = config->output_configs->items[i]; |
297 | if (strcasecmp("*", oc->name) == 0) { | 305 | } else { |
298 | break; | ||
299 | } | ||
300 | oc = NULL; | 306 | oc = NULL; |
301 | } | 307 | } |
302 | } | 308 | } |