]> git.sur5r.net Git - i3/i3/blob - testcases/t/214-layout-restore-criteria.t
tests: replace http:// with https:// where appropriate
[i3/i3] / testcases / t / 214-layout-restore-criteria.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 # Tests all supported criteria for the "swallows" key.
18 use i3test;
19 use File::Temp qw(tempfile);
20 use IO::Handle;
21 use X11::XCB qw(PROP_MODE_REPLACE);
22
23 sub verify_swallow_criterion {
24     my ($cfgline, $open_window_cb) = @_;
25
26     my $ws = fresh_workspace;
27
28     my @content = @{get_ws_content($ws)};
29     is(@content, 0, "no nodes on the new workspace yet ($cfgline)");
30
31     my ($fh, $filename) = tempfile(UNLINK => 1);
32     print $fh <<EOT;
33 {
34     "layout": "splitv",
35     "nodes": [
36         {
37             "swallows": [
38                 {
39                     $cfgline
40                 }
41             ]
42         }
43     ]
44 }
45 EOT
46     $fh->flush;
47     cmd "append_layout $filename";
48
49     does_i3_live;
50
51     @content = @{get_ws_content($ws)};
52     is(@content, 1, "one node on the workspace now ($cfgline)");
53
54     my $top = $open_window_cb->();
55
56     @content = @{get_ws_content($ws)};
57     is(@content, 1, "still one node on the workspace now ($cfgline)");
58     my @nodes = @{$content[0]->{nodes}};
59     is($nodes[0]->{window}, $top->id, "top window on top ($cfgline)");
60
61     close($fh);
62 }
63
64 verify_swallow_criterion(
65     '"class": "^special_class$"',
66     sub { open_window(wm_class => 'special_class') }
67 );
68
69 # Run the same test again to verify that the window is not being swallowed by
70 # the first container. Each swallow condition should only swallow precisely one
71 # window.
72 verify_swallow_criterion(
73     '"class": "^special_class$"',
74     sub { open_window(wm_class => 'special_class') }
75 );
76
77 verify_swallow_criterion(
78     '"instance": "^special_instance$"',
79     sub { open_window(wm_class => '', instance => 'special_instance') }
80 );
81
82 verify_swallow_criterion(
83     '"title": "^special_title$"',
84     sub { open_window(name => 'special_title') }
85 );
86
87 verify_swallow_criterion(
88     '"window_role": "^special_role$"',
89     sub {
90         open_window(
91             name => 'roletest',
92             before_map => sub {
93                 my ($window) = @_;
94                 my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
95                 my $atomtype = $x->atom(name => 'STRING');
96                 $x->change_property(
97                     PROP_MODE_REPLACE,
98                     $window->id,
99                     $atomname->id,
100                     $atomtype->id,
101                     8,
102                     length("special_role") + 1,
103                     "special_role\x00"
104                 );
105             },
106         );
107     }
108 );
109
110 done_testing;