2 # vim:ts=4:sw=4:expandtab
5 use List::Util qw(first);
7 my $i3 = i3(get_socket_path());
9 my $tmp = fresh_workspace;
11 sub fullscreen_windows {
12 scalar grep { $_->{fullscreen_mode} != 0 } @{get_ws_content($tmp)}
15 # get the output of this workspace
16 my $tree = $i3->get_tree->recv;
17 my @outputs = @{$tree->{nodes}};
19 for my $o (@outputs) {
20 # get the first CT_CON of each output
21 my $content = first { $_->{type} == 2 } @{$o->{nodes}};
22 if (defined(first { $_->{name} eq $tmp } @{$content->{nodes}})) {
28 ##################################
29 # map a window, then fullscreen it
30 ##################################
32 my $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
34 my $window = open_window(
35 rect => $original_rect,
39 isa_ok($window, 'X11::XCB::Window');
41 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
47 # open another container to make the window get only half of the screen
50 my $new_rect = $window->rect;
51 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned");
52 $original_rect = $new_rect;
54 $window->fullscreen(1);
58 $new_rect = $window->rect;
59 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned after fullscreen");
61 my $orect = $output->{rect};
62 my $wrect = $new_rect;
64 # see if the window really is fullscreen. 20 px for borders are allowed
66 ok(($wrect->{x} - $orect->{x}) < $threshold, 'x coordinate fullscreen');
67 ok(($wrect->{y} - $orect->{y}) < $threshold, 'y coordinate fullscreen');
68 ok(abs($wrect->{width} - $orect->{width}) < $threshold, 'width coordinate fullscreen');
69 ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate fullscreen');
74 #########################################################
75 # test with a window which is fullscreened before mapping
76 #########################################################
78 # open another container because the empty one will swallow the window we
82 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
83 $window = open_window(
84 rect => $original_rect,
88 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
90 $window->fullscreen(1);
95 $new_rect = $window->rect;
96 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned after fullscreen");
97 ok($window->mapped, "Window is mapped after opening it in fullscreen mode");
101 # see if the window really is fullscreen. 20 px for borders are allowed
102 ok(($wrect->{x} - $orect->{x}) < $threshold, 'x coordinate fullscreen');
103 ok(($wrect->{y} - $orect->{y}) < $threshold, 'y coordinate fullscreen');
104 ok(abs($wrect->{width} - $orect->{width}) < $threshold, 'width coordinate fullscreen');
105 ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate fullscreen');
107 ###############################################################################
108 # test if setting two windows in fullscreen mode at the same time does not work
109 ###############################################################################
111 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
112 my $swindow = open_window(
113 rect => $original_rect,
121 ok(!$swindow->mapped, 'window not mapped while fullscreen window active');
123 $new_rect = $swindow->rect;
124 ok(!eq_hash($new_rect, $original_rect), "Window got repositioned");
126 $swindow->fullscreen(1);
129 is(fullscreen_windows(), 1, 'amount of fullscreen windows');
131 $window->fullscreen(0);
133 is(fullscreen_windows(), 0, 'amount of fullscreen windows');
135 ok($swindow->mapped, 'window mapped after other fullscreen ended');
137 ###########################################################################
138 # as $swindow is out of state at the moment (it requested to be fullscreen,
139 # but the WM denied), we check what happens if we go out of fullscreen now
140 # (nothing should happen)
141 ###########################################################################
143 $swindow->fullscreen(0);
146 is(fullscreen_windows(), 0, 'amount of fullscreen windows after disabling');
150 is(fullscreen_windows(), 1, 'amount of fullscreen windows after fullscreen command');
154 is(fullscreen_windows(), 0, 'amount of fullscreen windows after fullscreen command');
156 # clean up the workspace so that it will be cleaned when switching away
157 cmd 'kill' for (@{get_ws_content($tmp)});
159 ################################################################################
160 # Verify that changing focus while in fullscreen does not work.
161 ################################################################################
163 $tmp = fresh_workspace;
165 my $other = open_window;
166 is($x->input_focus, $other->id, 'other window focused');
168 $window = open_window;
169 is($x->input_focus, $window->id, 'window focused');
172 is($x->input_focus, $window->id, 'fullscreen window focused');
175 is($x->input_focus, $window->id, 'fullscreen window still focused');