aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/214-layout-restore-criteria.t
blob: a6d73a20427565f230b93589c8900ee48c913e23 (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
#!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)
#
# • https://i3wm.org/downloads/modern_perl_a4.pdf
#   (unless you are already familiar with Perl)
#
# Tests all supported criteria for the "swallows" key.
use i3test;
use File::Temp qw(tempfile);
use IO::Handle;
use X11::XCB qw(PROP_MODE_REPLACE);

sub verify_swallow_criterion {
    my ($cfgline, $open_window_cb) = @_;

    my $ws = fresh_workspace;

    my @content = @{get_ws_content($ws)};
    is(@content, 0, "no nodes on the new workspace yet ($cfgline)");

    my ($fh, $filename) = tempfile(UNLINK => 1);
    print $fh <<EOT;
{
    "layout": "splitv",
    "nodes": [
        {
            "swallows": [
                {
                    $cfgline
                }
            ]
        }
    ]
}
EOT
    $fh->flush;
    cmd "append_layout $filename";

    does_i3_live;

    @content = @{get_ws_content($ws)};
    is(@content, 1, "one node on the workspace now ($cfgline)");

    my $top = $open_window_cb->();

    @content = @{get_ws_content($ws)};
    is(@content, 1, "still one node on the workspace now ($cfgline)");
    my @nodes = @{$content[0]->{nodes}};
    is($nodes[0]->{window}, $top->id, "top window on top ($cfgline)");

    close($fh);
}

verify_swallow_criterion(
    '"class": "^special_class$"',
    sub { open_window(wm_class => 'special_class') }
);

# Run the same test again to verify that the window is not being swallowed by
# the first container. Each swallow condition should only swallow precisely one
# window.
verify_swallow_criterion(
    '"class": "^special_class$"',
    sub { open_window(wm_class => 'special_class') }
);

verify_swallow_criterion(
    '"instance": "^special_instance$"',
    sub { open_window(wm_class => '', instance => 'special_instance') }
);

verify_swallow_criterion(
    '"title": "^special_title$"',
    sub { open_window(name => 'special_title') }
);

verify_swallow_criterion(
    '"window_role": "^special_role$"',
    sub {
        open_window(
            name => 'roletest',
            before_map => sub {
                my ($window) = @_;
                my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
                my $atomtype = $x->atom(name => 'STRING');
                $x->change_property(
                    PROP_MODE_REPLACE,
                    $window->id,
                    $atomname->id,
                    $atomtype->id,
                    8,
                    length("special_role") + 1,
                    "special_role\x00"
                );
            },
        );
    }
);

done_testing;