]> git.sur5r.net Git - i3/i3/blob - testcases/t/280-wm-class-change-handler.t
resize set for floating: interpret 0 as 'no change'
[i3/i3] / testcases / t / 280-wm-class-change-handler.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://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 # Test that changes to WM_CLASS are internally processed by i3 by updating the
18 # cached property and running assignments. This allows the property to be used
19 # in criteria selection
20 # Ticket: #1052
21 # Bug still in: 4.8-73-g6bf7f8e
22 use i3test i3_config => <<EOT;
23 # i3 config file (v4)
24 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
25 for_window [class="Special"] mark special_class_mark
26 EOT
27 use X11::XCB qw(PROP_MODE_REPLACE);
28
29 sub change_window_class {
30     my ($window, $class, $length) = @_;
31     my $atomname = $x->atom(name => 'WM_CLASS');
32     my $atomtype = $x->atom(name => 'STRING');
33     $length ||= length($class) + 1;
34     $x->change_property(
35         PROP_MODE_REPLACE,
36         $window->id,
37         $atomname->id,
38         $atomtype->id,
39         8,
40         $length,
41         $class
42     );
43     sync_with_i3;
44 }
45
46 my $ws = fresh_workspace;
47
48 my $win = open_window;
49
50 change_window_class($win, "special\0Special");
51
52 my $con = @{get_ws_content($ws)}[0];
53
54 is($con->{window_properties}->{class}, 'Special',
55     'The container class should be updated when a window changes class');
56
57 is($con->{window_properties}->{instance}, 'special',
58     'The container instance should be updated when a window changes instance');
59
60 # The mark `special_class_mark` is added in a `for_window` assignment in the
61 # config for testing purposes
62 is_deeply($con->{marks}, [ 'special_class_mark' ],
63     'A `for_window` assignment should run for a match when the window changes class');
64
65 change_window_class($win, "abcdefghijklmnopqrstuv\0abcd", 24);
66
67 $con = @{get_ws_content($ws)}[0];
68
69 is($con->{window_properties}->{class}, 'a',
70     'Non-null-terminated strings should be handled correctly');
71
72 done_testing;