From de5286da594cf2dd7677ee7b0e1da3a2a4991013 Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Sat, 24 Sep 2011 15:11:37 +0100 Subject: [PATCH] tests: lib/i3test: Remove open_standard_window, introduce open_window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- testcases/t/05-ipc.t | 3 +- testcases/t/06-focus.t | 20 ++--- testcases/t/08-focus-stack.t | 13 +--- testcases/t/10-dock.t | 69 +++++++---------- testcases/t/11-goto.t | 13 +--- testcases/t/12-floating-resize.t | 3 +- testcases/t/13-urgent.t | 4 +- testcases/t/14-client-leader.t | 78 ++++---------------- testcases/t/19-match.t | 2 +- testcases/t/29-focus-after-close.t | 2 +- testcases/t/33-size-hints.t | 8 +- testcases/t/35-floating-focus.t | 40 ++++------ testcases/t/36-floating-ws-empty.t | 2 +- testcases/t/37-floating-unmap.t | 2 +- testcases/t/38-floating-attach.t | 12 +-- testcases/t/39-ws-numbers.t | 12 +-- testcases/t/40-focus-lost.t | 6 +- testcases/t/41-resize.t | 10 +-- testcases/t/45-flattening.t | 6 +- testcases/t/46-floating-reinsert.t | 10 +-- testcases/t/47-regress-floatingmove.t | 6 +- testcases/t/48-regress-floatingmovews.t | 4 +- testcases/t/50-regress-dock-restart.t | 34 +++------ testcases/t/53-floating-originalsize.t | 13 +--- testcases/t/54-regress-multiple-dock.t | 30 ++------ testcases/t/55-floating-split-size.t | 28 ++----- testcases/t/56-fullscreen-focus.t | 18 ++--- testcases/t/57-regress-fullscreen-level-up.t | 3 +- testcases/t/58-wm_take_focus.t | 1 - testcases/t/61-regress-borders-restart.t | 2 +- testcases/t/63-wm-state.t | 14 +--- testcases/t/64-kill-win-vs-client.t | 4 +- testcases/t/65-for_window.t | 2 +- testcases/t/67-workspace_layout.t | 12 +-- testcases/t/68-regress-fullscreen-restart.t | 4 +- testcases/t/70-force_focus_wrapping.t | 12 +-- testcases/t/74-border-config.t | 32 +------- testcases/t/lib/i3test.pm | 59 ++++++++++----- 38 files changed, 207 insertions(+), 386 deletions(-) diff --git a/testcases/t/05-ipc.t b/testcases/t/05-ipc.t index 0d18040e..982ece7e 100644 --- a/testcases/t/05-ipc.t +++ b/testcases/t/05-ipc.t @@ -12,8 +12,7 @@ fresh_workspace; ##################################################################### # Create a window so we can get a focus different from NULL -my $window = open_standard_window($x); -sync_with_i3($x); +my $window = open_window($x); my $focus = $x->input_focus; diff --git a/testcases/t/06-focus.t b/testcases/t/06-focus.t index b3add322..5ded494f 100644 --- a/testcases/t/06-focus.t +++ b/testcases/t/06-focus.t @@ -2,15 +2,9 @@ # vim:ts=4:sw=4:expandtab 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 $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; ##################################################################### @@ -21,14 +15,9 @@ my $tmp = fresh_workspace; cmd 'layout default'; cmd 'split v'; -my $top = open_standard_window($x); -my $mid = open_standard_window($x); -my $bottom = open_standard_window($x); -##sleep 0.25; - -diag("top id = " . $top->id); -diag("mid id = " . $mid->id); -diag("bottom id = " . $bottom->id); +my $top = open_window($x); +my $mid = open_window($x); +my $bottom = open_window($x); # # 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 { my $msg = shift; - $i3->command($msg)->recv; + cmd $msg; + sync_with_i3 $x; return $x->input_focus; } diff --git a/testcases/t/08-focus-stack.t b/testcases/t/08-focus-stack.t index 33a5884a..b5be284c 100644 --- a/testcases/t/08-focus-stack.t +++ b/testcases/t/08-focus-stack.t @@ -7,28 +7,23 @@ use i3test; my $x = X11::XCB::Connection->new; -my $i3 = i3(get_socket_path()); fresh_workspace; cmd 'split h'; -my $tiled_left = open_standard_window($x); -my $tiled_right = open_standard_window($x); - -sync_with_i3($x); +my $tiled_left = open_window($x); +my $tiled_right = open_window($x); # Get input focus before creating the floating window my $focus = $x->input_focus; # Create a floating window which is smaller than the minimum enforced size of i3 -my $window = open_standard_window($x, undef, 1); -sync_with_i3($x); +my $window = open_floating_window($x); is($x->input_focus, $window->id, 'floating window focused'); $window->unmap; -# TODO: wait for unmap -sync_with_i3($x); +wait_for_unmap($x); is($x->input_focus, $focus, 'Focus correctly restored'); diff --git a/testcases/t/10-dock.t b/testcases/t/10-dock.t index 988d92db..cad54c26 100644 --- a/testcases/t/10-dock.t +++ b/testcases/t/10-dock.t @@ -29,18 +29,9 @@ my $screens = $x->screens; my $primary = first { $_->primary } @{$screens}; # TODO: focus the primary screen before - -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'), - event_mask => [ 'structure_notify' ], -); - -$window->map; - -wait_for_map $x; +my $window = open_window($x, { + window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), + }); my $rect = $window->rect; 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) ##################################################################### -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 1000, 30, 30], - background_color => '#FF0000', - window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), - event_mask => [ 'structure_notify' ], -); - -$window->map; - -wait_for_map $x; +$window = open_window($x, { + rect => [ 0, 1000, 30, 30 ], + background_color => '#FF0000', + window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), + }); my $rect = $window->rect; 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) ##################################################################### -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 1000, 30, 30], - background_color => '#FF0000', - window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), - event_mask => [ 'structure_notify' ], -); +$window = open_window($x, { + dont_map => 1, + rect => [ 0, 1000, 30, 30 ], + background_color => '#FF0000', + window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), + }); $window->_create(); @@ -159,13 +143,12 @@ wait_for_unmap $x; @docked = get_dock_clients(); is(@docked, 0, 'no more dock clients'); -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 1000, 30, 30], - background_color => '#FF0000', - window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), - event_mask => [ 'structure_notify' ], -); +$window = open_window($x, { + dont_map => 1, + rect => [ 0, 1000, 30, 30 ], + background_color => '#FF0000', + window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), + }); $window->_create(); @@ -197,13 +180,11 @@ $window->destroy; # regression test: transient dock client ##################################################################### -my $fwindow = $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'), - event_mask => [ 'structure_notify' ], -); +$fwindow = open_window($x, { + dont_map => 1, + background_color => '#FF0000', + window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), + }); $fwindow->transient_for($window); $fwindow->map; diff --git a/testcases/t/11-goto.t b/testcases/t/11-goto.t index 44cf55ab..5bec5892 100644 --- a/testcases/t/11-goto.t +++ b/testcases/t/11-goto.t @@ -11,7 +11,6 @@ BEGIN { my $x = X11::XCB::Connection->new; -my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; cmd 'split h'; @@ -20,13 +19,9 @@ cmd 'split h'; # Create two windows and make sure focus switching works ##################################################################### -my $top = open_standard_window($x); -my $mid = open_standard_window($x); -my $bottom = open_standard_window($x); - -diag("top id = " . $top->id); -diag("mid id = " . $mid->id); -diag("bottom id = " . $bottom->id); +my $top = open_window($x); +my $mid = open_window($x); +my $bottom = open_window($x); # # 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|); is($focus, $mid->id, "focus unchanged"); -$i3->command("mark $random_mark")->recv; +cmd "mark $random_mark"; $focus = focus_after('focus left'); is($focus, $top->id, "Top window focused"); diff --git a/testcases/t/12-floating-resize.t b/testcases/t/12-floating-resize.t index 1aec9573..ac3387a9 100644 --- a/testcases/t/12-floating-resize.t +++ b/testcases/t/12-floating-resize.t @@ -16,8 +16,7 @@ fresh_workspace; # Create a floating window and see if resizing works ##################################################################### -# Create a floating window -my $window = open_standard_window($x, undef, 1); +my $window = open_floating_window($x); # See if configurerequests cause window movements (they should not) my ($a, $t) = $window->rect; diff --git a/testcases/t/13-urgent.t b/testcases/t/13-urgent.t index 83c36a98..7954408f 100644 --- a/testcases/t/13-urgent.t +++ b/testcases/t/13-urgent.t @@ -19,8 +19,8 @@ my $tmp = fresh_workspace; cmd 'split v'; -my $top = open_standard_window($x); -my $bottom = open_standard_window($x); +my $top = open_window($x); +my $bottom = open_window($x); my @urgent = grep { $_->{urgent} } @{get_ws_content($tmp)}; is(@urgent, 0, 'no window got the urgent flag'); diff --git a/testcases/t/14-client-leader.t b/testcases/t/14-client-leader.t index 08deabf8..6f7ffce0 100644 --- a/testcases/t/14-client-leader.t +++ b/testcases/t/14-client-leader.t @@ -20,40 +20,15 @@ my $tmp = fresh_workspace; # one of both (depending on your screen resolution) will be positioned wrong. #################################################################################### -my $left = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - 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 $left = open_window($x, { name => 'Left' }); +my $right = open_window($x, { name => 'Right' }); my ($abs, $rgeom) = $right->rect; -my $child = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#C0C0C0', - window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'), - event_mask => [ 'structure_notify' ], -); - -$child->name('Child window'); +my $child = open_floating_window($x, { + dont_map => 1, + name => 'Child window', + }); $child->client_leader($right); $child->map; @@ -63,15 +38,10 @@ my $cgeom; ($abs, $cgeom) = $child->rect; cmp_ok($cgeom->x, '>=', $rgeom->x, 'Child X >= right container X'); -my $child2 = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#C0C0C0', - window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'), - event_mask => [ 'structure_notify' ], -); - -$child2->name('Child window 2'); +my $child2 = open_floating_window($x, { + dont_map => 1, + name => 'Child window 2', + }); $child2->client_leader($left); $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'); # check wm_transient_for - - -my $fwindow = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30], - background_color => '#FF0000', - event_mask => [ 'structure_notify' ], -); - +my $fwindow = open_window($x, { dont_map => 1 }); $fwindow->transient_for($right); $fwindow->map; @@ -105,14 +67,7 @@ SKIP: { # Create a parent window ##################################################################### -my $window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#C0C0C0', - event_mask => [ 'structure_notify' ], -); - -$window->name('Parent window'); +my $window = open_window($x, { dont_map => 1, name => 'Parent window' }); $window->map; ok(wait_for_map($x), 'parent window mapped'); @@ -123,14 +78,7 @@ ok(wait_for_map($x), 'parent window mapped'); ######################################################################### fresh_workspace; -my $child = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#C0C0C0', - event_mask => [ 'structure_notify' ], -); - -$child->name('Child window'); +my $child = open_window($x, { dont_map => 1, name => 'Child window' }); $child->client_leader($window); $child->map; diff --git a/testcases/t/19-match.t b/testcases/t/19-match.t index aab54456..8b9d21d3 100644 --- a/testcases/t/19-match.t +++ b/testcases/t/19-match.t @@ -12,7 +12,7 @@ ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); # Open a new window my $x = X11::XCB::Connection->new; -my $window = open_standard_window($x); +my $window = open_window($x); my $content = get_ws_content($tmp); ok(@{$content} == 1, 'window mapped'); my $win = $content->[0]; diff --git a/testcases/t/29-focus-after-close.t b/testcases/t/29-focus-after-close.t index ac029eb1..8d225613 100644 --- a/testcases/t/29-focus-after-close.t +++ b/testcases/t/29-focus-after-close.t @@ -102,7 +102,7 @@ $first = 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 $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|; $win->destroy; diff --git a/testcases/t/33-size-hints.t b/testcases/t/33-size-hints.t index 0d607dbc..d2d77e8e 100644 --- a/testcases/t/33-size-hints.t +++ b/testcases/t/33-size-hints.t @@ -11,13 +11,7 @@ my $tmp = fresh_workspace; ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); -my $win = $x->root->create_child( - 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' ], -); - +my $win = open_window($x, { dont_map => 1 }); # XXX: we should check screen size. in screens with an AR of 2.0, # this is not a good idea. my $aspect = X11::XCB::Sizehints::Aspect->new; diff --git a/testcases/t/35-floating-focus.t b/testcases/t/35-floating-focus.t index fc94c440..4c5b562f 100644 --- a/testcases/t/35-floating-focus.t +++ b/testcases/t/35-floating-focus.t @@ -13,10 +13,8 @@ my $tmp = fresh_workspace; # 1: see if focus stays the same when toggling tiling/floating mode ############################################################################# -my $first = open_standard_window($x); -my $second = open_standard_window($x); - -sync_with_i3($x); +my $first = open_window($x); +my $second = open_window($x); 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; -$first = open_standard_window($x); # window 2 -$second = open_standard_window($x); # window 3 -my $third = open_standard_window($x); # window 4 - -sync_with_i3($x); +$first = open_window($x); # window 2 +$second = open_window($x); # window 3 +my $third = open_window($x); # window 4 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; -$first = open_standard_window($x, '#ff0000'); # window 5 -$second = open_standard_window($x, '#00ff00'); # window 6 -my $third = open_standard_window($x, '#0000ff'); # window 7 - -sync_with_i3($x); +$first = open_window($x, '#ff0000'); # window 5 +$second = open_window($x, '#00ff00'); # window 6 +my $third = open_window($x, '#0000ff'); # window 7 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; -$first = open_standard_window($x, '#ff0000'); # window 5 +$first = open_window($x, { background_color => '#ff0000' }); # window 5 cmd 'split v'; cmd 'layout stacked'; -$second = open_standard_window($x, '#00ff00'); # window 6 -$third = open_standard_window($x, '#0000ff'); # window 7 - -sync_with_i3($x); +$second = open_window($x, { background_color => '#00ff00' }); # window 6 +$third = open_window($x, { background_color => '#0000ff' }); # window 7 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; -$first = open_standard_window($x, '#ff0000'); # window 8 -$second = open_standard_window($x, '#00ff00'); # window 9 +$first = open_window($x, { background_color => '#ff0000' }); # window 8 +$second = open_window($x, { background_color => '#00ff00' }); # window 9 sync_with_i3($x); @@ -195,9 +187,9 @@ is($x->input_focus, $second->id, 'second (floating) container focused'); $tmp = fresh_workspace; -$first = open_standard_window($x, '#ff0000', 1); # window 10 -$second = open_standard_window($x, '#00ff00', 1); # window 11 -$third = open_standard_window($x, '#0000ff', 1); # window 12 +$first = open_floating_window($x, { background_color => '#ff0000' });# window 10 +$second = open_floating_window($x, { background_color => '#00ff00' }); # window 11 +$third = open_floating_window($x, { background_color => '#0000ff' }); # window 12 sync_with_i3($x); diff --git a/testcases/t/36-floating-ws-empty.t b/testcases/t/36-floating-ws-empty.t index 91467ed3..a6e0e405 100644 --- a/testcases/t/36-floating-ws-empty.t +++ b/testcases/t/36-floating-ws-empty.t @@ -22,7 +22,7 @@ ok(workspace_exists($tmp), "workspace $tmp exists"); my $x = X11::XCB::Connection->new; # 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'); # switch to a different workspace, see if the window is still mapped? diff --git a/testcases/t/37-floating-unmap.t b/testcases/t/37-floating-unmap.t index b3be1348..ab1a33d3 100644 --- a/testcases/t/37-floating-unmap.t +++ b/testcases/t/37-floating-unmap.t @@ -21,7 +21,7 @@ my $tmp = fresh_workspace; my $x = X11::XCB::Connection->new; # 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'); # switch to a different workspace, see if the window is still mapped? diff --git a/testcases/t/38-floating-attach.t b/testcases/t/38-floating-attach.t index 411ffa8e..b08190a2 100644 --- a/testcases/t/38-floating-attach.t +++ b/testcases/t/38-floating-attach.t @@ -21,7 +21,7 @@ my $tmp = fresh_workspace; my $x = X11::XCB::Connection->new; # Create a floating window -my $window = open_standard_window($x, undef, 1); +my $window = open_floating_window($x); ok($window->mapped, 'Window is mapped'); my $ws = get_ws($tmp); @@ -31,7 +31,7 @@ is(@{$ws->{floating_nodes}}, 1, 'one floating node'); is(@{$nodes}, 0, 'no tiling nodes'); # Create a tiling window -my $twindow = open_standard_window($x); +my $twindow = open_window($x); ($nodes, $focus) = get_ws_content($tmp); @@ -44,8 +44,8 @@ is(@{$nodes}, 1, 'one tiling node'); $tmp = fresh_workspace; -my $first = open_standard_window($x); -my $second = open_standard_window($x); +my $first = open_window($x); +my $second = open_window($x); 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)'); # Create a floating window -my $window = open_standard_window($x, undef, 1); +my $window = open_floating_window($x); ok($window->mapped, 'Window is mapped'); $ws = get_ws($tmp); is(@{$ws->{floating_nodes}}, 1, 'one floating nodes'); is(@{$ws->{nodes}}, 1, 'one tiling node (stacked con)'); -my $third = open_standard_window($x); +my $third = open_window($x); $ws = get_ws($tmp); diff --git a/testcases/t/39-ws-numbers.t b/testcases/t/39-ws-numbers.t index 3afd281b..31f013ef 100644 --- a/testcases/t/39-ws-numbers.t +++ b/testcases/t/39-ws-numbers.t @@ -30,7 +30,7 @@ check_order('workspace order alright before testing'); cmd "workspace 93"; -open_standard_window($x); +open_window($x); my @ws = @{$i3->get_workspaces->recv}; 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'); cmd "workspace 92"; -open_standard_window($x); +open_window($x); check_order('workspace order alright after opening 92'); cmd "workspace 94"; -open_standard_window($x); +open_window($x); check_order('workspace order alright after opening 94'); cmd "workspace 96"; -open_standard_window($x); +open_window($x); check_order('workspace order alright after opening 96'); cmd "workspace foo"; -open_standard_window($x); +open_window($x); check_order('workspace order alright after opening foo'); cmd "workspace 91"; -open_standard_window($x); +open_window($x); check_order('workspace order alright after opening 91'); done_testing; diff --git a/testcases/t/40-focus-lost.t b/testcases/t/40-focus-lost.t index 1121f124..fb77f01e 100644 --- a/testcases/t/40-focus-lost.t +++ b/testcases/t/40-focus-lost.t @@ -24,9 +24,9 @@ sub check_order { my $tmp = fresh_workspace; -my $left = open_standard_window($x); -my $mid = open_standard_window($x); -my $right = open_standard_window($x); +my $left = open_window($x); +my $mid = open_window($x); +my $right = open_window($x); sync_with_i3($x); diff --git a/testcases/t/41-resize.t b/testcases/t/41-resize.t index 2a3846d8..8691a044 100644 --- a/testcases/t/41-resize.t +++ b/testcases/t/41-resize.t @@ -14,8 +14,8 @@ my $tmp = fresh_workspace; cmd 'split v'; -my $top = open_standard_window($x); -my $bottom = open_standard_window($x); +my $top = open_window($x); +my $bottom = open_window($x); sync_with_i3($x); @@ -54,8 +54,8 @@ $tmp = fresh_workspace; cmd 'split v'; -$top = open_standard_window($x); -$bottom = open_standard_window($x); +$top = open_window($x); +$bottom = open_window($x); cmd 'split h'; cmd 'layout stacked'; @@ -76,7 +76,7 @@ is($nodes->[1]->{percent}, 0.75, 'bottom window got 75%'); $tmp = fresh_workspace; -$top = open_standard_window($x); +$top = open_window($x); cmd 'floating enable'; diff --git a/testcases/t/45-flattening.t b/testcases/t/45-flattening.t index 4a57f211..904252e7 100644 --- a/testcases/t/45-flattening.t +++ b/testcases/t/45-flattening.t @@ -17,9 +17,9 @@ my $x = X11::XCB::Connection->new; my $tmp = fresh_workspace; -my $left = open_standard_window($x); -my $mid = open_standard_window($x); -my $right = open_standard_window($x); +my $left = open_window($x); +my $mid = open_window($x); +my $right = open_window($x); cmd 'move before v'; cmd 'move after h'; diff --git a/testcases/t/46-floating-reinsert.t b/testcases/t/46-floating-reinsert.t index 07f78956..bc1302bb 100644 --- a/testcases/t/46-floating-reinsert.t +++ b/testcases/t/46-floating-reinsert.t @@ -12,11 +12,11 @@ my $x = X11::XCB::Connection->new; my $tmp = fresh_workspace; -my $left = open_standard_window($x); -my $mid = open_standard_window($x); +my $left = open_window($x); +my $mid = open_window($x); cmd 'split v'; -my $bottom = open_standard_window($x); +my $bottom = open_window($x); 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 ############################################################################# -my $x = X11::XCB::Connection->new; - # Create a floating window -my $window = open_standard_window($x, undef, 1); +my $window = open_floating_window($x); ok($window->mapped, 'Window is mapped'); ($nodes, $focus) = get_ws_content($tmp); diff --git a/testcases/t/47-regress-floatingmove.t b/testcases/t/47-regress-floatingmove.t index 8425f6d9..771ace32 100644 --- a/testcases/t/47-regress-floatingmove.t +++ b/testcases/t/47-regress-floatingmove.t @@ -16,9 +16,9 @@ my $x = X11::XCB::Connection->new; my $tmp = fresh_workspace; -my $left = open_standard_window($x); -my $mid = open_standard_window($x); -my $right = open_standard_window($x); +my $left = open_window($x); +my $mid = open_window($x); +my $right = open_window($x); # go to workspace level cmd 'level up'; diff --git a/testcases/t/48-regress-floatingmovews.t b/testcases/t/48-regress-floatingmovews.t index 355e697a..6f9dfc40 100644 --- a/testcases/t/48-regress-floatingmovews.t +++ b/testcases/t/48-regress-floatingmovews.t @@ -16,13 +16,13 @@ my $x = X11::XCB::Connection->new; my $tmp = fresh_workspace; # open a tiling window on the first workspace -open_standard_window($x); +open_window($x); #sleep 0.25; my $first = get_focused($tmp); # on a different ws, open a floating window my $otmp = fresh_workspace; -open_standard_window($x); +open_window($x); #sleep 0.25; my $float = get_focused($otmp); cmd 'mode toggle'; diff --git a/testcases/t/50-regress-dock-restart.t b/testcases/t/50-regress-dock-restart.t index caadb9e3..e294e6bd 100644 --- a/testcases/t/50-regress-dock-restart.t +++ b/testcases/t/50-regress-dock-restart.t @@ -11,7 +11,6 @@ BEGIN { } my $x = X11::XCB::Connection->new; -my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; @@ -26,17 +25,10 @@ is(@docked, 0, 'no dock clients yet'); # open a dock client -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'), - event_mask => [ 'structure_notify' ], -); - -$window->map; - -wait_for_map $x; +my $window = open_window($x, { + background_color => '#FF0000', + window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), + }); ##################################################################### # 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 ##################################################################### -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - border => 1, - rect => [ 0, 0, 30, 20], - background_color => '#00FF00', - window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), - event_mask => [ 'structure_notify' ], -); - -$window->map; - -wait_for_map $x; +$window = open_window($x, { + border => 1, + rect => [ 0, 0, 30, 20 ], + background_color => '#00FF00', + window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), + }); @docked = get_dock_clients; is(@docked, 1, 'one dock client found'); diff --git a/testcases/t/53-floating-originalsize.t b/testcases/t/53-floating-originalsize.t index b1dc6199..db0b6e9c 100644 --- a/testcases/t/53-floating-originalsize.t +++ b/testcases/t/53-floating-originalsize.t @@ -11,18 +11,7 @@ my $tmp = fresh_workspace; my $x = X11::XCB::Connection->new; # Create a floating window which is smaller than the minimum enforced size of i3 -my $window = $x->root->create_child( - 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 $window = open_window($x, { rect => [ 0, 0, 400, 150 ] }); my ($absolute, $top) = $window->rect; diff --git a/testcases/t/54-regress-multiple-dock.t b/testcases/t/54-regress-multiple-dock.t index b1809493..21cb9696 100644 --- a/testcases/t/54-regress-multiple-dock.t +++ b/testcases/t/54-regress-multiple-dock.t @@ -27,33 +27,19 @@ is(@docked, 0, 'no dock clients yet'); # open a dock client ##################################################################### -my $first = $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'), - event_mask => [ 'structure_notify' ], -); - -$first->map; - -wait_for_map $x; +my $first = open_window($x, { + background_color => '#FF0000', + window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), + }); ##################################################################### # Open a second dock client ##################################################################### -my $second = $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'), - event_mask => [ 'structure_notify' ], -); - -$second->map; - -wait_for_map $x; +my $second = open_window($x, { + background_color => '#FF0000', + window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), + }); ##################################################################### # Kill the second dock client diff --git a/testcases/t/55-floating-split-size.t b/testcases/t/55-floating-split-size.t index 0ba5cdc4..5de05e8b 100644 --- a/testcases/t/55-floating-split-size.t +++ b/testcases/t/55-floating-split-size.t @@ -19,31 +19,19 @@ my $tmp = fresh_workspace; # open a window with 200x80 ##################################################################### -my $first = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 200, 80], - background_color => '#FF0000', - event_mask => [ 'structure_notify' ], -); - -$first->map; - -wait_for_map $x; +my $first = open_window($x, { + rect => [ 0, 0, 200, 80], + background_color => '#FF0000', + }); ##################################################################### # Open a second window with 300x90 ##################################################################### -my $second = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 300, 90], - background_color => '#00FF00', - event_mask => [ 'structure_notify' ], -); - -$second->map; - -wait_for_map $x; +my $second = open_window($x, { + rect => [ 0, 0, 300, 90], + background_color => '#00FF00', + }); ##################################################################### # Set the parent to floating diff --git a/testcases/t/56-fullscreen-focus.t b/testcases/t/56-fullscreen-focus.t index 2eb35a6b..a559b5a5 100644 --- a/testcases/t/56-fullscreen-focus.t +++ b/testcases/t/56-fullscreen-focus.t @@ -20,7 +20,7 @@ my $tmp = fresh_workspace; # 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'); @@ -30,7 +30,7 @@ diag("left = " . $left->id); # Open the right window ##################################################################### -my $right = open_standard_window($x, '#00ff00'); +my $right = open_window($x, { background_color => '#00ff00' }); diag("right = " . $right->id); @@ -44,16 +44,12 @@ cmd 'fullscreen'; # Open a third window ##################################################################### -#my $third = open_standard_window($x, '#0000ff'); +my $third = open_window($x, { + background_color => '#0000ff', + name => 'Third window', + dont_map => 1, + }); -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', - event_mask => [ 'structure_notify' ], -); - -$third->name('Third window'); $third->map; sync_with_i3 $x; diff --git a/testcases/t/57-regress-fullscreen-level-up.t b/testcases/t/57-regress-fullscreen-level-up.t index 3e0b2fe1..7a101dbc 100644 --- a/testcases/t/57-regress-fullscreen-level-up.t +++ b/testcases/t/57-regress-fullscreen-level-up.t @@ -11,7 +11,6 @@ BEGIN { } my $x = X11::XCB::Connection->new; -my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; @@ -19,7 +18,7 @@ my $tmp = fresh_workspace; # open a window, verify it’s not in fullscreen mode ##################################################################### -my $win = open_standard_window($x); +my $win = open_window($x); my $nodes = get_ws_content $tmp; is(@$nodes, 1, 'exactly one client'); diff --git a/testcases/t/58-wm_take_focus.t b/testcases/t/58-wm_take_focus.t index 04c785ae..372f41cd 100644 --- a/testcases/t/58-wm_take_focus.t +++ b/testcases/t/58-wm_take_focus.t @@ -17,7 +17,6 @@ BEGIN { } my $x = X11::XCB::Connection->new; -my $i3 = i3(get_socket_path()); subtest 'Window without WM_TAKE_FOCUS', sub { diff --git a/testcases/t/61-regress-borders-restart.t b/testcases/t/61-regress-borders-restart.t index 1acf6c66..c5e3ef80 100644 --- a/testcases/t/61-regress-borders-restart.t +++ b/testcases/t/61-regress-borders-restart.t @@ -12,7 +12,7 @@ use i3test; my $x = X11::XCB::Connection->new; my $i3 = i3(get_socket_path()); my $tmp = fresh_workspace; -my $window = open_standard_window($x); +my $window = open_window($x); sub get_border_style { my @content = @{get_ws_content($tmp)}; diff --git a/testcases/t/63-wm-state.t b/testcases/t/63-wm-state.t index b9161400..e55d8682 100644 --- a/testcases/t/63-wm-state.t +++ b/testcases/t/63-wm-state.t @@ -7,27 +7,17 @@ use X11::XCB qw(:all); 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 $window = open_standard_window($x); +my $window = open_window($x); sync_with_i3($x); -diag('window mapped'); - is($window->state, ICCCM_WM_STATE_NORMAL, 'WM_STATE normal'); $window->unmap; -# TODO: wait for unmapnotify -sync_with_i3($x); +wait_for_unmap $x; is($window->state, ICCCM_WM_STATE_WITHDRAWN, 'WM_STATE withdrawn'); diff --git a/testcases/t/64-kill-win-vs-client.t b/testcases/t/64-kill-win-vs-client.t index 89077500..ef45a789 100644 --- a/testcases/t/64-kill-win-vs-client.t +++ b/testcases/t/64-kill-win-vs-client.t @@ -13,8 +13,8 @@ sub two_windows { ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); - my $first = open_standard_window($x); - my $second = open_standard_window($x); + my $first = open_window($x); + my $second = open_window($x); sync_with_i3 $x; diff --git a/testcases/t/65-for_window.t b/testcases/t/65-for_window.t index 0dbe99c3..36a20ea9 100644 --- a/testcases/t/65-for_window.t +++ b/testcases/t/65-for_window.t @@ -186,7 +186,7 @@ wait_for_map $x; cmp_ok(@content, '==', 1, 'one node on this workspace now'); is($content[0]->{border}, 'none', 'no border'); -my $other = open_standard_window($x); +my $other = open_window($x); @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 2, 'two nodes'); diff --git a/testcases/t/67-workspace_layout.t b/testcases/t/67-workspace_layout.t index 0e07ebf7..6ff3f15b 100644 --- a/testcases/t/67-workspace_layout.t +++ b/testcases/t/67-workspace_layout.t @@ -27,8 +27,8 @@ my $tmp = fresh_workspace; ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); -my $first = open_standard_window($x); -my $second = open_standard_window($x); +my $first = open_window($x); +my $second = open_window($x); sync_with_i3($x); @@ -56,8 +56,8 @@ $tmp = fresh_workspace; ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); -$first = open_standard_window($x); -$second = open_standard_window($x); +$first = open_window($x); +$second = open_window($x); sync_with_i3($x); @@ -72,8 +72,8 @@ is($content[0]->{layout}, 'stacked', 'layout stacked'); ##################################################################### cmd 'focus parent'; -my $right_top = open_standard_window($x); -my $right_bot = open_standard_window($x); +my $right_top = open_window($x); +my $right_bot = open_window($x); @content = @{get_ws_content($tmp)}; is(@content, 2, 'two cons at workspace level after focus parent'); diff --git a/testcases/t/68-regress-fullscreen-restart.t b/testcases/t/68-regress-fullscreen-restart.t index fcc9ac7e..1418b402 100644 --- a/testcases/t/68-regress-fullscreen-restart.t +++ b/testcases/t/68-regress-fullscreen-restart.t @@ -11,8 +11,8 @@ my $x = X11::XCB::Connection->new; fresh_workspace; -open_standard_window($x); -open_standard_window($x); +open_window($x); +open_window($x); cmd 'layout stacking'; sleep 1; diff --git a/testcases/t/70-force_focus_wrapping.t b/testcases/t/70-force_focus_wrapping.t index cf1c3216..2aa5407d 100644 --- a/testcases/t/70-force_focus_wrapping.t +++ b/testcases/t/70-force_focus_wrapping.t @@ -25,13 +25,13 @@ my $tmp = fresh_workspace; ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); -my $first = open_standard_window($x); -my $second = open_standard_window($x); +my $first = open_window($x); +my $second = open_window($x); cmd 'layout tabbed'; cmd 'focus parent'; -my $third = open_standard_window($x); +my $third = open_window($x); is($x->input_focus, $third->id, 'third window focused'); cmd 'focus left'; @@ -66,13 +66,13 @@ $tmp = fresh_workspace; ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); -$first = open_standard_window($x); -$second = open_standard_window($x); +$first = open_window($x); +$second = open_window($x); cmd 'layout tabbed'; cmd 'focus parent'; -$third = open_standard_window($x); +$third = open_window($x); sync_with_i3($x); diff --git a/testcases/t/74-border-config.t b/testcases/t/74-border-config.t index d66ef477..617e37b9 100644 --- a/testcases/t/74-border-config.t +++ b/testcases/t/74-border-config.t @@ -25,7 +25,7 @@ my $tmp = fresh_workspace; 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)}; ok(@content == 1, 'one container opened'); @@ -51,7 +51,7 @@ $tmp = fresh_workspace; ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); -$first = open_standard_window($x); +$first = open_window($x); @content = @{get_ws_content($tmp)}; ok(@content == 1, 'one container opened'); @@ -75,19 +75,7 @@ $tmp = fresh_workspace; ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); -# Create a floating window which is smaller than the minimum enforced size of i3 -$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; +$first = open_floating_window($x); my $wscontent = get_ws($tmp); my @floating = @{$wscontent->{floating_nodes}}; @@ -115,19 +103,7 @@ $tmp = fresh_workspace; ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); -# Create a floating window which is smaller than the minimum enforced size of i3 -$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; +$first = open_floating_window($x); $wscontent = get_ws($tmp); @floating = @{$wscontent->{floating_nodes}}; diff --git a/testcases/t/lib/i3test.pm b/testcases/t/lib/i3test.pm index 40e84044..87cb769d 100644 --- a/testcases/t/lib/i3test.pm +++ b/testcases/t/lib/i3test.pm @@ -26,7 +26,8 @@ our @EXPORT = qw( get_ws get_focused open_empty_con - open_standard_window + open_window + open_floating_window get_dock_clients cmd sync_with_i3 @@ -124,33 +125,53 @@ sub wait_for_unmap { 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 ' +# +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 - my @args = ( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30 ), - background_color => $color, - event_mask => [ 'structure_notify' ], - ); + $args{class} = WINDOW_CLASS_INPUT_OUTPUT unless exists $args{class}; + $args{rect} = [ 0, 0, 30, 30 ] unless exists $args{rect}; + $args{background_color} = '#c0c0c0' unless exists $args{background_color}; + $args{event_mask} = [ 'structure_notify' ] unless exists $args{event_mask}; + $args{name} = 'Window ' . counter_window() unless exists $args{name}; - if (defined($floating) && $floating) { - @args = (@args, window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY')); - } + my $window = $x->root->create_child(%args); - my $window = $x->root->create_child(@args); + return $window if $dont_map; - $window->name('Window ' . counter_window()); $window->map; - - wait_for_event $x, 0.5, sub { $_[0]->{response_type} == MAP_NOTIFY }; - + wait_for_map($x); + # We sync with i3 here to make sure $x->input_focus is updated. + sync_with_i3($x); return $window; } +# 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 : ()); + + $args{window_type} = $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'); + + return open_window($x, \%args); +} + sub open_empty_con { my ($i3) = @_;