2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • http://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
18 use List::Util qw(first);
20 my $i3 = i3(get_socket_path());
22 my $tmp = fresh_workspace;
24 sub fullscreen_windows {
25 scalar grep { $_->{fullscreen_mode} != 0 } @{get_ws_content($tmp)}
28 # get the output of this workspace
29 my $tree = $i3->get_tree->recv;
30 my @outputs = @{$tree->{nodes}};
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}})) {
41 ##################################
42 # map a window, then fullscreen it
43 ##################################
45 my $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
47 my $window = open_window(
48 rect => $original_rect,
52 isa_ok($window, 'X11::XCB::Window');
54 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
60 # open another container to make the window get only half of the screen
63 my $new_rect = $window->rect;
64 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned");
65 $original_rect = $new_rect;
67 $window->fullscreen(1);
71 $new_rect = $window->rect;
72 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned after fullscreen");
74 my $orect = $output->{rect};
75 my $wrect = $new_rect;
77 # see if the window really is fullscreen. 20 px for borders are allowed
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');
87 #########################################################
88 # test with a window which is fullscreened before mapping
89 #########################################################
91 # open another container because the empty one will swallow the window we
95 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
96 $window = open_window(
97 rect => $original_rect,
101 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
103 $window->fullscreen(1);
106 wait_for_map $window;
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");
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');
120 ################################################################################
121 # Verify that when one window wants to go into fullscreen mode, the old
122 # fullscreen window will be replaced.
123 ################################################################################
125 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
126 my $swindow = open_window(
127 rect => $original_rect,
135 ok(!$swindow->mapped, 'window not mapped while fullscreen window active');
137 $new_rect = $swindow->rect;
138 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned");
140 $swindow->fullscreen(1);
143 is(fullscreen_windows(), 1, 'amount of fullscreen windows');
145 $window->fullscreen(0);
147 is(fullscreen_windows(), 1, 'amount of fullscreen windows');
149 ok($swindow->mapped, 'window mapped after other fullscreen ended');
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 ###########################################################################
157 $swindow->fullscreen(0);
160 is(fullscreen_windows(), 0, 'amount of fullscreen windows after disabling');
164 is(fullscreen_windows(), 1, 'amount of fullscreen windows after fullscreen command');
168 is(fullscreen_windows(), 0, 'amount of fullscreen windows after fullscreen command');
170 # clean up the workspace so that it will be cleaned when switching away
171 cmd 'kill' for (@{get_ws_content($tmp)});
173 ################################################################################
174 # Verify that changing focus while in fullscreen does not work.
175 ################################################################################
177 $tmp = fresh_workspace;
179 my $other = open_window;
180 is($x->input_focus, $other->id, 'other window focused');
182 $window = open_window;
183 is($x->input_focus, $window->id, 'window focused');
186 is($x->input_focus, $window->id, 'fullscreen window focused');
189 is($x->input_focus, $window->id, 'fullscreen window still focused');