]> git.sur5r.net Git - i3/i3/blob - testcases/t/521-ewmh-desktop-viewport.t
t/*ewmh*: fix flakiness by syncing
[i3/i3] / testcases / t / 521-ewmh-desktop-viewport.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16 #
17 # Test that the EWMH specified property _NET_DESKTOP_VIEWPORT is updated
18 # properly on the root window. We interpret this as a list of x/y coordinate
19 # pairs for the upper left corner of the respective outputs of the workspaces
20 # Ticket: #1241
21 use i3test i3_autostart => 0;
22
23 my $config = <<EOT;
24 # i3 config file (v4)
25 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
26
27 workspace 0 output fake-0
28 workspace 1 output fake-1
29
30 fake-outputs 1024x768+0+0,1024x768+1024+0
31 EOT
32
33 my $pid = launch_with_config($config);
34
35 sub get_desktop_viewport {
36     # Make sure that i3 pushed its changes to X11 before querying.
37     sync_with_i3;
38
39     my $cookie = $x->get_property(
40         0,
41         $x->get_root_window(),
42         $x->atom(name => '_NET_DESKTOP_VIEWPORT')->id,
43         $x->atom(name => 'CARDINAL')->id,
44         0,
45         4096
46     );
47
48     my $reply = $x->get_property_reply($cookie->{sequence});
49
50     return 0 if $reply->{value_len} == 0;
51
52     my $len = $reply->{length};
53
54     return unpack ("L$len", $reply->{value});
55 }
56
57 # initialize the workspaces
58 cmd 'workspace 1';
59 cmd 'workspace 0';
60
61 my @expected_viewport = (0, 0, 1024, 0);
62 my @desktop_viewport = get_desktop_viewport;
63
64 is_deeply(\@desktop_viewport, \@expected_viewport,
65     '_NET_DESKTOP_VIEWPORT should be an array of x/y coordinate pairs for the upper left corner of the respective outputs of the workspaces');
66
67 cmd 'workspace 0';
68 open_window;
69 cmd 'workspace 3';
70
71 @expected_viewport = (0, 0, 0, 0, 1024, 0);
72 @desktop_viewport = get_desktop_viewport;
73
74 is_deeply(\@desktop_viewport, \@expected_viewport,
75     'it should be updated when a new workspace appears');
76
77 cmd 'rename workspace 3 to 2';
78
79 @expected_viewport = (0, 0, 0, 0, 1024, 0);
80 @desktop_viewport = get_desktop_viewport;
81
82 is_deeply(\@desktop_viewport, \@expected_viewport,
83     'it should stay up to date when a workspace is renamed');
84
85 cmd 'workspace 0';
86
87 @expected_viewport = (0, 0, 1024, 0);
88 @desktop_viewport = get_desktop_viewport;
89
90 is_deeply(\@desktop_viewport, \@expected_viewport,
91     'it should be updated when a workspace is emptied');
92
93 exit_gracefully($pid);
94
95 done_testing;