my @outputs = @{$tree->{nodes}};
my @cons;
for my $output (@outputs) {
+ next if $output->{name} eq '__i3';
# get the first CT_CON of each output
my $content = first { $_->{type} == 2 } @{$output->{nodes}};
@cons = (@cons, @{$content->{nodes}});
$tmp
}
+=head2 fresh_workspace(...)
+
+Switches to an unused workspace and returns the name of that workspace.
+
+Optionally switches to the specified output first.
+
+ my $ws = fresh_workspace;
+
+ # Get a fresh workspace on the second output.
+ my $ws = fresh_workspace(output => 1);
+
+=cut
sub fresh_workspace {
+ my %args = @_;
+ if (exists($args{output})) {
+ my $i3 = i3(get_socket_path());
+ my $tree = $i3->get_tree->recv;
+ my $output = first { $_->{name} eq "xinerama-$args{output}" }
+ @{$tree->{nodes}};
+ die "BUG: Could not find output $args{output}" unless defined($output);
+ # Get the focused workspace on that output and switch to it.
+ my $content = first { $_->{type} == 2 } @{$output->{nodes}};
+ my $focused = $content->{focus}->[0];
+ my $workspace = first { $_->{id} == $focused } @{$content->{nodes}};
+ $workspace = $workspace->{name};
+ cmd("workspace $workspace");
+ }
+
my $unused = get_unused_workspace;
cmd("workspace $unused");
$unused
@{$output->{nodes}});
} elsif ($which eq 'top') {
my $first = first { $_->{type} == 5 } @{$output->{nodes}};
- @docked = (@docked, @{$first->{nodes}});
+ @docked = (@docked, @{$first->{nodes}}) if defined($first);
} elsif ($which eq 'bottom') {
my @matching = grep { $_->{type} == 5 } @{$output->{nodes}};
my $last = $matching[-1];
- @docked = (@docked, @{$last->{nodes}});
+ @docked = (@docked, @{$last->{nodes}}) if defined($last);
}
}
return @docked;
($name ~~ @{get_workspace_names()})
}
+=head2 focused_ws
+
+Returns the name of the currently focused workspace.
+
+=cut
sub focused_ws {
my $i3 = i3(get_socket_path());
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 $first = first { $_->{fullscreen_mode} == 1 } @{$content->{nodes}};
- return $first->{name}
- }
+ my $focused = $tree->{focus}->[0];
+ my $output = first { $_->{id} == $focused } @{$tree->{nodes}};
+ my $content = first { $_->{type} == 2 } @{$output->{nodes}};
+ my $first = first { $_->{fullscreen_mode} == 1 } @{$content->{nodes}};
+ return $first->{name}
}
#
testname => $ENV{TESTNAME},
valgrind => $ENV{VALGRIND},
strace => $ENV{STRACE},
+ restart => $ENV{RESTART},
cv => $cv,
);