diff --git a/testcases/t/lib/i3test.pm b/testcases/t/lib/i3test.pm index 4b76b7f4..da3c1b28 100644 --- a/testcases/t/lib/i3test.pm +++ b/testcases/t/lib/i3test.pm @@ -19,7 +19,7 @@ use AnyEvent::I3; #use Exporter qw(import); use base 'Exporter'; -our @EXPORT = qw(get_workspace_names get_unused_workspace get_ws_content get_ws); +our @EXPORT = qw(get_workspace_names get_unused_workspace get_ws_content get_ws get_focused); BEGIN { my $window_count = 0; @@ -76,6 +76,28 @@ sub get_ws_content { return wantarray ? ($cons[0]->{nodes}, $cons[0]->{focus}) : $cons[0]->{nodes}; } +sub get_focused { + my ($ws) = @_; + my $i3 = i3("/tmp/nestedcons"); + my $tree = $i3->get_workspaces->recv; + + my @ws = map { @{$_->{nodes}} } @{$tree->{nodes}}; + my @cons = grep { $_->{name} eq $ws } @ws; + my $con = $cons[0]; + + my @focused = @{$con->{focus}}; + my $lf; + while (@focused > 0) { + $lf = $focused[0]; + last unless defined($con->{focus}); + @focused = @{$con->{focus}}; + @cons = grep { $_->{id} == $lf } (@{$con->{nodes}}, @{$con->{'floating-nodes'}}); + $con = $cons[0]; + } + + return $lf; +} + sub get_ws { my ($name) = @_; my $i3 = i3("/tmp/nestedcons"); @@ -85,5 +107,4 @@ sub get_ws { return $cons[0]; } - 1