2 # vim:ts=4:sw=4:expandtab
4 # Please read the following documents before working on tests:
5 # • https://build.i3wm.org/docs/testsuite.html
8 # • https://build.i3wm.org/docs/lib-i3test.html
9 # (alternatively: perldoc ./testcases/lib/i3test.pm)
11 # • https://build.i3wm.org/docs/ipc.html
14 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
15 # (unless you are already familiar with Perl)
17 # Tests for the special value "__focused__" in command criteria.
20 use X11::XCB qw(PROP_MODE_REPLACE);
24 sub open_window_with_role {
29 my $atomname = $x->atom(name => 'WM_WINDOW_ROLE');
30 my $atomtype = $x->atom(name => 'STRING');
44 ###############################################################################
45 # 1: Test __focused__ for window class.
46 ###############################################################################
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');
54 cmd '[class=__focused__] move to workspace trash';
55 is(@{get_ws($ws)->{nodes}}, 1, '__focused__ works for window class');
57 ###############################################################################
58 # 2: Test __focused__ for window instance.
59 ###############################################################################
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');
67 cmd '[instance=__focused__] move to workspace trash';
68 is(@{get_ws($ws)->{nodes}}, 1, '__focused__ works for window instance');
70 ###############################################################################
71 # 3: Test __focused__ for window title.
72 ###############################################################################
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');
80 cmd '[title=__focused__] move to workspace trash';
81 is(@{get_ws($ws)->{nodes}}, 1, '__focused__ works for title');
83 ###############################################################################
84 # 4: Test __focused__ for window role.
85 ###############################################################################
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');
93 cmd '[window_role=__focused__] move to workspace trash';
94 is(@{get_ws($ws)->{nodes}}, 1, '__focused__ works for window_role');
96 ###############################################################################
97 # 5: Test __focused__ for workspace.
98 ###############################################################################
100 $ws = fresh_workspace;
103 is(@{get_ws($ws)->{nodes}}, 2, 'sanity check: workspace contains two windows');
105 cmd '[workspace=__focused__] move to workspace trash';
106 is(@{get_ws($ws)->{nodes}}, 0, '__focused__ works for workspace');
108 ###############################################################################