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