introduce new command to rename focused workspace

The corresponding command is 'rename workspace to <name>'. As a side-effect
this fixes the command 'rename workspace 1 to to'.

Signed-off-by: Michael Walle <michael@walle.cc>
This commit is contained in:
Michael Walle 2012-10-29 22:42:20 +01:00 committed by Michael Stapelberg
parent 2f90321d16
commit ae14fe9141
4 changed files with 64 additions and 11 deletions

View File

@ -1503,19 +1503,24 @@ specify a default name if there's currently no workspace starting with a "1".
You can rename workspaces. This might be useful to start with the default You can rename workspaces. This might be useful to start with the default
numbered workspaces, do your work, and rename the workspaces afterwards to numbered workspaces, do your work, and rename the workspaces afterwards to
reflect whats actually on them. reflect whats actually on them. You can also omit the old name to rename
the currently focused workspace. This is handy if you wan't to use the
rename command with +i3-input+.
*Syntax*: *Syntax*:
---------------------------------------------------- ----------------------------------------------------
rename workspace <old_name> to <new_name> rename workspace <old_name> to <new_name>
rename workspace to <new_name>
---------------------------------------------------- ----------------------------------------------------
*Examples*: *Examples*:
------------------------------------------------ --------------------------------------------------------------------------
i3-msg 'rename workspace 5 to 6' i3-msg 'rename workspace 5 to 6'
i3-msg 'rename workspace 1 to "1: www"' i3-msg 'rename workspace 1 to "1: www"'
i3-msg 'rename workspace "1: www" to "10: www"' i3-msg 'rename workspace "1: www" to "10: www"'
------------------------------------------------ i3-msg 'rename workspace to "2: mail"
bindsym $mod+r exec i3-input -F 'rename workspace to %s' -P 'New name: '
--------------------------------------------------------------------------
=== Moving containers/workspaces to RandR outputs === Moving containers/workspaces to RandR outputs

View File

@ -195,17 +195,30 @@ state RESIZE_TILING_OR:
-> call cmd_resize($way, $direction, $resize_px, $resize_ppt) -> call cmd_resize($way, $direction, $resize_px, $resize_ppt)
# rename workspace <name> to <name> # rename workspace <name> to <name>
# rename workspace to <name>
state RENAME: state RENAME:
'workspace' 'workspace'
-> RENAME_WORKSPACE -> RENAME_WORKSPACE
state RENAME_WORKSPACE: state RENAME_WORKSPACE:
old_name = 'to'
-> RENAME_WORKSPACE_LIKELY_TO
old_name = word old_name = word
-> RENAME_WORKSPACE_TO -> RENAME_WORKSPACE_TO
state RENAME_WORKSPACE_LIKELY_TO:
'to'
-> RENAME_WORKSPACE_NEW_NAME
new_name = word
-> call cmd_rename_workspace(NULL, $new_name)
state RENAME_WORKSPACE_TO: state RENAME_WORKSPACE_TO:
'to' 'to'
-> -> RENAME_WORKSPACE_NEW_NAME
state RENAME_WORKSPACE_NEW_NAME:
end
-> call cmd_rename_workspace(NULL, "to")
new_name = string new_name = string
-> call cmd_rename_workspace($old_name, $new_name) -> call cmd_rename_workspace($old_name, $new_name)

View File

@ -1802,16 +1802,24 @@ void cmd_scratchpad_show(I3_CMD) {
} }
/* /*
* Implementation of 'rename workspace <name> to <name>' * Implementation of 'rename workspace [<name>] to <name>'
* *
*/ */
void cmd_rename_workspace(I3_CMD, char *old_name, char *new_name) { void cmd_rename_workspace(I3_CMD, char *old_name, char *new_name) {
if (old_name) {
LOG("Renaming workspace \"%s\" to \"%s\"\n", old_name, new_name); LOG("Renaming workspace \"%s\" to \"%s\"\n", old_name, new_name);
} else {
LOG("Renaming current workspace to \"%s\"\n", new_name);
}
Con *output, *workspace = NULL; Con *output, *workspace = NULL;
if (old_name) {
TAILQ_FOREACH(output, &(croot->nodes_head), nodes) TAILQ_FOREACH(output, &(croot->nodes_head), nodes)
GREP_FIRST(workspace, output_get_content(output), GREP_FIRST(workspace, output_get_content(output),
!strcasecmp(child->name, old_name)); !strcasecmp(child->name, old_name));
} else {
workspace = con_get_workspace(focused);
}
if (!workspace) { if (!workspace) {
// TODO: we should include the old workspace name here and use yajl for // TODO: we should include the old workspace name here and use yajl for

View File

@ -254,11 +254,38 @@ $ws = get_ws('qux');
is($ws->{num}, -1, 'number correctly changed'); is($ws->{num}, -1, 'number correctly changed');
workspace_numbers_sorted(); workspace_numbers_sorted();
# 5: already existing workspace # 4: rename current workspace
cmd 'workspace 4711';
is(focused_ws(), '4711', 'now on workspace 4711');
ok(!workspace_exists('42'), 'workspace 42 does not exist yet');
cmd 'rename workspace to 42';
ok(!workspace_exists('4711'), 'workspace 4711 does not exist anymore');
is(focused_ws(), '42', 'now on workspace 42');
$ws = get_ws('42');
is($ws->{num}, 42, 'number correctly changed');
workspace_numbers_sorted();
# 5: special cases
cmd 'workspace bla';
is(focused_ws(), 'bla', 'now on workspace to');
ok(!workspace_exists('to'), 'workspace to does not exist yet');
cmd 'rename workspace bla to to';
ok(!workspace_exists('bla'), 'workspace bla does not exist anymore');
is(focused_ws(), 'to', 'now on workspace to');
cmd 'rename workspace to to bla';
ok(!workspace_exists('to'), 'workspace to does not exist anymore');
is(focused_ws(), 'bla', 'now on workspace bla');
cmd 'rename workspace to to';
ok(!workspace_exists('bla'), 'workspace bla does not exist anymore');
is(focused_ws(), 'to', 'now on workspace to');
# 6: already existing workspace
my $result = cmd 'rename workspace qux to 11: bar'; my $result = cmd 'rename workspace qux to 11: bar';
ok(!$result->[0]->{success}, 'renaming workspace to an already existing one failed'); ok(!$result->[0]->{success}, 'renaming workspace to an already existing one failed');
# 6: non-existing old workspace (verify command result) # 7: non-existing old workspace (verify command result)
$result = cmd 'rename workspace notexistant to bleh'; $result = cmd 'rename workspace notexistant to bleh';
ok(!$result->[0]->{success}, 'renaming workspace which does not exist failed'); ok(!$result->[0]->{success}, 'renaming workspace which does not exist failed');