diff options
author | Drew DeVault <sir@cmpwn.com> | 2015-11-19 18:25:15 -0500 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2015-11-19 18:25:15 -0500 |
commit | 79b277fe9b3f637fa9a1bd47e73218b3cb2cd5bd (patch) | |
tree | 6be55b666541832a5a2a13fd38ecd74aacb6cf4e /sway | |
parent | Stretch image to fit output resolution (diff) | |
download | sway-79b277fe9b3f637fa9a1bd47e73218b3cb2cd5bd.tar.gz sway-79b277fe9b3f637fa9a1bd47e73218b3cb2cd5bd.tar.zst sway-79b277fe9b3f637fa9a1bd47e73218b3cb2cd5bd.zip |
Parse output background config
Diffstat (limited to 'sway')
-rw-r--r-- | sway/commands.c | 39 |
1 files changed, 37 insertions, 2 deletions
diff --git a/sway/commands.c b/sway/commands.c index 3181b434..ea50b528 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <strings.h> | 8 | #include <strings.h> |
9 | #include <unistd.h> | 9 | #include <unistd.h> |
10 | #include <ctype.h> | 10 | #include <ctype.h> |
11 | #include <wordexp.h> | ||
11 | #include <sys/types.h> | 12 | #include <sys/types.h> |
12 | #include <sys/wait.h> | 13 | #include <sys/wait.h> |
13 | #include "stringop.h" | 14 | #include "stringop.h" |
@@ -78,6 +79,11 @@ static struct modifier_key { | |||
78 | { "Mod5", WLC_BIT_MOD_MOD5 }, | 79 | { "Mod5", WLC_BIT_MOD_MOD5 }, |
79 | }; | 80 | }; |
80 | 81 | ||
82 | static char *bg_options[] = { | ||
83 | "stretch", | ||
84 | "center" | ||
85 | }; | ||
86 | |||
81 | enum expected_args { | 87 | enum expected_args { |
82 | EXPECTED_MORE_THAN, | 88 | EXPECTED_MORE_THAN, |
83 | EXPECTED_AT_LEAST, | 89 | EXPECTED_AT_LEAST, |
@@ -712,6 +718,7 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
712 | if (strcasecmp(argv[1], "disable") == 0) { | 718 | if (strcasecmp(argv[1], "disable") == 0) { |
713 | output->enabled = false; | 719 | output->enabled = false; |
714 | } | 720 | } |
721 | // TODO: Check missing params after each sub-command | ||
715 | 722 | ||
716 | int i; | 723 | int i; |
717 | for (i = 1; i < argc; ++i) { | 724 | for (i = 1; i < argc; ++i) { |
@@ -751,6 +758,33 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
751 | } | 758 | } |
752 | output->x = x; | 759 | output->x = x; |
753 | output->y = y; | 760 | output->y = y; |
761 | } else if (strcasecmp(argv[i], "bg") == 0 || strcasecmp(argv[i], "background") == 0) { | ||
762 | wordexp_t p; | ||
763 | char *src = argv[++i]; | ||
764 | char *mode = argv[++i]; | ||
765 | if (wordexp(src, &p, 0) != 0) { | ||
766 | return cmd_results_new(CMD_INVALID, "output", "Invalid syntax (%s)", src); | ||
767 | } | ||
768 | src = p.we_wordv[0]; | ||
769 | if (access(src, F_OK) == -1) { | ||
770 | return cmd_results_new(CMD_INVALID, "output", "Background file unreadable (%s)", src); | ||
771 | } | ||
772 | for (char *m = mode; *m; ++m) *m = tolower(*m); | ||
773 | // Check mode | ||
774 | bool valid = false; | ||
775 | size_t j; | ||
776 | for (j = 0; j < sizeof(bg_options) / sizeof(char *); ++j) { | ||
777 | if (strcasecmp(mode, bg_options[j]) == 0) { | ||
778 | valid = true; | ||
779 | break; | ||
780 | } | ||
781 | } | ||
782 | if (!valid) { | ||
783 | return cmd_results_new(CMD_INVALID, "output", "Invalid background scaling mode."); | ||
784 | } | ||
785 | output->background = strdup(src); | ||
786 | output->background_option = strdup(mode); | ||
787 | wordfree(&p); | ||
754 | } | 788 | } |
755 | } | 789 | } |
756 | 790 | ||
@@ -765,8 +799,9 @@ static struct cmd_results *cmd_output(int argc, char **argv) { | |||
765 | } | 799 | } |
766 | list_add(config->output_configs, output); | 800 | list_add(config->output_configs, output); |
767 | 801 | ||
768 | sway_log(L_DEBUG, "Config stored for output %s (%d x %d @ %d, %d)", | 802 | sway_log(L_DEBUG, "Config stored for output %s (%d x %d @ %d, %d) (bg %s %s)", |
769 | output->name, output->width, output->height, output->x, output->y); | 803 | output->name, output->width, output->height, output->x, output->y, |
804 | output->background, output->background_option); | ||
770 | 805 | ||
771 | if (output->name) { | 806 | if (output->name) { |
772 | // Try to find the output container and apply configuration now. If | 807 | // Try to find the output container and apply configuration now. If |