diff options
author | 2015-12-17 22:28:41 +0100 | |
---|---|---|
committer | 2015-12-18 01:21:31 +0100 | |
commit | 8f1ac1ef2c77665e7c17eaa6a46ea1b6d68e5c22 (patch) | |
tree | 83806713b8d0f1c562b70ca2f2a87bde30095191 /sway/workspace.c | |
parent | Merge pull request #351 from mikkeloscar/swaygrab-default-file (diff) | |
download | sway-8f1ac1ef2c77665e7c17eaa6a46ea1b6d68e5c22.tar.gz sway-8f1ac1ef2c77665e7c17eaa6a46ea1b6d68e5c22.tar.zst sway-8f1ac1ef2c77665e7c17eaa6a46ea1b6d68e5c22.zip |
sway: enable workspace selection by number
Diffstat (limited to 'sway/workspace.c')
-rw-r--r-- | sway/workspace.c | 22 |
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 @@ | |||
17 | #include "ipc.h" | 17 | #include "ipc.h" |
18 | 18 | ||
19 | char *prev_workspace_name = NULL; | 19 | char *prev_workspace_name = NULL; |
20 | struct workspace_by_number_data { | ||
21 | int len; | ||
22 | const char *cset; | ||
23 | const char *name; | ||
24 | }; | ||
20 | 25 | ||
21 | char *workspace_next_name(void) { | 26 | char *workspace_next_name(void) { |
22 | sway_log(L_DEBUG, "Workspace: Generating new name"); | 27 | sway_log(L_DEBUG, "Workspace: Generating new name"); |
@@ -133,6 +138,23 @@ swayc_t *workspace_by_name(const char* name) { | |||
133 | } | 138 | } |
134 | } | 139 | } |
135 | 140 | ||
141 | static bool _workspace_by_number(swayc_t *view, void *data) { | ||
142 | if (view->type != C_WORKSPACE) { | ||
143 | return false; | ||
144 | } | ||
145 | struct workspace_by_number_data *wbnd = data; | ||
146 | int a = strspn(view->name, wbnd->cset); | ||
147 | return a == wbnd->len && strncmp(view->name, wbnd->name, a) == 0; | ||
148 | } | ||
149 | swayc_t *workspace_by_number(const char* name) { | ||
150 | struct workspace_by_number_data wbnd = {0, "1234567890", name}; | ||
151 | wbnd.len = strspn(name, wbnd.cset); | ||
152 | if (wbnd.len <= 0) { | ||
153 | return NULL; | ||
154 | } | ||
155 | return swayc_by_test(&root_container, _workspace_by_number, (void *) &wbnd); | ||
156 | } | ||
157 | |||
136 | /** | 158 | /** |
137 | * Get the previous or next workspace on the specified output. | 159 | * Get the previous or next workspace on the specified output. |
138 | * Wraps around at the end and beginning. | 160 | * Wraps around at the end and beginning. |