]> 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 # Verifies that scratchpad windows show up on the proper output.
5 # ticket #596, bug present until up to commit
6 # 89dded044b4fffe78f9d70778748fabb7ac533e9.
7 #
8 use i3test;
9
10 my $i3 = i3(get_socket_path());
11
12 ################################################################################
13 # Open a workspace on the second output, put a window to scratchpad, display
14 # it, verify it’s on the same workspace.
15 ################################################################################
16
17 sub verify_scratchpad_on_same_ws {
18     my ($ws) = @_;
19
20     is(scalar @{get_ws($ws)->{nodes}}, 0, 'no nodes on this ws');
21
22     my $window = open_window;
23
24     is(scalar @{get_ws($ws)->{nodes}}, 1, 'one nodes on this ws');
25
26     cmd 'move scratchpad';
27
28     is(scalar @{get_ws($ws)->{nodes}}, 0, 'no nodes on this ws');
29
30     cmd 'scratchpad show';
31     is(scalar @{get_ws($ws)->{nodes}}, 0, 'no nodes on this ws');
32     is(scalar @{get_ws($ws)->{floating_nodes}}, 1, 'one floating node on this ws');
33 }
34
35 my $second = fresh_workspace(output => 1);
36
37 verify_scratchpad_on_same_ws($second);
38
39 ################################################################################
40 # The same thing, but on the first output.
41 ################################################################################
42
43 my $first = fresh_workspace(output => 0);
44
45 verify_scratchpad_on_same_ws($first);
46
47 ################################################################################
48 # Now open the scratchpad on one output and switch to another.
49 ################################################################################
50
51 sub verify_scratchpad_switch {
52     my ($first, $second) = @_;
53
54     cmd "workspace $first";
55
56     is(scalar @{get_ws($first)->{nodes}}, 0, 'no nodes on this ws');
57
58     my $window = open_window;
59
60     is(scalar @{get_ws($first)->{nodes}}, 1, 'one nodes on this ws');
61
62     cmd 'move scratchpad';
63
64     is(scalar @{get_ws($first)->{nodes}}, 0, 'no nodes on this ws');
65
66     cmd "workspace $second";
67
68     cmd 'scratchpad show';
69     my $ws = get_ws($second);
70     is(scalar @{$ws->{nodes}}, 0, 'no nodes on this ws');
71     is(scalar @{$ws->{floating_nodes}}, 1, 'one floating node on this ws');
72
73     # Verify that the coordinates are within bounds.
74     my $srect = $ws->{floating_nodes}->[0]->{rect};
75     my $rect = $ws->{rect};
76     cmd 'nop before bounds check';
77     cmp_ok($srect->{x}, '>=', $rect->{x}, 'x within bounds');
78     cmp_ok($srect->{y}, '>=', $rect->{y}, 'y within bounds');
79     cmp_ok($srect->{x} + $srect->{width}, '<=', $rect->{x} + $rect->{width},
80            'width within bounds');
81     cmp_ok($srect->{y} + $srect->{height}, '<=', $rect->{y} + $rect->{height},
82            'height within bounds');
83 }
84
85 $first = fresh_workspace(output => 0);
86 $second = fresh_workspace(output => 1);
87
88 verify_scratchpad_switch($first, $second);
89
90 $first = fresh_workspace(output => 1);
91 $second = fresh_workspace(output => 0);
92
93 verify_scratchpad_switch($first, $second);
94
95 done_testing;