From: Michael Stapelberg Date: Sun, 8 Jan 2012 16:32:58 +0000 (+0000) Subject: tests: make focused_ws multi-monitor-safe, document it X-Git-Tag: 4.2~148^2~1 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=6e4a86b7d175bfe08043da9c5189cec5baafbef3;p=i3%2Fi3 tests: make focused_ws multi-monitor-safe, document it --- diff --git a/testcases/lib/i3test.pm b/testcases/lib/i3test.pm index f9cec64e..1e70bf52 100644 --- a/testcases/lib/i3test.pm +++ b/testcases/lib/i3test.pm @@ -383,18 +383,19 @@ sub workspace_exists { ($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) { - next if $output->{name} eq '__i3'; - # 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} } #