aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/177-bar-config.t
blob: 278fd59698ba6fd3eb68edba7b3651147986ac15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • https://build.i3wm.org/docs/testsuite.html
#   (or docs/testsuite)
#
# • https://build.i3wm.org/docs/lib-i3test.html
#   (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • https://build.i3wm.org/docs/ipc.html
#   (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Checks that the bar config is parsed correctly.
#

use i3test i3_autostart => 0;

#####################################################################
# test a config without any bars
#####################################################################

my $config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
EOT

my $pid = launch_with_config($config);

my $i3 = i3(get_socket_path(0));
my $bars = $i3->get_bar_config()->recv;
is(@$bars, 0, 'no bars configured');

exit_gracefully($pid);

#####################################################################
# now provide a simple bar configuration
#####################################################################

$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

bar {
    # Start a default instance of i3bar which provides workspace buttons.
    # Additionally, i3status will provide a statusline.
    status_command i3status --foo
}
EOT

$pid = launch_with_config($config);

$i3 = i3(get_socket_path(0));
$bars = $i3->get_bar_config()->recv;
is(@$bars, 1, 'one bar configured');

my $bar_id = shift @$bars;

my $bar_config = $i3->get_bar_config($bar_id)->recv;
is($bar_config->{status_command}, 'i3status --foo', 'status_command correct');
ok(!$bar_config->{verbose}, 'verbose off by default');
ok($bar_config->{workspace_buttons}, 'workspace buttons enabled per default');
is($bar_config->{workspace_min_width}, 0, 'workspace_min_width ok');
ok($bar_config->{binding_mode_indicator}, 'mode indicator enabled per default');
is($bar_config->{mode}, 'dock', 'dock mode by default');
is($bar_config->{position}, 'bottom', 'position bottom by default');
is($bar_config->{tray_padding}, 2, 'tray_padding ok');

#####################################################################
# ensure that reloading cleans up the old bar configs
#####################################################################

cmd 'reload';
$bars = $i3->get_bar_config()->recv;
is(@$bars, 1, 'still one bar configured');

exit_gracefully($pid);

#####################################################################
# validate a more complex configuration
#####################################################################

$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

bar {
    # Start a default instance of i3bar which does not provide
    # workspace buttons.
    # Additionally, i3status will provide a statusline.
    status_command i3status --bar

    output HDMI1
    output HDMI2

    tray_output LVDS1
    tray_output HDMI2
    tray_padding 0
    position top
    mode dock
    font Terminus
    workspace_buttons no
    workspace_min_width 30
    binding_mode_indicator no
    verbose yes
    socket_path /tmp/foobar

    colors {
        background #ff0000
        statusline   #00ff00
        focused_background #cc0000
        focused_statusline #cccc00
        focused_separator  #0000cc

        focused_workspace   #4c7899 #285577 #ffffff
        active_workspace    #333333 #222222 #888888
        inactive_workspace  #333333 #222222 #888888
        urgent_workspace    #2f343a #900000 #ffffff
        binding_mode        #abc123 #123abc #ababab
    }

    # old syntax for compatibility with i3-gaps
    height 50
    # new syntax: top right bottom left
    #             y   width height x
    padding 4px 2px 4px 2px
}
EOT

$pid = launch_with_config($config);

$i3 = i3(get_socket_path(0));
$bars = $i3->get_bar_config()->recv;
is(@$bars, 1, 'one bar configured');

$bar_id = shift @$bars;

$bar_config = $i3->get_bar_config($bar_id)->recv;
is($bar_config->{status_command}, 'i3status --bar', 'status_command correct');
ok($bar_config->{verbose}, 'verbose on');
ok(!$bar_config->{workspace_buttons}, 'workspace buttons disabled');
is($bar_config->{workspace_min_width}, 30, 'workspace_min_width ok');
ok(!$bar_config->{binding_mode_indicator}, 'mode indicator disabled');
is($bar_config->{mode}, 'dock', 'dock mode');
is($bar_config->{position}, 'top', 'position top');
is_deeply($bar_config->{outputs}, [ 'HDMI1', 'HDMI2' ], 'outputs ok');
is_deeply($bar_config->{tray_outputs}, [ 'LVDS1', 'HDMI2' ], 'tray_output ok');
is($bar_config->{tray_padding}, 0, 'tray_padding ok');
is($bar_config->{font}, 'Terminus', 'font ok');
is($bar_config->{socket_path}, '/tmp/foobar', 'socket_path ok');
is($bar_config->{bar_height}, 50, 'bar_height ok');
is_deeply($bar_config->{padding},
	  {
	      x => 2,
	      y => 4,
	      width => 2,
	      height => 4,
	  }, 'padding ok');
is_deeply($bar_config->{colors},
    {
        background => '#ff0000',
        statusline => '#00ff00',
        focused_background => '#cc0000',
        focused_statusline=> '#cccc00',
        focused_separator => '#0000cc',
        focused_workspace_border => '#4c7899',
        focused_workspace_text => '#ffffff',
        focused_workspace_bg => '#285577',
        active_workspace_border => '#333333',
        active_workspace_text => '#888888',
        active_workspace_bg => '#222222',
        inactive_workspace_border => '#333333',
        inactive_workspace_text => '#888888',
        inactive_workspace_bg => '#222222',
        urgent_workspace_border => '#2f343a',
        urgent_workspace_text => '#ffffff',
        urgent_workspace_bg => '#900000',
        binding_mode_border => '#abc123',
        binding_mode_text => '#ababab',
        binding_mode_bg => '#123abc',
    }, 'colors ok');

exit_gracefully($pid);

#####################################################################
# validate one-value padding directive
#####################################################################

$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

bar {
    # all padding is 25px
    padding 25px
}
EOT

$pid = launch_with_config($config);

