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