]> git.sur5r.net Git - i3/i3/blob - testcases/t/100-fullscreen.t
Merge branch 'master' into next
[i3/i3] / testcases / t / 100-fullscreen.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 use i3test;
18 use List::Util qw(first);
19
20 my $i3 = i3(get_socket_path());
21
22 my $tmp = fresh_workspace;
23
24 sub fullscreen_windows {
25     scalar grep { $_->{fullscreen_mode} != 0 } @{get_ws_content($tmp)}
26 }
27
28 # get the output of this workspace
29 my $tree = $i3->get_tree->recv;
30 my @outputs = @{$tree->{nodes}};
31 my $output;
32 for my $o (@outputs) {
33     # get the first CT_CON of each output
34     my $content = first { $_->{type} == 2 } @{$o->{nodes}};
35     if (defined(first { $_->{name} eq $tmp } @{$content->{nodes}})) {
36         $output = $o;
37         last;
38     }
39 }
40
41 ##################################
42 # map a window, then fullscreen it
43 ##################################
44
45 my $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
46
47 my $window = open_window(
48     rect => $original_rect,
49     dont_map => 1,
50 );
51
52 isa_ok($window, 'X11::XCB::Window');
53
54 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
55
56 $window->map;
57
58 wait_for_map $window;
59
60 # open another container to make the window get only half of the screen
61 cmd 'open';
62
63 my $new_rect = $window->rect;
64 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned");
65 $original_rect = $new_rect;
66
67 $window->fullscreen(1);
68
69 sync_with_i3;
70
71 $new_rect = $window->rect;
72 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned after fullscreen");
73
74 my $orect = $output->{rect};
75 my $wrect = $new_rect;
76
77 # see if the window really is fullscreen. 20 px for borders are allowed
78 my $threshold = 20;
79 ok(($wrect->{x} - $orect->{x}) < $threshold, 'x coordinate fullscreen');
80 ok(($wrect->{y} - $orect->{y}) < $threshold, 'y coordinate fullscreen');
81 ok(abs($wrect->{width} - $orect->{width}) < $threshold, 'width coordinate fullscreen');
82 ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate fullscreen');
83
84
85 $window->unmap;
86
87 #########################################################
88 # test with a window which is fullscreened before mapping
89 #########################################################
90
91 # open another container because the empty one will swallow the window we
92 # map in a second
93 cmd 'open';
94
95 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
96 $window = open_window(
97     rect => $original_rect,
98     dont_map => 1,
99 );
100
101 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
102
103 $window->fullscreen(1);
104 $window->map;
105
106 wait_for_map $window;
107
108 $new_rect = $window->rect;
109 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned after fullscreen");
110 ok($window->mapped, "Window is mapped after opening it in fullscreen mode");
111
112 $wrect = $new_rect;
113
114 # see if the window really is fullscreen. 20 px for borders are allowed
115 ok(($wrect->{x} - $orect->{x}) < $threshold, 'x coordinate fullscreen');
116 ok(($wrect->{y} - $orect->{y}) < $threshold, 'y coordinate fullscreen');
117 ok(abs($wrect->{width} - $orect->{width}) < $threshold, 'width coordinate fullscreen');
118 ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate fullscreen');
119
120 ################################################################################
121 # Verify that when one window wants to go into fullscreen mode, the old
122 # fullscreen window will be replaced.
123 ################################################################################
124
125 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
126 my $swindow = open_window(
127     rect => $original_rect,
128     dont_map => 1,
129 );
130
131 $swindow->map;
132
133 sync_with_i3;
134
135 ok(!$swindow->mapped, 'window not mapped while fullscreen window active');
136
137 $new_rect = $swindow->rect;
138 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned");
139
140 $swindow->fullscreen(1);
141 sync_with_i3;
142
143 is(fullscreen_windows(), 1, 'amount of fullscreen windows');
144
145 $window->fullscreen(0);
146 sync_with_i3;
147 is(fullscreen_windows(), 1, 'amount of fullscreen windows');
148
149 ok($swindow->mapped, 'window mapped after other fullscreen ended');
150
151 ###########################################################################
152 # as $swindow is out of state at the moment (it requested to be fullscreen,
153 # but the WM denied), we check what happens if we go out of fullscreen now
154 # (nothing should happen)
155 ###########################################################################
156
157 $swindow->fullscreen(0);
158 sync_with_i3;
159
160 is(fullscreen_windows(), 0, 'amount of fullscreen windows after disabling');
161
162 cmd 'fullscreen';
163
164 is(fullscreen_windows(), 1, 'amount of fullscreen windows after fullscreen command');
165
166 cmd 'fullscreen';
167
168 is(fullscreen_windows(), 0, 'amount of fullscreen windows after fullscreen command');
169
170 # clean up the workspace so that it will be cleaned when switching away
171 cmd 'kill' for (@{get_ws_content($tmp)});
172
173 ################################################################################
174 # Verify that changing focus while in fullscreen does not work.
175 ################################################################################
176
177 $tmp = fresh_workspace;
178
179 my $other = open_window;
180 is($x->input_focus, $other->id, 'other window focused');
181
182 $window = open_window;
183 is($x->input_focus, $window->id, 'window focused');
184
185 cmd 'fullscreen';
186 is($x->input_focus, $window->id, 'fullscreen window focused');
187
188 cmd 'focus left';
189 is($x->input_focus, $window->id, 'fullscreen window still focused');
190
191 done_testing;