From ae14fe9141f93dd97a5bebabfa584444e6743206 Mon Sep 17 00:00:00 2001 From: Michael Walle Date: Mon, 29 Oct 2012 22:42:20 +0100 Subject: [PATCH] introduce new command to rename focused workspace The corresponding command is 'rename workspace to '. As a side-effect this fixes the command 'rename workspace 1 to to'. Signed-off-by: Michael Walle --- docs/userguide | 11 ++++++++--- parser-specs/commands.spec | 15 ++++++++++++++- src/commands.c | 18 +++++++++++++----- testcases/t/117-workspace.t | 31 +++++++++++++++++++++++++++++-- 4 files changed, 64 insertions(+), 11 deletions(-) diff --git a/docs/userguide b/docs/userguide index 72555b53..f78b4913 100644 --- a/docs/userguide +++ b/docs/userguide @@ -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 numbered workspaces, do your work, and rename the workspaces afterwards to -reflect what’s actually on them. +reflect what’s 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*: ---------------------------------------------------- rename workspace to +rename workspace to ---------------------------------------------------- *Examples*: ------------------------------------------------- +-------------------------------------------------------------------------- i3-msg 'rename workspace 5 to 6' i3-msg 'rename workspace 1 to "1: 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 diff --git a/parser-specs/commands.spec b/parser-specs/commands.spec index 4224707c..c9b881b3 100644 --- a/parser-specs/commands.spec +++ b/parser-specs/commands.spec @@ -195,17 +195,30 @@ state RESIZE_TILING_OR: -> call cmd_resize($way, $direction, $resize_px, $resize_ppt) # rename workspace to +# rename workspace to state RENAME: 'workspace' -> RENAME_WORKSPACE state RENAME_WORKSPACE: + old_name = 'to' + -> RENAME_WORKSPACE_LIKELY_TO old_name = word -> 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: 'to' - -> + -> RENAME_WORKSPACE_NEW_NAME + +state RENAME_WORKSPACE_NEW_NAME: + end + -> call cmd_rename_workspace(NULL, "to") new_name = string -> call cmd_rename_workspace($old_name, $new_name) diff --git a/src/commands.c b/src/commands.c index 4b2b2d2a..cb53a31e 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1802,16 +1802,24 @@ void cmd_scratchpad_show(I3_CMD) { } /* - * Implementation of 'rename workspace to ' + * Implementation of 'rename workspace [] to ' * */ void cmd_rename_workspace(I3_CMD, char *old_name, char *new_name) { - LOG("Renaming workspace \"%s\" to \"%s\"\n", old_name, new_name); + if (old_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; - TAILQ_FOREACH(output, &(croot->nodes_head), nodes) - GREP_FIRST(workspace, output_get_content(output), - !strcasecmp(child->name, old_name)); + if (old_name) { + TAILQ_FOREACH(output, &(croot->nodes_head), nodes) + GREP_FIRST(workspace, output_get_content(output), + !strcasecmp(child->name, old_name)); + } else { + workspace = con_get_workspace(focused); + } if (!workspace) { // TODO: we should include the old workspace name here and use yajl for diff --git a/testcases/t/117-workspace.t b/testcases/t/117-workspace.t index 2283ddc1..d8a8733b 100644 --- a/testcases/t/117-workspace.t +++ b/testcases/t/117-workspace.t @@ -254,11 +254,38 @@ $ws = get_ws('qux'); is($ws->{num}, -1, 'number correctly changed'); 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'; 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'; ok(!$result->[0]->{success}, 'renaming workspace which does not exist failed'); -- 2.39.5