529-net-wm-desktop: avoid timeout, avoid restarts, split

This shaves off almost half a second of the wall-clock time (from 5.9s to 5.6s).
This commit is contained in:
Michael Stapelberg 2017-09-09 18:39:56 +02:00
parent e46dc19f82
commit dbd3ca749c
2 changed files with 87 additions and 74 deletions

View File

@ -66,8 +66,15 @@ sub open_window_with_net_wm_desktop {
pack('L', $idx), pack('L', $idx),
); );
}, },
dont_map => 1,
); );
# We dont wait for MapNotify and instead sync with i3 so that we dont need
# to encounter the full timeout of 4s when opening a window on a non-visible
# workspace.
$window->map;
sync_with_i3;
return $window; return $window;
} }
@ -80,9 +87,7 @@ sub kill_windows {
############################################################################### ###############################################################################
my ($config, $config_mm, $pid, $con); my $config = <<EOT;
$config = <<EOT;
# i3 config file (v4) # i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
@ -91,42 +96,25 @@ bar {
} }
EOT EOT
$config_mm = <<EOT; my $pid = launch_with_config($config);
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
workspace "0" output "fake-0"
workspace "1" output "fake-0"
workspace "2" output "fake-0"
workspace "10" output "fake-1"
workspace "11" output "fake-1"
workspace "12" output "fake-1"
fake-outputs 1024x768+0+0,1024x768+1024+0
EOT
############################################################################### ###############################################################################
# Upon managing a window which does not set _NET_WM_DESKTOP, the property is # Upon managing a window which does not set _NET_WM_DESKTOP, the property is
# set on the window. # set on the window.
############################################################################### ###############################################################################
$pid = launch_with_config($config);
cmd 'workspace 1'; cmd 'workspace 1';
$con = open_window; my $con = open_window;
is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set upon managing a window'); is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set upon managing a window');
kill_windows; kill_windows;
exit_gracefully($pid);
############################################################################### ###############################################################################
# Upon managing a window which sets _NET_WM_DESKTOP, the window is moved to # Upon managing a window which sets _NET_WM_DESKTOP, the window is moved to
# the specified desktop. # the specified desktop.
############################################################################### ###############################################################################
$pid = launch_with_config($config);
cmd 'workspace 0'; cmd 'workspace 0';
open_window; open_window;
cmd 'workspace 1'; cmd 'workspace 1';
@ -140,15 +128,12 @@ is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP still has the correct value');
is_num_children('1', 2, 'The window was moved to workspace 1'); is_num_children('1', 2, 'The window was moved to workspace 1');
kill_windows; kill_windows;
exit_gracefully($pid);
############################################################################### ###############################################################################
# Upon managing a window which sets _NET_WM_DESKTOP to the appropriate value, # Upon managing a window which sets _NET_WM_DESKTOP to the appropriate value,
# the window is made sticky and floating. # the window is made sticky and floating.
############################################################################### ###############################################################################
$pid = launch_with_config($config);
cmd 'workspace 0'; cmd 'workspace 0';
$con = open_window_with_net_wm_desktop(0xFFFFFFFF); $con = open_window_with_net_wm_desktop(0xFFFFFFFF);
@ -157,15 +142,12 @@ is(@{get_ws('0')->{floating_nodes}}, 1, 'The window is floating');
ok(get_ws('0')->{floating_nodes}->[0]->{nodes}->[0]->{sticky}, 'The window is sticky'); ok(get_ws('0')->{floating_nodes}->[0]->{nodes}->[0]->{sticky}, 'The window is sticky');
kill_windows; kill_windows;
exit_gracefully($pid);
############################################################################### ###############################################################################
# _NET_WM_DESKTOP is updated when the window is moved to another workspace # _NET_WM_DESKTOP is updated when the window is moved to another workspace
# on the same output. # on the same output.
############################################################################### ###############################################################################
$pid = launch_with_config($config);
cmd 'workspace 0'; cmd 'workspace 0';
open_window; open_window;
cmd 'workspace 1'; cmd 'workspace 1';
@ -178,15 +160,12 @@ cmd 'move window to workspace 1';
is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated when moving the window'); is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated when moving the window');
kill_windows; kill_windows;
exit_gracefully($pid);
############################################################################### ###############################################################################
# _NET_WM_DESKTOP is updated when the floating window is moved to another # _NET_WM_DESKTOP is updated when the floating window is moved to another
# workspace on the same output. # workspace on the same output.
############################################################################### ###############################################################################
$pid = launch_with_config($config);
cmd 'workspace 0'; cmd 'workspace 0';
open_window; open_window;
cmd 'workspace 1'; cmd 'workspace 1';
@ -200,35 +179,11 @@ cmd 'move window to workspace 1';
is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated when moving the window'); is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated when moving the window');
kill_windows; kill_windows;
exit_gracefully($pid);
###############################################################################
# _NET_WM_DESKTOP is updated when the window is moved to another workspace
# on another output.
###############################################################################
$pid = launch_with_config($config_mm);
cmd 'workspace 0';
open_window;
cmd 'workspace 10';
open_window;
cmd 'workspace 0';
$con = open_window;
cmd 'move window to workspace 10';
is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated when moving the window');
kill_windows;
exit_gracefully($pid);
############################################################################### ###############################################################################
# _NET_WM_DESKTOP is removed when the window is withdrawn. # _NET_WM_DESKTOP is removed when the window is withdrawn.
############################################################################### ###############################################################################
$pid = launch_with_config($config);
$con = open_window; $con = open_window;
is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set (sanity check)'); is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set (sanity check)');
@ -238,15 +193,12 @@ wait_for_unmap($con);
is(get_net_wm_desktop($con), undef, '_NET_WM_DESKTOP is removed'); is(get_net_wm_desktop($con), undef, '_NET_WM_DESKTOP is removed');
kill_windows; kill_windows;
exit_gracefully($pid);
############################################################################### ###############################################################################
# A _NET_WM_DESKTOP client message sent to the root window moves a window # A _NET_WM_DESKTOP client message sent to the root window moves a window
# to the correct workspace. # to the correct workspace.
############################################################################### ###############################################################################
$pid = launch_with_config($config);
cmd 'workspace 0'; cmd 'workspace 0';
open_window; open_window;
cmd 'workspace 1'; cmd 'workspace 1';
@ -263,15 +215,12 @@ is_num_children('1', 2, 'The window is now on workspace 1');
is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated'); is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated');
kill_windows; kill_windows;
exit_gracefully($pid);
############################################################################### ###############################################################################
# A _NET_WM_DESKTOP client message sent to the root window can make a window # A _NET_WM_DESKTOP client message sent to the root window can make a window
# sticky. # sticky.
############################################################################### ###############################################################################
$pid = launch_with_config($config);
cmd 'workspace 0'; cmd 'workspace 0';
$con = open_window; $con = open_window;
@ -282,15 +231,12 @@ is(@{get_ws('0')->{floating_nodes}}, 1, 'The window is floating');
ok(get_ws('0')->{floating_nodes}->[0]->{nodes}->[0]->{sticky}, 'The window is sticky'); ok(get_ws('0')->{floating_nodes}->[0]->{nodes}->[0]->{sticky}, 'The window is sticky');
kill_windows; kill_windows;
exit_gracefully($pid);
############################################################################### ###############################################################################
# _NET_WM_DESKTOP is updated when a new workspace with a lower number is # _NET_WM_DESKTOP is updated when a new workspace with a lower number is
# opened and closed. # opened and closed.
############################################################################### ###############################################################################
$pid = launch_with_config($config);
cmd 'workspace 1'; cmd 'workspace 1';
$con = open_window; $con = open_window;
is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)'); is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)');
@ -299,14 +245,11 @@ cmd 'workspace 0';
is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated'); is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated');
kill_windows; kill_windows;
exit_gracefully($pid);
############################################################################### ###############################################################################
# _NET_WM_DESKTOP is updated when a window is made sticky by command. # _NET_WM_DESKTOP is updated when a window is made sticky by command.
############################################################################### ###############################################################################
$pid = launch_with_config($config);
cmd 'workspace 0'; cmd 'workspace 0';
$con = open_window; $con = open_window;
cmd 'floating enable'; cmd 'floating enable';
@ -316,14 +259,11 @@ cmd 'sticky enable';
is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP is updated'); is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP is updated');
kill_windows; kill_windows;
exit_gracefully($pid);
############################################################################### ###############################################################################
# _NET_WM_DESKTOP is updated when a window is made sticky by client message. # _NET_WM_DESKTOP is updated when a window is made sticky by client message.
############################################################################### ###############################################################################
$pid = launch_with_config($config);
cmd 'workspace 0'; cmd 'workspace 0';
$con = open_window; $con = open_window;
cmd 'floating enable'; cmd 'floating enable';
@ -343,14 +283,11 @@ sync_with_i3;
is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP is updated'); is(get_net_wm_desktop($con), 0xFFFFFFFF, '_NET_WM_DESKTOP is updated');
kill_windows; kill_windows;
exit_gracefully($pid);
############################################################################### ###############################################################################
# _NET_WM_DESKTOP is updated when a window is moved to the scratchpad. # _NET_WM_DESKTOP is updated when a window is moved to the scratchpad.
############################################################################### ###############################################################################
$pid = launch_with_config($config);
cmd 'workspace 0'; cmd 'workspace 0';
$con = open_window; $con = open_window;
cmd 'floating enable'; cmd 'floating enable';
@ -363,8 +300,9 @@ cmd 'scratchpad show';
is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)'); is(get_net_wm_desktop($con), 0, '_NET_WM_DESKTOP is set sanity check)');
kill_windows; kill_windows;
exit_gracefully($pid);
############################################################################### ###############################################################################
exit_gracefully($pid);
done_testing; done_testing;

