]> git.sur5r.net Git - i3/i3/blob - testcases/t/114-client-leader.t
Merge pull request #2953 from CyberShadow/focus_wrapping
[i3/i3] / testcases / t / 114-client-leader.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • https://build.i3wm.org/docs/ipc.html
12 #   (or docs/ipc)
13 #
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 #   (unless you are already familiar with Perl)
16
17 use i3test;
18
19 my $tmp = fresh_workspace;
20
21 ####################################################################################
22 # first part: test if a floating window will be correctly positioned above its leader
23 #
24 # This is verified by opening two windows, then opening a floating window above the
25 # right one, then above the left one. If the floating windows are all positioned alike,
26 # one of both (depending on your screen resolution) will be positioned wrong.
27 ####################################################################################
28
29 my $left = open_window({ name => 'Left' });
30 my $right = open_window({ name => 'Right' });
31
32 my ($abs, $rgeom) = $right->rect;
33
34 my $child = open_floating_window({
35         dont_map => 1,
36         name => 'Child window',
37     });
38 $child->client_leader($right);
39 $child->map;
40
41 ok(wait_for_map($child), 'child window mapped');
42
43 my $cgeom;
44 ($abs, $cgeom) = $child->rect;
45 cmp_ok($cgeom->x, '>=', $rgeom->x, 'Child X >= right container X');
46
47 my $child2 = open_floating_window({
48         dont_map => 1,
49         name => 'Child window 2',
50     });
51 $child2->client_leader($left);
52 $child2->map;
53
54 ok(wait_for_map($child2), 'second child window mapped');
55
56 ($abs, $cgeom) = $child2->rect;
57 cmp_ok(($cgeom->x + $cgeom->width), '<', $rgeom->x, 'child above left window');
58
59 # check wm_transient_for
60 my $fwindow = open_window({ dont_map => 1 });
61 $fwindow->transient_for($right);
62 $fwindow->map;
63
64 ok(wait_for_map($fwindow), 'transient window mapped');
65
66 my ($absolute, $top) = $fwindow->rect;
67 ok($absolute->{x} != 0 && $absolute->{y} != 0, 'i3 did not map it to (0x0)');
68
69 SKIP: {
70     skip "(workspace placement by client_leader not yet implemented)", 3;
71
72 #####################################################################
73 # Create a parent window
74 #####################################################################
75
76 my $window = open_window({ dont_map => 1, name => 'Parent window' });
77 $window->map;
78
79 ok(wait_for_map($window), 'parent window mapped');
80
81 #########################################################################
82 # Switch to a different workspace and open a child window. It should be opened
83 # on the old workspace.
84 #########################################################################
85 fresh_workspace;
86
87 my $child = open_window({ dont_map => 1, name => 'Child window' });
88 $child->client_leader($window);
89 $child->map;
90
91 ok(wait_for_map($child), 'child window mapped');
92
93 isnt($x->input_focus, $child->id, "Child window focused");
94
95 # Switch back
96 cmd "workspace $tmp";
97
98 is($x->input_focus, $child->id, "Child window focused");
99
100 }
101
102 ################################################################################
103 # Verify that transient_for can be set and unset.
104 ################################################################################
105
106 $tmp = fresh_workspace;
107
108 $fwindow = open_window({ dont_map => 1 });
109 $fwindow->transient_for($right);
110 $fwindow->map;
111
112 wait_for_map($fwindow);
113
114 my $floating_con = get_ws($tmp)->{floating_nodes}[0]->{nodes}[0];
115 is($floating_con->{window_properties}->{transient_for}, $right->id, 'WM_TRANSIENT_FOR properly parsed');
116
117 $x->delete_property($fwindow->id, $x->atom(name => 'WM_TRANSIENT_FOR')->id);
118 $x->flush;
119
120 sync_with_i3;
121
122 $floating_con = get_ws($tmp)->{floating_nodes}[0]->{nodes}[0];
123 is($floating_con->{window_properties}->{transient_for}, undef, 'WM_TRANSIENT_FOR properly removed');
124
125 done_testing;