$i3 = i3(get_socket_path(0));
$bars = $i3->get_bar_config()->recv;
is(@$bars, 1, 'one bar configured');

$bar_id = shift @$bars;

$bar_config = $i3->get_bar_config($bar_id)->recv;
is_deeply($bar_config->{padding},
	  {
	      x => 25,
	      y => 25,
	      width => 25,
	      height => 25,
	  }, 'padding ok');

exit_gracefully($pid);

#####################################################################
# validate two-value padding directive
#####################################################################

$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

bar {
    # top and bottom padding is 25px, right and left padding is 50px
    padding 25px 50px
}
EOT

$pid = launch_with_config($config);

$i3 = i3(get_socket_path(0));
$bars = $i3->get_bar_config()->recv;
is(@$bars, 1, 'one bar configured');

$bar_id = shift @$bars;

$bar_config = $i3->get_bar_config($bar_id)->recv;
is_deeply($bar_config->{padding},
	  {
	      x => 50,
	      y => 25,
	      width => 50,
	      height => 25,
	  }, 'padding ok');

exit_gracefully($pid);

#####################################################################
# validate three-value padding directive
#####################################################################

$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

bar {
    # top padding is 25px, right and left padding is 50px, bottom padding is 75px
    padding 25px 50px 75px
}
EOT

$pid = launch_with_config($config);

$i3 = i3(get_socket_path(0));
$bars = $i3->get_bar_config()->recv;
is(@$bars, 1, 'one bar configured');

$bar_id = shift @$bars;

$bar_config = $i3->get_bar_config($bar_id)->recv;
is_deeply($bar_config->{padding},
	  {
	      x => 50,
	      y => 25,
	      width => 50,
	      height => 75,
	  }, 'padding ok');

exit_gracefully($pid);

#####################################################################
# ensure that multiple bars get different IDs
#####################################################################

$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

bar {
    # Start a default instance of i3bar which provides workspace buttons.
    # Additionally, i3status will provide a statusline.
    status_command i3status --bar

    output HDMI1
}

bar {
    output VGA1
}
EOT

$pid = launch_with_config($config);

$i3 = i3(get_socket_path(0));
$bars = $i3->get_bar_config()->recv;
is(@$bars, 2, 'two bars configured');
isnt($bars->[0], $bars->[1], 'bar IDs are different');

my $bar1_config = $i3->get_bar_config($bars->[0])->recv;
my $bar2_config = $i3->get_bar_config($bars->[1])->recv;

isnt($bar1_config->{outputs}, $bar2_config->{outputs}, 'outputs different');

exit_gracefully($pid);

#####################################################################
# make sure comments work properly
#####################################################################

$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

bar {
    # Start a default instance of i3bar which provides workspace buttons.
    # Additionally, i3status will provide a statusline.
    status_command i3status --bar
    #status_command i3status --qux
#status_command i3status --qux

    output HDMI1
    colors {
        background #000000
        #background #ffffff
    }
}
EOT

$pid = launch_with_config($config);

$i3 = i3(get_socket_path(0));
$bars = $i3->get_bar_config()->recv;
$bar_id = shift @$bars;

$bar_config = $i3->get_bar_config($bar_id)->recv;
is($bar_config->{status_command}, 'i3status --bar', 'status_command correct');
is($bar_config->{colors}->{background}, '#000000', 'background color ok');

exit_gracefully($pid);

#####################################################################
# verify that the old syntax still works
#####################################################################

$config = <<EOT;
# i3 config file (v4)
font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1

bar {
    # Start a default instance of i3bar which does not provide
    # workspace buttons.
    # Additionally, i3status will provide a statusline.
    status_command i3status --bar

    output HDMI1
    output HDMI2

    tray_output LVDS1
    tray_output HDMI2
    position top
    mode dock
    font Terminus
    workspace_buttons no
    binding_mode_indicator yes
    verbose yes
    socket_path /tmp/foobar

    colors {
        background #ff0000
        statusline   #00ff00

        focused_workspace   #ffffff #285577
        active_workspace    #888888 #222222
        inactive_workspace  #888888 #222222
        urgent_workspace    #ffffff #900000
    }
}
EOT

$pid = launch_with_config($config);

$i3 = i3(get_socket_path(0));
$bars = $i3->get_bar_config()->recv;
is(@$bars, 1, 'one bar configured');

$bar_id = shift @$bars;

cmd 'nop yeah';
$bar_config = $i3->get_bar_config($bar_id)->recv;
is($bar_config->{status_command}, 'i3status --bar', 'status_command correct');
ok($bar_config->{verbose}, 'verbose on');
ok(!$bar_config->{workspace_buttons}, 'workspace buttons disabled');
ok($bar_config->{binding_mode_indicator}, 'mode indicator enabled');
is($bar_config->{mode}, 'dock', 'dock mode');
is($bar_config->{position}, 'top', 'position top');
is_deeply($bar_config->{outputs}, [ 'HDMI1', 'HDMI2' ], 'outputs ok');
is_deeply($bar_config->{tray_outputs}, [ 'LVDS1', 'HDMI2' ], 'tray_output ok');
is($bar_config->{font}, 'Terminus', 'font ok');
is($bar_config->{socket_path}, '/tmp/foobar', 'socket_path ok');
is_deeply($bar_config->{colors},
    {
        background => '#ff0000',
        statusline => '#00ff00',
        focused_workspace_text => '#ffffff',
        focused_workspace_bg => '#285577',
        active_workspace_text => '#888888',
        active_workspace_bg => '#222222',
        inactive_workspace_text => '#888888',
        inactive_workspace_bg => '#222222',
        urgent_workspace_text => '#ffffff',
        urgent_workspace_bg => '#900000',
    }, '(old) colors ok');

exit_gracefully($pid);


done_testing;