diff options
author | Drew DeVault <sir@cmpwn.com> | 2016-03-30 07:37:55 -0400 |
---|---|---|
committer | Drew DeVault <sir@cmpwn.com> | 2016-03-30 07:37:55 -0400 |
commit | 3ffff5e4f246fd444b8059820825df42e627fef1 (patch) | |
tree | 9f353bfb428694dbea01ccea42f80111ca02e25a | |
parent | Merge pull request #553 from Hummer12007/master (diff) | |
parent | Allow surrounding spaces in mode name (diff) | |
download | sway-3ffff5e4f246fd444b8059820825df42e627fef1.tar.gz sway-3ffff5e4f246fd444b8059820825df42e627fef1.tar.zst sway-3ffff5e4f246fd444b8059820825df42e627fef1.zip |
Merge pull request #555 from mikkeloscar/mode-name-spaces
Allow surrounding spaces in mode name
-rw-r--r-- | sway/commands.c | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/sway/commands.c b/sway/commands.c index 4d0da26e..d2be2f9b 100644 --- a/sway/commands.c +++ b/sway/commands.c | |||
@@ -678,16 +678,12 @@ static struct cmd_results *cmd_mode(int argc, char **argv) { | |||
678 | if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) { | 678 | if ((error = checkarg(argc, "mode", EXPECTED_AT_LEAST, 1))) { |
679 | return error; | 679 | return error; |
680 | } | 680 | } |
681 | char *mode_name = join_args(argv, argc); | 681 | |
682 | int mode_len = strlen(mode_name); | 682 | const char *mode_name = argv[0]; |
683 | bool mode_make = mode_name[mode_len-1] == '{'; | 683 | bool mode_make = (argc == 2 && strcmp(argv[1], "{") == 0); |
684 | if (mode_make) { | 684 | if (mode_make) { |
685 | if (!config->reading) | 685 | if (!config->reading) |
686 | return cmd_results_new(CMD_FAILURE, "mode", "Can only be used in config file."); | 686 | return cmd_results_new(CMD_FAILURE, "mode", "Can only be used in config file."); |
687 | // Trim trailing spaces | ||
688 | do { | ||
689 | mode_name[--mode_len] = 0; | ||
690 | } while(isspace(mode_name[mode_len-1])); | ||
691 | } | 687 | } |
692 | struct sway_mode *mode = NULL; | 688 | struct sway_mode *mode = NULL; |
693 | // Find mode | 689 | // Find mode |
@@ -708,13 +704,11 @@ static struct cmd_results *cmd_mode(int argc, char **argv) { | |||
708 | } | 704 | } |
709 | if (!mode) { | 705 | if (!mode) { |
710 | error = cmd_results_new(CMD_INVALID, "mode", "Unknown mode `%s'", mode_name); | 706 | error = cmd_results_new(CMD_INVALID, "mode", "Unknown mode `%s'", mode_name); |
711 | free(mode_name); | ||
712 | return error; | 707 | return error; |
713 | } | 708 | } |
714 | if ((config->reading && mode_make) || (!config->reading && !mode_make)) { | 709 | if ((config->reading && mode_make) || (!config->reading && !mode_make)) { |
715 | sway_log(L_DEBUG, "Switching to mode `%s'",mode->name); | 710 | sway_log(L_DEBUG, "Switching to mode `%s'",mode->name); |
716 | } | 711 | } |
717 | free(mode_name); | ||
718 | // Set current mode | 712 | // Set current mode |
719 | config->current_mode = mode; | 713 | config->current_mode = mode; |
720 | if (!mode_make) { | 714 | if (!mode_make) { |