X-Git-Url: https://git.sur5r.net/?p=i3%2Fi3;a=blobdiff_plain;f=testcases%2Flib%2Fi3test.pm.in;fp=testcases%2Flib%2Fi3test.pm.in;h=5734eca70206cc15196f3c0ac78c9075186166aa;hp=e754c0c17f6bf3b8b5b92e72233ebbe05ab8198a;hb=1847938d4eeba98260cc79ca45a11a134274c2ea;hpb=c54f5008395b10c046f380cc3069ff779e5d2877 diff --git a/testcases/lib/i3test.pm.in b/testcases/lib/i3test.pm.in index e754c0c1..5734eca7 100644 --- a/testcases/lib/i3test.pm.in +++ b/testcases/lib/i3test.pm.in @@ -26,6 +26,7 @@ use Data::Dumper (); use Exporter (); our @EXPORT = qw( get_workspace_names + get_output_for_workspace get_unused_workspace fresh_workspace get_ws_content @@ -51,6 +52,7 @@ our @EXPORT = qw( kill_all_windows events_for listen_for_binding + is_net_wm_state_focused ); =head1 NAME @@ -401,6 +403,29 @@ sub get_workspace_names { [ map { $_->{name} } @cons ] } +=head2 get_output_for_workspace() + +Returns the name of the output on which this workspace resides + + cmd 'focus output fake-1'; + cmd 'workspace 1'; + is(get_output_for_workspace('1', 'fake-0', 'Workspace 1 in output fake-0'); + +=cut +sub get_output_for_workspace { + my $ws_name = shift @_; + my $i3 = i3(get_socket_path()); + my $tree = $i3->get_tree->recv; + my @outputs = @{$tree->{nodes}}; + + foreach (grep { not $_->{name} =~ /^__/ } @outputs) { + my $output = $_->{name}; + foreach (grep { $_->{name} =~ "content" } @{$_->{nodes}}) { + return $output if $_->{nodes}[0]->{name} =~ $ws_name; + } + } +} + =head2 get_unused_workspace Returns a workspace name which has not yet been used. See also @@ -1026,6 +1051,40 @@ sub listen_for_binding { return $command; } +=head2 is_net_wm_state_focused + +Returns true if the given window has the _NET_WM_STATE_FOCUSED atom. + + ok(is_net_wm_state_focused($window), '_NET_WM_STATE_FOCUSED set'); + +=cut +sub is_net_wm_state_focused { + my ($window) = @_; + + sync_with_i3; + my $atom = $x->atom(name => '_NET_WM_STATE_FOCUSED'); + my $cookie = $x->get_property( + 0, + $window->{id}, + $x->atom(name => '_NET_WM_STATE')->id, + GET_PROPERTY_TYPE_ANY, + 0, + 4096 + ); + + my $reply = $x->get_property_reply($cookie->{sequence}); + my $len = $reply->{length}; + return 0 if $len == 0; + + my @atoms = unpack("L$len", $reply->{value}); + for (my $i = 0; $i < $len; $i++) { + return 1 if $atoms[$i] == $atom->id; + } + + return 0; +} + + =head1 AUTHOR Michael Stapelberg