aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/sway/commands.h1
-rw-r--r--include/sway/criteria.h9
-rw-r--r--sway/commands.c1
-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
-rw-r--r--sway/meson.build1
-rw-r--r--sway/sway.5.scd19
-rw-r--r--sway/tree/view.c23
-rw-r--r--sway/tree/workspace.c25
16 files changed, 121 insertions, 57 deletions
diff --git a/include/sway/commands.h b/include/sway/commands.h
index 545b21e6..8e91c158 100644
--- a/include/sway/commands.h
+++ b/include/sway/commands.h
@@ -136,6 +136,7 @@ sway_cmd cmd_mark;
136sway_cmd cmd_mode; 136sway_cmd cmd_mode;
137sway_cmd cmd_mouse_warping; 137sway_cmd cmd_mouse_warping;
138sway_cmd cmd_move; 138sway_cmd cmd_move;
139sway_cmd cmd_nop;
139sway_cmd cmd_opacity; 140sway_cmd cmd_opacity;
140sway_cmd cmd_new_float; 141sway_cmd cmd_new_float;
141sway_cmd cmd_new_window; 142sway_cmd cmd_new_window;
diff --git a/include/sway/criteria.h b/include/sway/criteria.h
index b4ff7d49..7a1e547b 100644
--- a/include/sway/criteria.h
+++ b/include/sway/criteria.h
@@ -7,10 +7,11 @@
7#include "tree/view.h" 7#include "tree/view.h"
8 8
9enum criteria_type { 9enum criteria_type {
10 CT_COMMAND = 1 << 0, 10 CT_COMMAND = 1 << 0,
11 CT_ASSIGN_OUTPUT = 1 << 1, 11 CT_ASSIGN_OUTPUT = 1 << 1,
12 CT_ASSIGN_WORKSPACE = 1 << 2, 12 CT_ASSIGN_WORKSPACE = 1 << 2,
13 CT_NO_FOCUS = 1 << 3, 13 CT_ASSIGN_WORKSPACE_NUMBER = 1 << 3,
14 CT_NO_FOCUS = 1 << 4,
14}; 15};
15 16
16struct criteria { 17struct criteria {
diff --git a/sway/commands.c b/sway/commands.c
index 364c26da..d9c54adc 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -146,6 +146,7 @@ static struct cmd_handler command_handlers[] = {
146 { "layout", cmd_layout }, 146 { "layout", cmd_layout },
147 { "mark", cmd_mark }, 147 { "mark", cmd_mark },
148 { "move", cmd_move }, 148 { "move", cmd_move },
149 { "nop", cmd_nop },
149 { "opacity", cmd_opacity }, 150 { "opacity", cmd_opacity },
150 { "reload", cmd_reload }, 151 { "reload", cmd_reload },
151 { "rename", cmd_rename }, 152 { "rename", cmd_rename },
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);
diff --git a/sway/meson.build b/sway/meson.build
index 2a457270..676422d0 100644
--- a/sway/meson.build
+++ b/sway/meson.build
@@ -64,6 +64,7 @@ sway_sources = files(
64 'commands/mouse_warping.c', 64 'commands/mouse_warping.c',
65 'commands/move.c', 65 'commands/move.c',
66 'commands/no_focus.c', 66 'commands/no_focus.c',
67 'commands/nop.c',
67 'commands/output.c', 68 'commands/output.c',
68 'commands/reload.c', 69 'commands/reload.c',
69 'commands/rename.c', 70 'commands/rename.c',
diff --git a/sway/sway.5.scd b/sway/sway.5.scd
index 70b74a45..83188067 100644
--- a/sway/sway.5.scd
+++ b/sway/sway.5.scd
@@ -51,7 +51,7 @@ The following commands may only be used in the configuration file.
51 *wordexp*(3) for details). The same include file can only be included once; 51 *wordexp*(3) for details). The same include file can only be included once;
52 subsequent attempts will be ignored. 52 subsequent attempts will be ignored.
53 53
54*set* <name> <value> 54*set* $<name> <value>
55 Sets variable $_name_ to _value_. You can use the new variable in the 55 Sets variable $_name_ to _value_. You can use the new variable in the
56 arguments of future commands. 56 arguments of future commands.
57 57
@@ -132,7 +132,7 @@ They are expected to be used with *bindsym* or at runtime through *swaymsg*(1).
132 If unspecified, the default is 10 pixels. Pixels are ignored when moving 132 If unspecified, the default is 10 pixels. Pixels are ignored when moving
133 tiled containers. 133 tiled containers.
134 134
135*move* [absolute] position <pos_x> [px] <pos_y> [px] 135*move* [absolute] position <pos\_x> [px] <pos\_y> [px]
136 Moves the focused container to the specified position. 136 Moves the focused container to the specified position.
137 137
138*move* [absolute] position center|mouse 138*move* [absolute] position center|mouse
@@ -154,7 +154,7 @@ They are expected to be used with *bindsym* or at runtime through *swaymsg*(1).
154 Moves the focused container to the previous or next workspace on this 154 Moves the focused container to the previous or next workspace on this
155 output, wrapping around if already at the first or last workspace. 155 output, wrapping around if already at the first or last workspace.
156 156
157*move* container|window [to] workspace back_and_forth 157*move* container|window [to] workspace back\_and\_forth
158 Moves the focused container to previously focused workspace. 158 Moves the focused container to previously focused workspace.
159 159
160*move* container|window|workspace [to] output <name> 160*move* container|window|workspace [to] output <name>
@@ -167,6 +167,10 @@ They are expected to be used with *bindsym* or at runtime through *swaymsg*(1).
167*move* [to] scratchpad 167*move* [to] scratchpad
168 Moves the focused window to the scratchpad. 168 Moves the focused window to the scratchpad.
169 169
170*nop* <comment>
171 A no operation command that can be used to override default behaviour. The
172 optional comment argument is ignored, but logged for debugging purposes.
173
170*reload* 174*reload*
171 Reloads the sway config file and applies any changes. 175 Reloads the sway config file and applies any changes.
172 176
@@ -215,13 +219,20 @@ They are expected to be used with *bindsym* or at runtime through *swaymsg*(1).
215The following commands may be used either in the configuration file or at 219The following commands may be used either in the configuration file or at
216runtime. 220runtime.
217 221
218*assign* <criteria> [→] <workspace> 222*assign* <criteria> [→] [workspace] [number] <workspace>
219 Assigns views matching _criteria_ (see *CRITERIA* for details) to 223 Assigns views matching _criteria_ (see *CRITERIA* for details) to
220 _workspace_. The → (U+2192) is optional and cosmetic. This command is 224 _workspace_. The → (U+2192) is optional and cosmetic. This command is
221 equivalent to: 225 equivalent to:
222 226
223 for\_window <criteria> move container to workspace <workspace> 227 for\_window <criteria> move container to workspace <workspace>
224 228
229*assign* <criteria> [→] output left|right|up|down|<name>
230 Assigns views matching _criteria_ (see *CRITERIA* for details) to the
231 specified output. The → (U+2192) is optional and cosmetic. This command is
232 equivalent to:
233
234 for\_window <criteria> move container to output <output>
235
225*bindsym* [--release|--locked] <key combo> <command> 236*bindsym* [--release|--locked] <key combo> <command>
226 Binds _key combo_ to execute the sway command _command_ when pressed. You 237 Binds _key combo_ to execute the sway command _command_ when pressed. You
227 may use XKB key names here (*xev*(1) is a good tool for discovering these). 238 may use XKB key names here (*xev*(1) is a good tool for discovering these).
diff --git a/sway/tree/view.c b/sway/tree/view.c
index 1c1fdb47..7a2c1950 100644
--- a/sway/tree/view.c
+++ b/sway/tree/view.c
@@ -450,12 +450,22 @@ static struct sway_container *select_workspace(struct sway_view *view) {
450 450
451 // Check if there's any `assign` criteria for the view 451 // Check if there's any `assign` criteria for the view
452 list_t *criterias = criteria_for_view(view, 452 list_t *criterias = criteria_for_view(view,
453 CT_ASSIGN_WORKSPACE | CT_ASSIGN_OUTPUT); 453 CT_ASSIGN_WORKSPACE | CT_ASSIGN_WORKSPACE_NUMBER | CT_ASSIGN_OUTPUT);
454 struct sway_container *ws = NULL; 454 struct sway_container *ws = NULL;
455 for (int i = 0; i < criterias->length; ++i) { 455 for (int i = 0; i < criterias->length; ++i) {
456 struct criteria *criteria = criterias->items[i]; 456 struct criteria *criteria = criterias->items[i];
457 if (criteria->type == CT_ASSIGN_WORKSPACE) { 457 if (criteria->type == CT_ASSIGN_OUTPUT) {
458 ws = workspace_by_name(criteria->target); 458 struct sway_container *output = output_by_name(criteria->target);
459 if (output) {
460 ws = seat_get_active_child(seat, output);
461 break;
462 }
463 } else {
464 // CT_ASSIGN_WORKSPACE(_NUMBER)
465 ws = criteria->type == CT_ASSIGN_WORKSPACE_NUMBER ?
466 workspace_by_number(criteria->target) :
467 workspace_by_name(criteria->target);
468
459 if (!ws) { 469 if (!ws) {
460 if (strcasecmp(criteria->target, "back_and_forth") == 0) { 470 if (strcasecmp(criteria->target, "back_and_forth") == 0) {
461 if (prev_workspace_name) { 471 if (prev_workspace_name) {
@@ -466,13 +476,6 @@ static struct sway_container *select_workspace(struct sway_view *view) {
466 } 476 }
467 } 477 }
468 break; 478 break;
469 } else {
470 // CT_ASSIGN_OUTPUT
471 struct sway_container *output = output_by_name(criteria->target);
472 if (output) {
473 ws = seat_get_active_child(seat, output);
474 break;
475 }
476 } 479 }
477 } 480 }
478 list_free(criterias); 481 list_free(criterias);
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index b7090de6..a6d1870c 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -82,11 +82,6 @@ struct sway_container *workspace_create(struct sway_container *output,
82} 82}
83 83
84char *prev_workspace_name = NULL; 84char *prev_workspace_name = NULL;
85struct workspace_by_number_data {
86 int len;
87 const char *cset;
88 const char *name;
89};
90 85
91void next_name_map(struct sway_container *ws, void *data) { 86void next_name_map(struct sway_container *ws, void *data) {
92 int *count = data; 87 int *count = data;
@@ -154,7 +149,7 @@ static void workspace_name_from_binding(const struct sway_binding * binding,
154 wlr_log(WLR_DEBUG, "Isolated name from workspace number: '%s'", _target); 149 wlr_log(WLR_DEBUG, "Isolated name from workspace number: '%s'", _target);
155 150
156 // Make sure the workspace number doesn't already exist 151 // Make sure the workspace number doesn't already exist
157 if (workspace_by_number(_target)) { 152 if (isdigit(_target[0]) && workspace_by_number(_target)) {
158 free(_target); 153 free(_target);
159 free(dup); 154 free(dup);
160 return; 155 return;
@@ -233,18 +228,18 @@ static bool _workspace_by_number(struct sway_container *view, void *data) {
233 if (view->type != C_WORKSPACE) { 228 if (view->type != C_WORKSPACE) {
234 return false; 229 return false;
235 } 230 }
236 struct workspace_by_number_data *wbnd = data; 231 char *name = data;
237 int a = strspn(view->name, wbnd->cset); 232 char *view_name = view->name;
238 return a == wbnd->len && strncmp(view->name, wbnd->name, a) == 0; 233 while (isdigit(*name)) {
234 if (*name++ != *view_name++) {
235 return false;
236 }
237 }
238 return !isdigit(*view_name);
239} 239}
240 240
241struct sway_container *workspace_by_number(const char* name) { 241struct sway_container *workspace_by_number(const char* name) {
242 struct workspace_by_number_data wbnd = {0, "1234567890", name}; 242 return root_find_workspace(_workspace_by_number, (void *) name);
243 wbnd.len = strspn(name, wbnd.cset);
244 if (wbnd.len <= 0) {
245 return NULL;
246 }
247 return root_find_workspace(_workspace_by_number, (void *) &wbnd);
248} 243}
249 244
250static bool _workspace_by_name(struct sway_container *view, void *data) { 245static bool _workspace_by_name(struct sway_container *view, void *data) {