]> git.sur5r.net Git - i3/i3/blobdiff - testcases/t/185-scratchpad.t
Merge branch 'release-4.16.1'
[i3/i3] / testcases / t / 185-scratchpad.t
index 598f2b360e6a05a27f7b4ef520347ccd1a605395..fd3827f740c16de5b6526b237d74466c9c944f32 100644 (file)
@@ -2,13 +2,13 @@
 # vim:ts=4:sw=4:expandtab
 #
 # Please read the following documents before working on tests:
-# • http://build.i3wm.org/docs/testsuite.html
+# • https://build.i3wm.org/docs/testsuite.html
 #   (or docs/testsuite)
 #
-# • http://build.i3wm.org/docs/lib-i3test.html
+# • https://build.i3wm.org/docs/lib-i3test.html
 #   (alternatively: perldoc ./testcases/lib/i3test.pm)
 #
-# • http://build.i3wm.org/docs/ipc.html
+# • https://build.i3wm.org/docs/ipc.html
 #   (or docs/ipc)
 #
 # • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
@@ -35,7 +35,7 @@ is($tree->{name}, 'root', 'root node is the first thing we get');
 my @__i3 = grep { $_->{name} eq '__i3' } @{$tree->{nodes}};
 is(scalar @__i3, 1, 'output __i3 found');
 
-my $content = first { $_->{type} == 2 } @{$__i3[0]->{nodes}};
+my $content = first { $_->{type} eq 'con' } @{$__i3[0]->{nodes}};
 my @workspaces = @{$content->{nodes}};
 my @workspace_names = map { $_->{name} } @workspaces;
 ok('__i3_scratch' ~~ @workspace_names, '__i3_scratch workspace found');
@@ -93,8 +93,7 @@ is(scalar @{$__i3_scratch->{floating_nodes}}, 0, '__i3_scratch ws empty');
 ################################################################################
 # 3: Verify that 'scratchpad toggle' sends a window to the __i3_scratch
 # workspace and sets the scratchpad flag to SCRATCHPAD_FRESH. The window’s size
-# and position will be changed (once!) on the next 'scratchpad show' and the
-# flag will be changed to SCRATCHPAD_CHANGED.
+# and position will be changed on the next 'scratchpad show'.
 ################################################################################
 
 my ($nodes, $focus) = get_ws_content($tmp);
@@ -165,10 +164,33 @@ $__i3_scratch = get_ws('__i3_scratch');
 @scratch_nodes = @{$__i3_scratch->{floating_nodes}};
 is(scalar @scratch_nodes, 1, '__i3_scratch contains our window');
 
-is($scratch_nodes[0]->{scratchpad_state}, 'changed', 'scratchpad_state changed');
+################################################################################
+# 6: Resizing the window should disable auto centering on scratchpad show
+################################################################################
+
+cmd 'scratchpad show';
+
+$ws = get_ws($tmp);
+is($ws->{floating_nodes}->[0]->{scratchpad_state}, 'fresh',
+   'scratchpad_state fresh');
+
+cmd 'resize grow width 10 px';
+cmd 'scratchpad show';
+cmd 'scratchpad show';
+
+$ws = get_ws($tmp);
+$scratchrect = $ws->{floating_nodes}->[0]->{rect};
+$outputrect = $output->{rect};
+
+is($ws->{floating_nodes}->[0]->{scratchpad_state}, 'changed',
+   'scratchpad_state changed');
+is($scratchrect->{width}, $outputrect->{width} * 0.5 + 10, 'scratch width is 50% + 10px');
+
+cmd 'resize shrink width 10 px';
+cmd 'scratchpad show';
 
 ################################################################################
-# 6: Verify that repeated 'scratchpad show' cycle through the stack, that is,
+# 7: Verify that repeated 'scratchpad show' cycle through the stack, that is,
 # toggling a visible window should insert it at the bottom of the stack of the
 # __i3_scratch workspace.
 ################################################################################
