To change to a specific workspace, use the +workspace+ command, followed by the
number or name of the workspace. To move containers, use +move workspace+.
-//////////////////////////////////////////////////////////////////////////////
-TODO: not yet implemented
-
-You can also switch to the next and previous workspace with the commands +nw+
-and +pw+, which is handy, for example, if you have workspace 1, 3, 4 and 9 and
-you want to cycle through them with a single key combination.
-//////////////////////////////////////////////////////////////////////////////
+You can also switch to the next and previous workspace with the commands
++workspace next+ and +workspace prev+, which is handy, for example, if you have
+workspace 1, 3, 4 and 9 and you want to cycle through them with a single key
+combination.
*Examples*:
-------------------------
cmdyycolumn = 1;
}
+ /* the next/prev tokens are here to recognize them *before* handling
+ * strings ('workspace' command) */
+next { return TOK_NEXT; }
+prev { return TOK_PREV; }
+
<WANT_STRING>\"[^\"]+\" {
BEGIN(INITIAL);
/* strip quotes */
focus { return TOK_FOCUS; }
move { return TOK_MOVE; }
open { return TOK_OPEN; }
-prev { return TOK_PREV; }
split { return TOK_SPLIT; }
horizontal { return TOK_HORIZONTAL; }
vertical { return TOK_VERTICAL; }
ipc_send_event("workspace", I3_IPC_EVENT_WORKSPACE, "{\"change\":\"focus\"}");
}
+/*
+ * Focuses the next workspace.
+ *
+ */
+void workspace_next() {
+ Con *ws = con_get_workspace(focused);
+ Con *next = TAILQ_NEXT(ws, nodes);
+ if (!next)
+ next = TAILQ_FIRST(&(ws->parent->nodes_head));
+
+ workspace_show(next->name);
+}
+
+/*
+ * Focuses the previous workspace.
+ *
+ */
+void workspace_prev() {
+ Con *ws = con_get_workspace(focused);
+ Con *prev = TAILQ_PREV(ws, nodes_head, nodes);
+ if (!prev)
+ prev = TAILQ_LAST(&(ws->parent->nodes_head), nodes_head);
+
+ workspace_show(prev->name);
+}
+
static bool get_urgency_flag(Con *con) {
Con *child;
TAILQ_FOREACH(child, &(con->nodes_head), nodes)
# Tests whether we can switch to a non-existant workspace
# (necessary for further tests)
#
+use List::Util qw(first);
use i3test;
sub workspace_exists {
cmd "workspace $otmp";
ok(workspace_exists($otmp), 'other workspace still exists');
+
+#####################################################################
+# check if the workspace next / prev commands work
+#####################################################################
+
+cmd 'workspace next';
+
+ok(!workspace_exists('next'), 'workspace "next" does not exist');
+
+cmd "workspace $tmp";
+cmd 'open';
+
+ok(workspace_exists($tmp), 'workspace created');
+
+cmd "workspace $otmp";
+cmd 'open';
+
+ok(workspace_exists($tmp), 'workspace tmp still exists');
+ok(workspace_exists($otmp), 'workspace otmp created');
+
+sub focused_ws_con {
+ my $i3 = i3("/tmp/nestedcons");
+ my $tree = $i3->get_tree->recv;
+ my @outputs = @{$tree->{nodes}};
+ my @cons;
+ for my $output (@outputs) {
+ # get the first CT_CON of each output
+ my $content = first { $_->{type} == 2 } @{$output->{nodes}};
+ my @focused = @{$content->{focus}};
+ return first { $_->{id} == $focused[0] } @{$content->{nodes}};
+ }
+}
+
+sub focused_ws {
+ my $con = focused_ws_con;
+ return $con->{name};
+}
+
+is(focused_ws(), $otmp, 'focused workspace is otmp');
+
+cmd 'workspace prev';
+is(focused_ws(), $tmp, 'focused workspace is tmp after workspace prev');
+
+cmd 'workspace next';
+is(focused_ws(), $otmp, 'focused workspace is otmp after workspace next');
+
+
+#####################################################################
+# check that wrapping works
+#####################################################################
+
+cmd 'workspace next';
+is(focused_ws(), '1', 'focused workspace is 1 after workspace next');
+
+cmd 'workspace next';
+is(focused_ws(), $tmp, 'focused workspace is tmp after workspace next');
+
+cmd 'workspace next';
+is(focused_ws(), $otmp, 'focused workspace is otmp after workspace next');
+
+
+cmd 'workspace prev';
+is(focused_ws(), $tmp, 'focused workspace is tmp after workspace prev');
+
+cmd 'workspace prev';
+is(focused_ws(), '1', 'focused workspace is tmp after workspace prev');
+
+cmd 'workspace prev';
+is(focused_ws(), $otmp, 'focused workspace is otmp after workspace prev');
+
+
+#####################################################################
+# check if we can change to "next" / "prev"
+#####################################################################
+
+cmd 'workspace "next"';
+
+ok(workspace_exists('next'), 'workspace "next" exists');
+is(focused_ws(), 'next', 'now on workspace next');
+
+cmd 'workspace "prev"';
+
+ok(workspace_exists('prev'), 'workspace "prev" exists');
+is(focused_ws(), 'prev', 'now on workspace prev');
+
done_testing;