Workspace command number selection

If a `workspace {N}` or `move to workspace {N}` command is given with N
as a plain number, the workspace of this number is selected for the
context of the command if one exists and there is no workspace with a
name that exactly matches N.
This commit is contained in:
Tony Crisci
2014-06-22 12:24:26 -04:00
committed by Michael Stapelberg
parent 4205973135
commit cbd51ce664
2 changed files with 97 additions and 2 deletions

View File

@ -513,7 +513,27 @@ void cmd_move_con_to_workspace_name(I3_CMD, char *name) {
LOG("should move window to workspace %s\n", name);
/* get the workspace */
Con *ws = workspace_get(name, NULL);
Con *ws = NULL;
Con *output = NULL;
/* first look for a workspace with this name */
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
GREP_FIRST(ws, output_get_content(output), !strcasecmp(child->name, name));
}
/* if the name is plain digits, we interpret this as a "workspace number"
* command */
if (!ws && name_is_digits(name)) {
long parsed_num = ws_name_to_number(name);
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
GREP_FIRST(ws, output_get_content(output),
child->num == parsed_num);
}
}
/* if no workspace was found, make a new one */
if (!ws)
ws = workspace_get(name, NULL);
ws = maybe_auto_back_and_forth_workspace(ws);
@ -1006,7 +1026,30 @@ void cmd_workspace_name(I3_CMD, char *name) {
DLOG("should switch to workspace %s\n", name);
if (maybe_back_and_forth(cmd_output, name))
return;
workspace_show_by_name(name);
Con *ws = NULL;
Con *output = NULL;
/* first look for a workspace with this name */
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
GREP_FIRST(ws, output_get_content(output), !strcasecmp(child->name, name));
}
/* if the name is only digits, we interpret this as a "workspace number"
* command */
if (!ws && name_is_digits(name)) {
long parsed_num = ws_name_to_number(name);
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) {
GREP_FIRST(ws, output_get_content(output),
child->num == parsed_num);
}
}
/* if no workspace was found, make a new one */
if (!ws)
ws = workspace_get(name, NULL);
workspace_show(ws);
cmd_output->needs_tree_render = true;
// XXX: default reply for now, make this a better reply