lib/i3test: Implement get_focused
This commit is contained in:
parent
712605e69f
commit
afa8be9547
|
@ -19,7 +19,7 @@ use AnyEvent::I3;
|
||||||
#use Exporter qw(import);
|
#use Exporter qw(import);
|
||||||
use base 'Exporter';
|
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 {
|
BEGIN {
|
||||||
my $window_count = 0;
|
my $window_count = 0;
|
||||||
|
@ -76,6 +76,28 @@ sub get_ws_content {
|
||||||
return wantarray ? ($cons[0]->{nodes}, $cons[0]->{focus}) : $cons[0]->{nodes};
|
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 {
|
sub get_ws {
|
||||||
my ($name) = @_;
|
my ($name) = @_;
|
||||||
my $i3 = i3("/tmp/nestedcons");
|
my $i3 = i3("/tmp/nestedcons");
|
||||||
|
@ -85,5 +107,4 @@ sub get_ws {
|
||||||
return $cons[0];
|
return $cons[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
1
|
1
|
||||||
|
|
Loading…
Reference in New Issue