2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # TODO: Description of this file.
19 # Bug still in: 4.13-12-g2ff3d9d
20 use File::Temp qw(tempfile);
21 use i3test i3_autostart => 0;
23 my $monitor_name = 'i3-fake-monitor';
24 my $output_name = 'i3-fake-output';
28 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
35 my ($outfh, $outname) = tempfile('i3-randr15reply-XXXXXX', UNLINK => 1);
37 # Prepare a RRGetMonitors reply, see A.2.4 in
38 # https://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt
39 my $reply = pack('cxSLLLLx[LLL]',
41 0, # sequence (will be filled in by inject_randr15)
42 # 60 = length($reply) + length($monitor1)
43 # 32 = minimum X11 reply length
44 (60-32) / 4, # length in words
49 # Manually intern _NET_CURRENT_DESKTOP as $x->atom will not create atoms if
50 # they are not yet interned.
51 my $atom_cookie = $x->intern_atom(0, length($monitor_name), $monitor_name);
52 my $monitor_name_atom = $x->intern_atom_reply($atom_cookie->{sequence})->{atom};
54 # MONITORINFO is defined in A.1.1 in
55 # https://cgit.freedesktop.org/xorg/proto/randrproto/tree/randrproto.txt
56 my $monitor1 = pack('LccSssSSLLL',
57 $monitor_name_atom, # name (ATOM)
63 3840, # width in pixels
64 2160, # height in pixels
65 520, # width in millimeters
66 290, # height in millimeters
67 12345); # output ID #0
70 print $outfh $monitor1;
74 # Prepare a RRGetOutputInfo reply as well; see RRGetOutputInfo in
75 # https://www.x.org/releases/current/doc/randrproto/randrproto.txt
76 ($outfh, my $outname_moninfo) = tempfile('i3-randr15reply-XXXXXX', UNLINK => 1);
77 my $moninfo = pack('cxSLLLx[LLccSSSS]S a* x!4',
79 0, # sequence (will be filled in by inject_randr15)
80 # 36 = length($moninfo) (without name and padding)
81 # 32 = minimum X11 reply length
82 ((36 + length($output_name) - 32) + 3) / 4, # length in words
85 length($output_name), # length of name
88 print $outfh $moninfo;
91 my $pid = launch_with_config($config,
92 inject_randr15 => $outname,
93 inject_randr15_outputinfo => $outname_moninfo);
95 my $tree = i3->get_tree->recv;
96 my @outputs = map { $_->{name} } @{$tree->{nodes}};
97 is_deeply(\@outputs, [ '__i3', $monitor_name ], 'outputs are __i3 and the fake monitor');
99 my ($output_data) = grep { $_->{name} eq $monitor_name } @{$tree->{nodes}};
100 is_deeply($output_data->{rect}, {
105 }, "Fake output at 3840x2160+0+0");
107 # Verify that i3 canonicalizes RandR output names to i3 output names
108 # (RandR monitor names) for bar configs
110 my $bars = i3->get_bar_config()->recv;
111 is(@$bars, 1, 'one bar configured');
113 my $bar_id = shift @$bars;
115 my $bar_config = i3->get_bar_config($bar_id)->recv;
116 is_deeply($bar_config->{outputs}, [ $monitor_name ], 'bar_config output name is normalized');
118 exit_gracefully($pid);
120 ################################################################################
121 # Verify that adding monitors with RandR 1.5 results in i3 outputs.
122 ################################################################################
124 # When inject_randr15 is defined but false, fake-xinerama will be turned off,
125 # but inject_randr15 will not actually be used.
126 $pid = launch_with_config($config, inject_randr15 => '');
128 $tree = i3->get_tree->recv;
129 @outputs = map { $_->{name} } @{$tree->{nodes}};
130 is_deeply(\@outputs, [ '__i3', 'default' ], 'outputs are __i3 and default');
133 skip 'xrandr --setmonitor failed (xrandr too old?)', 1 unless
134 system(q|xrandr --setmonitor up2414q 3840/527x2160/296+1280+0 none|) == 0;
138 $tree = i3->get_tree->recv;
139 @outputs = map { $_->{name} } @{$tree->{nodes}};
140 is_deeply(\@outputs, [ '__i3', 'default', 'up2414q' ], 'outputs are __i3, default and up2414q');
143 exit_gracefully($pid);