Files
contrib
debian
docs
i3-config-wizard
i3-dump-log
i3-input
i3-msg
i3-nagbar
i3bar
include
libi3
man
parser-specs
src
testcases
lib
t
000-load-deps.t
001-tile.t
002-i3-sync.t
003-ipc.t
004-unmanaged.t
005-floating.t
100-fullscreen.t
101-focus.t
102-dock.t
103-move.t
104-focus-stack.t
105-stacking.t
111-goto.t
112-floating-resize.t
113-urgent.t
114-client-leader.t
115-ipc-workspaces.t
116-nestedcons.t
117-workspace.t
118-openkill.t
119-match.t
120-multiple-cmds.t
121-next-prev.t
122-split.t
124-move.t
126-regress-close.t
127-regress-floating-parent.t
128-open-order.t
129-focus-after-close.t
130-close-empty-split.t
131-stacking-order.t
132-move-workspace.t
133-size-hints.t
134-invalid-command.t
135-floating-focus.t
136-floating-ws-empty.t
137-floating-unmap.t
138-floating-attach.t
139-ws-numbers.t
140-focus-lost.t
141-resize.t
142-regress-move-floating.t
143-regress-floating-restart.t
144-regress-floating-resize.t
145-flattening.t
146-floating-reinsert.t
147-regress-floatingmove.t
148-regress-floatingmovews.t
150-regress-dock-restart.t
151-regress-float-size.t
152-regress-level-up.t
153-floating-originalsize.t
154-regress-multiple-dock.t
155-floating-split-size.t
156-fullscreen-focus.t
158-wm_take_focus.t
159-socketpaths.t
161-regress-borders-restart.t
162-regress-dock-urgent.t
163-wm-state.t
164-kill-win-vs-client.t
165-for_window.t
166-assign.t
167-workspace_layout.t
168-regress-fullscreen-restart.t
169-border-toggle.t
170-force_focus_wrapping.t
171-config-migrate.t
172-start-on-named-ws.t
173-get-marks.t
173-regress-focus-assign.t
174-border-config.t
174-regress-focus-toggle.t
175-startup-notification.t
176-workspace-baf.t
177-bar-config.t
178-regress-workspace-open.t
179-regress-multiple-ws.t
180-fd-leaks.t
181-regress-float-border.t
182-regress-focus-dock.t
183-config-variables.t
184-regress-float-split-resize.t
185-scratchpad.t
186-regress-assign-focus-parent.t
187-commands-parser.t
188-regress-focus-restart.t
189-floating-constraints.t
190-scratchpad-diff-ws.t
191-resize-levels.t
192-layout.t
193-ipc-version.t
194-regress-floating-size.t
195-net-active-window.t
196-randr-output-names.t
197-regression-move-vanish.t
198-regression-scratchpad-crash.t
199-ipc-mode-event.t
200-urgency-timer.t
201-config-parser.t
202-scratchpad-criteria.t
203-regress-assign-and-move.t
204-regress-scratchpad-move.t
205-ipc-windows.t
206-fullscreen-scratchpad.t
207-shmlog.t
208-regress-floating-criteria.t
209-ewmh-net-workarea.t
210-mark-unmark.t
211-regress-urgency-assign.t
212-assign-urgency.t
213-layout-restore-simple.t
213-move-branch-position.t
214-layout-restore-criteria.t
215-layout-restore-crash.t
216-layout-restore-split-swallows.t
217-NET_CURRENT_DESKTOP.t
218-regress-floating-split.t
219-ipc-window-focus.t
220-ipc-window-title.t
221-floating-type-hints.t
222-regress-dock-resize.t
223-net-client-list.t
224-regress-resize-branch.t
500-multi-monitor.t
501-scratchpad.t
502-focus-output.t
503-workspace.t
504-move-workspace-to-output.t
505-scratchpad-resolution.t
506-focus-right.t
507-workspace-move-crash.t
509-workspace_layout.t
510-focus-across-outputs.t
511-scratchpad-configure-request.t
512-move-wraps.t
513-move-workspace.t
514-ipc-workspace-multi-monitor.t
515-create-workspace.t
516-move.t
517-regress-move-direction-ipc.t
.gitignore
Makefile.PL
Xdummy
complete-run.pl
i3-test.config
new-test
restart-state.golden
valgrind.supp
tests
yajl-fallback
.gitignore
DEPENDS
LICENSE
Makefile
PACKAGE-MAINTAINER
RELEASE-NOTES-4.2
RELEASE-NOTES-4.3
RELEASE-NOTES-4.4
RELEASE-NOTES-4.5
RELEASE-NOTES-4.5.1
RELEASE-NOTES-4.6
RELEASE-NOTES-4.7
RELEASE-NOTES-4.7.1
RELEASE-NOTES-4.7.2
common.mk
generate-command-parser.pl
i3-dmenu-desktop
i3-migrate-config-to-v4
i3-save-tree
i3-sensible-editor
i3-sensible-pager
i3-sensible-terminal
i3-with-shmlog.xsession.desktop
i3.applications.desktop
i3.config
i3.config.keycodes
i3.xsession.desktop
logo.svg
pseudo-doc.doxygen
i3/testcases/t/202-scratchpad-criteria.t

176 lines
5.5 KiB
Perl

