tests: lib/i3test: Remove open_standard_window, introduce open_window

open_window has a better API than open_standard_window. It uses named
parameters and supplies default values for everything you don’t specify. This
way, you can use every feature which X11::XCB::Window supports.
This commit is contained in:
Michael Stapelberg 2011-09-24 15:11:37 +01:00
parent c3eb9f6c45
commit de5286da59
38 changed files with 207 additions and 386 deletions

View File

@ -12,8 +12,7 @@ fresh_workspace;
##################################################################### #####################################################################
# Create a window so we can get a focus different from NULL # Create a window so we can get a focus different from NULL
my $window = open_standard_window($x); my $window = open_window($x);
sync_with_i3($x);
my $focus = $x->input_focus; my $focus = $x->input_focus;

View File

@ -2,15 +2,9 @@
# vim:ts=4:sw=4:expandtab # vim:ts=4:sw=4:expandtab
use i3test; use i3test;
use X11::XCB qw(:all);
BEGIN {
use_ok('X11::XCB::Connection') or BAIL_OUT('Cannot load X11::XCB::Connection');
}
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $i3 = i3(get_socket_path());
my $tmp = fresh_workspace; my $tmp = fresh_workspace;
##################################################################### #####################################################################
@ -21,14 +15,9 @@ my $tmp = fresh_workspace;
cmd 'layout default'; cmd 'layout default';
cmd 'split v'; cmd 'split v';
my $top = open_standard_window($x); my $top = open_window($x);
my $mid = open_standard_window($x); my $mid = open_window($x);
my $bottom = open_standard_window($x); my $bottom = open_window($x);
##sleep 0.25;
diag("top id = " . $top->id);
diag("mid id = " . $mid->id);
diag("bottom id = " . $bottom->id);
# #
# Returns the input focus after sending the given command to i3 via IPC # Returns the input focus after sending the given command to i3 via IPC
@ -37,7 +26,8 @@ diag("bottom id = " . $bottom->id);
sub focus_after { sub focus_after {
my $msg = shift; my $msg = shift;
$i3->command($msg)->recv; cmd $msg;
sync_with_i3 $x;
return $x->input_focus; return $x->input_focus;
} }

View File

@ -7,28 +7,23 @@ use i3test;
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $i3 = i3(get_socket_path());
fresh_workspace; fresh_workspace;
cmd 'split h'; cmd 'split h';
my $tiled_left = open_standard_window($x); my $tiled_left = open_window($x);
my $tiled_right = open_standard_window($x); my $tiled_right = open_window($x);
sync_with_i3($x);
# Get input focus before creating the floating window # Get input focus before creating the floating window
my $focus = $x->input_focus; my $focus = $x->input_focus;
# Create a floating window which is smaller than the minimum enforced size of i3 # Create a floating window which is smaller than the minimum enforced size of i3
my $window = open_standard_window($x, undef, 1); my $window = open_floating_window($x);
sync_with_i3($x);
is($x->input_focus, $window->id, 'floating window focused'); is($x->input_focus, $window->id, 'floating window focused');
$window->unmap; $window->unmap;
# TODO: wait for unmap wait_for_unmap($x);
sync_with_i3($x);
is($x->input_focus, $focus, 'Focus correctly restored'); is($x->input_focus, $focus, 'Focus correctly restored');

View File

@ -29,18 +29,9 @@ my $screens = $x->screens;
my $primary = first { $_->primary } @{$screens}; my $primary = first { $_->primary } @{$screens};
# TODO: focus the primary screen before # TODO: focus the primary screen before
my $window = open_window($x, {
my $window = $x->root->create_child(
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 0, 30, 30],
background_color => '#FF0000',
window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
event_mask => [ 'structure_notify' ], });
);
$window->map;
wait_for_map $x;
my $rect = $window->rect; my $rect = $window->rect;
is($rect->width, $primary->rect->width, 'dock client is as wide as the screen'); is($rect->width, $primary->rect->width, 'dock client is as wide as the screen');
@ -91,17 +82,11 @@ is(@docked, 0, 'no more dock clients');
# check if it gets placed on bottom (by coordinates) # check if it gets placed on bottom (by coordinates)
##################################################################### #####################################################################
$window = $x->root->create_child( $window = open_window($x, {
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 1000, 30, 30 ], rect => [ 0, 1000, 30, 30 ],
background_color => '#FF0000', background_color => '#FF0000',
window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
event_mask => [ 'structure_notify' ], });
);
$window->map;
wait_for_map $x;
my $rect = $window->rect; my $rect = $window->rect;
is($rect->width, $primary->rect->width, 'dock client is as wide as the screen'); is($rect->width, $primary->rect->width, 'dock client is as wide as the screen');
@ -121,13 +106,12 @@ is(@docked, 0, 'no more dock clients');
# check if it gets placed on bottom (by hint) # check if it gets placed on bottom (by hint)
##################################################################### #####################################################################
$window = $x->root->create_child( $window = open_window($x, {
class => WINDOW_CLASS_INPUT_OUTPUT, dont_map => 1,
rect => [ 0, 1000, 30, 30 ], rect => [ 0, 1000, 30, 30 ],
background_color => '#FF0000', background_color => '#FF0000',
window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
event_mask => [ 'structure_notify' ], });
);
$window->_create(); $window->_create();
@ -159,13 +143,12 @@ wait_for_unmap $x;
@docked = get_dock_clients(); @docked = get_dock_clients();
is(@docked, 0, 'no more dock clients'); is(@docked, 0, 'no more dock clients');
$window = $x->root->create_child( $window = open_window($x, {
class => WINDOW_CLASS_INPUT_OUTPUT, dont_map => 1,
rect => [ 0, 1000, 30, 30 ], rect => [ 0, 1000, 30, 30 ],
background_color => '#FF0000', background_color => '#FF0000',
window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
event_mask => [ 'structure_notify' ], });
);
$window->_create(); $window->_create();
@ -197,13 +180,11 @@ $window->destroy;
# regression test: transient dock client # regression test: transient dock client
##################################################################### #####################################################################
my $fwindow = $x->root->create_child( $fwindow = open_window($x, {
class => WINDOW_CLASS_INPUT_OUTPUT, dont_map => 1,
rect => [ 0, 0, 30, 30],
background_color => '#FF0000', background_color => '#FF0000',
window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
event_mask => [ 'structure_notify' ], });
);
$fwindow->transient_for($window); $fwindow->transient_for($window);
$fwindow->map; $fwindow->map;

