]> git.sur5r.net Git - i3/i3/blob - testcases/t/02-fullscreen.t
Implement dock mode, update testsuite
[i3/i3] / testcases / t / 02-fullscreen.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use i3test tests => 24;
5 use X11::XCB qw(:all);
6 use List::Util qw(first);
7 use Time::HiRes qw(sleep);
8
9 my $i3 = i3("/tmp/nestedcons");
10
11 my $tmp = get_unused_workspace();
12 $i3->command("workspace $tmp")->recv;
13
14 sub fullscreen_windows {
15     scalar grep { $_->{fullscreen_mode} != 0 } @{get_ws_content($tmp)}
16 }
17
18 # get the output of this workspace
19 my $tree = $i3->get_tree->recv;
20 my @outputs = @{$tree->{nodes}};
21 my $output;
22 for my $o (@outputs) {
23     # get the first CT_CON of each output
24     my $content = first { $_->{type} == 2 } @{$o->{nodes}};
25     if (defined(first { $_->{name} eq $tmp } @{$content->{nodes}})) {
26         $output = $o;
27         last;
28     }
29 }
30
31 BEGIN {
32     use_ok('X11::XCB::Window');
33 }
34
35 my $x = X11::XCB::Connection->new;
36
37 ##################################
38 # map a window, then fullscreen it
39 ##################################
40
41 my $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
42
43 my $window = $x->root->create_child(
44     class => WINDOW_CLASS_INPUT_OUTPUT,
45     rect => $original_rect,
46     background_color => '#C0C0C0',
47 );
48
49 isa_ok($window, 'X11::XCB::Window');
50
51 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
52
53 $window->map;
54
55 sleep(0.25);
56
57 # open another container to make the window get only half of the screen
58 $i3->command('open')->recv;
59
60 my $new_rect = $window->rect;
61 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned");
62 $original_rect = $new_rect;
63
64 sleep(0.25);
65
66 $window->fullscreen(1);
67
68 sleep(0.25);
69
70 $new_rect = $window->rect;
71 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned after fullscreen");
72
73 my $orect = $output->{rect};
74 my $wrect = $new_rect;
75
76 # see if the window really is fullscreen. 20 px for borders are allowed
77 my $threshold = 20;
78 ok(($wrect->{x} - $orect->{x}) < $threshold, 'x coordinate fullscreen');
79 ok(($wrect->{y} - $orect->{y}) < $threshold, 'y coordinate fullscreen');
80 ok(abs($wrect->{width} - $orect->{width}) < $threshold, 'width coordinate fullscreen');
81 ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate fullscreen');
82
83
84 $window->unmap;
85
86 #########################################################
87 # test with a window which is fullscreened before mapping
88 #########################################################
89
90 # open another container because the empty one will swallow the window we
91 # map in a second
92 $i3->command('open')->recv;
93
94 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
95 $window = $x->root->create_child(
96     class => WINDOW_CLASS_INPUT_OUTPUT,
97     rect => $original_rect,
98     background_color => 61440,
99 );
100
101 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
102
103 $window->fullscreen(1);
104 $window->map;
105
106 sleep(0.25);
107
108 $new_rect = $window->rect;
109 ok(!eq_deeply($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 # test if setting two windows in fullscreen mode at the same time does not work
122 ###############################################################################
123
124 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
125 my $swindow = $x->root->create_child(
126     class => WINDOW_CLASS_INPUT_OUTPUT,
127     rect => $original_rect,
128     background_color => '#C0C0C0',
129 );
130
131 $swindow->map;
132 sleep(0.25);
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 sleep 0.25;
141
142 is(fullscreen_windows(), 1, 'amount of fullscreen windows');
143
144 $window->fullscreen(0);
145 sleep 0.25;
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 sleep 0.25;
158
159 is(fullscreen_windows(), 0, 'amount of fullscreen windows after disabling');
160
161 $i3->command('fullscreen')->recv;
162
163 is(fullscreen_windows(), 1, 'amount of fullscreen windows after fullscreen command');
164
165 $i3->command('fullscreen')->recv;
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 $i3->command('kill')->recv for (@{get_ws_content($tmp)});
171
172
173 diag( "Testing i3, Perl $], $^X" );