]> git.sur5r.net Git - i3/i3/blob - testcases/t/246-window-decoration-focus.t
Merge branch 'next' into master
[i3/i3] / testcases / t / 246-window-decoration-focus.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 # Ensure that hovering over the window decoration of a window causes it to focus
18 # correctly.
19 # Ticket: #1056
20 # Bug still in: 4.10.2-174-g8029ff0
21 use i3test;
22
23 my ($ws, $A, $B, $C, $target, $y);
24 my @cons;
25
26 # ==================================================================================
27 # Given the following layout (= denotes the window decoration),
28 # when moving the mouse from 1 to 2,
29 # then the C should be focused.
30 #
31 # This should especially be the case if B is the focus head of its vertically split parent container.
32 #
33 # +===A===+===B===+
34 # |       |       |
35 # |     1 +=2=C===+
36 # |       |       |
37 # +-------+-------+
38 #
39 # ==================================================================================
40
41 $ws = fresh_workspace;
42
43 open_window;
44 $B = open_window;
45 cmd 'split v';
46 open_window;
47 $target = get_focused($ws);
48
49 @cons = @{get_ws($ws)->{nodes}};
50 $A = $cons[0];
51 $C = $cons[1]->{nodes}[1];
52
53 $y = $C->{rect}->{y} - 0.5 * $C->{deco_rect}->{height};
54
55 # make sure that B is the focus head of its parent
56 cmd '[id="' . $B->{id} . '"] focus';
57
58 # move pointer to position 1
59 $x->root->warp_pointer($C->{rect}->{x} - 0.5 * $A->{rect}->{width}, $y);
60 sync_with_i3;
61
62 # move pointer to position 2
63 $x->root->warp_pointer($C->{rect}->{x} + 0.5 * $C->{rect}->{width}, $y);
64 sync_with_i3;
65
66 is(get_focused($ws), $target, 'focus switched to container C');
67
68 # ==================================================================================
69 # Given a tabbed container when the mouse is moved onto the window decoration
70 # then the focus head of the tabbed container is focused regardless of which particular
71 # tab's decoration the mouse is on.
72 #
73 # +=========+=========+
74 # |         |         |
75 # |       1 +=2==|****| <- tab to the right is focus head of tabbed container
76 # |         |         |
77 # +---------+---------+
78 #
79 # ==================================================================================
80
81 $ws = fresh_workspace;
82
83 open_window;
84 open_window;
85 cmd 'split v';
86 open_window;
87 cmd 'split h';
88 open_window;
89 $target = get_focused($ws);
90 cmd 'layout tabbed';
91
92 @cons = @{get_ws($ws)->{nodes}};
93 $A = $cons[0];
94 $B = $cons[1]->{nodes}[1]->{nodes}[1];
95
96 $y = $B->{rect}->{y} - 0.5 * $B->{deco_rect}->{height};
97
98 $x->root->warp_pointer($B->{rect}->{x} - 0.5 * $A->{rect}->{width}, $y);
99 sync_with_i3;
100
101 $x->root->warp_pointer($B->{rect}->{x} + 0.2 * $B->{rect}->{width}, $y);
102 sync_with_i3;
103
104 is(get_focused($ws), $target, 'focus switched to the focus head of the tabbed container');
105
106 # ==================================================================================
107 # Given a stacked container when the mouse is moved onto the window decoration
108 # then the focus head of the stacked container is focused regardless of which particular
109 # tab's decoration the mouse is on.
110 #
111 # +=========+=========+
112 # |         |         |
113 # |       1 +=2=======+
114 # |         +*********+ <- the lower tab is the focus head of the stacked container
115 # |         |         |
116 # +---------+---------+
117 #
118 # ==================================================================================
119
120 $ws = fresh_workspace;
121
122 open_window;
123 open_window;
124 cmd 'split v';
125 open_window;
126 cmd 'split h';
127 open_window;
128 $target = get_focused($ws);
129 cmd 'layout stacked';
130
131 @cons = @{get_ws($ws)->{nodes}};
132 $A = $cons[0];
133 $B = $cons[1]->{nodes}[1]->{nodes}[0];
134 $C = $cons[1]->{nodes}[1]->{nodes}[1];
135
136 $y = $B->{rect}->{y} - 1.5 * $B->{deco_rect}->{height};
137
138 $x->root->warp_pointer($B->{rect}->{x} - 0.5 * $A->{rect}->{width}, $y);
139 sync_with_i3;
140
141 $x->root->warp_pointer($B->{rect}->{x} + 0.5 * $B->{rect}->{width}, $y);
142 sync_with_i3;
143
144 is(get_focused($ws), $target, 'focus switched to the focus head of the stacked container');
145
146 # ==================================================================================
147
148 done_testing;