]> git.sur5r.net Git - i3/i3/blob - testcases/t/02-fullscreen.t
extend t/02-fullscreen.t
[i3/i3] / testcases / t / 02-fullscreen.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3
4 use Test::More tests => 16;
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 my $original_rect = X11::XCB::Rect->new(x => 0, y => 0, width => 30, height => 30);
36
37 my $window = $x->root->create_child(
38     class => WINDOW_CLASS_INPUT_OUTPUT,
39     rect => $original_rect,
40     background_color => '#C0C0C0',
41 );
42
43 isa_ok($window, 'X11::XCB::Window');
44
45 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
46
47 $window->map;
48
49 sleep(0.25);
50
51 # open another container to make the window get only half of the screen
52 $i3->command('open')->recv;
53
54 my $new_rect = $window->rect;
55 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned");
56 $original_rect = $new_rect;
57
58 sleep(0.25);
59
60 $window->fullscreen(1);
61
62 sleep(0.25);
63
64 $new_rect = $window->rect;
65 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned after fullscreen");
66
67 my $orect = $output->{rect};
68 my $wrect = $new_rect;
69
70 # see if the window really is fullscreen. 20 px for borders are allowed
71 my $threshold = 20;
72 ok(($wrect->{x} - $orect->{x}) < $threshold, 'x coordinate fullscreen');
73 ok(($wrect->{y} - $orect->{y}) < $threshold, 'y coordinate fullscreen');
74 ok(abs($wrect->{width} - $orect->{width}) < $threshold, 'width coordinate fullscreen');
75 ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate fullscreen');
76
77 $window->unmap;
78
79 # open another container because the empty one will swallow the window we
80 # map in a second
81 $i3->command('open')->recv;
82
83 $window = $x->root->create_child(
84     class => WINDOW_CLASS_INPUT_OUTPUT,
85     rect => $original_rect,
86     background_color => 61440,
87 );
88
89 is_deeply($window->rect, $original_rect, "rect unmodified before mapping");
90
91 $window->fullscreen(1);
92 $window->map;
93
94 sleep(0.25);
95
96 $new_rect = $window->rect;
97 ok(!eq_deeply($new_rect, $original_rect), "Window got repositioned after fullscreen");
98 ok($window->mapped, "Window is mapped after opening it in fullscreen mode");
99
100 $wrect = $new_rect;
101
102 # see if the window really is fullscreen. 20 px for borders are allowed
103 my $threshold = 20;
104 ok(($wrect->{x} - $orect->{x}) < $threshold, 'x coordinate fullscreen');
105 ok(($wrect->{y} - $orect->{y}) < $threshold, 'y coordinate fullscreen');
106 ok(abs($wrect->{width} - $orect->{width}) < $threshold, 'width coordinate fullscreen');
107 ok(abs($wrect->{height} - $orect->{height}) < $threshold, 'height coordinate fullscreen');
108
109 diag( "Testing i3, Perl $], $^X" );