diff options
Diffstat (limited to 'sway/commands/rename.c')
-rw-r--r-- | sway/commands/rename.c | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/sway/commands/rename.c b/sway/commands/rename.c index 491dbab0..a68302c4 100644 --- a/sway/commands/rename.c +++ b/sway/commands/rename.c | |||
@@ -10,7 +10,7 @@ | |||
10 | #include "sway/tree/container.h" | 10 | #include "sway/tree/container.h" |
11 | #include "sway/tree/workspace.h" | 11 | #include "sway/tree/workspace.h" |
12 | 12 | ||
13 | static const char* expected_syntax = | 13 | static const char expected_syntax[] = |
14 | "Expected 'rename workspace <old_name> to <new_name>' or " | 14 | "Expected 'rename workspace <old_name> to <new_name>' or " |
15 | "'rename workspace to <new_name>'"; | 15 | "'rename workspace to <new_name>'"; |
16 | 16 | ||
@@ -20,11 +20,11 @@ struct cmd_results *cmd_rename(int argc, char **argv) { | |||
20 | return error; | 20 | return error; |
21 | } | 21 | } |
22 | if (!root->outputs->length) { | 22 | if (!root->outputs->length) { |
23 | return cmd_results_new(CMD_INVALID, "rename", | 23 | return cmd_results_new(CMD_INVALID, |
24 | "Can't run this command while there's no outputs connected."); | 24 | "Can't run this command while there's no outputs connected."); |
25 | } | 25 | } |
26 | if (strcasecmp(argv[0], "workspace") != 0) { | 26 | if (strcasecmp(argv[0], "workspace") != 0) { |
27 | return cmd_results_new(CMD_INVALID, "rename", expected_syntax); | 27 | return cmd_results_new(CMD_INVALID, expected_syntax); |
28 | } | 28 | } |
29 | 29 | ||
30 | int argn = 1; | 30 | int argn = 1; |
@@ -36,7 +36,7 @@ struct cmd_results *cmd_rename(int argc, char **argv) { | |||
36 | } else if (strcasecmp(argv[1], "number") == 0) { | 36 | } else if (strcasecmp(argv[1], "number") == 0) { |
37 | // 'rename workspace number x to new_name' | 37 | // 'rename workspace number x to new_name' |
38 | if (!isdigit(argv[2][0])) { | 38 | if (!isdigit(argv[2][0])) { |
39 | return cmd_results_new(CMD_INVALID, "rename", | 39 | return cmd_results_new(CMD_INVALID, |
40 | "Invalid workspace number '%s'", argv[2]); | 40 | "Invalid workspace number '%s'", argv[2]); |
41 | } | 41 | } |
42 | workspace = workspace_by_number(argv[2]); | 42 | workspace = workspace_by_number(argv[2]); |
@@ -56,14 +56,14 @@ struct cmd_results *cmd_rename(int argc, char **argv) { | |||
56 | } | 56 | } |
57 | 57 | ||
58 | if (!workspace) { | 58 | if (!workspace) { |
59 | return cmd_results_new(CMD_INVALID, "rename", | 59 | return cmd_results_new(CMD_INVALID, |
60 | "There is no workspace with that name"); | 60 | "There is no workspace with that name"); |
61 | } | 61 | } |
62 | 62 | ||
63 | ++argn; // move past "to" | 63 | ++argn; // move past "to" |
64 | 64 | ||
65 | if (argn >= argc) { | 65 | if (argn >= argc) { |
66 | return cmd_results_new(CMD_INVALID, "rename", expected_syntax); | 66 | return cmd_results_new(CMD_INVALID, expected_syntax); |
67 | } | 67 | } |
68 | 68 | ||
69 | char *new_name = join_args(argv + argn, argc - argn); | 69 | char *new_name = join_args(argv + argn, argc - argn); |
@@ -75,17 +75,16 @@ struct cmd_results *cmd_rename(int argc, char **argv) { | |||
75 | strcasecmp(new_name, "current") == 0 || | 75 | strcasecmp(new_name, "current") == 0 || |
76 | strcasecmp(new_name, "number") == 0) { | 76 | strcasecmp(new_name, "number") == 0) { |
77 | free(new_name); | 77 | free(new_name); |
78 | return cmd_results_new(CMD_INVALID, "rename", | 78 | return cmd_results_new(CMD_INVALID, |
79 | "Cannot use special workspace name '%s'", argv[argn]); | 79 | "Cannot use special workspace name '%s'", argv[argn]); |
80 | } | 80 | } |
81 | struct sway_workspace *tmp_workspace = workspace_by_name(new_name); | 81 | struct sway_workspace *tmp_workspace = workspace_by_name(new_name); |
82 | if (tmp_workspace) { | 82 | if (tmp_workspace) { |
83 | free(new_name); | 83 | free(new_name); |
84 | if (tmp_workspace == workspace) { | 84 | if (tmp_workspace == workspace) { |
85 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 85 | return cmd_results_new(CMD_SUCCESS, NULL); |
86 | } else { | 86 | } else { |
87 | return cmd_results_new(CMD_INVALID, "rename", | 87 | return cmd_results_new(CMD_INVALID, "Workspace already exists"); |
88 | "Workspace already exists"); | ||
89 | } | 88 | } |
90 | } | 89 | } |
91 | 90 | ||
@@ -96,5 +95,5 @@ struct cmd_results *cmd_rename(int argc, char **argv) { | |||
96 | output_sort_workspaces(workspace->output); | 95 | output_sort_workspaces(workspace->output); |
97 | ipc_event_workspace(NULL, workspace, "rename"); | 96 | ipc_event_workspace(NULL, workspace, "rename"); |
98 | 97 | ||
99 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 98 | return cmd_results_new(CMD_SUCCESS, NULL); |
100 | } | 99 | } |