#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;
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");
return $cons[0];
}
-
1