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:
parent
4205973135
commit
cbd51ce664
|
@ -513,7 +513,27 @@ void cmd_move_con_to_workspace_name(I3_CMD, char *name) {
|
||||||
|
|
||||||
LOG("should move window to workspace %s\n", name);
|
LOG("should move window to workspace %s\n", name);
|
||||||
/* get the workspace */
|
/* 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);
|
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);
|
DLOG("should switch to workspace %s\n", name);
|
||||||
if (maybe_back_and_forth(cmd_output, name))
|
if (maybe_back_and_forth(cmd_output, name))
|
||||||
return;
|
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;
|
cmd_output->needs_tree_render = true;
|
||||||
// XXX: default reply for now, make this a better reply
|
// XXX: default reply for now, make this a better reply
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
#!perl
|
||||||
|
# vim:ts=4:sw=4:expandtab
|
||||||
|
#
|
||||||
|
# Please read the following documents before working on tests:
|
||||||
|
# • http://build.i3wm.org/docs/testsuite.html
|
||||||
|
# (or docs/testsuite)
|
||||||
|
#
|
||||||
|
# • http://build.i3wm.org/docs/lib-i3test.html
|
||||||
|
# (alternatively: perldoc ./testcases/lib/i3test.pm)
|
||||||
|
#
|
||||||
|
# • http://build.i3wm.org/docs/ipc.html
|
||||||
|
# (or docs/ipc)
|
||||||
|
#
|
||||||
|
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
|
||||||
|
# (unless you are already familiar with Perl)
|
||||||
|
#
|
||||||
|
# Test that `workspace {N}` acts like `workspace number {N}` when N is a plain
|
||||||
|
# digit, and likewise for `move to workspace {N}`.
|
||||||
|
# Ticket: #1238
|
||||||
|
# Bug still in: 4.8-16-g3f5a0f0
|
||||||
|
use i3test;
|
||||||
|
|
||||||
|
cmd 'workspace 5:foo';
|
||||||
|
open_window;
|
||||||
|
fresh_workspace;
|
||||||
|
cmd 'workspace 5';
|
||||||
|
|
||||||
|
is(focused_ws, '5:foo',
|
||||||
|
'a command to switch to a workspace with a bare number should switch to a workspace of that number');
|
||||||
|
|
||||||
|
fresh_workspace;
|
||||||
|
my $win = open_window;
|
||||||
|
cmd '[id="' . $win->{id} . '"] move to workspace 5';
|
||||||
|
|
||||||
|
is(@{get_ws('5:foo')->{nodes}}, 2,
|
||||||
|
'a command to move a container to a workspace with a bare number should move that container to a workspace of that number');
|
||||||
|
|
||||||
|
fresh_workspace;
|
||||||
|
cmd 'workspace 7';
|
||||||
|
open_window;
|
||||||
|
cmd 'workspace 7:foo';
|
||||||
|
$win = open_window;
|
||||||
|
|
||||||
|
cmd 'workspace 7';
|
||||||
|
is(focused_ws, '7',
|
||||||
|
'a workspace with a name that is a matching plain number should be preferred when switching');
|
||||||
|
|
||||||
|
cmd '[id="' . $win->{id} . '"] move to workspace 7';
|
||||||
|
is(@{get_ws('7')->{nodes}}, 2,
|
||||||
|
'a workspace with a name that is a matching plain number should be preferred when moving');
|
||||||
|
|
||||||
|
done_testing;
|
Loading…
Reference in New Issue