]> git.sur5r.net Git - i3/i3/blob - testcases/t/235-wm-class-change-handler.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 235-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 # • 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 # 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_autostart => 0;
23 use X11::XCB qw(PROP_MODE_REPLACE);
24
25 my $config = <<EOT;
26 # i3 config file (v4)
27 font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1
28 for_window [class="Special"] mark special_class_mark
29 EOT
30
31 my $pid = launch_with_config($config);
32
33 sub change_window_class {
34     my ($window, $class, $length) = @_;
35     my $atomname = $x->atom(name => 'WM_CLASS');
36     my $atomtype = $x->atom(name => 'STRING');
37     $length ||= length($class) + 1;
38     $x->change_property(
39         PROP_MODE_REPLACE,
40         $window->id,
41         $atomname->id,
42         $atomtype->id,
43         8,
44         $length,
45         $class
46     );
47     sync_with_i3;
48 }
49
50 my $ws = fresh_workspace;
51
52 my $win = open_window;
53
54 change_window_class($win, "special\0Special");
55
56 my $con = @{get_ws_content($ws)}[0];
57
58 is($con->{window_properties}->{class}, 'Special',
59     'The container class should be updated when a window changes class');
60
61 is($con->{window_properties}->{instance}, 'special',
62     'The container instance should be updated when a window changes instance');
63
64 # The mark `special_class_mark` is added in a `for_window` assignment in the
65 # config for testing purposes
66 is($con->{mark}, 'special_class_mark',
67     'A `for_window` assignment should run for a match when the window changes class');
68
69 change_window_class($win, "abcdefghijklmnopqrstuv\0abcd", 24);
70
71 $con = @{get_ws_content($ws)}[0];
72
73 is($con->{window_properties}->{class}, 'a',
74     'Non-null-terminated strings should be handled correctly');
75
76 exit_gracefully($pid);
77
78 done_testing;