aboutsummaryrefslogtreecommitdiff
path: root/sway/workspace.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/workspace.c')
-rw-r--r--sway/workspace.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/sway/workspace.c b/sway/workspace.c
index 5e6ea799..761a5f4e 100644
--- a/sway/workspace.c
+++ b/sway/workspace.c
@@ -17,6 +17,11 @@
#include "ipc.h"
char *prev_workspace_name = NULL;
+struct workspace_by_number_data {
+ int len;
+ const char *cset;
+ const char *name;
+};
char *workspace_next_name(void) {
sway_log(L_DEBUG, "Workspace: Generating new name");
@@ -133,6 +138,23 @@ swayc_t *workspace_by_name(const char* name) {
}
}
+static bool _workspace_by_number(swayc_t *view, void *data) {
+ if (view->type != C_WORKSPACE) {
+ return false;
+ }
+ struct workspace_by_number_data *wbnd = data;
+ int a = strspn(view->name, wbnd->cset);
+ return a == wbnd->len && strncmp(view->name, wbnd->name, a) == 0;
+}
+swayc_t *workspace_by_number(const char* name) {
+ struct workspace_by_number_data wbnd = {0, "1234567890", name};
+ wbnd.len = strspn(name, wbnd.cset);
+ if (wbnd.len <= 0) {
+ return NULL;
+ }
+ return swayc_by_test(&root_container, _workspace_by_number, (void *) &wbnd);
+}
+
/**
* Get the previous or next workspace on the specified output.
* Wraps around at the end and beginning.