]> git.sur5r.net Git - i3/i3/blob - testcases/t/533-randr15.t
533-randr15.t: Add test for bar output name canonicalization
[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 $monitor_name = 'i3-fake-monitor';
24 my $output_name = 'i3-fake-output';
25
26 my $config = <<EOT;
27 # i3 config file (v4)
28 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
29
30 bar {
31     output $output_name
32 }
33 EOT
34
35 my ($outfh, $outname) = tempfile('i3-randr15reply-XXXXXX', UNLINK => 1);
36
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]',
40      1, # reply
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
45      0, # timestamp TODO
46      1, # nmonitors
47      1); # noutputs
48
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};
53
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)
58         1, # primary
59         1, # automatic
60         1, # ncrtcs
61         0, # x
62         0, # y
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
68
69 print $outfh $reply;
70 print $outfh $monitor1;
71
72 close($outfh);
73
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',
78                    1, # reply
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
83                    0, # timestamp TODO
84                    12345, # CRTC
85                    length($output_name), # length of name
86                    $output_name); # name
87
88 print $outfh $moninfo;
89 close($outfh);
90
91 my $pid = launch_with_config($config,
92                              inject_randr15 => $outname,
93                              inject_randr15_outputinfo => $outname_moninfo);
94
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');
98
99 my ($output_data) = grep { $_->{name} eq $monitor_name } @{$tree->{nodes}};
100 is_deeply($output_data->{rect}, {
101         width => 3840,
102         height => 2160,
103         x => 0,
104         y => 0,
105     }, "Fake output at 3840x2160+0+0");
106
107 # Verify that i3 canonicalizes RandR output names to i3 output names
108 # (RandR monitor names) for bar configs
109
110 my $bars = i3->get_bar_config()->recv;
111 is(@$bars, 1, 'one bar configured');
112
113 my $bar_id = shift @$bars;
114
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');
117
118 exit_gracefully($pid);
119
120 ################################################################################
121 # Verify that adding monitors with RandR 1.5 results in i3 outputs.
122 ################################################################################
123
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 => '');
127
128 $tree = i3->get_tree->recv;
129 @outputs = map { $_->{name} } @{$tree->{nodes}};
130 is_deeply(\@outputs, [ '__i3', 'default' ], 'outputs are __i3 and default');
131
132 SKIP: {
133     skip 'xrandr --setmonitor failed (xrandr too old?)', 1 unless
134         system(q|xrandr --setmonitor up2414q 3840/527x2160/296+1280+0 none|) == 0;
135
136     sync_with_i3;
137
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');
141 }
142
143 exit_gracefully($pid);
144
145 done_testing;