View File

@ -11,7 +11,6 @@ BEGIN {
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $i3 = i3(get_socket_path());
my $tmp = fresh_workspace; my $tmp = fresh_workspace;
cmd 'split h'; cmd 'split h';
@ -20,13 +19,9 @@ cmd 'split h';
# Create two windows and make sure focus switching works # Create two windows and make sure focus switching works
##################################################################### #####################################################################
my $top = open_standard_window($x); my $top = open_window($x);
my $mid = open_standard_window($x); my $mid = open_window($x);
my $bottom = open_standard_window($x); my $bottom = open_window($x);
diag("top id = " . $top->id);
diag("mid id = " . $mid->id);
diag("bottom id = " . $bottom->id);
# #
# Returns the input focus after sending the given command to i3 via IPC # Returns the input focus after sending the given command to i3 via IPC
@ -55,7 +50,7 @@ my $random_mark = sha1_base64(rand());
$focus = focus_after(qq|[con_mark="$random_mark"] focus|); $focus = focus_after(qq|[con_mark="$random_mark"] focus|);
is($focus, $mid->id, "focus unchanged"); is($focus, $mid->id, "focus unchanged");
$i3->command("mark $random_mark")->recv; cmd "mark $random_mark";
$focus = focus_after('focus left'); $focus = focus_after('focus left');
is($focus, $top->id, "Top window focused"); is($focus, $top->id, "Top window focused");

View File

@ -16,8 +16,7 @@ fresh_workspace;
# Create a floating window and see if resizing works # Create a floating window and see if resizing works
##################################################################### #####################################################################
# Create a floating window my $window = open_floating_window($x);
my $window = open_standard_window($x, undef, 1);
# See if configurerequests cause window movements (they should not) # See if configurerequests cause window movements (they should not)
my ($a, $t) = $window->rect; my ($a, $t) = $window->rect;

View File

@ -19,8 +19,8 @@ my $tmp = fresh_workspace;
cmd 'split v'; cmd 'split v';
my $top = open_standard_window($x); my $top = open_window($x);
my $bottom = open_standard_window($x); my $bottom = open_window($x);
my @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)}; my @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)};
is(@urgent, 0, 'no window got the urgent flag'); is(@urgent, 0, 'no window got the urgent flag');

View File

