]> git.sur5r.net Git - i3/i3/blob - testcases/t/02-fullscreen.t
extend fullscreen testcase
[i3/i3] / testcases / t / 02-fullscreen.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use Test::More tests => 19;
5 use Test::Deep;
6 use X11::XCB qw(:all);
7 use Data::Dumper;
8 use FindBin;
9 use lib "$FindBin::Bin/lib";
10 use i3test;
11 use AnyEvent::I3;
12 use List::Util qw(first);
13 use v5.10;
14
15 # We use relatively long sleeps (1/4 second) to make sure the window manager
16 # reacted.
17 use Time::HiRes qw(sleep);
18
19 my $i3 = i3("/tmp/nestedcons");
20
21 my $tmp = get_unused_workspace();
22 $i3->command("workspace $tmp")->recv;
23
24 # get the output of this workspace
25 my $tree = $i3->get_workspaces->recv;
26 my @outputs = @{$tree->{nodes}};
27 my $output = first { defined(first { $_->{name} eq $tmp } @{$_->{nodes}}) } @outputs;
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 );
46
47 isa_ok($window, 'X11::XCB::Window');
48
49 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
50
51 $window->map;
52
53 sleep(0.25);
54
55 # open another container to make the window get only half of the screen
56 $i3->command('open')->recv;
57
58 my $new_rect = $window->rect;
59 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned");
60 $original_rect = $new_rect;
61
62 sleep(0.25);
63
64 $window->fullscreen(1);
65
66 sleep(0.25);
67
68 $new_rect = $window->rect;
69 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned after fullscreen");
70
71 my $orect = $output->{rect};
72 my $wrect = $new_rect;
73
74 # see if the window really is fullscreen. 20 px for borders are allowed
75 my $threshold = 20;
76 ok(($wrect->{x} - $orect->{x}) < $threshold, 'x coordinate fullscreen');
77 ok(($wrect->{y} - $orect->{y}) < $threshold, 'y coordinate fullscreen');
78 ok(abs($wrect->{width} - $orect->{width}) < $threshold, 'width coordinate fullscreen');
79 ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate fullscreen');
80
81
82 $window->unmap;
83
84 #########################################################
85 # test with a window which is fullscreened before mapping
86 #########################################################
87
88 # open another container because the empty one will swallow the window we
89 # map in a second
90 $i3->command('open')->recv;
91
92 $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
93 $window = $x->root->create_child(
94     class => WINDOW_CLASS_INPUT_OUTPUT,
95     rect => $original_rect,
96     background_color => 61440,
97 );
98
99 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
100
101 $window->fullscreen(1);
102 $window->map;
103
104 sleep(0.25);
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 );
128
129 $swindow->map;
130 sleep(0.25);
131
132 ok(!$swindow->mapped, 'window not mapped while fullscreen window active');
133
134 $new_rect = $swindow->rect;
135 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned");
136
137 sleep(0.25);
138 $swindow->fullscreen(1);
139 sleep(0.25);
140
141 my $content = get_ws_content($tmp);
142
143 my $fullscreen_windows = grep { $_->{fullscreen_mode} != 0 } @{$content};
144 is($fullscreen_windows, 1, 'amount of fullscreen windows');
145
146 # clean up the workspace so that it will be cleaned when switching away
147 $i3->command('kill')->recv for (@{$content});
148
149 diag( "Testing i3, Perl $], $^X" );