X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=testcases%2Flib%2Fi3test.pm;h=32a17934d8e23d6e91cfb9645dcee68faeecf432;hb=5a29e61a4605cb3a1a9333d8e85d9afdc6b51ab1;hp=aecec5342ea7e1b5d52d928c7999605c6dc700b3;hpb=a930994dc983190c9f43f262d496f97285604a76;p=i3%2Fi3 diff --git a/testcases/lib/i3test.pm b/testcases/lib/i3test.pm index aecec534..32a17934 100644 --- a/testcases/lib/i3test.pm +++ b/testcases/lib/i3test.pm @@ -33,6 +33,7 @@ our @EXPORT = qw( open_floating_window get_dock_clients cmd + cmp_float sync_with_i3 does_i3_live exit_gracefully @@ -247,7 +248,7 @@ sub open_empty_con { my ($i3) = @_; my $reply = $i3->command('open')->recv; - return $reply->{id}; + return $reply->[0]->{id}; } sub get_workspace_names { @@ -256,6 +257,7 @@ sub get_workspace_names { 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}}; @cons = (@cons, @{$content->{nodes}}); @@ -270,7 +272,34 @@ sub get_unused_workspace { $tmp } +=head2 fresh_workspace(...) + +Switches to an unused workspace and returns the name of that workspace. + +Optionally switches to the specified output first. + + my $ws = fresh_workspace; + + # Get a fresh workspace on the second output. + my $ws = fresh_workspace(output => 1); + +=cut sub fresh_workspace { + my %args = @_; + if (exists($args{output})) { + my $i3 = i3(get_socket_path()); + my $tree = $i3->get_tree->recv; + my $output = first { $_->{name} eq "fake-$args{output}" } + @{$tree->{nodes}}; + die "BUG: Could not find output $args{output}" unless defined($output); + # Get the focused workspace on that output and switch to it. + my $content = first { $_->{type} == 2 } @{$output->{nodes}}; + my $focused = $content->{focus}->[0]; + my $workspace = first { $_->{id} == $focused } @{$content->{nodes}}; + $workspace = $workspace->{name}; + cmd("workspace $workspace"); + } + my $unused = get_unused_workspace; cmd("workspace $unused"); $unused @@ -336,11 +365,11 @@ sub get_dock_clients { @{$output->{nodes}}); } elsif ($which eq 'top') { my $first = first { $_->{type} == 5 } @{$output->{nodes}}; - @docked = (@docked, @{$first->{nodes}}); + @docked = (@docked, @{$first->{nodes}}) if defined($first); } elsif ($which eq 'bottom') { my @matching = grep { $_->{type} == 5 } @{$output->{nodes}}; my $last = $matching[-1]; - @docked = (@docked, @{$last->{nodes}}); + @docked = (@docked, @{$last->{nodes}}) if defined($last); } } return @docked; @@ -355,17 +384,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) { - # 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} } # @@ -379,16 +410,22 @@ sub focused_ws { # See also docs/testsuite for a long explanation # sub sync_with_i3 { + my %args = @_ == 1 ? %{$_[0]} : @_; + # Since we need a (mapped) window for receiving a ClientMessage, we create # one on the first call of sync_with_i3. It will be re-used in all # subsequent calls. - if (!defined($_sync_window)) { + if (!exists($args{window_id}) && + (!defined($_sync_window) || exists($args{no_cache}))) { $_sync_window = open_window( rect => [ -15, -15, 10, 10 ], override_redirect => 1, ); } + my $window_id = delete $args{window_id}; + $window_id //= $_sync_window->id; + my $root = $x->get_root_window(); # Generate a random number to identify this particular ClientMessage. my $myrnd = int(rand(255)) + 1; @@ -401,7 +438,7 @@ sub sync_with_i3 { $root, # destination window $x->atom(name => 'I3_SYNC')->id, - $_sync_window->id, # data[0]: our own window id + $window_id, # data[0]: our own window id $myrnd, # data[1]: a random value to identify the request 0, 0, @@ -468,6 +505,9 @@ sub get_socket_path { my $cookie = $x->get_property(0, $x->get_root_window(), $atom->id, GET_PROPERTY_TYPE_ANY, 0, 256); my $reply = $x->get_property_reply($cookie->{sequence}); my $socketpath = $reply->{value}; + if ($socketpath eq "/tmp/nested-$ENV{DISPLAY}") { + $socketpath .= '-activation'; + } $_cached_socket_path = $socketpath; return $socketpath; } @@ -480,6 +520,8 @@ sub launch_with_config { $tmp_socket_path = "/tmp/nested-$ENV{DISPLAY}"; + $args{dont_create_temp_dir} //= 0; + my ($fh, $tmpfile) = tempfile("i3-cfg-for-$ENV{TESTNAME}-XXXXX", UNLINK => 1); if ($config ne '-default') { @@ -505,7 +547,9 @@ sub launch_with_config { testname => $ENV{TESTNAME}, valgrind => $ENV{VALGRIND}, strace => $ENV{STRACE}, + restart => $ENV{RESTART}, cv => $cv, + dont_create_temp_dir => $args{dont_create_temp_dir}, ); # force update of the cached socket path in lib/i3test @@ -520,6 +564,14 @@ sub launch_with_config { return $i3_pid; } +# compares two floats and return true if they differ less +# then 1e-6 +sub cmp_float { + my ($a, $b) = @_; + + return abs($a - $b) < 1e-6; +} + package i3test::X11; use parent 'X11::XCB::Connection';