]> git.sur5r.net Git - i3/i3/blob - testcases/t/501-scratchpad.t
tests: use i3_config arg instead of precisely one launch_with_config
[i3/i3] / testcases / t / 501-scratchpad.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 # Verifies that scratchpad windows show up on the proper output.
18 # ticket #596, bug present until up to commit
19 # 89dded044b4fffe78f9d70778748fabb7ac533e9.
20 #
21 use i3test i3_config => <<EOT;
22 # i3 config file (v4)
23 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
24
25 fake-outputs 1024x768+0+0,1024x768+1024+0
26 EOT
27
28 ################################################################################
29 # Open a workspace on the second output, put a window to scratchpad, display
30 # it, verify it’s on the same workspace.
31 ################################################################################
32
33 sub verify_scratchpad_on_same_ws {
34     my ($ws) = @_;
35
36     is_num_children($ws, 0, 'no nodes on this ws');
37
38     my $window = open_window;
39
40     is_num_children($ws, 1, 'one nodes on this ws');
41
42     cmd 'move scratchpad';
43
44     is_num_children($ws, 0, 'no nodes on this ws');
45
46     cmd 'scratchpad show';
47     is_num_children($ws, 0, 'no nodes on this ws');
48     is(scalar @{get_ws($ws)->{floating_nodes}}, 1, 'one floating node on this ws');
49 }
50
51 my $second = fresh_workspace(output => 1);
52
53 verify_scratchpad_on_same_ws($second);
54
55 ################################################################################
56 # The same thing, but on the first output.
57 ################################################################################
58
59 my $first = fresh_workspace(output => 0);
60
61 verify_scratchpad_on_same_ws($first);
62
63 ################################################################################
64 # Now open the scratchpad on one output and switch to another.
65 ################################################################################
66
67 sub verify_scratchpad_switch {
68     my ($first, $second) = @_;
69
70     cmd "workspace $first";
71
72     is_num_children($first, 0, 'no nodes on this ws');
73
74     my $window = open_window;
75
76     is_num_children($first, 1, 'one nodes on this ws');
77
78     cmd 'move scratchpad';
79
80     is_num_children($first, 0, 'no nodes on this ws');
81
82     cmd "workspace $second";
83
84     cmd 'scratchpad show';
85     my $ws = get_ws($second);
86     is_num_children($second, 0, 'no nodes on this ws');
87     is(scalar @{$ws->{floating_nodes}}, 1, 'one floating node on this ws');
88
89     # Verify that the coordinates are within bounds.
90     my $srect = $ws->{floating_nodes}->[0]->{rect};
91     my $rect = $ws->{rect};
92     cmd 'nop before bounds check';
93     cmp_ok($srect->{x}, '>=', $rect->{x}, 'x within bounds');
94     cmp_ok($srect->{y}, '>=', $rect->{y}, 'y within bounds');
95     cmp_ok($srect->{x} + $srect->{width}, '<=', $rect->{x} + $rect->{width},
96            'width within bounds');
97     cmp_ok($srect->{y} + $srect->{height}, '<=', $rect->{y} + $rect->{height},
98            'height within bounds');
99 }
100
101 $first = fresh_workspace(output => 0);
102 $second = fresh_workspace(output => 1);
103
104 verify_scratchpad_switch($first, $second);
105
106 $first = fresh_workspace(output => 1);
107 $second = fresh_workspace(output => 0);
108
109 verify_scratchpad_switch($first, $second);
110
111 done_testing;