@ -20,40 +20,15 @@ my $tmp = fresh_workspace;
# one of both (depending on your screen resolution) will be positioned wrong. # one of both (depending on your screen resolution) will be positioned wrong.
#################################################################################### ####################################################################################
my $left = $x->root->create_child( my $left = open_window($x, { name => 'Left' });
class => WINDOW_CLASS_INPUT_OUTPUT, my $right = open_window($x, { name => 'Right' });
rect => [0, 0, 30, 30],
background_color => '#FF0000',
event_mask => [ 'structure_notify' ],
);
$left->name('Left');
$left->map;
my $right = $x->root->create_child(
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [0, 0, 30, 30],
background_color => '#FF0000',
event_mask => [ 'structure_notify' ],
);
$right->name('Right');
$right->map;
ok(wait_for_map($x), 'left window mapped');
ok(wait_for_map($x), 'right window mapped');
my ($abs, $rgeom) = $right->rect; my ($abs, $rgeom) = $right->rect;
my $child = $x->root->create_child( my $child = open_floating_window($x, {
class => WINDOW_CLASS_INPUT_OUTPUT, dont_map => 1,
rect => [ 0, 0, 30, 30 ], name => 'Child window',
background_color => '#C0C0C0', });
window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'),
event_mask => [ 'structure_notify' ],
);
$child->name('Child window');
$child->client_leader($right); $child->client_leader($right);
$child->map; $child->map;
@ -63,15 +38,10 @@ my $cgeom;
($abs, $cgeom) = $child->rect; ($abs, $cgeom) = $child->rect;
cmp_ok($cgeom->x, '>=', $rgeom->x, 'Child X >= right container X'); cmp_ok($cgeom->x, '>=', $rgeom->x, 'Child X >= right container X');
my $child2 = $x->root->create_child( my $child2 = open_floating_window($x, {
class => WINDOW_CLASS_INPUT_OUTPUT, dont_map => 1,
rect => [ 0, 0, 30, 30 ], name => 'Child window 2',
background_color => '#C0C0C0', });
window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'),
event_mask => [ 'structure_notify' ],
);
$child2->name('Child window 2');
$child2->client_leader($left); $child2->client_leader($left);
$child2->map; $child2->map;
@ -81,15 +51,7 @@ ok(wait_for_map($x), 'second child window mapped');
cmp_ok(($cgeom->x + $cgeom->width), '<', $rgeom->x, 'child above left window'); cmp_ok(($cgeom->x + $cgeom->width), '<', $rgeom->x, 'child above left window');
# check wm_transient_for # check wm_transient_for
my $fwindow = open_window($x, { dont_map => 1 });
my $fwindow = $x->root->create_child(
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 0, 30, 30],
background_color => '#FF0000',
event_mask => [ 'structure_notify' ],
);
$fwindow->transient_for($right); $fwindow->transient_for($right);
$fwindow->map; $fwindow->map;
@ -105,14 +67,7 @@ SKIP: {
# Create a parent window # Create a parent window
##################################################################### #####################################################################
my $window = $x->root->create_child( my $window = open_window($x, { dont_map => 1, name => 'Parent window' });
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 0, 30, 30 ],
background_color => '#C0C0C0',
event_mask => [ 'structure_notify' ],
);
$window->name('Parent window');
$window->map; $window->map;
ok(wait_for_map($x), 'parent window mapped'); ok(wait_for_map($x), 'parent window mapped');
@ -123,14 +78,7 @@ ok(wait_for_map($x), 'parent window mapped');
######################################################################### #########################################################################
fresh_workspace; fresh_workspace;
my $child = $x->root->create_child( my $child = open_window($x, { dont_map => 1, name => 'Child window' });
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 0, 30, 30 ],
background_color => '#C0C0C0',
event_mask => [ 'structure_notify' ],
);
$child->name('Child window');
$child->client_leader($window); $child->client_leader($window);
$child->map; $child->map;

View File

@ -12,7 +12,7 @@ ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
# Open a new window # Open a new window
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $window = open_standard_window($x); my $window = open_window($x);
my $content = get_ws_content($tmp); my $content = get_ws_content($tmp);
ok(@{$content} == 1, 'window mapped'); ok(@{$content} == 1, 'window mapped');
my $win = $content->[0]; my $win = $content->[0];

View File

@ -102,7 +102,7 @@ $first = open_empty_con($i3);
$middle = open_empty_con($i3); $middle = open_empty_con($i3);
# XXX: the $right empty con will be filled with the x11 window we are creating afterwards # XXX: the $right empty con will be filled with the x11 window we are creating afterwards
$right = open_empty_con($i3); $right = open_empty_con($i3);
my $win = open_standard_window($x, '#00ff00'); my $win = open_window($x, { background_color => '#00ff00' });
cmd qq|[con_id="$middle"] focus|; cmd qq|[con_id="$middle"] focus|;
$win->destroy; $win->destroy;

View File

@ -11,13 +11,7 @@ my $tmp = fresh_workspace;
ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
my $win = $x->root->create_child( my $win = open_window($x, { dont_map => 1 });
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30),
background_color => '#C0C0C0',
event_mask => [ 'structure_notify' ],
);
# XXX: we should check screen size. in screens with an AR of 2.0, # XXX: we should check screen size. in screens with an AR of 2.0,
# this is not a good idea. # this is not a good idea.
my $aspect = X11::XCB::Sizehints::Aspect->new; my $aspect = X11::XCB::Sizehints::Aspect->new;

View File