View File

@ -0,0 +1,75 @@
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • http://build.i3wm.org/docs/testsuite.html
# (or docs/testsuite)
#
# • http://build.i3wm.org/docs/lib-i3test.html
# (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • http://build.i3wm.org/docs/ipc.html
# (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
# (unless you are already familiar with Perl)
#
# Tests for _NET_WM_DESKTOP.
# Ticket: #2153
use i3test i3_autostart => 0;
use X11::XCB qw(:all);
sub get_net_wm_desktop {
sync_with_i3;
my ($con) = @_;
my $cookie = $x->get_property(
0,
$con->{id},
$x->atom(name => '_NET_WM_DESKTOP')->id,
$x->atom(name => 'CARDINAL')->id,
0,
1
);
my $reply = $x->get_property_reply($cookie->{sequence});
return undef if $reply->{length} != 1;
return unpack("L", $reply->{value});
}
my $config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
workspace "0" output "fake-0"
workspace "1" output "fake-0"
workspace "2" output "fake-0"
workspace "10" output "fake-1"
workspace "11" output "fake-1"
workspace "12" output "fake-1"
fake-outputs 1024x768+0+0,1024x768+1024+0
EOT
###############################################################################
# _NET_WM_DESKTOP is updated when the window is moved to another workspace
# on another output.
###############################################################################
my $pid = launch_with_config($config);
cmd 'workspace 0';
open_window;
cmd 'workspace 10';
open_window;
cmd 'workspace 0';
my $con = open_window;
cmd 'move window to workspace 10';
is(get_net_wm_desktop($con), 1, '_NET_WM_DESKTOP is updated when moving the window');
exit_gracefully($pid);
done_testing;