]> git.sur5r.net Git - i3/i3/blob - testcases/t/100-fullscreen.t
testcases: use $x in wait_for_(un)map change to wait_for_(un)map($win)
[i3/i3] / testcases / t / 100-fullscreen.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use i3test;
5 use X11::XCB 'WINDOW_CLASS_INPUT_OUTPUT';
6 use List::Util qw(first);
7
8 my $i3 = i3(get_socket_path());
9
10 my $tmp = fresh_workspace;
11
12 sub fullscreen_windows {
13     scalar grep { $_->{fullscreen_mode} != 0 } @{get_ws_content($tmp)}
14 }
15
16 # get the output of this workspace
17 my $tree = $i3->get_tree->recv;
18 my @outputs = @{$tree->{nodes}};
19 my $output;
20 for my $o (@outputs) {
21     # get the first CT_CON of each output
22     my $content = first { $_->{type} == 2 } @{$o->{nodes}};
23     if (defined(first { $_->{name} eq $tmp } @{$content->{nodes}})) {
24         $output = $o;
25         last;
26     }
27 }
28
29 ##################################
30 # map a window, then fullscreen it
31 ##################################
32
33 my $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
34
35 my $window = $x->root->create_child(
36     class => WINDOW_CLASS_INPUT_OUTPUT,
37     rect => $original_rect,
38     background_color => '#C0C0C0',
39     event_mask => [ 'structure_notify' ],
40 );
41
42 isa_ok($window, 'X11::XCB::Window');
43
44 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
45
46 $window->map;
47
48 wait_for_map $window;
49
50 # open another container to make the window get only half of the screen
51 cmd 'open';
52
53 my $new_rect = $window->rect;
54 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned");
55 $original_rect = $new_rect;
56
57 $window->fullscreen(1);
58
59 sync_with_i3($x);
60
61 $new_rect = $window->rect;
62 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned after fullscreen");
63
64 my $orect = $output->{rect};
65 my $wrect = $new_rect;
66
67 # see if the window really is fullscreen. 20 px for borders are allowed
68 my $threshold = 20;
69 ok(($wrect->{x} - $orect->{x}) < $threshold, 'x coordinate fullscreen');
70 ok(($wrect->{y} - $orect->{y}) < $threshold, 'y coordinate fullscreen');
71 ok(abs($wrect->{width} - $orect->{width}) < $threshold, 'width coordinate fullscreen');
72 ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate fullscreen');
73
74
75 $window->unmap;
76
77 #########################################################
78 # test with a window which is fullscreened before mapping
79 #########################################################
80
81 # open another container because the empty one will swallow the window we
82 # map in a second
83 cmd 'open';
84
85 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
86 $window = $x->root->create_child(
87     class => WINDOW_CLASS_INPUT_OUTPUT,
88     rect => $original_rect,
89     background_color => 61440,
90     event_mask => [ 'structure_notify' ],
91 );
92
93 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
94
95 $window->fullscreen(1);
96 $window->map;
97
98 wait_for_map $window;
99
100 $new_rect = $window->rect;
101 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned after fullscreen");
102 ok($window->mapped, "Window is mapped after opening it in fullscreen mode");
103
104 $wrect = $new_rect;
105
106 # see if the window really is fullscreen. 20 px for borders are allowed
107 ok(($wrect->{x} - $orect->{x}) < $threshold, 'x coordinate fullscreen');
108 ok(($wrect->{y} - $orect->{y}) < $threshold, 'y coordinate fullscreen');
109 ok(abs($wrect->{width} - $orect->{width}) < $threshold, 'width coordinate fullscreen');
110 ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate fullscreen');
111
112 ###############################################################################
113 # test if setting two windows in fullscreen mode at the same time does not work
114 ###############################################################################
115
116 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
117 my $swindow = $x->root->create_child(
118     class => WINDOW_CLASS_INPUT_OUTPUT,
119     rect => $original_rect,
120     background_color => '#C0C0C0',
121     event_mask => [ 'structure_notify' ],
122 );
123
124 $swindow->map;
125
126 sync_with_i3($x);
127
128 ok(!$swindow->mapped, 'window not mapped while fullscreen window active');
129
130 $new_rect = $swindow->rect;
131 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned");
132
133 $swindow->fullscreen(1);
134 sync_with_i3($x);
135
136 is(fullscreen_windows(), 1, 'amount of fullscreen windows');
137
138 $window->fullscreen(0);
139 sync_with_i3($x);
140 is(fullscreen_windows(), 0, 'amount of fullscreen windows');
141
142 ok($swindow->mapped, 'window mapped after other fullscreen ended');
143
144 ###########################################################################
145 # as $swindow is out of state at the moment (it requested to be fullscreen,
146 # but the WM denied), we check what happens if we go out of fullscreen now
147 # (nothing should happen)
148 ###########################################################################
149
150 $swindow->fullscreen(0);
151 sync_with_i3($x);
152
153 is(fullscreen_windows(), 0, 'amount of fullscreen windows after disabling');
154
155 cmd 'fullscreen';
156
157 is(fullscreen_windows(), 1, 'amount of fullscreen windows after fullscreen command');
158
159 cmd 'fullscreen';
160
161 is(fullscreen_windows(), 0, 'amount of fullscreen windows after fullscreen command');
162
163 # clean up the workspace so that it will be cleaned when switching away
164 cmd 'kill' for (@{get_ws_content($tmp)});
165
166 done_testing;