@ -13,10 +13,8 @@ my $tmp = fresh_workspace;
# 1: see if focus stays the same when toggling tiling/floating mode # 1: see if focus stays the same when toggling tiling/floating mode
############################################################################# #############################################################################
my $first = open_standard_window($x); my $first = open_window($x);
my $second = open_standard_window($x); my $second = open_window($x);
sync_with_i3($x);
is($x->input_focus, $second->id, 'second window focused'); is($x->input_focus, $second->id, 'second window focused');
@ -32,11 +30,9 @@ is($x->input_focus, $second->id, 'second window still focused after mode toggle'
$tmp = fresh_workspace; $tmp = fresh_workspace;
$first = open_standard_window($x); # window 2 $first = open_window($x); # window 2
$second = open_standard_window($x); # window 3 $second = open_window($x); # window 3
my $third = open_standard_window($x); # window 4 my $third = open_window($x); # window 4
sync_with_i3($x);
is($x->input_focus, $third->id, 'last container focused'); is($x->input_focus, $third->id, 'last container focused');
@ -66,11 +62,9 @@ is($x->input_focus, $second->id, 'second con still focused after killing third')
$tmp = fresh_workspace; $tmp = fresh_workspace;
$first = open_standard_window($x, '#ff0000'); # window 5 $first = open_window($x, '#ff0000'); # window 5
$second = open_standard_window($x, '#00ff00'); # window 6 $second = open_window($x, '#00ff00'); # window 6
my $third = open_standard_window($x, '#0000ff'); # window 7 my $third = open_window($x, '#0000ff'); # window 7
sync_with_i3($x);
is($x->input_focus, $third->id, 'last container focused'); is($x->input_focus, $third->id, 'last container focused');
@ -105,13 +99,11 @@ is($x->input_focus, $first->id, 'first con focused after killing all floating co
$tmp = fresh_workspace; $tmp = fresh_workspace;
$first = open_standard_window($x, '#ff0000'); # window 5 $first = open_window($x, { background_color => '#ff0000' }); # window 5
cmd 'split v'; cmd 'split v';
cmd 'layout stacked'; cmd 'layout stacked';
$second = open_standard_window($x, '#00ff00'); # window 6 $second = open_window($x, { background_color => '#00ff00' }); # window 6
$third = open_standard_window($x, '#0000ff'); # window 7 $third = open_window($x, { background_color => '#0000ff' }); # window 7
sync_with_i3($x);
is($x->input_focus, $third->id, 'last container focused'); is($x->input_focus, $third->id, 'last container focused');
@ -148,8 +140,8 @@ is($x->input_focus, $first->id, 'first con focused after killing all floating co
$tmp = fresh_workspace; $tmp = fresh_workspace;
$first = open_standard_window($x, '#ff0000'); # window 8 $first = open_window($x, { background_color => '#ff0000' }); # window 8
$second = open_standard_window($x, '#00ff00'); # window 9 $second = open_window($x, { background_color => '#00ff00' }); # window 9
sync_with_i3($x); sync_with_i3($x);
@ -195,9 +187,9 @@ is($x->input_focus, $second->id, 'second (floating) container focused');
$tmp = fresh_workspace; $tmp = fresh_workspace;
$first = open_standard_window($x, '#ff0000', 1); # window 10 $first = open_floating_window($x, { background_color => '#ff0000' });# window 10
$second = open_standard_window($x, '#00ff00', 1); # window 11 $second = open_floating_window($x, { background_color => '#00ff00' }); # window 11
$third = open_standard_window($x, '#0000ff', 1); # window 12 $third = open_floating_window($x, { background_color => '#0000ff' }); # window 12
sync_with_i3($x); sync_with_i3($x);

View File

@ -22,7 +22,7 @@ ok(workspace_exists($tmp), "workspace $tmp exists");
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
# Create a floating window which is smaller than the minimum enforced size of i3 # Create a floating window which is smaller than the minimum enforced size of i3
my $window = open_standard_window($x, undef, 1); my $window = open_floating_window($x);
ok($window->mapped, 'Window is mapped'); ok($window->mapped, 'Window is mapped');
# switch to a different workspace, see if the window is still mapped? # switch to a different workspace, see if the window is still mapped?

View File

@ -21,7 +21,7 @@ my $tmp = fresh_workspace;
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
# Create a floating window which is smaller than the minimum enforced size of i3 # Create a floating window which is smaller than the minimum enforced size of i3
my $window = open_standard_window($x, undef, 1); my $window = open_floating_window($x);
ok($window->mapped, 'Window is mapped'); ok($window->mapped, 'Window is mapped');
# switch to a different workspace, see if the window is still mapped? # switch to a different workspace, see if the window is still mapped?

View File

@ -21,7 +21,7 @@ my $tmp = fresh_workspace;
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
# Create a floating window # Create a floating window
my $window = open_standard_window($x, undef, 1); my $window = open_floating_window($x);
ok($window->mapped, 'Window is mapped'); ok($window->mapped, 'Window is mapped');
my $ws = get_ws($tmp); my $ws = get_ws($tmp);
@ -31,7 +31,7 @@ is(@{$ws->{floating_nodes}}, 1, 'one floating node');
is(@{$nodes}, 0, 'no tiling nodes'); is(@{$nodes}, 0, 'no tiling nodes');
# Create a tiling window # Create a tiling window
my $twindow = open_standard_window($x); my $twindow = open_window($x);
($nodes, $focus) = get_ws_content($tmp); ($nodes, $focus) = get_ws_content($tmp);
@ -44,8 +44,8 @@ is(@{$nodes}, 1, 'one tiling node');
$tmp = fresh_workspace; $tmp = fresh_workspace;
my $first = open_standard_window($x); my $first = open_window($x);
my $second = open_standard_window($x); my $second = open_window($x);
cmd 'layout stacked'; cmd 'layout stacked';
@ -54,14 +54,14 @@ is(@{$ws->{floating_nodes}}, 0, 'no floating nodes so far');
is(@{$ws->{nodes}}, 1, 'one tiling node (stacked con)'); is(@{$ws->{nodes}}, 1, 'one tiling node (stacked con)');
# Create a floating window # Create a floating window
my $window = open_standard_window($x, undef, 1); my $window = open_floating_window($x);
ok($window->mapped, 'Window is mapped'); ok($window->mapped, 'Window is mapped');
$ws = get_ws($tmp); $ws = get_ws($tmp);
is(@{$ws->{floating_nodes}}, 1, 'one floating nodes'); is(@{$ws->{floating_nodes}}, 1, 'one floating nodes');
is(@{$ws->{nodes}}, 1, 'one tiling node (stacked con)'); is(@{$ws->{nodes}}, 1, 'one tiling node (stacked con)');
my $third = open_standard_window($x); my $third = open_window($x);
$ws = get_ws($tmp); $ws = get_ws($tmp);

View File

@ -30,7 +30,7 @@ check_order('workspace order alright before testing');
cmd "workspace 93"; cmd "workspace 93";
open_standard_window($x); open_window($x);
my @ws = @{$i3->get_workspaces->recv}; my @ws = @{$i3->get_workspaces->recv};
my @f = grep { defined($_->{num}) && $_->{num} == 93 } @ws; my @f = grep { defined($_->{num}) && $_->{num} == 93 } @ws;
@ -38,23 +38,23 @@ is(@f, 1, 'ws 93 found by num');
check_order('workspace order alright after opening 93'); check_order('workspace order alright after opening 93');
cmd "workspace 92"; cmd "workspace 92";
open_standard_window($x); open_window($x);
check_order('workspace order alright after opening 92'); check_order('workspace order alright after opening 92');
cmd "workspace 94"; cmd "workspace 94";
open_standard_window($x); open_window($x);
check_order('workspace order alright after opening 94'); check_order('workspace order alright after opening 94');
cmd "workspace 96"; cmd "workspace 96";
open_standard_window($x); open_window($x);
check_order('workspace order alright after opening 96'); check_order('workspace order alright after opening 96');
cmd "workspace foo"; cmd "workspace foo";
open_standard_window($x); open_window($x);
check_order('workspace order alright after opening foo'); check_order('workspace order alright after opening foo');
cmd "workspace 91"; cmd "workspace 91";
open_standard_window($x); open_window($x);
check_order('workspace order alright after opening 91'); check_order('workspace order alright after opening 91');
done_testing; done_testing;

View File

@ -24,9 +24,9 @@ sub check_order {
my $tmp = fresh_workspace; my $tmp = fresh_workspace;
my $left = open_standard_window($x); my $left = open_window($x);
my $mid = open_standard_window($x); my $mid = open_window($x);
my $right = open_standard_window($x); my $right = open_window($x);
sync_with_i3($x); sync_with_i3($x);

View File

@ -14,8 +14,8 @@ my $tmp = fresh_workspace;
cmd 'split v'; cmd 'split v';
my $top = open_standard_window($x); my $top = open_window($x);
my $bottom = open_standard_window($x); my $bottom = open_window($x);
sync_with_i3($x); sync_with_i3($x);
@ -54,8 +54,8 @@ $tmp = fresh_workspace;
cmd 'split v'; cmd 'split v';
$top = open_standard_window($x); $top = open_window($x);
$bottom = open_standard_window($x); $bottom = open_window($x);
cmd 'split h'; cmd 'split h';
cmd 'layout stacked'; cmd 'layout stacked';
@ -76,7 +76,7 @@ is($nodes->[1]->{percent}, 0.75, 'bottom window got 75%');
$tmp = fresh_workspace; $tmp = fresh_workspace;
$top = open_standard_window($x); $top = open_window($x);
cmd 'floating enable'; cmd 'floating enable';

View File

@ -17,9 +17,9 @@ my $x = X11::XCB::Connection->new;
my $tmp = fresh_workspace; my $tmp = fresh_workspace;
my $left = open_standard_window($x); my $left = open_window($x);
my $mid = open_standard_window($x); my $mid = open_window($x);
my $right = open_standard_window($x); my $right = open_window($x);
cmd 'move before v'; cmd 'move before v';
cmd 'move after h'; cmd 'move after h';

View File

@ -12,11 +12,11 @@ my $x = X11::XCB::Connection->new;
my $tmp = fresh_workspace; my $tmp = fresh_workspace;
my $left = open_standard_window($x); my $left = open_window($x);
my $mid = open_standard_window($x); my $mid = open_window($x);
cmd 'split v'; cmd 'split v';
my $bottom = open_standard_window($x); my $bottom = open_window($x);
my ($nodes, $focus) = get_ws_content($tmp); my ($nodes, $focus) = get_ws_content($tmp);
@ -24,10 +24,8 @@ my ($nodes, $focus) = get_ws_content($tmp);
# 1: open a floating window, get it mapped # 1: open a floating window, get it mapped
############################################################################# #############################################################################
my $x = X11::XCB::Connection->new;
# Create a floating window # Create a floating window
my $window = open_standard_window($x, undef, 1); my $window = open_floating_window($x);
ok($window->mapped, 'Window is mapped'); ok($window->mapped, 'Window is mapped');
($nodes, $focus) = get_ws_content($tmp); ($nodes, $focus) = get_ws_content($tmp);

View File

@ -16,9 +16,9 @@ my $x = X11::XCB::Connection->new;
my $tmp = fresh_workspace; my $tmp = fresh_workspace;
my $left = open_standard_window($x); my $left = open_window($x);
my $mid = open_standard_window($x); my $mid = open_window($x);
my $right = open_standard_window($x); my $right = open_window($x);
# go to workspace level # go to workspace level
cmd 'level up'; cmd 'level up';

View File

@ -16,13 +16,13 @@ my $x = X11::XCB::Connection->new;
my $tmp = fresh_workspace; my $tmp = fresh_workspace;
# open a tiling window on the first workspace # open a tiling window on the first workspace
open_standard_window($x); open_window($x);
#sleep 0.25; #sleep 0.25;
my $first = get_focused($tmp); my $first = get_focused($tmp);
# on a different ws, open a floating window # on a different ws, open a floating window
my $otmp = fresh_workspace; my $otmp = fresh_workspace;
open_standard_window($x); open_window($x);
#sleep 0.25; #sleep 0.25;
my $float = get_focused($otmp); my $float = get_focused($otmp);
cmd 'mode toggle'; cmd 'mode toggle';

View File

@ -11,7 +11,6 @@ BEGIN {
} }
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $i3 = i3(get_socket_path());
my $tmp = fresh_workspace; my $tmp = fresh_workspace;
@ -26,17 +25,10 @@ is(@docked, 0, 'no dock clients yet');
# open a dock client # open a dock client
my $window = $x->root->create_child( my $window = open_window($x, {
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 0, 30, 30],
background_color => '#FF0000', background_color => '#FF0000',
window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
event_mask => [ 'structure_notify' ], });
);
$window->map;
wait_for_map $x;
##################################################################### #####################################################################
# check that we can find it in the layout tree at the expected position # check that we can find it in the layout tree at the expected position
@ -79,18 +71,12 @@ is(@docked, 0, 'no dock clients found');
# create a dock client with a 1px border # create a dock client with a 1px border
##################################################################### #####################################################################
$window = $x->root->create_child( $window = open_window($x, {
class => WINDOW_CLASS_INPUT_OUTPUT,
border => 1, border => 1,
rect => [ 0, 0, 30, 20 ], rect => [ 0, 0, 30, 20 ],
background_color => '#00FF00', background_color => '#00FF00',
window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
event_mask => [ 'structure_notify' ], });
);
$window->map;
wait_for_map $x;
@docked = get_dock_clients; @docked = get_dock_clients;
is(@docked, 1, 'one dock client found'); is(@docked, 1, 'one dock client found');

View File

@ -11,18 +11,7 @@ my $tmp = fresh_workspace;
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
# Create a floating window which is smaller than the minimum enforced size of i3 # Create a floating window which is smaller than the minimum enforced size of i3
my $window = $x->root->create_child( my $window = open_window($x, { rect => [ 0, 0, 400, 150 ] });
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 0, 400, 150],
background_color => '#C0C0C0',
event_mask => [ 'structure_notify' ],
);
isa_ok($window, 'X11::XCB::Window');
$window->map;
wait_for_map $x;
my ($absolute, $top) = $window->rect; my ($absolute, $top) = $window->rect;

View File

@ -27,33 +27,19 @@ is(@docked, 0, 'no dock clients yet');
# open a dock client # open a dock client
##################################################################### #####################################################################
my $first = $x->root->create_child( my $first = open_window($x, {
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 0, 30, 30],
background_color => '#FF0000', background_color => '#FF0000',
window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
event_mask => [ 'structure_notify' ], });
);
$first->map;
wait_for_map $x;
##################################################################### #####################################################################
# Open a second dock client # Open a second dock client
##################################################################### #####################################################################
my $second = $x->root->create_child( my $second = open_window($x, {
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 0, 30, 30],
background_color => '#FF0000', background_color => '#FF0000',
window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'),
event_mask => [ 'structure_notify' ], });
);
$second->map;
wait_for_map $x;
##################################################################### #####################################################################
# Kill the second dock client # Kill the second dock client

