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