]> git.sur5r.net Git - i3/i3/blob - testcases/t/177-bar-config.t
Merge pull request #1731 from Airblader/feature-indicator-pango
[i3/i3] / testcases / t / 177-bar-config.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 # Checks that the bar config is parsed correctly.
18 #
19
20 use i3test i3_autostart => 0;
21
22 #####################################################################
23 # test a config without any bars
24 #####################################################################
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 EOT
30
31 my $pid = launch_with_config($config);
32
33 my $i3 = i3(get_socket_path(0));
34 my $bars = $i3->get_bar_config()->recv;
35 is(@$bars, 0, 'no bars configured');
36
37 exit_gracefully($pid);
38
39 #####################################################################
40 # now provide a simple bar configuration
41 #####################################################################
42
43 $config = <<EOT;
44 # i3 config file (v4)
45 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
46
47 bar {
48     # Start a default instance of i3bar which provides workspace buttons.
49     # Additionally, i3status will provide a statusline.
50     status_command i3status --foo
51 }
52 EOT
53
54 $pid = launch_with_config($config);
55
56 $i3 = i3(get_socket_path(0));
57 $bars = $i3->get_bar_config()->recv;
58 is(@$bars, 1, 'one bar configured');
59
60 my $bar_id = shift @$bars;
61
62 my $bar_config = $i3->get_bar_config($bar_id)->recv;
63 is($bar_config->{status_command}, 'i3status --foo', 'status_command correct');
64 ok(!$bar_config->{verbose}, 'verbose off by default');
65 ok($bar_config->{workspace_buttons}, 'workspace buttons enabled per default');
66 ok($bar_config->{binding_mode_indicator}, 'mode indicator enabled per default');
67 is($bar_config->{mode}, 'dock', 'dock mode by default');
68 is($bar_config->{position}, 'bottom', 'position bottom by default');
69
70 #####################################################################
71 # ensure that reloading cleans up the old bar configs
72 #####################################################################
73
74 cmd 'reload';
75 $bars = $i3->get_bar_config()->recv;
76 is(@$bars, 1, 'still one bar configured');
77
78 exit_gracefully($pid);
79
80 #####################################################################
81 # validate a more complex configuration
82 #####################################################################
83
84 $config = <<EOT;
85 # i3 config file (v4)
86 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
87
88 bar {
89     # Start a default instance of i3bar which does not provide
90     # workspace buttons.
91     # Additionally, i3status will provide a statusline.
92     status_command i3status --bar
93
94     output HDMI1
95     output HDMI2
96
97     tray_output LVDS1
98     tray_output HDMI2
99     position top
100     mode dock
101     font Terminus
102     workspace_buttons no
103     binding_mode_indicator no
104     verbose yes
105     socket_path /tmp/foobar
106
107     colors {
108         background #ff0000
109         statusline   #00ff00
110
111         focused_workspace   #4c7899 #285577 #ffffff
112         active_workspace    #333333 #222222 #888888
113         inactive_workspace  #333333 #222222 #888888
114         urgent_workspace    #2f343a #900000 #ffffff
115         binding_mode        #abc123 #123abc #ababab
116     }
117 }
118 EOT
119
120 $pid = launch_with_config($config);
121
122 $i3 = i3(get_socket_path(0));
123 $bars = $i3->get_bar_config()->recv;
124 is(@$bars, 1, 'one bar configured');
125
126 $bar_id = shift @$bars;
127
128 $bar_config = $i3->get_bar_config($bar_id)->recv;
129 is($bar_config->{status_command}, 'i3status --bar', 'status_command correct');
130 ok($bar_config->{verbose}, 'verbose on');
131 ok(!$bar_config->{workspace_buttons}, 'workspace buttons disabled');
132 ok(!$bar_config->{binding_mode_indicator}, 'mode indicator disabled');
133 is($bar_config->{mode}, 'dock', 'dock mode');
134 is($bar_config->{position}, 'top', 'position top');
135 is_deeply($bar_config->{outputs}, [ 'HDMI1', 'HDMI2' ], 'outputs ok');
136 is($bar_config->{tray_output}, 'HDMI2', 'tray_output ok');
137 is($bar_config->{font}, 'Terminus', 'font ok');
138 is($bar_config->{socket_path}, '/tmp/foobar', 'socket_path ok');
139 is_deeply($bar_config->{colors},
140     {
141         background => '#ff0000',
142         statusline => '#00ff00',
143         focused_workspace_border => '#4c7899',
144         focused_workspace_text => '#ffffff',
145         focused_workspace_bg => '#285577',
146         active_workspace_border => '#333333',
147         active_workspace_text => '#888888',
148         active_workspace_bg => '#222222',
149         inactive_workspace_border => '#333333',
150         inactive_workspace_text => '#888888',
151         inactive_workspace_bg => '#222222',
152         urgent_workspace_border => '#2f343a',
153         urgent_workspace_text => '#ffffff',
154         urgent_workspace_bg => '#900000',
155         binding_mode_border => '#abc123',
156         binding_mode_text => '#ababab',
157         binding_mode_bg => '#123abc',
158     }, 'colors ok');
159
160 exit_gracefully($pid);
161
162 #####################################################################
163 # ensure that multiple bars get different IDs
164 #####################################################################
165
166 $config = <<EOT;
167 # i3 config file (v4)
168 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
169
170 bar {
171     # Start a default instance of i3bar which provides workspace buttons.
172     # Additionally, i3status will provide a statusline.
173     status_command i3status --bar
174
175     output HDMI1
176 }
177
178 bar {
179     output VGA1
180 }
181 EOT
182
183 $pid = launch_with_config($config);
184
185 $i3 = i3(get_socket_path(0));
186 $bars = $i3->get_bar_config()->recv;
187 is(@$bars, 2, 'two bars configured');
188 isnt($bars->[0], $bars->[1], 'bar IDs are different');
189
190 my $bar1_config = $i3->get_bar_config($bars->[0])->recv;
191 my $bar2_config = $i3->get_bar_config($bars->[1])->recv;
192
193 isnt($bar1_config->{outputs}, $bar2_config->{outputs}, 'outputs different');
194
195 exit_gracefully($pid);
196
197 #####################################################################
198 # make sure comments work properly
199 #####################################################################
200
201 $config = <<EOT;
202 # i3 config file (v4)
203 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
204
205 bar {
206     # Start a default instance of i3bar which provides workspace buttons.
207     # Additionally, i3status will provide a statusline.
208     status_command i3status --bar
209     #status_command i3status --qux
210 #status_command i3status --qux
211
212     output HDMI1
213     colors {
214         background #000000
215         #background #ffffff
216     }
217 }
218 EOT
219
220 $pid = launch_with_config($config);
221
222 $i3 = i3(get_socket_path(0));
223 $bars = $i3->get_bar_config()->recv;
224 $bar_id = shift @$bars;
225
226 $bar_config = $i3->get_bar_config($bar_id)->recv;
227 is($bar_config->{status_command}, 'i3status --bar', 'status_command correct');
228 is($bar_config->{colors}->{background}, '#000000', 'background color ok');
229
230 exit_gracefully($pid);
231
232 #####################################################################
233 # verify that the old syntax still works
234 #####################################################################
235
236 $config = <<EOT;
237 # i3 config file (v4)
238 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
239
240 bar {
241     # Start a default instance of i3bar which does not provide
242     # workspace buttons.
243     # Additionally, i3status will provide a statusline.
244     status_command i3status --bar
245
246     output HDMI1
247     output HDMI2
248
249     tray_output LVDS1
250     tray_output HDMI2
251     position top
252     mode dock
253     font Terminus
254     workspace_buttons no
255     binding_mode_indicator yes
256     verbose yes
257     socket_path /tmp/foobar
258
259     colors {
260         background #ff0000
261         statusline   #00ff00
262
263         focused_workspace   #ffffff #285577
264         active_workspace    #888888 #222222
265         inactive_workspace  #888888 #222222
266         urgent_workspace    #ffffff #900000
267     }
268 }
269 EOT
270
271 $pid = launch_with_config($config);
272
273 $i3 = i3(get_socket_path(0));
274 $bars = $i3->get_bar_config()->recv;
275 is(@$bars, 1, 'one bar configured');
276
277 $bar_id = shift @$bars;
278
279 cmd 'nop yeah';
280 $bar_config = $i3->get_bar_config($bar_id)->recv;
281 is($bar_config->{status_command}, 'i3status --bar', 'status_command correct');
282 ok($bar_config->{verbose}, 'verbose on');
283 ok(!$bar_config->{workspace_buttons}, 'workspace buttons disabled');
284 ok($bar_config->{binding_mode_indicator}, 'mode indicator enabled');
285 is($bar_config->{mode}, 'dock', 'dock mode');
286 is($bar_config->{position}, 'top', 'position top');
287 is_deeply($bar_config->{outputs}, [ 'HDMI1', 'HDMI2' ], 'outputs ok');
288 is($bar_config->{tray_output}, 'HDMI2', 'tray_output ok');
289 is($bar_config->{font}, 'Terminus', 'font ok');
290 is($bar_config->{socket_path}, '/tmp/foobar', 'socket_path ok');
291 is_deeply($bar_config->{colors},
292     {
293         background => '#ff0000',
294         statusline => '#00ff00',
295         focused_workspace_text => '#ffffff',
296         focused_workspace_bg => '#285577',
297         active_workspace_text => '#888888',
298         active_workspace_bg => '#222222',
299         inactive_workspace_text => '#888888',
300         inactive_workspace_bg => '#222222',
301         urgent_workspace_text => '#ffffff',
302         urgent_workspace_bg => '#900000',
303     }, '(old) colors ok');
304
305 exit_gracefully($pid);
306
307
308 done_testing;