View File

@ -19,31 +19,19 @@ my $tmp = fresh_workspace;
# open a window with 200x80 # open a window with 200x80
##################################################################### #####################################################################
my $first = $x->root->create_child( my $first = open_window($x, {
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 0, 200, 80], rect => [ 0, 0, 200, 80],
background_color => '#FF0000', background_color => '#FF0000',
event_mask => [ 'structure_notify' ], });
);
$first->map;
wait_for_map $x;
##################################################################### #####################################################################
# Open a second window with 300x90 # Open a second window with 300x90
##################################################################### #####################################################################
my $second = $x->root->create_child( my $second = open_window($x, {
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 0, 300, 90], rect => [ 0, 0, 300, 90],
background_color => '#00FF00', background_color => '#00FF00',
event_mask => [ 'structure_notify' ], });
);
$second->map;
wait_for_map $x;
##################################################################### #####################################################################
# Set the parent to floating # Set the parent to floating

View File

@ -20,7 +20,7 @@ my $tmp = fresh_workspace;
# open the left window # open the left window
##################################################################### #####################################################################
my $left = open_standard_window($x, '#ff0000'); my $left = open_window($x, { background_color => '#ff0000' });
is($x->input_focus, $left->id, 'left window focused'); is($x->input_focus, $left->id, 'left window focused');
@ -30,7 +30,7 @@ diag("left = " . $left->id);
# Open the right window # Open the right window
##################################################################### #####################################################################
my $right = open_standard_window($x, '#00ff00'); my $right = open_window($x, { background_color => '#00ff00' });
diag("right = " . $right->id); diag("right = " . $right->id);
@ -44,16 +44,12 @@ cmd 'fullscreen';
# Open a third window # Open a third window
##################################################################### #####################################################################
#my $third = open_standard_window($x, '#0000ff'); my $third = open_window($x, {
my $third = $x->root->create_child(
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30 ),
background_color => '#0000ff', background_color => '#0000ff',
event_mask => [ 'structure_notify' ], name => 'Third window',
); dont_map => 1,
});
$third->name('Third window');
$third->map; $third->map;
sync_with_i3 $x; sync_with_i3 $x;

