]> git.sur5r.net Git - i3/i3/blob - testcases/t/533-randr15.t
533-randr15.t: Add a fake output connected to the fake monitor
[i3/i3] / testcases / t / 533-randr15.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 # TODO: Description of this file.
18 # Ticket: #999
19 # Bug still in: 4.13-12-g2ff3d9d
20 use File::Temp qw(tempfile);
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 EOT
28
29 my ($outfh, $outname) = tempfile('i3-randr15reply-XXXXXX', UNLINK => 1);
30
31 # Prepare a RRGetMonitors reply, see A.2.4 in
32 # https://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt
33 my $reply = pack('cxSLLLLx[LLL]',
34      1, # reply
35      0, # sequence (will be filled in by inject_randr15)
36      # 60 = length($reply) + length($monitor1)
37      # 32 = minimum X11 reply length
38      (60-32) / 4, # length in words
39      0, # timestamp TODO
40      1, # nmonitors
41      1); # noutputs
42
43 # Manually intern _NET_CURRENT_DESKTOP as $x->atom will not create atoms if
44 # they are not yet interned.
45 my $atom_cookie = $x->intern_atom(0, length("DP3"), "DP3");
46 my $DP3 = $x->intern_atom_reply($atom_cookie->{sequence})->{atom};
47
48 # MONITORINFO is defined in A.1.1 in
49 # https://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt
50 my $monitor1 = pack('LccSssSSLLL',
51         $DP3, # name (ATOM)
52         1, # primary
53         1, # automatic
54         1, # ncrtcs
55         0, # x
56         0, # y
57         3840, # width in pixels
58         2160, # height in pixels
59         520, # width in millimeters
60         290, # height in millimeters
61         12345); # output ID #0
62
63 print $outfh $reply;
64 print $outfh $monitor1;
65
66 close($outfh);
67
68 # Prepare a RRGetOutputInfo reply as well; see RRGetOutputInfo in
69 # https://www.x.org/releases/current/doc/randrproto/randrproto.txt
70 my $output_name = 'i3-fake-output';
71 ($outfh, my $outname_moninfo) = tempfile('i3-randr15reply-XXXXXX', UNLINK => 1);
72 my $moninfo = pack('cxSLLLx[LLccSSSS]S a* x!4',
73                    1, # reply
74                    0, # sequence (will be filled in by inject_randr15)
75                    # 36 = length($moninfo) (without name and padding)
76                    # 32 = minimum X11 reply length
77                    ((36 + length($output_name) - 32) + 3) / 4, # length in words
78                    0, # timestamp TODO
79                    12345, # CRTC
80                    length($output_name), # length of name
81                    $output_name); # name
82
83 print $outfh $moninfo;
84 close($outfh);
85
86 my $pid = launch_with_config($config,
87                              inject_randr15 => $outname,
88                              inject_randr15_outputinfo => $outname_moninfo);
89
90 my $tree = i3->get_tree->recv;
91 my @outputs = map { $_->{name} } @{$tree->{nodes}};
92 is_deeply(\@outputs, [ '__i3', 'DP3' ], 'outputs are __i3 and DP3');
93
94 my ($dp3) = grep { $_->{name} eq 'DP3' } @{$tree->{nodes}};
95 is_deeply($dp3->{rect}, {
96         width => 3840,
97         height => 2160,
98         x => 0,
99         y => 0,
100     }, 'Output DP3 at 3840x2160+0+0');
101
102 exit_gracefully($pid);
103
104 ################################################################################
105 # Verify that adding monitors with RandR 1.5 results in i3 outputs.
106 ################################################################################
107
108 # When inject_randr15 is defined but false, fake-xinerama will be turned off,
109 # but inject_randr15 will not actually be used.
110 $pid = launch_with_config($config, inject_randr15 => '');
111
112 $tree = i3->get_tree->recv;
113 @outputs = map { $_->{name} } @{$tree->{nodes}};
114 is_deeply(\@outputs, [ '__i3', 'default' ], 'outputs are __i3 and default');
115
116 SKIP: {
117     skip 'xrandr --setmonitor failed (xrandr too old?)', 1 unless
118         system(q|xrandr --setmonitor up2414q 3840/527x2160/296+1280+0 none|) == 0;
119
120     sync_with_i3;
121
122     $tree = i3->get_tree->recv;
123     @outputs = map { $_->{name} } @{$tree->{nodes}};
124     is_deeply(\@outputs, [ '__i3', 'default', 'up2414q' ], 'outputs are __i3, default and up2414q');
125 }
126
127 exit_gracefully($pid);
128
129 done_testing;