aboutsummaryrefslogtreecommitdiffstats
path: root/sway/commands
diff options
context:
space:
mode:
Diffstat (limited to 'sway/commands')
-rw-r--r--sway/commands/assign.c27
-rw-r--r--sway/commands/exec_always.c11
-rw-r--r--sway/commands/focus.c4
-rw-r--r--sway/commands/move.c9
-rw-r--r--sway/commands/nop.c5
-rw-r--r--sway/commands/rename.c8
-rw-r--r--sway/commands/set.c12
-rw-r--r--sway/commands/sticky.c16
-rw-r--r--sway/commands/workspace.c7
9 files changed, 75 insertions, 24 deletions
diff --git a/sway/commands/assign.c b/sway/commands/assign.c
index 0bc0929a..04582e88 100644
--- a/sway/commands/assign.c
+++ b/sway/commands/assign.c
@@ -22,27 +22,38 @@ struct cmd_results *cmd_assign(int argc, char **argv) {
22 return error; 22 return error;
23 } 23 }
24 24
25 ++argv; 25 --argc; ++argv;
26 int target_len = argc - 1;
27 26
28 if (strncmp(*argv, "→", strlen("→")) == 0) { 27 if (strncmp(*argv, "→", strlen("→")) == 0) {
29 if (argc < 3) { 28 if (argc < 2) {
30 free(criteria); 29 free(criteria);
31 return cmd_results_new(CMD_INVALID, "assign", "Missing workspace"); 30 return cmd_results_new(CMD_INVALID, "assign", "Missing workspace");
32 } 31 }
32 --argc;
33 ++argv; 33 ++argv;
34 --target_len;
35 } 34 }
36 35
37 if (strcmp(*argv, "output") == 0) { 36 if (strcmp(*argv, "output") == 0) {
38 criteria->type = CT_ASSIGN_OUTPUT; 37 criteria->type = CT_ASSIGN_OUTPUT;
39 ++argv; 38 --argc; ++argv;
40 --target_len;
41 } else { 39 } else {
42 criteria->type = CT_ASSIGN_WORKSPACE; 40 if (strcmp(*argv, "workspace") == 0) {
41 --argc; ++argv;
42 }
43 if (strcmp(*argv, "number") == 0) {
44 --argc; ++argv;
45 if (argv[0][0] < '0' || argv[0][0] > '9') {
46 free(criteria);
47 return cmd_results_new(CMD_INVALID, "assign",
48 "Invalid workspace number '%s'", argv[0]);
49 }
50 criteria->type = CT_ASSIGN_WORKSPACE_NUMBER;
51 } else {
52 criteria->type = CT_ASSIGN_WORKSPACE;
53 }
43 } 54 }
44 55
45 criteria->target = join_args(argv, target_len); 56 criteria->target = join_args(argv, argc);
46 57
47 list_add(config->criteria, criteria); 58 list_add(config->criteria, criteria);
48 wlr_log(WLR_DEBUG, "assign: '%s' -> '%s' added", criteria->raw, 59 wlr_log(WLR_DEBUG, "assign: '%s' -> '%s' added", criteria->raw,
diff --git a/sway/commands/exec_always.c b/sway/commands/exec_always.c
index 00e39ae7..5ce7919b 100644
--- a/sway/commands/exec_always.c
+++ b/sway/commands/exec_always.c
@@ -26,7 +26,16 @@ struct cmd_results *cmd_exec_always(int argc, char **argv) {
26 return error; 26 return error;
27 } 27 }
28 28
29 tmp = join_args(argv + 1, argc - 1); 29 --argc; ++argv;
30 }
31
32 if (argv[0][0] == '\'' || argv[0][0] == '"') {
33 if (argc > 0) {
34 return cmd_results_new(CMD_INVALID, "exec_always",
35 "command cannot be partially quoted");
36 }
37 tmp = strdup(argv[0]);
38 strip_quotes(tmp);
30 } else { 39 } else {
31 tmp = join_args(argv, argc); 40 tmp = join_args(argv, argc);
32 } 41 }
diff --git a/sway/commands/focus.c b/sway/commands/focus.c
index 135a2908..fe15b4c7 100644
--- a/sway/commands/focus.c
+++ b/sway/commands/focus.c
@@ -52,6 +52,10 @@ static struct cmd_results *focus_mode(struct sway_container *con,
52 } 52 }
53 if (new_focus) { 53 if (new_focus) {
54 seat_set_focus(seat, new_focus); 54 seat_set_focus(seat, new_focus);
55 } else {
56 return cmd_results_new(CMD_FAILURE, "focus",
57 "Failed to find a %s container in workspace",
58 floating ? "floating" : "tiling");
55 } 59 }
56 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 60 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
57} 61}
diff --git a/sway/commands/move.c b/sway/commands/move.c
index acdc50b5..33d1ee4a 100644
--- a/sway/commands/move.c
+++ b/sway/commands/move.c
@@ -1,4 +1,5 @@
1#define _XOPEN_SOURCE 500 1#define _XOPEN_SOURCE 500
2#include <ctype.h>
2#include <stdbool.h> 3#include <stdbool.h>
3#include <string.h> 4#include <string.h>
4#include <strings.h> 5#include <strings.h>
@@ -22,7 +23,7 @@
22static const char *expected_syntax = 23static const char *expected_syntax =
23 "Expected 'move <left|right|up|down> <[px] px>' or " 24 "Expected 'move <left|right|up|down> <[px] px>' or "
24 "'move [--no-auto-back-and-forth] <container|window> [to] workspace <name>' or " 25 "'move [--no-auto-back-and-forth] <container|window> [to] workspace <name>' or "
25 "'move [--no-auto-back-and-forth] <container|window|workspace> [to] output <name|direction>' or " 26 "'move <container|window|workspace> [to] output <name|direction>' or "
26 "'move <container|window> [to] mark <mark>'"; 27 "'move <container|window> [to] mark <mark>'";
27 28
28static struct sway_container *output_in_direction(const char *direction, 29static struct sway_container *output_in_direction(const char *direction,
@@ -124,7 +125,11 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
124 return cmd_results_new(CMD_INVALID, "move", 125 return cmd_results_new(CMD_INVALID, "move",
125 expected_syntax); 126 expected_syntax);
126 } 127 }
127 ws_name = strdup(argv[3]); 128 if (!isdigit(argv[3][0])) {
129 return cmd_results_new(CMD_INVALID, "move",
130 "Invalid workspace number '%s'", argv[3]);
131 }
132 ws_name = join_args(argv + 3, argc - 3);
128 ws = workspace_by_number(ws_name); 133 ws = workspace_by_number(ws_name);
129 } else { 134 } else {
130 ws_name = join_args(argv + 2, argc - 2); 135 ws_name = join_args(argv + 2, argc - 2);
diff --git a/sway/commands/nop.c b/sway/commands/nop.c
new file mode 100644
index 00000000..c12fe15a
--- /dev/null
+++ b/sway/commands/nop.c
@@ -0,0 +1,5 @@
1#include "sway/commands.h"
2
3struct cmd_results *cmd_nop(int argc, char **argv) {
4 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
5}
diff --git a/sway/commands/rename.c b/sway/commands/rename.c
index c69bbdac..21d2aa64 100644
--- a/sway/commands/rename.c
+++ b/sway/commands/rename.c
@@ -1,4 +1,5 @@
1#define _XOPEN_SOURCE 500 1#define _XOPEN_SOURCE 500
2#include <ctype.h>
2#include <string.h> 3#include <string.h>
3#include <strings.h> 4#include <strings.h>
4#include "log.h" 5#include "log.h"
@@ -34,6 +35,10 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
34 } 35 }
35 } else if (strcasecmp(argv[1], "number") == 0) { 36 } else if (strcasecmp(argv[1], "number") == 0) {
36 // 'rename workspace number x to new_name' 37 // 'rename workspace number x to new_name'
38 if (!isdigit(argv[2][0])) {
39 return cmd_results_new(CMD_INVALID, "rename",
40 "Invalid workspace number '%s'", argv[2]);
41 }
37 workspace = workspace_by_number(argv[2]); 42 workspace = workspace_by_number(argv[2]);
38 while (argn < argc && strcasecmp(argv[argn], "to") != 0) { 43 while (argn < argc && strcasecmp(argv[argn], "to") != 0) {
39 ++argn; 44 ++argn;
@@ -67,7 +72,8 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
67 strcasecmp(new_name, "next_on_output") == 0 || 72 strcasecmp(new_name, "next_on_output") == 0 ||
68 strcasecmp(new_name, "prev_on_output") == 0 || 73 strcasecmp(new_name, "prev_on_output") == 0 ||
69 strcasecmp(new_name, "back_and_forth") == 0 || 74 strcasecmp(new_name, "back_and_forth") == 0 ||
70 strcasecmp(new_name, "current") == 0) { 75 strcasecmp(new_name, "current") == 0 ||
76 strcasecmp(new_name, "number") == 0) {
71 free(new_name); 77 free(new_name);
72 return cmd_results_new(CMD_INVALID, "rename", 78 return cmd_results_new(CMD_INVALID, "rename",
73 "Cannot use special workspace name '%s'", argv[argn]); 79 "Cannot use special workspace name '%s'", argv[argn]);
diff --git a/sway/commands/set.c b/sway/commands/set.c
index ea388d3b..be51230b 100644
--- a/sway/commands/set.c
+++ b/sway/commands/set.c
@@ -25,23 +25,13 @@ void free_sway_variable(struct sway_variable *var) {
25} 25}
26 26
27struct cmd_results *cmd_set(int argc, char **argv) { 27struct cmd_results *cmd_set(int argc, char **argv) {
28 char *tmp;
29 struct cmd_results *error = NULL; 28 struct cmd_results *error = NULL;
30 if ((error = checkarg(argc, "set", EXPECTED_AT_LEAST, 2))) { 29 if ((error = checkarg(argc, "set", EXPECTED_AT_LEAST, 2))) {
31 return error; 30 return error;
32 } 31 }
33 32
34 if (argv[0][0] != '$') { 33 if (argv[0][0] != '$') {
35 wlr_log(WLR_INFO, "Warning: variable '%s' doesn't start with $", argv[0]); 34 return cmd_results_new(CMD_INVALID, "set", "variable '%s' must start with $", argv[0]);
36
37 size_t size = snprintf(NULL, 0, "$%s", argv[0]);
38 tmp = malloc(size + 1);
39 if (!tmp) {
40 return cmd_results_new(CMD_FAILURE, "set", "Not possible to create variable $'%s'", argv[0]);
41 }
42 snprintf(tmp, size+1, "$%s", argv[0]);
43
44 argv[0] = tmp;
45 } 35 }
46 36
47 struct sway_variable *var = NULL; 37 struct sway_variable *var = NULL;
diff --git a/sway/commands/sticky.c b/sway/commands/sticky.c
index 732ccb98..a0dd7215 100644
--- a/sway/commands/sticky.c
+++ b/sway/commands/sticky.c
@@ -36,5 +36,21 @@ struct cmd_results *cmd_sticky(int argc, char **argv) {
36 36
37 container->is_sticky = wants_sticky; 37 container->is_sticky = wants_sticky;
38 38
39 if (wants_sticky) {
40 // move container to focused workspace
41 struct sway_container *output = container_parent(container, C_OUTPUT);
42 struct sway_seat *seat = input_manager_current_seat(input_manager);
43 struct sway_container *focus = seat_get_focus_inactive(seat, output);
44 struct sway_container *focused_workspace = container_parent(focus, C_WORKSPACE);
45 struct sway_container *current_workspace = container_parent(container, C_WORKSPACE);
46 if (current_workspace != focused_workspace) {
47 container_move_to(container, focused_workspace);
48 arrange_windows(focused_workspace);
49 if (!container_reap_empty(current_workspace)) {
50 arrange_windows(current_workspace);
51 }
52 }
53 }
54
39 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 55 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
40} 56}
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index f5558bb4..ceb4cd6e 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -1,4 +1,5 @@
1#define _XOPEN_SOURCE 500 1#define _XOPEN_SOURCE 500
2#include <ctype.h>
2#include <string.h> 3#include <string.h>
3#include <strings.h> 4#include <strings.h>
4#include "sway/commands.h" 5#include "sway/commands.h"
@@ -60,9 +61,13 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
60 struct sway_container *ws = NULL; 61 struct sway_container *ws = NULL;
61 if (strcasecmp(argv[0], "number") == 0) { 62 if (strcasecmp(argv[0], "number") == 0) {
62 if (argc < 2) { 63 if (argc < 2) {
63 cmd_results_new(CMD_INVALID, "workspace", 64 return cmd_results_new(CMD_INVALID, "workspace",
64 "Expected workspace number"); 65 "Expected workspace number");
65 } 66 }
67 if (!isdigit(argv[1][0])) {
68 return cmd_results_new(CMD_INVALID, "workspace",
69 "Invalid workspace number '%s'", argv[1]);
70 }
66 if (!(ws = workspace_by_number(argv[1]))) { 71 if (!(ws = workspace_by_number(argv[1]))) {
67 char *name = join_args(argv + 1, argc - 1); 72 char *name = join_args(argv + 1, argc - 1);
68 ws = workspace_create(NULL, name); 73 ws = workspace_create(NULL, name);