View File

@ -11,7 +11,6 @@ BEGIN {
} }
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $i3 = i3(get_socket_path());
my $tmp = fresh_workspace; my $tmp = fresh_workspace;
@ -19,7 +18,7 @@ my $tmp = fresh_workspace;
# open a window, verify its not in fullscreen mode # open a window, verify its not in fullscreen mode
##################################################################### #####################################################################
my $win = open_standard_window($x); my $win = open_window($x);
my $nodes = get_ws_content $tmp; my $nodes = get_ws_content $tmp;
is(@$nodes, 1, 'exactly one client'); is(@$nodes, 1, 'exactly one client');

View File

@ -17,7 +17,6 @@ BEGIN {
} }
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $i3 = i3(get_socket_path());
subtest 'Window without WM_TAKE_FOCUS', sub { subtest 'Window without WM_TAKE_FOCUS', sub {

View File

@ -12,7 +12,7 @@ use i3test;
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $i3 = i3(get_socket_path()); my $i3 = i3(get_socket_path());
my $tmp = fresh_workspace; my $tmp = fresh_workspace;
my $window = open_standard_window($x); my $window = open_window($x);
sub get_border_style { sub get_border_style {
my @content = @{get_ws_content($tmp)}; my @content = @{get_ws_content($tmp)};

View File

@ -7,27 +7,17 @@
use X11::XCB qw(:all); use X11::XCB qw(:all);
use i3test; use i3test;
BEGIN {
use_ok('X11::XCB::Window');
use_ok('X11::XCB::Event::Generic');
use_ok('X11::XCB::Event::MapNotify');
use_ok('X11::XCB::Event::ClientMessage');
}
my $x = X11::XCB::Connection->new; my $x = X11::XCB::Connection->new;
my $window = open_standard_window($x); my $window = open_window($x);
sync_with_i3($x); sync_with_i3($x);
diag('window mapped');
is($window->state, ICCCM_WM_STATE_NORMAL, 'WM_STATE normal'); is($window->state, ICCCM_WM_STATE_NORMAL, 'WM_STATE normal');
$window->unmap; $window->unmap;
# TODO: wait for unmapnotify wait_for_unmap $x;
sync_with_i3($x);
is($window->state, ICCCM_WM_STATE_WITHDRAWN, 'WM_STATE withdrawn'); is($window->state, ICCCM_WM_STATE_WITHDRAWN, 'WM_STATE withdrawn');

View File

@ -13,8 +13,8 @@ sub two_windows {
ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
my $first = open_standard_window($x); my $first = open_window($x);
my $second = open_standard_window($x); my $second = open_window($x);
sync_with_i3 $x; sync_with_i3 $x;

View File

@ -186,7 +186,7 @@ wait_for_map $x;
cmp_ok(@content, '==', 1, 'one node on this workspace now'); cmp_ok(@content, '==', 1, 'one node on this workspace now');
is($content[0]->{border}, 'none', 'no border'); is($content[0]->{border}, 'none', 'no border');
my $other = open_standard_window($x); my $other = open_window($x);
@content = @{get_ws_content($tmp)}; @content = @{get_ws_content($tmp)};
cmp_ok(@content, '==', 2, 'two nodes'); cmp_ok(@content, '==', 2, 'two nodes');

View File

@ -27,8 +27,8 @@ my $tmp = fresh_workspace;
ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
my $first = open_standard_window($x); my $first = open_window($x);
my $second = open_standard_window($x); my $second = open_window($x);
sync_with_i3($x); sync_with_i3($x);
@ -56,8 +56,8 @@ $tmp = fresh_workspace;
ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
$first = open_standard_window($x); $first = open_window($x);
$second = open_standard_window($x); $second = open_window($x);
sync_with_i3($x); sync_with_i3($x);
@ -72,8 +72,8 @@ is($content[0]->{layout}, 'stacked', 'layout stacked');
##################################################################### #####################################################################
cmd 'focus parent'; cmd 'focus parent';
my $right_top = open_standard_window($x); my $right_top = open_window($x);
my $right_bot = open_standard_window($x); my $right_bot = open_window($x);
@content = @{get_ws_content($tmp)}; @content = @{get_ws_content($tmp)};
is(@content, 2, 'two cons at workspace level after focus parent'); is(@content, 2, 'two cons at workspace level after focus parent');

View File

@ -11,8 +11,8 @@ my $x = X11::XCB::Connection->new;
fresh_workspace; fresh_workspace;
open_standard_window($x); open_window($x);
open_standard_window($x); open_window($x);
cmd 'layout stacking'; cmd 'layout stacking';
sleep 1; sleep 1;

View File

@ -25,13 +25,13 @@ my $tmp = fresh_workspace;
ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
my $first = open_standard_window($x); my $first = open_window($x);
my $second = open_standard_window($x); my $second = open_window($x);
cmd 'layout tabbed'; cmd 'layout tabbed';
cmd 'focus parent'; cmd 'focus parent';
my $third = open_standard_window($x); my $third = open_window($x);
is($x->input_focus, $third->id, 'third window focused'); is($x->input_focus, $third->id, 'third window focused');
cmd 'focus left'; cmd 'focus left';
@ -66,13 +66,13 @@ $tmp = fresh_workspace;
ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
$first = open_standard_window($x); $first = open_window($x);
$second = open_standard_window($x); $second = open_window($x);
cmd 'layout tabbed'; cmd 'layout tabbed';
cmd 'focus parent'; cmd 'focus parent';
$third = open_standard_window($x); $third = open_window($x);
sync_with_i3($x); sync_with_i3($x);

View File

@ -25,7 +25,7 @@ my $tmp = fresh_workspace;
ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
my $first = open_standard_window($x); my $first = open_window($x);
my @content = @{get_ws_content($tmp)}; my @content = @{get_ws_content($tmp)};
ok(@content == 1, 'one container opened'); ok(@content == 1, 'one container opened');
@ -51,7 +51,7 @@ $tmp = fresh_workspace;
ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
$first = open_standard_window($x); $first = open_window($x);
@content = @{get_ws_content($tmp)}; @content = @{get_ws_content($tmp)};
ok(@content == 1, 'one container opened'); ok(@content == 1, 'one container opened');
@ -75,19 +75,7 @@ $tmp = fresh_workspace;
ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
# Create a floating window which is smaller than the minimum enforced size of i3 $first = open_floating_window($x);
$first = $x->root->create_child(
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 0, 30, 30],
background_color => '#C0C0C0',
# replace the type with 'utility' as soon as the coercion works again in X11::XCB
window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'),
event_mask => [ 'structure_notify' ],
);
$first->map;
wait_for_map $x;
my $wscontent = get_ws($tmp); my $wscontent = get_ws($tmp);
my @floating = @{$wscontent->{floating_nodes}}; my @floating = @{$wscontent->{floating_nodes}};
@ -115,19 +103,7 @@ $tmp = fresh_workspace;
ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); ok(@{get_ws_content($tmp)} == 0, 'no containers yet');
# Create a floating window which is smaller than the minimum enforced size of i3 $first = open_floating_window($x);
$first = $x->root->create_child(
class => WINDOW_CLASS_INPUT_OUTPUT,
rect => [ 0, 0, 30, 30],
background_color => '#C0C0C0',
# replace the type with 'utility' as soon as the coercion works again in X11::XCB
window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'),
event_mask => [ 'structure_notify' ],
);
$first->map;
wait_for_map $x;
$wscontent = get_ws($tmp); $wscontent = get_ws($tmp);
@floating = @{$wscontent->{floating_nodes}}; @floating = @{$wscontent->{floating_nodes}};

View File

@ -26,7 +26,8 @@ our @EXPORT = qw(
get_ws get_ws
get_focused get_focused
open_empty_con open_empty_con
open_standard_window open_window
open_floating_window
get_dock_clients get_dock_clients
cmd cmd
sync_with_i3 sync_with_i3
@ -124,31 +125,51 @@ sub wait_for_unmap {
sync_with_i3($x); sync_with_i3($x);
} }
sub open_standard_window { #
my ($x, $color, $floating) = @_; # Opens a new window (see X11::XCB::Window), maps it, waits until it got mapped
# and synchronizes with i3.
#
# set dont_map to a true value to avoid mapping
#
# default values:
# class => WINDOW_CLASS_INPUT_OUTPUT
# rect => [ 0, 0, 30, 30 ]
# background_color => '#c0c0c0'
# event_mask => [ 'structure_notify' ]
# name => 'Window <n>'
#
sub open_window {
my ($x, $args) = @_;
my %args = ($args ? %$args : ());
$color ||= '#c0c0c0'; my $dont_map = delete $args{dont_map};
# We cannot use a hashref here because create_child expands the arguments into an array $args{class} = WINDOW_CLASS_INPUT_OUTPUT unless exists $args{class};
my @args = ( $args{rect} = [ 0, 0, 30, 30 ] unless exists $args{rect};
class => WINDOW_CLASS_INPUT_OUTPUT, $args{background_color} = '#c0c0c0' unless exists $args{background_color};
rect => X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30 ), $args{event_mask} = [ 'structure_notify' ] unless exists $args{event_mask};
background_color => $color, $args{name} = 'Window ' . counter_window() unless exists $args{name};
event_mask => [ 'structure_notify' ],
);
if (defined($floating) && $floating) { my $window = $x->root->create_child(%args);
@args = (@args, window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'));
return $window if $dont_map;
$window->map;
wait_for_map($x);
# We sync with i3 here to make sure $x->input_focus is updated.
sync_with_i3($x);
return $window;
} }
my $window = $x->root->create_child(@args); # Thin wrapper around open_window which sets window_type to
# _NET_WM_WINDOW_TYPE_UTILITY to make the window floating.
sub open_floating_window {
my ($x, $args) = @_;
my %args = ($args ? %$args : ());
$window->name('Window ' . counter_window()); $args{window_type} = $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY');
$window->map;
wait_for_event $x, 0.5, sub { $_[0]->{response_type} == MAP_NOTIFY }; return open_window($x, \%args);
return $window;
} }
sub open_empty_con { sub open_empty_con {