aboutsummaryrefslogtreecommitdiff
path: root/testcases/t/283-net-wm-state-hidden.t
blob: d6c7b2f8b70d5c5c5e48c2a6a2dddcfe9b1aac0a (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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
#!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 for setting and removing the _NET_WM_STATE_HIDDEN atom properly.
# Ticket: #1648
use i3test;
use X11::XCB qw(:all);

sub is_hidden {
    sync_with_i3;
    my $atom = $x->atom(name => '_NET_WM_STATE_HIDDEN');

    my ($con) = @_;
    my $cookie = $x->get_property(
        0,
        $con->{id},
        $x->atom(name => '_NET_WM_STATE')->id,
        GET_PROPERTY_TYPE_ANY,
        0,
        4096
    );

    my $reply = $x->get_property_reply($cookie->{sequence});
    my $len = $reply->{length};
    return 0 if $len == 0;

    my @atoms = unpack("L$len", $reply->{value});
    for (my $i = 0; $i < $len; $i++) {
        return 1 if $atoms[$i] == $atom->id;
    }

    return 0;
}

my ($tabA, $tabB, $tabC, $subtabA, $subtabB, $windowA, $windowB);

###############################################################################
# Given two containers next to each other, when focusing one, then the other
# one does not have _NET_WM_STATE_HIDDEN set.
###############################################################################

fresh_workspace;
$windowA = open_window;
$windowB = open_window;

ok(!is_hidden($windowA), 'left window does not have _NET_WM_STATE_HIDDEN set');
ok(!is_hidden($windowB), 'right window does not have _NET_WM_STATE_HIDDEN set');

###############################################################################
# Given two containers on different workspaces, when one is focused, then
# the other one does not have _NET_WM_STATE_HIDDEN set.
###############################################################################

fresh_workspace;
$windowA = open_window;
fresh_workspace;
$windowB = open_window;

ok(!is_hidden($windowA), 'left window does not have _NET_WM_STATE_HIDDEN set');
ok(!is_hidden($windowB), 'right window does not have _NET_WM_STATE_HIDDEN set');

###############################################################################
# Given two containers in the same tabbed container, when one is focused, then
# (only) the other one has _NET_WM_STATE_HIDDEN set.
# Given the other tab is focused, then the atom is transferred.
###############################################################################

fresh_workspace;
$tabA = open_window;
cmd 'layout tabbed';
$tabB = open_window;

ok(is_hidden($tabA), 'unfocused tab has _NET_WM_STATE_HIDDEN set');
ok(!is_hidden($tabB), 'focused tab does not have _NET_WM_STATE_HIDDEN set');

cmd 'focus left';

ok(!is_hidden($tabA), 'focused tab does not have _NET_WM_STATE_HIDDEN set');
ok(is_hidden($tabB), 'unfocused tab has _NET_WM_STATE_HIDDEN set');

###############################################################################
# Given three containers in the same stacked container, when the focused tab
# is moved to another workspace, then the now focused tab does not have
# _NET_WM_STATE_HIDDEN set anymore.
###############################################################################

fresh_workspace;
$tabA = open_window;
cmd 'layout stacked';
$tabB = open_window;
$tabC = open_window;
cmd 'move window to workspace unused';

ok(is_hidden($tabA), 'unfocused tab has _NET_WM_STATE_HIDDEN set');
ok(!is_hidden($tabB), 'focused tab does not have _NET_WM_STATE_HIDDEN set');
ok(!is_hidden($tabC), 'moved window does not have _NET_WM_STATE_HIDDEN set');

###############################################################################
# Given three containers in the same stacked container, when a not focused
# tab is moved to another workspace, then it does not have _NET_WM_STATE_HIDDEN
# set anymore.
###############################################################################

fresh_workspace;
$tabA = open_window;
cmd 'layout stacked';
$tabB = open_window;
cmd 'mark moveme';
$tabC = open_window;
cmd '[con_mark="moveme"] move window to workspace unused';

ok(is_hidden($tabA), 'unfocused tab has _NET_WM_STATE_HIDDEN set');
ok(!is_hidden($tabB), 'moved window does not have _NET_WM_STATE_HIDDEN set');
ok(!is_hidden($tabC), 'focused tab does not have _NET_WM_STATE_HIDDEN set');

###############################################################################
# Given a tabbed container and some other container, when the latter is moved
# into the tabbed container, then all other tabs have _NET_WM_STATE_HIDDEN
# set.
###############################################################################

fresh_workspace;
$tabA = open_window;
cmd 'layout tabbed';
$tabB = open_window;
cmd 'focus parent';
cmd 'split h';
$tabC = open_window;
cmd 'move left';

ok(is_hidden($tabA), 'unfocused tab has _NET_WM_STATE_HIDDEN set');
ok(is_hidden($tabB), 'unfocused tab has _NET_WM_STATE_HIDDEN set');
ok(!is_hidden($tabC), 'focused tab does not have _NET_WM_STATE_HIDDEN set');

###############################################################################
# Given a stacked container nested inside another tabbed container with the
# inner one being in the currently focused tab, then the focused tab of the
# inner container does not have _NET_WM_STATE_HIDDEN set.
###############################################################################

fresh_workspace;
$tabA = open_window;
cmd 'layout tabbed';
$tabB = open_window;
cmd 'split h';
open_window;
cmd 'split v';
cmd 'layout stacked';
$subtabA = open_window;
$subtabB = open_window;

ok(is_hidden($tabA), 'unfocused outer tab has _NET_WM_STATE_HIDDEN set');
ok(!is_hidden($tabB), 'focused outer tab does not have _NET_WM_STATE_HIDDEN set');
ok(is_hidden($subtabA), 'unfocused inner tab has _NET_WM_STATE_HIDDEN set');
ok(!is_hidden($subtabB), 'focused inner tab does not have _NET_WM_STATE_HIDDEN set');

cmd 'focus left';

ok(!is_hidden($subtabB), 'focused inner tab does not have _NET_WM_STATE_HIDDEN set');

###############################################################################
# Given a stacked container nested inside another tabbed container with the
# inner one being in a currently not focused tab, then all tabs of the inner
# container have _NET_WM_STATE_HIDDEN set.
###############################################################################

fresh_workspace;
$tabA = open_window;
cmd 'layout tabbed';
$tabB = open_window;
cmd 'split h';
open_window;
cmd 'split v';
cmd 'layout stacked';
$subtabA = open_window;
$subtabB = open_window;
cmd 'focus parent';
cmd 'focus parent';
cmd 'focus left';

ok(!is_hidden($tabA), 'focused outer tab does not have _NET_WM_STATE_HIDDEN set');
ok(is_hidden($tabB), 'unfocused outer tab has _NET_WM_STATE_HIDDEN set');
ok(is_hidden($subtabA), 'unfocused inner tab has _NET_WM_STATE_HIDDEN set');
ok(is_hidden($subtabB), 'unfocused inner tab has _NET_WM_STATE_HIDDEN set');

###############################################################################

done_testing;