]> git.sur5r.net Git - i3/i3/blob - testcases/t/253-multiple-net-wm-state-atoms.t
3a3e7c6e8bcf8a87b7686c3c43586bbba2aa839a
[i3/i3] / testcases / t / 253-multiple-net-wm-state-atoms.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 # Ticket: #1873
18 use i3test;
19 use X11::XCB qw(:all);
20
21 sub get_wm_state {
22     sync_with_i3;
23
24     my ($con) = @_;
25     my $cookie = $x->get_property(
26         0,
27         $con->{id},
28         $x->atom(name => '_NET_WM_STATE')->id,
29         GET_PROPERTY_TYPE_ANY,
30         0,
31         4096
32     );
33
34     my $reply = $x->get_property_reply($cookie->{sequence});
35     my $len = $reply->{length};
36     return undef if $len == 0;
37
38     my @atoms = unpack("L$len", $reply->{value});
39     return @atoms;
40 }
41
42 my $wm_state_sticky = $x->atom(name => '_NET_WM_STATE_STICKY')->id;
43 my $wm_state_fullscreen = $x->atom(name => '_NET_WM_STATE_FULLSCREEN')->id;
44
45 ##########################################################################
46 # Given a sticky container, when it is fullscreened, then both wm state
47 # atoms are set. When the container is unfullscreened, then only the
48 # sticky atom is still set.
49 ##########################################################################
50
51 fresh_workspace;
52 my $window = open_window;
53 cmd 'sticky enable';
54 my @state = get_wm_state($window);
55 ok((scalar grep { $_ == $wm_state_sticky } @state) > 0, 'sanity check: _NET_WM_STATE_STICKY is set');
56
57 cmd 'fullscreen enable';
58 @state = get_wm_state($window);
59 ok((scalar grep { $_ == $wm_state_sticky } @state) > 0, '_NET_WM_STATE_STICKY is set');
60 ok((scalar grep { $_ == $wm_state_fullscreen } @state) > 0, '_NET_WM_STATE_FULLSCREEN is set');
61
62 cmd 'sticky disable';
63 @state = get_wm_state($window);
64 ok((scalar grep { $_ == $wm_state_sticky } @state) == 0, '_NET_WM_STATE_STICKY is not set');
65 ok((scalar grep { $_ == $wm_state_fullscreen } @state) > 0, '_NET_WM_STATE_FULLSCREEN is set');
66
67 cmd 'sticky enable';
68 cmd 'fullscreen disable';
69 @state = get_wm_state($window);
70 ok((scalar grep { $_ == $wm_state_sticky } @state) > 0, '_NET_WM_STATE_STICKY is set');
71 ok((scalar grep { $_ == $wm_state_fullscreen } @state) == 0, '_NET_WM_STATE_FULLSCREEN is not set');
72
73 ###############################################################################
74 # _NET_WM_STATE is removed when the window is withdrawn.
75 ###############################################################################
76
77 fresh_workspace;
78 $window = open_window;
79 cmd 'sticky enable';
80 @state = get_wm_state($window);
81 ok((scalar grep { $_ == $wm_state_sticky } @state) > 0, '_NET_WM_STATE_STICKY is set');
82
83 $window->unmap;
84 wait_for_unmap($window);
85
86 is(get_wm_state($window), undef, '_NET_WM_STATE is removed');
87
88 ##########################################################################
89
90 done_testing;