]> git.sur5r.net Git - i3/i3/blob - testcases/t/02-fullscreen.t
Support pkg-config if the modules are available.
[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 = first { defined(first { $_->{name} eq $tmp } @{$_->{nodes}}) } @outputs;
22
23 BEGIN {
24     use_ok('X11::XCB::Window');
25 }
26
27 my $x = X11::XCB::Connection->new;
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 );
40
41 isa_ok($window, 'X11::XCB::Window');
42
43 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
44
45 $window->map;
46
47 sleep(0.25);
48
49 # open another container to make the window get only half of the screen
50 $i3->command('open')->recv;
51
52 my $new_rect = $window->rect;
53 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned");
54 $original_rect = $new_rect;
55
56 sleep(0.25);
57
58 $window->fullscreen(1);
59
60 sleep(0.25);
61
62 $new_rect = $window->rect;
63 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned after fullscreen");
64
65 my $orect = $output->{rect};
66 my $wrect = $new_rect;
67
68 # see if the window really is fullscreen. 20 px for borders are allowed
69 my $threshold = 20;
70 ok(($wrect->{x} - $orect->{x}) < $threshold, 'x coordinate fullscreen');
71 ok(($wrect->{y} - $orect->{y}) < $threshold, 'y coordinate fullscreen');
72 ok(abs($wrect->{width} - $orect->{width}) < $threshold, 'width coordinate fullscreen');
73 ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate fullscreen');
74
75
76 $window->unmap;
77
78 #########################################################
79 # test with a window which is fullscreened before mapping
80 #########################################################
81
82 # open another container because the empty one will swallow the window we
83 # map in a second
84 $i3->command('open')->recv;
85
86 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
87 $window = $x->root->create_child(
88     class => WINDOW_CLASS_INPUT_OUTPUT,
89     rect => $original_rect,
90     background_color => 61440,
91 );
92
93 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
94
95 $window->fullscreen(1);
96 $window->map;
97
98 sleep(0.25);
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 );
122
123 $swindow->map;
124 sleep(0.25);
125
126 ok(!$swindow->mapped, 'window not mapped while fullscreen window active');
127
128 $new_rect = $swindow->rect;
129 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned");
130
131 $swindow->fullscreen(1);
132 sleep 0.25;
133
134 is(fullscreen_windows(), 1, 'amount of fullscreen windows');
135
136 $window->fullscreen(0);
137 sleep 0.25;
138 is(fullscreen_windows(), 0, 'amount of fullscreen windows');
139
140 ok($swindow->mapped, 'window mapped after other fullscreen ended');
141
142 ###########################################################################
143 # as $swindow is out of state at the moment (it requested to be fullscreen,
144 # but the WM denied), we check what happens if we go out of fullscreen now
145 # (nothing should happen)
146 ###########################################################################
147
148 $swindow->fullscreen(0);
149 sleep 0.25;
150
151 is(fullscreen_windows(), 0, 'amount of fullscreen windows after disabling');
152
153 $i3->command('fullscreen')->recv;
154
155 is(fullscreen_windows(), 1, 'amount of fullscreen windows after fullscreen command');
156
157 $i3->command('fullscreen')->recv;
158
159 is(fullscreen_windows(), 0, 'amount of fullscreen windows after fullscreen command');
160
161 # clean up the workspace so that it will be cleaned when switching away
162 $i3->command('kill')->recv for (@{get_ws_content($tmp)});
163
164
165 diag( "Testing i3, Perl $], $^X" );