#!perl
# vim:ts=4:sw=4:expandtab
#
# Please read the following documents before working on tests:
# • http://build.i3wm.org/docs/testsuite.html
# (or docs/testsuite)
#
# • http://build.i3wm.org/docs/lib-i3test.html
# (alternatively: perldoc ./testcases/lib/i3test.pm)
#
# • http://build.i3wm.org/docs/ipc.html
# (or docs/ipc)
#
# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
# (unless you are already familiar with Perl)
#
# Verifies that using criteria to address scratchpad windows works.
use i3test;
my $i3 = i3(get_socket_path());
#####################################################################
# Verify that using scratchpad show with criteria works as expected:
# - When matching a scratchpad window which is visible,
# it should hide it.
# - When matching a scratchpad window which is on __i3_scratch,
# it should show it.
# - When matching a non-scratchpad window, it should be a no-op.
# - When matching a scratchpad window,
# non-matching windows shouldn't appear
######################################################################
my $tmp = fresh_workspace;
my $third_window = open_window(name => 'scratch-match');
cmd 'move scratchpad';
#####################################################################
# Verify that using 'scratchpad show' without any matching windows is
# a no-op.
#####################################################################
my $old_focus = get_focused($tmp);
cmd '[title="nomatch"] scratchpad show';
is(get_focused($tmp), $old_focus, 'non-matching criteria have no effect');
#####################################################################
# Verify that we can use criteria to show a scratchpad window.
#####################################################################
cmd '[title="scratch-match"] scratchpad show';
my $scratch_focus = get_focused($tmp);
isnt($scratch_focus, $old_focus, 'matching criteria works');
# Check that the window was centered and resized too.
my $tree = $i3->get_tree->recv;
my $ws = get_ws($tmp);
my $scratchrect = $ws->{floating_nodes}->[0]->{rect};
my $output = $tree->{nodes}->[1];
my $outputrect = $output->{rect};
is($scratchrect->{width}, $outputrect->{width} * 0.5, 'scratch width is 50%');
is($scratchrect->{height}, $outputrect->{height} * 0.75, 'scratch height is 75%');
is($scratchrect->{x},
($outputrect->{width} / 2) - ($scratchrect->{width} / 2),
'scratch window centered horizontally');
is($scratchrect->{y},
($outputrect->{height} / 2 ) - ($scratchrect->{height} / 2),
'scratch window centered vertically');
cmd '[title="scratch-match"] scratchpad show';
isnt(get_focused($tmp), $scratch_focus, 'matching criteria works');
is(get_focused($tmp), $old_focus, 'focus restored');
#####################################################################
# Verify that we cannot use criteria to show a non-scratchpad window.
#####################################################################
my $tmp2 = fresh_workspace;
my $non_scratch_window = open_window(name => 'non-scratch');
cmd "workspace $tmp";
is(get_focused($tmp), $old_focus, 'focus still ok');
cmd '[title="non-scratch"] scratchpad show';
is(get_focused($tmp), $old_focus, 'focus unchanged');
#####################################################################
# Verify that non-matching windows doesn't appear
#####################################################################
# Subroutine to clear scratchpad
sub clear_scratchpad {
while (scalar @{get_ws('__i3_scratch')->{floating_nodes}}) {
cmd 'scratchpad show';
cmd 'kill';
}
}
#Start from an empty fresh workspace
my $empty_ws = fresh_workspace;
cmd "workspace $empty_ws";
my $no_focused = get_focused($empty_ws);
cmd '[title="nothingmatchthistitle"] scratchpad show';
#Check nothing match
is(get_focused($empty_ws), $no_focused, "no window to focus on");
clear_scratchpad;
open_window(name => "my-scratch-window");
my $w1_focus = get_focused($empty_ws);
cmd 'move scratchpad';
cmd '[title="my-scratch-window"] scratchpad show';
#Check we created and shown a scratchpad window
is(get_focused($empty_ws), $w1_focus, "focus on scratchpad window");
#Switching workspace
my $empty_ws2 = fresh_workspace;
cmd "workspace $empty_ws2";
open_window(name => "my-second-scratch-window");
my $w2_focus = get_focused($empty_ws2);
cmd 'move scratchpad';
cmd '[title="my-second-scratch-window"] scratchpad show';
#Check we got the correct window
is(get_focused($empty_ws2), $w2_focus, "focus is on second window");
#####################################################################
# Verify that 'scratchpad show' correctly hide multiple scratchpad
# windows
#####################################################################
clear_scratchpad;
sub check_floating {
my($rws, $n) = @_;
my $ws = get_ws($rws);
is(scalar @{$ws->{nodes}}, 0, 'no windows on ws');
is(scalar @{$ws->{floating_nodes}}, $n, "$n floating windows on ws");
}
my $empty_ws3 = fresh_workspace;
cmd "workspace $empty_ws3";
check_floating($empty_ws3, 0);
#Creating two scratchpad windows
open_window(name => "toggle-1");
cmd 'move scratchpad';
open_window(name => "toggle-2");
cmd 'move scratchpad';
check_floating($empty_ws3, 0);
#Showing both
cmd '[title="toggle-"] scratchpad show';
check_floating($empty_ws3, 2);
#Hiding both
cmd '[title="toggle-"] scratchpad show';
check_floating($empty_ws3, 0);
#Showing both again
cmd '[title="toggle-"] scratchpad show';
check_floating($empty_ws3, 2);
#Hiding one
cmd 'scratchpad show';
check_floating($empty_ws3, 1);
#Hiding the last
cmd 'scratchpad show';
check_floating($empty_ws3, 0);
done_testing;