diff options
author | Ian Fan <ianfan0@gmail.com> | 2018-08-12 00:32:13 +0100 |
---|---|---|
committer | Ian Fan <ianfan0@gmail.com> | 2018-08-18 17:25:06 +0100 |
commit | e81cc8a5754386d9484b84cf97ab2f8755c35294 (patch) | |
tree | a3a9f64d0e179b07f94e2fff1484f5099f440432 /sway/tree | |
parent | 69e00151bbd5c2648194b538ad80aba1d305d24a (diff) |
commands: saner workspace number handling
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/workspace.c | 25 |
1 files changed, 10 insertions, 15 deletions
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, } char *prev_workspace_name = NULL; -struct workspace_by_number_data { - int len; - const char *cset; - const char *name; -}; void next_name_map(struct sway_container *ws, void *data) { int *count = data; @@ -154,7 +149,7 @@ static void workspace_name_from_binding(const struct sway_binding * binding, wlr_log(WLR_DEBUG, "Isolated name from workspace number: '%s'", _target); // Make sure the workspace number doesn't already exist - if (workspace_by_number(_target)) { + if (isdigit(_target[0]) && workspace_by_number(_target)) { free(_target); free(dup); return; @@ -233,18 +228,18 @@ static bool _workspace_by_number(struct sway_container *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; + char *name = data; + char *view_name = view->name; + while (isdigit(*name)) { + if (*name++ != *view_name++) { + return false; + } + } + return !isdigit(*view_name); } struct sway_container *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 root_find_workspace(_workspace_by_number, (void *) &wbnd); + return root_find_workspace(_workspace_by_number, (void *) name); } static bool _workspace_by_name(struct sway_container *view, void *data) { |