]> git.sur5r.net Git - i3/i3/blob - testcases/t/195-net-active-window.t
Merge branch 'master' into next
[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.
19 # ticket #774, bug still present in commit 1e49f1b08a3035c1f238fcd6615e332216ab582e
20 # ticket #1136, bug still present in commit fd07f989fdf441ef335245dd3436a70ff60e8896
21 use i3test;
22
23 sub send_net_active_window {
24     my ($id) = @_;
25
26     my $msg = pack "CCSLLLLLLL",
27         X11::XCB::CLIENT_MESSAGE, # response_type
28         32, # format
29         0, # sequence
30         $id, # destination window
31         $x->atom(name => '_NET_ACTIVE_WINDOW')->id,
32         0,
33         0,
34         0,
35         0,
36         0;
37
38     $x->send_event(0, $x->get_root_window(), X11::XCB::EVENT_MASK_SUBSTRUCTURE_REDIRECT, $msg);
39 }
40
41 my $ws1 = fresh_workspace;
42 my $win1 = open_window;
43 my $win2 = open_window;
44
45 ################################################################################
46 # Ensure that the _NET_ACTIVE_WINDOW ClientMessage works when windows are visible
47 ################################################################################
48
49 is($x->input_focus, $win2->id, 'window 2 has focus');
50
51 send_net_active_window($win1->id);
52
53 is($x->input_focus, $win1->id, 'window 1 has focus');
54
55 ################################################################################
56 # Switch to a different workspace and ensure sending the _NET_ACTIVE_WINDOW
57 # ClientMessage has no effect anymore.
58 ################################################################################
59
60 my $ws2 = fresh_workspace;
61 my $win3 = open_window;
62
63 is($x->input_focus, $win3->id, 'window 3 has focus');
64
65 send_net_active_window($win1->id);
66
67 is($x->input_focus, $win3->id, 'window 3 still has focus');
68
69 ################################################################################
70 # Move a window to the scratchpad, send a _NET_ACTIVE_WINDOW for it and verify
71 # that focus is still unchanged.
72 ################################################################################
73
74 my $scratch = open_window;
75
76 is($x->input_focus, $scratch->id, 'to-scratchpad window has focus');
77
78 cmd 'move scratchpad';
79
80 is($x->input_focus, $win3->id, 'focus reverted to window 3');
81
82 send_net_active_window($scratch->id);
83
84 is($x->input_focus, $win3->id, 'window 3 still focused');
85
86 done_testing;