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