aboutsummaryrefslogtreecommitdiff
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) {
return error;
}
- ++argv;
- int target_len = argc - 1;
+ --argc; ++argv;
if (strncmp(*argv, "→", strlen("→")) == 0) {
- if (argc < 3) {
+ if (argc < 2) {
free(criteria);
return cmd_results_new(CMD_INVALID, "assign", "Missing workspace");
}
+ --argc;
++argv;
- --target_len;
}
if (strcmp(*argv, "output") == 0) {
criteria->type = CT_ASSIGN_OUTPUT;
- ++argv;
- --target_len;
+ --argc; ++argv;
} else {
- criteria->type = CT_ASSIGN_WORKSPACE;
+ if (strcmp(*argv, "workspace") == 0) {
+ --argc; ++argv;
+ }
+ if (strcmp(*argv, "number") == 0) {
+ --argc; ++argv;
+ if (argv[0][0] < '0' || argv[0][0] > '9') {
+ free(criteria);
+ return cmd_results_new(CMD_INVALID, "assign",
+ "Invalid workspace number '%s'", argv[0]);
+ }
+ criteria->type = CT_ASSIGN_WORKSPACE_NUMBER;
+ } else {
+ criteria->type = CT_ASSIGN_WORKSPACE;
+ }
}
- criteria->target = join_args(argv, target_len);
+ criteria->target = join_args(argv, argc);
list_add(config->criteria, criteria);
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) {
return error;
}
- tmp = join_args(argv + 1, argc - 1);
+ --argc; ++argv;
+ }
+
+ if (argv[0][0] == '\'' || argv[0][0] == '"') {
+ if (argc > 0) {
+ return cmd_results_new(CMD_INVALID, "exec_always",
+ "command cannot be partially quoted");
+ }
+ tmp = strdup(argv[0]);
+ strip_quotes(tmp);
} else {
tmp = join_args(argv, argc);
}
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,
}
if (new_focus) {
seat_set_focus(seat, new_focus);
+ } else {
+ return cmd_results_new(CMD_FAILURE, "focus",
+ "Failed to find a %s container in workspace",
+ floating ? "floating" : "tiling");
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
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 @@
#define _XOPEN_SOURCE 500
+#include <ctype.h>
#include <stdbool.h>
#include <string.h>
#include <strings.h>
@@ -22,7 +23,7 @@
static const char *expected_syntax =
"Expected 'move <left|right|up|down> <[px] px>' or "
"'move [--no-auto-back-and-forth] <container|window> [to] workspace <name>' or "
- "'move [--no-auto-back-and-forth] <container|window|workspace> [to] output <name|direction>' or "
+ "'move <container|window|workspace> [to] output <name|direction>' or "
"'move <container|window> [to] mark <mark>'";
static struct sway_container *output_in_direction(const char *direction,
@@ -124,7 +125,11 @@ static struct cmd_results *cmd_move_container(struct sway_container *current,
return cmd_results_new(CMD_INVALID, "move",
expected_syntax);
}
- ws_name = strdup(argv[3]);
+ if (!isdigit(argv[3][0])) {
+ return cmd_results_new(CMD_INVALID, "move",
+ "Invalid workspace number '%s'", argv[3]);
+ }
+ ws_name = join_args(argv + 3, argc - 3);
ws = workspace_by_number(ws_name);
} else {
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 @@
+#include "sway/commands.h"
+
+struct cmd_results *cmd_nop(int argc, char **argv) {
+ return cmd_results_new(CMD_SUCCESS, NULL, NULL);
+}
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 @@
#define _XOPEN_SOURCE 500
+#include <ctype.h>
#include <string.h>
#include <strings.h>
#include "log.h"
@@ -34,6 +35,10 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
}
} else if (strcasecmp(argv[1], "number") == 0) {
// 'rename workspace number x to new_name'
+ if (!isdigit(argv[2][0])) {
+ return cmd_results_new(CMD_INVALID, "rename",
+ "Invalid workspace number '%s'", argv[2]);
+ }
workspace = workspace_by_number(argv[2]);
while (argn < argc && strcasecmp(argv[argn], "to") != 0) {
++argn;
@@ -67,7 +72,8 @@ struct cmd_results *cmd_rename(int argc, char **argv) {
strcasecmp(new_name, "next_on_output") == 0 ||
strcasecmp(new_name, "prev_on_output") == 0 ||
strcasecmp(new_name, "back_and_forth") == 0 ||
- strcasecmp(new_name, "current") == 0) {
+ strcasecmp(new_name, "current") == 0 ||
+ strcasecmp(new_name, "number") == 0) {
free(new_name);
return cmd_results_new(CMD_INVALID, "rename",
"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) {
}
struct cmd_results *cmd_set(int argc, char **argv) {
- char *tmp;
struct cmd_results *error = NULL;
if ((error = checkarg(argc, "set", EXPECTED_AT_LEAST, 2))) {
return error;
}
if (argv[0][0] != '$') {
- wlr_log(WLR_INFO, "Warning: variable '%s' doesn't start with $", argv[0]);
-
- size_t size = snprintf(NULL, 0, "$%s", argv[0]);
- tmp = malloc(size + 1);
- if (!tmp) {
- return cmd_results_new(CMD_FAILURE, "set", "Not possible to create variable $'%s'", argv[0]);
- }
- snprintf(tmp, size+1, "$%s", argv[0]);
-
- argv[0] = tmp;
+ return cmd_results_new(CMD_INVALID, "set", "variable '%s' must start with $", argv[0]);
}
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) {
container->is_sticky = wants_sticky;
+ if (wants_sticky) {
+ // move container to focused workspace
+ struct sway_container *output = container_parent(container, C_OUTPUT);
+ struct sway_seat *seat = input_manager_current_seat(input_manager);
+ struct sway_container *focus = seat_get_focus_inactive(seat, output);
+ struct sway_container *focused_workspace = container_parent(focus, C_WORKSPACE);
+ struct sway_container *current_workspace = container_parent(container, C_WORKSPACE);
+ if (current_workspace != focused_workspace) {
+ container_move_to(container, focused_workspace);
+ arrange_windows(focused_workspace);
+ if (!container_reap_empty(current_workspace)) {
+ arrange_windows(current_workspace);
+ }
+ }
+ }
+
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
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 @@
#define _XOPEN_SOURCE 500
+#include <ctype.h>
#include <string.h>
#include <strings.h>
#include "sway/commands.h"
@@ -60,9 +61,13 @@ struct cmd_results *cmd_workspace(int argc, char **argv) {
struct sway_container *ws = NULL;
if (strcasecmp(argv[0], "number") == 0) {
if (argc < 2) {
- cmd_results_new(CMD_INVALID, "workspace",
+ return cmd_results_new(CMD_INVALID, "workspace",
"Expected workspace number");
}
+ if (!isdigit(argv[1][0])) {
+ return cmd_results_new(CMD_INVALID, "workspace",
+ "Invalid workspace number '%s'", argv[1]);
+ }
if (!(ws = workspace_by_number(argv[1]))) {
char *name = join_args(argv + 1, argc - 1);
ws = workspace_create(NULL, name);