aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/542-layout-restore-remanage.t
blob: 100150655d237d7e01a635854685c25c6727c648 (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
#!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 that swallowing still works after a window gets managed and its property
# updated.
use i3test;
use File::Temp qw(tempfile);
use IO::Handle;
use X11::XCB qw(PROP_MODE_REPLACE);

sub change_window_title {
    my ($window, $title, $length) = @_;
    my $atomname = $x->atom(name => '_NET_WM_NAME');
    my $atomtype = $x->atom(name => 'UTF8_STRING');
    $length ||= length($title) + 1;
    $x->change_property(
        PROP_MODE_REPLACE,
        $window->id,
        $atomname->id,
        $atomtype->id,
        8,
        $length,
        $title
    );
    sync_with_i3;
}

my $ws = fresh_workspace;

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

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

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

my $window = open_window(
    name => 'original_title',
    wm_class => 'a',
);

@content = @{get_ws_content($ws)};
is(@content, 2, 'two nodes on the workspace now');

change_window_title($window, "different_title");

does_i3_live;

@content = @{get_ws_content($ws)};
my @nodes = @{$content[0]->{nodes}};
is(@content, 1, 'only one node on the workspace now');
is($nodes[0]->{name}, 'different_title', 'test window got swallowed');

close($fh);

############################################################
# Make sure window only gets swallowed once
############################################################
# Regression, issue #3888
$ws = fresh_workspace;

($fh, $filename) = tempfile(UNLINK => 1);
print $fh <<'EOT';
// vim:ts=4:sw=4:et
{
    // splith split container with 2 children
    "layout": "splith",
    "type": "con",
    "nodes": [
        {
            "type": "con",
            "swallows": [
               {
               "class": "^foo$"
               }
            ]
        },
        {
            // splitv split container with 2 children
            "layout": "splitv",
            "type": "con",
            "nodes": [
                {
                    "type": "con",
                    "swallows": [
                       {
                        "class": "^foo$"
                       }
                    ]
                },
                {
                    "type": "con",
                    "swallows": [
                       {
                        "class": "^foo$"
                       }
                    ]
                }
            ]
        }
    ]
}
EOT
$fh->flush;
cmd "append_layout $filename";

$window = open_window wm_class => 'foo';

# Changing an unrelated window property originally resulted in the window
# getting remanaged and swallowd by a different placeholder, even though the
# matching property (class for the layout above) didn't change.
change_window_title($window, "different_title");

@content = @{get_ws_content($ws)};

subtest 'regression test that window gets only swallowed once', sub {
    is($content[0]->{nodes}[0]->{window}, $window->id, 'first placeholder swallowed window');
    isnt($content[0]->{nodes}[1]->{nodes}[0]->{window}, $window->id, 'second placeholder did not swallow window');
    isnt($content[0]->{nodes}[1]->{nodes}[1]->{window}, $window->id, 'thid placeholder did not swallow window');
};

done_testing;