]> git.sur5r.net Git - i3/i3/blob - testcases/t/195-net-active-window.t
Check output crossing on ENTER_NOTIFY to dockarea. (#2477)
[i3/i3] / testcases / t / 195-net-active-window.t
1 #!perl
2 # vim:ts=4:sw=4:expandtab
3 #
4 # Please read the following documents before working on tests:
5 # • http://build.i3wm.org/docs/testsuite.html
6 #   (or docs/testsuite)
7 #
8 # • http://build.i3wm.org/docs/lib-i3test.html
9 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
10 #
11 # • http://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 # Verifies that the _NET_ACTIVE_WINDOW message only changes focus when the
18 # window is on a visible workspace and that focus changes properly update this
19 # property on the root window.
20 # ticket #774, bug still present in commit 1e49f1b08a3035c1f238fcd6615e332216ab582e
21 # ticket #1136, bug still present in commit fd07f989fdf441ef335245dd3436a70ff60e8896
22 use i3test;
23
24 sub send_net_active_window {
25     my ($id, $source) = @_;
26
27     $source = ($source eq 'pager' ? 2 : 0);
28
29     my $msg = pack "CCSLLLLLLL",
30         X11::XCB::CLIENT_MESSAGE, # response_type
31         32, # format
32         0, # sequence
33         $id, # destination window
34         $x->atom(name => '_NET_ACTIVE_WINDOW')->id,
35         $source,
36         0,
37         0,
38         0,
39         0;
40
41     $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
42 }
43
44 sub get_net_active_window {
45     my $cookie = $x->get_property(
46         0,
47         $x->get_root_window(),
48         $x->atom(name => '_NET_ACTIVE_WINDOW')->id,
49         $x->atom(name => 'WINDOW')->id,
50         0,
51         4096,
52     );
53     my $reply = $x->get_property_reply($cookie->{sequence});
54     my $len = $reply->{length};
55
56     return -1 if $len == 0;
57     return unpack("L", $reply->{value});
58
59 }
60
61 my $ws1 = fresh_workspace;
62 my $win1 = open_window;
63 my $win2 = open_window;
64
65 ################################################################################
66 # Ensure that the _NET_ACTIVE_WINDOW ClientMessage works when windows are visible
67 ################################################################################
68
69 is($x->input_focus, $win2->id, 'window 2 has focus');
70
71 send_net_active_window($win1->id);
72
73 is($x->input_focus, $win1->id, 'window 1 has focus');
74
75 ################################################################################
76 # Switch to a different workspace and ensure sending the _NET_ACTIVE_WINDOW
77 # ClientMessage switches to that workspaces only if source indicates it is a
78 # pager and otherwise sets the urgent hint.
79 ################################################################################
80
81 my $ws2 = fresh_workspace;
82 my $win3 = open_window;
83
84 is($x->input_focus, $win3->id, 'window 3 has focus');
85
86 send_net_active_window($win1->id, 'pager');
87
88 is($x->input_focus, $win1->id, 'focus switched to window 1 when message source was a pager');
89
90 cmd '[id="' . $win3->id . '"] focus';
91
92 send_net_active_window($win1->id);
93
94 is($x->input_focus, $win3->id,
95     'focus did not switch to window 1 on a hidden workspace when message source was an application');
96
97 ok(get_ws($ws1)->{urgent}, 'urgent hint set on ws 1');
98
99
100 ################################################################################
101 # Make sure the ClientMessage only works with managed windows, and specifying a
102 # window that is not managed does not crash i3 (#774)
103 ################################################################################
104
105 my $dock = open_window(window_type => $x->atom(name => '_NET_WM_WINDOW_TYPE_DOCK'));
106
107 send_net_active_window($dock->id);
108
109 does_i3_live;
110 is($x->input_focus, $win3->id, 'dock did not get input focus');
111
112 send_net_active_window($x->get_root_window());
113
114 does_i3_live;
115 is($x->input_focus, $win3->id, 'root window did not get input focus');
116
117 ################################################################################
118 # Move a window to the scratchpad, send a _NET_ACTIVE_WINDOW for it and verify
119 # that focus is still unchanged.
120 ################################################################################
121
122 my $scratch = open_window;
123
124 is($x->input_focus, $scratch->id, 'to-scratchpad window has focus');
125
126 cmd 'move scratchpad';
127
128 is($x->input_focus, $win3->id, 'focus reverted to window 3');
129
130 send_net_active_window($scratch->id);
131
132 is($x->input_focus, $win3->id, 'window 3 still focused');
133
134 ################################################################################
135 # Verify that the _NET_ACTIVE_WINDOW property is updated on the root window
136 # correctly.
137 ################################################################################
138
139 fresh_workspace;
140
141 sync_with_i3;
142
143 is(get_net_active_window(), 0, 'workspace content focus is indicated by the root property as "None" window');
144
145 my $win4 = open_window;
146
147 cmd '[id="' . $win4->id . '"] focus';
148
149 sync_with_i3;
150
151 is(get_net_active_window(), $win4->id, 'window 4 is indicated as focused by the root property');
152
153 # make a branch
154 open_window;
155 open_window;
156 cmd 'split h';
157 open_window;
158 cmd 'focus parent';
159
160 sync_with_i3;
161
162 is(get_net_active_window(), 0, 'branch focus is indicated by the root property as "None" window');
163
164 done_testing;