diff options
author | Ryan Dwyer <RyanDwyer@users.noreply.github.com> | 2018-08-19 16:16:32 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-19 16:16:32 +1000 |
commit | 389d159c81502aa8b951895de11c3720bbd5ba7d (patch) | |
tree | c5d96041e3270b1d1d50f8a42d91652d615c9938 /sway/tree | |
parent | d0a24465d75cc7197ee253e1de9fa961071cd034 (diff) | |
parent | 7f22fab3895ff090d5e26936f4e964e081090164 (diff) |
Merge pull request #2453 from ianyfan/commands
More commands
Diffstat (limited to 'sway/tree')
-rw-r--r-- | sway/tree/view.c | 23 | ||||
-rw-r--r-- | sway/tree/workspace.c | 25 |
2 files changed, 23 insertions, 25 deletions
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) { // Check if there's any `assign` criteria for the view list_t *criterias = criteria_for_view(view, - CT_ASSIGN_WORKSPACE | CT_ASSIGN_OUTPUT); + CT_ASSIGN_WORKSPACE | CT_ASSIGN_WORKSPACE_NUMBER | CT_ASSIGN_OUTPUT); struct sway_container *ws = NULL; for (int i = 0; i < criterias->length; ++i) { struct criteria *criteria = criterias->items[i]; - if (criteria->type == CT_ASSIGN_WORKSPACE) { - ws = workspace_by_name(criteria->target); + if (criteria->type == CT_ASSIGN_OUTPUT) { + struct sway_container *output = output_by_name(criteria->target); + if (output) { + ws = seat_get_active_child(seat, output); + break; + } + } else { + // CT_ASSIGN_WORKSPACE(_NUMBER) + ws = criteria->type == CT_ASSIGN_WORKSPACE_NUMBER ? + workspace_by_number(criteria->target) : + workspace_by_name(criteria->target); + if (!ws) { if (strcasecmp(criteria->target, "back_and_forth") == 0) { if (prev_workspace_name) { @@ -466,13 +476,6 @@ static struct sway_container *select_workspace(struct sway_view *view) { } } break; - } else { - // CT_ASSIGN_OUTPUT - struct sway_container *output = output_by_name(criteria->target); - if (output) { - ws = seat_get_active_child(seat, output); - break; - } } } 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, } 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) { |