diff --git a/testcases/lib/i3test.pm b/testcases/lib/i3test.pm index 0f2f2e07..8437a534 100644 --- a/testcases/lib/i3test.pm +++ b/testcases/lib/i3test.pm @@ -144,6 +144,12 @@ sub wait_for_unmap { # # set dont_map to a true value to avoid mapping # +# if you want to change aspects of your window before it would be mapped, +# set before_map to a coderef. $window gets passed as $_ and as first argument. +# +# if you set both dont_map and before_map, the coderef will be called nevertheless +# +# # default values: # class => WINDOW_CLASS_INPUT_OUTPUT # rect => [ 0, 0, 30, 30 ] @@ -152,10 +158,10 @@ sub wait_for_unmap { # name => 'Window ' # sub open_window { - my ($args) = @_; - my %args = ($args ? %$args : ()); + my %args = @_ == 1 ? %{$_[0]} : @_; my $dont_map = delete $args{dont_map}; + my $before_map = delete $args{before_map}; $args{class} //= WINDOW_CLASS_INPUT_OUTPUT; $args{rect} //= [ 0, 0, 30, 30 ]; @@ -165,6 +171,12 @@ sub open_window { my $window = $x->root->create_child(%args); + if ($before_map) { + # TODO: investigate why _create is not needed + $window->_create; + $before_map->($window) for $window; + } + return $window if $dont_map; $window->map; @@ -175,8 +187,7 @@ sub open_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 ($args) = @_; - my %args = ($args ? %$args : ()); + my %args = @_ == 1 ? %{$_[0]} : @_; $args{window_type} = $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'); @@ -323,17 +334,10 @@ sub sync_with_i3 { # one on the first call of sync_with_i3. It will be re-used in all # subsequent calls. if (!defined($_sync_window)) { - $_sync_window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => X11::XCB::Rect->new(x => -15, y => -15, width => 10, height => 10 ), + $_sync_window = open_window( + rect => [ -15, -15, 10, 10 ], override_redirect => 1, - background_color => '#ff0000', - event_mask => [ 'structure_notify' ], ); - - $_sync_window->map; - - wait_for_event 2, sub { $_[0]->{response_type} == MAP_NOTIFY }; } my $root = $x->get_root_window(); diff --git a/testcases/t/001-tile.t b/testcases/t/001-tile.t index 460cbd90..c13b87c4 100644 --- a/testcases/t/001-tile.t +++ b/testcases/t/001-tile.t @@ -2,23 +2,16 @@ # vim:ts=4:sw=4:expandtab use i3test; -use X11::XCB 'WINDOW_CLASS_INPUT_OUTPUT'; my $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30); -my $window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => $original_rect, - background_color => '#C0C0C0', -); - +my $window = open_window(rect => $original_rect, dont_map => 1); isa_ok($window, 'X11::XCB::Window'); is_deeply($window->rect, $original_rect, "rect unmodified before mapping"); $window->map; - -sleep(0.25); +wait_for_map $window; my $new_rect = $window->rect; ok(!eq_hash($new_rect, $original_rect), "Window got repositioned"); diff --git a/testcases/t/004-unmanaged.t b/testcases/t/004-unmanaged.t index 70bdb557..e998eb46 100644 --- a/testcases/t/004-unmanaged.t +++ b/testcases/t/004-unmanaged.t @@ -2,15 +2,13 @@ # vim:ts=4:sw=4:expandtab use i3test; -use X11::XCB 'WINDOW_CLASS_INPUT_OUTPUT'; my $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30); -my $window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, +my $window = open_window( rect => $original_rect, override_redirect => 1, - background_color => '#C0C0C0', + dont_map => 1, ); isa_ok($window, 'X11::XCB::Window'); diff --git a/testcases/t/005-floating.t b/testcases/t/005-floating.t index 6de3ea80..9ac45627 100644 --- a/testcases/t/005-floating.t +++ b/testcases/t/005-floating.t @@ -2,24 +2,12 @@ # vim:ts=4:sw=4:expandtab use i3test; -use X11::XCB 'WINDOW_CLASS_INPUT_OUTPUT'; # 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, 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' ], -); +my $window = open_floating_window; isa_ok($window, 'X11::XCB::Window'); -$window->map; - -wait_for_map $window; - my ($absolute, $top) = $window->rect; ok($window->mapped, 'Window is mapped'); @@ -30,20 +18,10 @@ ok($absolute->{x} != 0 && $absolute->{y} != 0, 'i3 did not map it to (0x0)'); $window->unmap; -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 1, 1, 80, 90], - background_color => '#C0C0C0', - window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'), - event_mask => [ 'structure_notify' ], -); +$window = open_floating_window(rect => [ 1, 1, 80, 90 ]); isa_ok($window, 'X11::XCB::Window'); -$window->map; - -wait_for_map $window; - ($absolute, $top) = $window->rect; cmp_ok($absolute->{width}, '==', 80, "i3 let the width at 80"); @@ -61,20 +39,10 @@ $window->unmap; # at least the size of its initial geometry ##################################################################### -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 1, 1, 80, 90], - background_color => '#C0C0C0', - #window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'), - event_mask => [ 'structure_notify' ], -); +$window = open_window(rect => [ 1, 1, 80, 90 ]); isa_ok($window, 'X11::XCB::Window'); -$window->map; - -wait_for_map $window; - cmd 'floating enable'; sync_with_i3; diff --git a/testcases/t/100-fullscreen.t b/testcases/t/100-fullscreen.t index 4a8f87a7..cc893adc 100644 --- a/testcases/t/100-fullscreen.t +++ b/testcases/t/100-fullscreen.t @@ -2,7 +2,6 @@ # vim:ts=4:sw=4:expandtab use i3test; -use X11::XCB 'WINDOW_CLASS_INPUT_OUTPUT'; use List::Util qw(first); my $i3 = i3(get_socket_path()); @@ -32,11 +31,9 @@ for my $o (@outputs) { my $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30); -my $window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, +my $window = open_window( rect => $original_rect, - background_color => '#C0C0C0', - event_mask => [ 'structure_notify' ], + dont_map => 1, ); isa_ok($window, 'X11::XCB::Window'); @@ -83,11 +80,9 @@ $window->unmap; cmd 'open'; $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30); -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, +$window = open_window( rect => $original_rect, - background_color => 61440, - event_mask => [ 'structure_notify' ], + dont_map => 1, ); is_deeply($window->rect, $original_rect, "rect unmodified before mapping"); @@ -114,11 +109,9 @@ ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate ful ############################################################################### $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30); -my $swindow = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, +my $swindow = open_window( rect => $original_rect, - background_color => '#C0C0C0', - event_mask => [ 'structure_notify' ], + dont_map => 1, ); $swindow->map; diff --git a/testcases/t/119-match.t b/testcases/t/119-match.t index 2124c02e..e6a4e832 100644 --- a/testcases/t/119-match.t +++ b/testcases/t/119-match.t @@ -4,7 +4,7 @@ # Tests all kinds of matching methods # use i3test; -use X11::XCB qw(PROP_MODE_REPLACE WINDOW_CLASS_INPUT_OUTPUT); +use X11::XCB qw(PROP_MODE_REPLACE); my $tmp = fresh_workspace; @@ -69,31 +69,21 @@ sub set_wm_class { ); } -my $left = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#0000ff', - event_mask => [ 'structure_notify' ], -); +sub open_special { + my %args = @_; + my $wm_class = delete($args{wm_class}) || 'special'; -$left->_create; -set_wm_class($left->id, 'special', 'special'); -$left->name('left'); -$left->map; -ok(wait_for_map($left), 'left window mapped'); + return open_window( + %args, + before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) }, + ); +} -my $right = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#0000ff', - event_mask => [ 'structure_notify' ], -); +my $left = open_special(name => 'left'); +ok($left->mapped, 'left window mapped'); -$right->_create; -set_wm_class($right->id, 'special', 'special'); -$right->name('right'); -$right->map; -ok(wait_for_map($right), 'right window mapped'); +my $right = open_special(name => 'right'); +ok($right->mapped, 'right window mapped'); # two windows should be here $content = get_ws_content($tmp); @@ -112,18 +102,8 @@ is(@{$content}, 1, 'one window still there'); $tmp = fresh_workspace; -$left = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#0000ff', - event_mask => [ 'structure_notify' ], -); - -$left->_create; -set_wm_class($left->id, 'special7', 'special7'); -$left->name('left'); -$left->map; -ok(wait_for_map($left), 'left window mapped'); +$left = open_special(name => 'left', wm_class => 'special7'); +ok($left->mapped, 'left window mapped'); # two windows should be here $content = get_ws_content($tmp); @@ -142,18 +122,8 @@ is(@{$content}, 0, 'window killed'); $tmp = fresh_workspace; -$left = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#0000ff', - event_mask => [ 'structure_notify' ], -); - -$left->_create; -set_wm_class($left->id, 'special7', 'special7'); -$left->name('ä 3'); -$left->map; -ok(wait_for_map($left), 'left window mapped'); +$left = open_special(name => 'ä 3', wm_class => 'special7'); +ok($left->mapped, 'left window mapped'); # two windows should be here $content = get_ws_content($tmp); diff --git a/testcases/t/122-split.t b/testcases/t/122-split.t index 3484c7fc..71736db4 100644 --- a/testcases/t/122-split.t +++ b/testcases/t/122-split.t @@ -4,7 +4,6 @@ # Tests splitting # use i3test; -use X11::XCB qw(:all); my $tmp = fresh_workspace; diff --git a/testcases/t/127-regress-floating-parent.t b/testcases/t/127-regress-floating-parent.t index 52b8b9c0..c83c0809 100644 --- a/testcases/t/127-regress-floating-parent.t +++ b/testcases/t/127-regress-floating-parent.t @@ -16,8 +16,7 @@ cmd 'open'; my $floating = get_focused($tmp); diag("focused floating: " . get_focused($tmp)); cmd 'mode toggle'; -# TODO: eliminate this race conditition -sleep 1; +sync_with_i3; # kill old container cmd qq|[con_id="$old"] focus|; @@ -33,7 +32,7 @@ cmd 'kill'; cmd qq|[con_id="$floating"] focus|; is(get_focused($tmp), $floating, 'floating window focused'); -sleep 1; +sync_with_i3; cmd 'mode toggle'; does_i3_live; diff --git a/testcases/t/129-focus-after-close.t b/testcases/t/129-focus-after-close.t index 3913f4c6..5fc3786e 100644 --- a/testcases/t/129-focus-after-close.t +++ b/testcases/t/129-focus-after-close.t @@ -42,9 +42,8 @@ isnt(get_focused($tmp), $second, 'different container focused'); ############################################################## cmd 'kill'; -# TODO: this testcase sometimes has different outcomes when the -# sleep is missing. why? -sleep 0.25; +sync_with_i3; + ($nodes, $focus) = get_ws_content($tmp); is($nodes->[1]->{nodes}->[0]->{id}, $second, 'second container found'); ok($nodes->[1]->{nodes}->[0]->{focused}, 'second container focused'); @@ -103,8 +102,7 @@ my $win = open_window({ background_color => '#00ff00' }); cmd qq|[con_id="$middle"] focus|; $win->destroy; - -sleep 0.25; +sync_with_i3; is(get_focused($tmp), $middle, 'middle container focused'); diff --git a/testcases/t/144-regress-floating-resize.t b/testcases/t/144-regress-floating-resize.t index de33eeb3..03318d7a 100644 --- a/testcases/t/144-regress-floating-resize.t +++ b/testcases/t/144-regress-floating-resize.t @@ -11,23 +11,24 @@ use List::Util qw(sum); my $tmp = fresh_workspace; -cmd 'exec /usr/bin/urxvt'; -sleep 0.5; -cmd 'exec /usr/bin/urxvt'; -sleep 0.5; +my $first = open_window; +my $second = open_window; + my ($nodes, $focus) = get_ws_content($tmp); my $old_sum = sum map { $_->{rect}->{width} } @{$nodes}; -#cmd 'open'; + cmd 'resize grow left 10 px or 25 ppt'; cmd 'split v'; -#cmd 'open'; -cmd 'exec /usr/bin/urxvt'; -sleep 0.5; -cmd 'mode toggle'; -sleep 0.5; -cmd 'kill'; -sleep 0.5; +sync_with_i3; + +my $third = open_window; + +cmd 'mode toggle'; +sync_with_i3; + +cmd 'kill'; +sync_with_i3; ($nodes, $focus) = get_ws_content($tmp); my $new_sum = sum map { $_->{rect}->{width} } @{$nodes}; diff --git a/testcases/t/147-regress-floatingmove.t b/testcases/t/147-regress-floatingmove.t index ed85b57b..5a2c87d3 100644 --- a/testcases/t/147-regress-floatingmove.t +++ b/testcases/t/147-regress-floatingmove.t @@ -6,6 +6,11 @@ # use i3test; +sub sync_cmd { + cmd @_; + sync_with_i3; +} + my $tmp = fresh_workspace; my $left = open_window; @@ -13,23 +18,19 @@ my $mid = open_window; my $right = open_window; # go to workspace level -cmd 'level up'; -sleep 0.25; +sync_cmd 'level up'; # make it floating -cmd 'mode toggle'; -sleep 0.25; +sync_cmd 'mode toggle'; # move the con outside the floating con -cmd 'move up'; -sleep 0.25; +sync_cmd 'move up'; does_i3_live; # move another con outside -cmd '[id="' . $mid->id . '"] focus'; -cmd 'move up'; -sleep 0.25; +sync_cmd '[id="' . $mid->id . '"] focus'; +sync_cmd 'move up'; does_i3_live; diff --git a/testcases/t/148-regress-floatingmovews.t b/testcases/t/148-regress-floatingmovews.t index 44d5a445..3d71b500 100644 --- a/testcases/t/148-regress-floatingmovews.t +++ b/testcases/t/148-regress-floatingmovews.t @@ -10,20 +10,18 @@ my $tmp = fresh_workspace; # open a tiling window on the first workspace open_window; -#sleep 0.25; my $first = get_focused($tmp); # on a different ws, open a floating window my $otmp = fresh_workspace; open_window; -#sleep 0.25; my $float = get_focused($otmp); cmd 'mode toggle'; -#sleep 0.25; +sync_with_i3; # move the floating con to first workspace cmd "move workspace $tmp"; -#sleep 0.25; +sync_with_i3; # switch to the first ws and check focus is(get_focused($tmp), $float, 'floating client correctly focused'); diff --git a/testcases/t/162-regress-dock-urgent.t b/testcases/t/162-regress-dock-urgent.t index 7a0ac487..3562ba7a 100644 --- a/testcases/t/162-regress-dock-urgent.t +++ b/testcases/t/162-regress-dock-urgent.t @@ -5,7 +5,6 @@ # found in 4be3178d4d360c2996217d811e61161c84d25898 # use i3test; -use X11::XCB 'WINDOW_CLASS_INPUT_OUTPUT'; my $i3 = i3(get_socket_path()); @@ -22,17 +21,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', +my $window = open_window( window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), ); -$window->map; - -sleep 0.25; - ##################################################################### # check that we can find it in the layout tree at the expected position ##################################################################### diff --git a/testcases/t/165-for_window.t b/testcases/t/165-for_window.t index c7601809..0ca5bd11 100644 --- a/testcases/t/165-for_window.t +++ b/testcases/t/165-for_window.t @@ -4,7 +4,7 @@ # # use i3test; -use X11::XCB qw(PROP_MODE_REPLACE WINDOW_CLASS_INPUT_OUTPUT); +use X11::XCB qw(PROP_MODE_REPLACE); ############################################################## # 1: test the following directive: @@ -25,16 +25,7 @@ my $pid = launch_with_config($config); my $tmp = fresh_workspace; -my $window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#00ff00', - event_mask => [ 'structure_notify' ], -); - -$window->name('Border window'); -$window->map; -wait_for_map $window; +my $window = open_window(name => 'Border window'); my @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); @@ -47,14 +38,6 @@ wait_for_unmap $window; cmp_ok(@content, '==', 0, 'no more nodes'); diag('content = '. Dumper(\@content)); -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#00ff00', - event_mask => [ 'structure_notify' ], -); - -$window->_create; # TODO: move this to X11::XCB::Window sub set_wm_class { @@ -75,10 +58,10 @@ sub set_wm_class { ); } -set_wm_class($window->id, 'borderless', 'borderless'); -$window->name('Borderless window'); -$window->map; -wait_for_map $window; +$window = open_window( + name => 'Borderless window', + before_map => sub { set_wm_class($_->id, 'borderless', 'borderless') }, +); @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); @@ -108,16 +91,7 @@ $pid = launch_with_config($config); $tmp = fresh_workspace; -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#00ff00', - event_mask => [ 'structure_notify' ], -); - -$window->name('special title'); -$window->map; -wait_for_map $window; +$window = open_window(name => 'special title'); @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); @@ -168,16 +142,7 @@ $pid = launch_with_config($config); $tmp = fresh_workspace; -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#00ff00', - event_mask => [ 'structure_notify' ], -); - -$window->name('special mark title'); -$window->map; -wait_for_map $window; +$window = open_window(name => 'special mark title'); @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); @@ -212,20 +177,11 @@ $pid = launch_with_config($config); $tmp = fresh_workspace; -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#00ff00', - event_mask => [ 'structure_notify' ], +$window = open_window( + name => 'usethis', + before_map => sub { set_wm_class($_->id, 'borderless', 'borderless') }, ); -$window->_create; - -set_wm_class($window->id, 'borderless', 'borderless'); -$window->name('usethis'); -$window->map; -wait_for_map $window; - @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); is($content[0]->{border}, 'none', 'no border'); @@ -268,20 +224,12 @@ $pid = launch_with_config($config); $tmp = fresh_workspace; -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#00ff00', - event_mask => [ 'structure_notify' ], + +$window = open_window( + name => 'usethis', + before_map => sub { set_wm_class($_->id, 'bar', 'foo') }, ); -$window->_create; - -set_wm_class($window->id, 'bar', 'foo'); -$window->name('usethis'); -$window->map; -wait_for_map $window; - @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); is($content[0]->{border}, 'normal', 'normal border, not matched'); @@ -303,20 +251,11 @@ $pid = launch_with_config($config); $tmp = fresh_workspace; -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#00ff00', - event_mask => [ 'structure_notify' ], +$window = open_window( + name => 'usethis', + before_map => sub { set_wm_class($_->id, 'bar', 'foo') }, ); -$window->_create; - -set_wm_class($window->id, 'bar', 'foo'); -$window->name('usethis'); -$window->map; -wait_for_map $window; - @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); is($content[0]->{border}, 'none', 'no border'); @@ -340,20 +279,11 @@ $pid = launch_with_config($config); $tmp = fresh_workspace; -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#00ff00', - event_mask => [ 'structure_notify' ], +$window = open_window( + name => 'usethis', + before_map => sub { set_wm_class($_->id, 'bar', 'foo') }, ); -$window->_create; - -set_wm_class($window->id, 'bar', 'foo'); -$window->name('usethis'); -$window->map; -wait_for_map $window; - @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); is($content[0]->{border}, 'normal', 'normal border'); @@ -377,31 +307,24 @@ $pid = launch_with_config($config); $tmp = fresh_workspace; -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#00ff00', - event_mask => [ 'structure_notify' ], +$window = open_window( + name => 'usethis', + before_map => sub { + my ($window) = @_; + my $atomname = $x->atom(name => 'WM_WINDOW_ROLE'); + my $atomtype = $x->atom(name => 'STRING'); + $x->change_property( + PROP_MODE_REPLACE, + $window->id, + $atomname->id, + $atomtype->id, + 8, + length("i3test") + 1, + "i3test\x00" + ); + }, ); -$window->_create; - -my $atomname = $x->atom(name => 'WM_WINDOW_ROLE'); -my $atomtype = $x->atom(name => 'STRING'); -$x->change_property( - PROP_MODE_REPLACE, - $window->id, - $atomname->id, - $atomtype->id, - 8, - length("i3test") + 1, - "i3test\x00" -); - -$window->name('usethis'); -$window->map; -wait_for_map $window; - @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); is($content[0]->{border}, 'none', 'no border (window_role)'); @@ -426,25 +349,14 @@ $pid = launch_with_config($config); $tmp = fresh_workspace; -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#00ff00', - event_mask => [ 'structure_notify' ], -); - -$window->_create; - -$window->name('usethis'); -$window->map; -wait_for_map $window; +$window = open_window(name => 'usethis'); @content = @{get_ws_content($tmp)}; cmp_ok(@content, '==', 1, 'one node on this workspace now'); is($content[0]->{border}, 'normal', 'normal border (window_role 2)'); -$atomname = $x->atom(name => 'WM_WINDOW_ROLE'); -$atomtype = $x->atom(name => 'STRING'); +my $atomname = $x->atom(name => 'WM_WINDOW_ROLE'); +my $atomtype = $x->atom(name => 'STRING'); $x->change_property( PROP_MODE_REPLACE, $window->id, diff --git a/testcases/t/166-assign.t b/testcases/t/166-assign.t index a10516a6..254616c5 100644 --- a/testcases/t/166-assign.t +++ b/testcases/t/166-assign.t @@ -5,7 +5,7 @@ # Tests if assignments work # use i3test; -use X11::XCB qw(PROP_MODE_REPLACE WINDOW_CLASS_INPUT_OUTPUT); +use X11::XCB qw(PROP_MODE_REPLACE); # TODO: move to X11::XCB sub set_wm_class { @@ -26,6 +26,16 @@ sub set_wm_class { ); } +sub open_special { + my %args = @_; + my $wm_class = delete($args{wm_class}) || 'special'; + $args{name} //= 'special window'; + + return open_window( + %args, + before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) }, + ); +} ##################################################################### # start a window and see that it does not get assigned with an empty config @@ -42,18 +52,7 @@ my $tmp = fresh_workspace; ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); -my $window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#0000ff', - event_mask => [ 'structure_notify' ], -); - -$window->_create; -set_wm_class($window->id, 'special', 'special'); -$window->name('special window'); -$window->map; -wait_for_map $window; +my $window = open_special; ok(@{get_ws_content($tmp)} == 1, 'special window got managed to current (random) workspace'); @@ -80,18 +79,7 @@ ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); my $workspaces = get_workspace_names; ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet'); -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#0000ff', - event_mask => [ 'structure_notify' ], -); - -$window->_create; -set_wm_class($window->id, 'special', 'special'); -$window->name('special window'); -$window->map; -wait_for_map $window; +$window = open_special; ok(@{get_ws_content($tmp)} == 0, 'still no containers'); ok("targetws" ~~ @{get_workspace_names()}, 'targetws exists'); @@ -120,21 +108,12 @@ $tmp = fresh_workspace; ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); ok("targetws" ~~ @{get_workspace_names()}, 'targetws does not exist yet'); -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#0000ff', - event_mask => [ 'structure_notify' ], -); - -$window->_create; -set_wm_class($window->id, 'special', 'special'); -$window->name('special window'); -$window->map; # We use sync_with_i3 instead of wait_for_map here because i3 will not actually # map the window -- it will be assigned to a different workspace and will only # be mapped once you switch to that workspace +$window = open_special(dont_map => 1); +$window->map; sync_with_i3; ok(@{get_ws_content($tmp)} == 0, 'still no containers'); @@ -161,18 +140,7 @@ ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); $workspaces = get_workspace_names; ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet'); -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#0000ff', - event_mask => [ 'structure_notify' ], -); - -$window->_create; -set_wm_class($window->id, 'special', 'special'); -$window->name('special window'); -$window->map; -wait_for_map $window; +$window = open_special; my $content = get_ws($tmp); ok(@{$content->{nodes}} == 0, 'no tiling cons'); @@ -202,18 +170,7 @@ ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); $workspaces = get_workspace_names; ok(!("targetws" ~~ @{$workspaces}), 'targetws does not exist yet'); -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#0000ff', - event_mask => [ 'structure_notify' ], -); - -$window->_create; -set_wm_class($window->id, 'SPEcial', 'SPEcial'); -$window->name('special window'); -$window->map; -wait_for_map $window; +$window = open_special(wm_class => 'SPEcial'); $content = get_ws($tmp); ok(@{$content->{nodes}} == 0, 'no tiling cons'); @@ -251,20 +208,10 @@ my @docked = get_dock_clients; # syntax is(@docked, 1, 'one dock client yet'); -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#0000ff', +$window = open_special( window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'), - event_mask => [ 'structure_notify' ], ); -$window->_create; -set_wm_class($window->id, 'special', 'special'); -$window->name('special window'); -$window->map; -wait_for_map $window; - $content = get_ws($tmp); ok(@{$content->{nodes}} == 0, 'no tiling cons'); ok(@{$content->{floating_nodes}} == 0, 'one floating con'); @@ -277,6 +224,4 @@ does_i3_live; exit_gracefully($pid); -sleep 0.25; - done_testing; diff --git a/testcases/t/168-regress-fullscreen-restart.t b/testcases/t/168-regress-fullscreen-restart.t index 74d284db..27812565 100644 --- a/testcases/t/168-regress-fullscreen-restart.t +++ b/testcases/t/168-regress-fullscreen-restart.t @@ -11,10 +11,10 @@ open_window; open_window; cmd 'layout stacking'; -sleep 1; +sync_with_i3; cmd 'fullscreen'; -sleep 1; +sync_with_i3; cmd 'restart'; sleep 1; diff --git a/testcases/t/173-regress-focus-assign.t b/testcases/t/173-regress-focus-assign.t index bd0ff647..cf3385cc 100644 --- a/testcases/t/173-regress-focus-assign.t +++ b/testcases/t/173-regress-focus-assign.t @@ -6,7 +6,7 @@ # assigned to an invisible workspace # use i3test; -use X11::XCB qw(PROP_MODE_REPLACE WINDOW_CLASS_INPUT_OUTPUT); +use X11::XCB qw(PROP_MODE_REPLACE); # TODO: move to X11::XCB sub set_wm_class { @@ -27,6 +27,16 @@ sub set_wm_class { ); } +sub open_special { + my %args = @_; + my $wm_class = delete($args{wm_class}) || 'special'; + $args{name} //= 'special window'; + + return open_window( + %args, + before_map => sub { set_wm_class($_->id, $wm_class, $wm_class) }, + ); +} ##################################################################### # start a window and see that it does not get assigned with an empty config @@ -45,18 +55,7 @@ my $tmp = fresh_workspace; ok(@{get_ws_content($tmp)} == 0, 'no containers yet'); ok(get_ws($tmp)->{focused}, 'current workspace focused'); -my $window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#0000ff', -); - -$window->_create; -set_wm_class($window->id, 'special', 'special'); -$window->name('special window'); -$window->map; -sleep 0.25; - +my $window = open_special; ok(@{get_ws_content($tmp)} == 0, 'special window not on current workspace'); ok(@{get_ws_content('targetws')} == 1, 'special window on targetws'); @@ -66,20 +65,10 @@ ok(get_ws($tmp)->{focused}, 'current workspace still focused'); # the same test, but with a floating window ##################################################################### -$window = $x->root->create_child( - class => WINDOW_CLASS_INPUT_OUTPUT, - rect => [ 0, 0, 30, 30 ], - background_color => '#0000ff', +$window = open_special( window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_UTILITY'), ); -$window->_create; -set_wm_class($window->id, 'special', 'special'); -$window->name('special window'); -$window->map; -sleep 0.25; - - ok(@{get_ws_content($tmp)} == 0, 'special window not on current workspace'); ok(@{get_ws_content('targetws')} == 1, 'special window on targetws'); ok(get_ws($tmp)->{focused}, 'current workspace still focused');