t/lib/i3test.pm: refactor get_ws and get_ws_content using List::Util’s first
This commit is contained in:
parent
7c3e88ad93
commit
03c8da0a74
|
@ -15,6 +15,7 @@ use X11::XCB::Rect;
|
||||||
use X11::XCB::Window;
|
use X11::XCB::Window;
|
||||||
use X11::XCB qw(:all);
|
use X11::XCB qw(:all);
|
||||||
use AnyEvent::I3;
|
use AnyEvent::I3;
|
||||||
|
use List::Util qw(first);
|
||||||
# Test::Kit already uses Exporter
|
# Test::Kit already uses Exporter
|
||||||
#use Exporter qw(import);
|
#use Exporter qw(import);
|
||||||
use base 'Exporter';
|
use base 'Exporter';
|
||||||
|
@ -60,6 +61,17 @@ sub get_unused_workspace {
|
||||||
$tmp
|
$tmp
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_ws {
|
||||||
|
my ($name) = @_;
|
||||||
|
my $i3 = i3("/tmp/nestedcons");
|
||||||
|
my $tree = $i3->get_workspaces->recv;
|
||||||
|
my @ws = map { @{$_->{nodes}} } @{$tree->{nodes}};
|
||||||
|
|
||||||
|
# as there can only be one workspace with this name, we can safely
|
||||||
|
# return the first entry
|
||||||
|
return first { $_->{name} eq $name } @ws;
|
||||||
|
}
|
||||||
|
|
||||||
#
|
#
|
||||||
# returns the content (== tree, starting from the node of a workspace)
|
# returns the content (== tree, starting from the node of a workspace)
|
||||||
# of a workspace. If called in array context, also includes the focus
|
# of a workspace. If called in array context, also includes the focus
|
||||||
|
@ -67,13 +79,8 @@ sub get_unused_workspace {
|
||||||
#
|
#
|
||||||
sub get_ws_content {
|
sub get_ws_content {
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
my $i3 = i3("/tmp/nestedcons");
|
my $con = get_ws($name);
|
||||||
my $tree = $i3->get_workspaces->recv;
|
return wantarray ? ($con->{nodes}, $con->{focus}) : $con->{nodes};
|
||||||
my @ws = map { @{$_->{nodes}} } @{$tree->{nodes}};
|
|
||||||
my @cons = grep { $_->{name} eq $name } @ws;
|
|
||||||
# as there can only be one workspace with this name, we can safely
|
|
||||||
# return the first entry
|
|
||||||
return wantarray ? ($cons[0]->{nodes}, $cons[0]->{focus}) : $cons[0]->{nodes};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_focused {
|
sub get_focused {
|
||||||
|
@ -98,13 +105,4 @@ sub get_focused {
|
||||||
return $lf;
|
return $lf;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub get_ws {
|
|
||||||
my ($name) = @_;
|
|
||||||
my $i3 = i3("/tmp/nestedcons");
|
|
||||||
my $tree = $i3->get_workspaces->recv;
|
|
||||||
my @ws = map { @{$_->{nodes}} } @{$tree->{nodes}};
|
|
||||||
my @cons = grep { $_->{name} eq $name } @ws;
|
|
||||||
return $cons[0];
|
|
||||||
}
|
|
||||||
|
|
||||||
1
|
1
|
||||||
|
|
Loading…
Reference in New Issue