]> git.sur5r.net Git - i3/i3/blob - testcases/t/251-command-criteria-focused.t
225394f7b6e2237090bddd5240872fcee6b87000
[i3/i3] / testcases / t / 251-command-criteria-focused.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 # Tests for the special value "__focused__" in command criteria.
18 # Ticket: #1770
19 use i3test;
20 use X11::XCB qw(PROP_MODE_REPLACE);
21
22 my ($ws);
23
24 sub open_window_with_role {
25     my ($role) = @_;
26     open_window(
27         before_map => sub {
28             my ($window) = @_;
29             my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
30             my $atomtype = $x->atom(name => 'STRING');
31             $x->change_property(
32                 PROP_MODE_REPLACE,
33                 $window->id,
34                 $atomname->id,
35                 $atomtype->id,
36                 8,
37                 length($role) + 1,
38                 "$role\x00"
39             );
40         }
41     );
42 }
43
44 ###############################################################################
45 # 1: Test __focused__ for window class.
46 ###############################################################################
47
48 $ws = fresh_workspace;
49 open_window(wm_class => 'notme');
50 open_window(wm_class => 'magic');
51 open_window(wm_class => 'magic');
52 is(@{get_ws($ws)->{nodes}}, 3, 'sanity check: workspace contains three windows');
53
54 cmd '[class=__focused__] move to workspace trash';
55 is(@{get_ws($ws)->{nodes}}, 1, '__focused__ works for window class');
56
57 ###############################################################################
58 # 2: Test __focused__ for window instance.
59 ###############################################################################
60
61 $ws = fresh_workspace;
62 open_window(instance => 'notme', wm_class => 'test');
63 open_window(instance => 'magic', wm_class => 'test');
64 open_window(instance => 'magic', wm_class => 'test');
65 is(@{get_ws($ws)->{nodes}}, 3, 'sanity check: workspace contains three windows');
66
67 cmd '[instance=__focused__] move to workspace trash';
68 is(@{get_ws($ws)->{nodes}}, 1, '__focused__ works for window instance');
69
70 ###############################################################################
71 # 3: Test __focused__ for window title.
72 ###############################################################################
73
74 $ws = fresh_workspace;
75 open_window(name => 'notme');
76 open_window(name => 'magic');
77 open_window(name => 'magic');
78 is(@{get_ws($ws)->{nodes}}, 3, 'sanity check: workspace contains three windows');
79
80 cmd '[title=__focused__] move to workspace trash';
81 is(@{get_ws($ws)->{nodes}}, 1, '__focused__ works for title');
82
83 ###############################################################################
84 # 4: Test __focused__ for window role.
85 ###############################################################################
86
87 $ws = fresh_workspace;
88 open_window_with_role("notme");
89 open_window_with_role("magic");
90 open_window_with_role("magic");
91 is(@{get_ws($ws)->{nodes}}, 3, 'sanity check: workspace contains three windows');
92
93 cmd '[window_role=__focused__] move to workspace trash';
94 is(@{get_ws($ws)->{nodes}}, 1, '__focused__ works for window_role');
95
96 ###############################################################################
97 # 5: Test __focused__ for workspace.
98 ###############################################################################
99
100 $ws = fresh_workspace;
101 open_window;
102 open_window;
103 is(@{get_ws($ws)->{nodes}}, 2, 'sanity check: workspace contains two windows');
104
105 cmd '[workspace=__focused__] move to workspace trash';
106 is(@{get_ws($ws)->{nodes}}, 0, '__focused__ works for workspace');
107
108 ###############################################################################
109
110 done_testing;