@@ -355,7 +377,7 @@ sub verify_scratchpad_move_with_visible_scratch_con {
     # this should bring up window 1
     cmd 'scratchpad show';
 
-    my $ws = get_ws($first);
+    $ws = get_ws($first);
     is(scalar @{$ws->{floating_nodes}}, 1, 'one floating node on ws1');
     is($x->input_focus, $window1->id, "showed the correct scratchpad window1");
 
@@ -400,6 +422,115 @@ $second = fresh_workspace;
 verify_scratchpad_move_with_visible_scratch_con($first, $second, 0);
 does_i3_live;
 
+
+################################################################################
+# 13: Test whether scratchpad show moves focus to the scratchpad window
+# when another window on the same workspace has focus
+################################################################################
+
+clear_scratchpad;
+$ws = fresh_workspace;
+
+open_window;
+my $scratch = get_focused($ws);
+cmd 'move scratchpad';
+cmd 'scratchpad show';
+
+open_window;
+my $not_scratch = get_focused($ws);
+is(get_focused($ws), $not_scratch, 'not scratch window has focus');
+
+cmd 'scratchpad show';
+
+is(get_focused($ws), $scratch, 'scratchpad is focused');
+
 # TODO: make i3bar display *something* when a window on the scratchpad has the urgency hint
 
+################################################################################
+# 14: Verify that 'move scratchpad' sends floating containers to scratchpad but
+# does not resize/resposition the container on the next 'scratchpad show', i.e.,
+# i3 sets the scratchpad flag to SCRATCHPAD_CHANGED
+################################################################################
+
+clear_scratchpad;
+$tmp = fresh_workspace;
+open_window;
+
+($nodes, $focus) = get_ws_content($tmp);
+is(scalar @$nodes, 1, 'precisely one window on current ws');
+is($nodes->[0]->{scratchpad_state}, 'none', 'scratchpad_state none');
+
+cmd 'floating toggle';
+cmd 'move scratchpad';
+
+$__i3_scratch = get_ws('__i3_scratch');
+@scratch_nodes = @{$__i3_scratch->{floating_nodes}};
+is(scalar @scratch_nodes, 1, '__i3_scratch contains our window');
+($nodes, $focus) = get_ws_content($tmp);
+is(scalar @$nodes, 0, 'no window on current ws anymore');
+
+is($scratch_nodes[0]->{scratchpad_state}, 'changed', 'scratchpad_state changed');
+
+################################################################################
+# 15: Verify that 'scratchpad show' returns correct info.
+################################################################################
+
+kill_all_windows;
+
+my $result = cmd 'scratchpad show';
+is($result->[0]->{success}, 0, 'no scratchpad window and call to scratchpad failed');
+
+open_window;
+cmd 'move scratchpad';
+$result = cmd 'scratchpad show';
+is($result->[0]->{success}, 1, 'call to scratchpad succeeded');
+$result = cmd 'scratchpad show';
+is($result->[0]->{success}, 1, 'call to scratchpad succeeded');
+
+kill_all_windows;
+$result = cmd 'scratchpad show';
+is($result->[0]->{success}, 0, 'call to scratchpad failed');
+
+################################################################################
+# 16: Verify that 'scratchpad show' with the criteria returns correct info.
+################################################################################
+
+open_window(name => "scratch-match");
+cmd 'move scratchpad';
+
+$result = cmd '[title="scratch-match"] scratchpad show';
+is($result->[0]->{success}, 1, 'call to scratchpad with the criteria succeeded');
+
+$result = cmd '[title="nomatch"] scratchpad show';
+is($result->[0]->{success}, 0, 'call to scratchpad with non-matching criteria failed');
+
+################################################################################
+# 17: Open a scratchpad window on a workspace, switch to another workspace and
+# call 'scratchpad show' again. Verify that it returns correct info.
+################################################################################
+
+fresh_workspace;
+open_window;
+cmd 'move scratchpad';
+
+fresh_workspace;
+$result = cmd 'scratchpad show';
+is($result->[0]->{success}, 1, 'call to scratchpad in another workspace succeeded');
+
+################################################################################
+# 18: Disabling floating for a scratchpad window should not work.
+################################################################################
+
+kill_all_windows;
+
+$ws = fresh_workspace;
+$window = open_window;
+cmd 'move scratchpad';
+cmd '[id=' . $window->id . '] floating disable';
+
+is(scalar @{get_ws_content($ws)}, 0, 'no window in workspace');
+cmd 'scratchpad show';
+is($x->input_focus, $window->id, 'scratchpad window shown');
+
+
 done_testing;