]> git.sur5r.net Git - i3/i3/blob - testcases/t/283-net-wm-state-hidden.t
3f2301c6b56d5a1b59b15f4e192b571d12810da5
[i3/i3] / testcases / t / 283-net-wm-state-hidden.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 # Tests for setting and removing the _NET_WM_STATE_HIDDEN atom properly.
18 # Ticket: #1648
19 use i3test;
20 use X11::XCB qw(:all);
21
22 sub is_hidden {
23     sync_with_i3;
24     my $atom = $x->atom(name => '_NET_WM_STATE_HIDDEN');
25
26     my ($con) = @_;
27     my $cookie = $x->get_property(
28         0,
29         $con->{id},
30         $x->atom(name => '_NET_WM_STATE')->id,
31         GET_PROPERTY_TYPE_ANY,
32         0,
33         4096
34     );
35
36     my $reply = $x->get_property_reply($cookie->{sequence});
37     my $len = $reply->{length};
38     return 0 if $len == 0;
39
40     my @atoms = unpack("L$len", $reply->{value});
41     for (my $i = 0; $i < $len; $i++) {
42         return 1 if $atoms[$i] == $atom->id;
43     }
44
45     return 0;
46 }
47
48 my ($tabA, $tabB, $tabC, $subtabA, $subtabB, $windowA, $windowB);
49
50 ###############################################################################
51 # Given two containers next to each other, when focusing one, then the other
52 # one does not have _NET_WM_STATE_HIDDEN set.
53 ###############################################################################
54
55 fresh_workspace;
56 $windowA = open_window;
57 $windowB = open_window;
58
59 ok(!is_hidden($windowA), 'left window does not have _NET_WM_STATE_HIDDEN set');
60 ok(!is_hidden($windowB), 'right window does not have _NET_WM_STATE_HIDDEN set');
61
62 ###############################################################################
63 # Given two containers on different workspaces, when one is focused, then
64 # the other one does not have _NET_WM_STATE_HIDDEN set.
65 ###############################################################################
66
67 fresh_workspace;
68 $windowA = open_window;
69 fresh_workspace;
70 $windowB = open_window;
71
72 ok(!is_hidden($windowA), 'left window does not have _NET_WM_STATE_HIDDEN set');
73 ok(!is_hidden($windowB), 'right window does not have _NET_WM_STATE_HIDDEN set');
74
75 ###############################################################################
76 # Given two containers in the same tabbed container, when one is focused, then
77 # (only) the other one has _NET_WM_STATE_HIDDEN set.
78 # Given the other tab is focused, then the atom is transferred.
79 ###############################################################################
80
81 fresh_workspace;
82 $tabA = open_window;
83 cmd 'layout tabbed';
84 $tabB = open_window;
85
86 ok(is_hidden($tabA), 'unfocused tab has _NET_WM_STATE_HIDDEN set');
87 ok(!is_hidden($tabB), 'focused tab does not have _NET_WM_STATE_HIDDEN set');
88
89 cmd 'focus left';
90
91 ok(!is_hidden($tabA), 'focused tab does not have _NET_WM_STATE_HIDDEN set');
92 ok(is_hidden($tabB), 'unfocused tab has _NET_WM_STATE_HIDDEN set');
93
94 ###############################################################################
95 # Given three containers in the same stacked container, when the focused tab
96 # is moved to another workspace, then the now focused tab does not have
97 # _NET_WM_STATE_HIDDEN set anymore.
98 ###############################################################################
99
100 fresh_workspace;
101 $tabA = open_window;
102 cmd 'layout stacked';
103 $tabB = open_window;
104 $tabC = open_window;
105 cmd 'move window to workspace unused';
106
107 ok(is_hidden($tabA), 'unfocused tab has _NET_WM_STATE_HIDDEN set');
108 ok(!is_hidden($tabB), 'focused tab does not have _NET_WM_STATE_HIDDEN set');
109 ok(!is_hidden($tabC), 'moved window does not have _NET_WM_STATE_HIDDEN set');
110
111 ###############################################################################
112 # Given three containers in the same stacked container, when a not focused
113 # tab is moved to another workspace, then it does not have _NET_WM_STATE_HIDDEN
114 # set anymore.
115 ###############################################################################
116
117 fresh_workspace;
118 $tabA = open_window;
119 cmd 'layout stacked';
120 $tabB = open_window;
121 cmd 'mark moveme';
122 $tabC = open_window;
123 cmd '[con_mark="moveme"] move window to workspace unused';
124
125 ok(is_hidden($tabA), 'unfocused tab has _NET_WM_STATE_HIDDEN set');
126 ok(!is_hidden($tabB), 'moved window does not have _NET_WM_STATE_HIDDEN set');
127 ok(!is_hidden($tabC), 'focused tab does not have _NET_WM_STATE_HIDDEN set');
128
129 ###############################################################################
130 # Given a tabbed container and some other container, when the latter is moved
131 # into the tabbed container, then all other tabs have _NET_WM_STATE_HIDDEN
132 # set.
133 ###############################################################################
134
135 fresh_workspace;
136 $tabA = open_window;
137 cmd 'layout tabbed';
138 $tabB = open_window;
139 cmd 'focus parent';
140 cmd 'split h';
141 $tabC = open_window;
142 cmd 'move left';
143
144 ok(is_hidden($tabA), 'unfocused tab has _NET_WM_STATE_HIDDEN set');
145 ok(is_hidden($tabB), 'unfocused tab has _NET_WM_STATE_HIDDEN set');
146 ok(!is_hidden($tabC), 'focused tab does not have _NET_WM_STATE_HIDDEN set');
147
148 ###############################################################################
149 # Given a stacked container nested inside another tabbed container with the
150 # inner one being in the currently focused tab, then the focused tab of the
151 # inner container does not have _NET_WM_STATE_HIDDEN set.
152 ###############################################################################
153
154 fresh_workspace;
155 $tabA = open_window;
156 cmd 'layout tabbed';
157 $tabB = open_window;
158 cmd 'split h';
159 open_window;
160 cmd 'split v';
161 cmd 'layout stacked';
162 $subtabA = open_window;
163 $subtabB = open_window;
164
165 ok(is_hidden($tabA), 'unfocused outer tab has _NET_WM_STATE_HIDDEN set');
166 ok(!is_hidden($tabB), 'focused outer tab does not have _NET_WM_STATE_HIDDEN set');
167 ok(is_hidden($subtabA), 'unfocused inner tab has _NET_WM_STATE_HIDDEN set');
168 ok(!is_hidden($subtabB), 'focused inner tab does not have _NET_WM_STATE_HIDDEN set');
169
170 cmd 'focus left';
171
172 ok(!is_hidden($subtabB), 'focused inner tab does not have _NET_WM_STATE_HIDDEN set');
173
174 ###############################################################################
175 # Given a stacked container nested inside another tabbed container with the
176 # inner one being in a currently not focused tab, then all tabs of the inner
177 # container have _NET_WM_STATE_HIDDEN set.
178 ###############################################################################
179
180 fresh_workspace;
181 $tabA = open_window;
182 cmd 'layout tabbed';
183 $tabB = open_window;
184 cmd 'split h';
185 open_window;
186 cmd 'split v';
187 cmd 'layout stacked';
188 $subtabA = open_window;
189 $subtabB = open_window;
190 cmd 'focus parent';
191 cmd 'focus parent';
192 cmd 'focus left';
193
194 ok(!is_hidden($tabA), 'focused outer tab does not have _NET_WM_STATE_HIDDEN set');
195 ok(is_hidden($tabB), 'unfocused outer tab has _NET_WM_STATE_HIDDEN set');
196 ok(is_hidden($subtabA), 'unfocused inner tab has _NET_WM_STATE_HIDDEN set');
197 ok(is_hidden($subtabB), 'unfocused inner tab has _NET_WM_STATE_HIDDEN set');
198
199 ###############################################################################
200
201 done_testing;