]> git.sur5r.net Git - i3/i3/blob - testcases/t/501-scratchpad.t
Merge branch 'master' into next
[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_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 fake-outputs 1024x768+0+0,1024x768+1024+0
28 EOT
29 my $pid = launch_with_config($config);
30
31 my $i3 = i3(get_socket_path());
32
33 ################################################################################
34 # Open a workspace on the second output, put a window to scratchpad, display
35 # it, verify it’s on the same workspace.
36 ################################################################################
37
38 sub verify_scratchpad_on_same_ws {
39     my ($ws) = @_;
40
41     is_num_children($ws, 0, 'no nodes on this ws');
42
43     my $window = open_window;
44
45     is_num_children($ws, 1, 'one nodes on this ws');
46
47     cmd 'move scratchpad';
48
49     is_num_children($ws, 0, 'no nodes on this ws');
50
51     cmd 'scratchpad show';
52     is_num_children($ws, 0, 'no nodes on this ws');
53     is(scalar @{get_ws($ws)->{floating_nodes}}, 1, 'one floating node on this ws');
54 }
55
56 my $second = fresh_workspace(output => 1);
57
58 verify_scratchpad_on_same_ws($second);
59
60 ################################################################################
61 # The same thing, but on the first output.
62 ################################################################################
63
64 my $first = fresh_workspace(output => 0);
65
66 verify_scratchpad_on_same_ws($first);
67
68 ################################################################################
69 # Now open the scratchpad on one output and switch to another.
70 ################################################################################
71
72 sub verify_scratchpad_switch {
73     my ($first, $second) = @_;
74
75     cmd "workspace $first";
76
77     is_num_children($first, 0, 'no nodes on this ws');
78
79     my $window = open_window;
80
81     is_num_children($first, 1, 'one nodes on this ws');
82
83     cmd 'move scratchpad';
84
85     is_num_children($first, 0, 'no nodes on this ws');
86
87     cmd "workspace $second";
88
89     cmd 'scratchpad show';
90     my $ws = get_ws($second);
91     is_num_children($second, 0, 'no nodes on this ws');
92     is(scalar @{$ws->{floating_nodes}}, 1, 'one floating node on this ws');
93
94     # Verify that the coordinates are within bounds.
95     my $srect = $ws->{floating_nodes}->[0]->{rect};
96     my $rect = $ws->{rect};
97     cmd 'nop before bounds check';
98     cmp_ok($srect->{x}, '>=', $rect->{x}, 'x within bounds');
99     cmp_ok($srect->{y}, '>=', $rect->{y}, 'y within bounds');
100     cmp_ok($srect->{x} + $srect->{width}, '<=', $rect->{x} + $rect->{width},
101            'width within bounds');
102     cmp_ok($srect->{y} + $srect->{height}, '<=', $rect->{y} + $rect->{height},
103            'height within bounds');
104 }
105
106 $first = fresh_workspace(output => 0);
107 $second = fresh_workspace(output => 1);
108
109 verify_scratchpad_switch($first, $second);
110
111 $first = fresh_workspace(output => 1);
112 $second = fresh_workspace(output => 0);
113
114 verify_scratchpad_switch($first, $second);
115
116 exit_gracefully($pid);
117
118 done_testing;