diff options
author | 2016-03-30 12:58:47 +0200 | |
---|---|---|
committer | 2016-03-30 12:58:50 +0200 | |
commit | 948c59413251a2bd15a3d47634cb175cf1300593 (patch) | |
tree | 9f353bfb428694dbea01ccea42f80111ca02e25a /sway | |
parent | Merge pull request #553 from Hummer12007/master (diff) | |
download | sway-948c59413251a2bd15a3d47634cb175cf1300593.tar.gz sway-948c59413251a2bd15a3d47634cb175cf1300593.tar.zst sway-948c59413251a2bd15a3d47634cb175cf1300593.zip |
Allow surrounding spaces in mode name
This makes it possible to define a mode name with surrounding spaces if
so desired. e.g.:
mode " hello " { }
Diffstat (limited to 'sway')
-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) { |