i3 - improved tiling WM


scratchpad_show focus unfocused scratchpad window

Patch status: merged

Patch by Sascha Kruse

Long description:

When there's an unfocused scratchpad window on the current workspace
scratchpad_show will focus that scratchpad window.

To apply this patch, use:
curl http://cr.i3wm.org/patch/26/raw.patch | git am

b/src/scratchpad.c

16
@@ -89,10 +89,27 @@ void scratchpad_show(Con *con) {
17
     }
18
 
19
     /* If this was 'scratchpad show' without criteria, we check if there is a
20
-     * visible scratchpad window on another workspace. In this case we move it
21
-     * to the current workspace. */
22
+     * unfocused scratchpad on the current workspace and focus it */
23
     Con *walk_con;
24
     Con *focused_ws = con_get_workspace(focused);
25
+    TAILQ_FOREACH(walk_con, &(focused_ws->floating_head), floating_windows) {
26
+        if ((floating = con_inside_floating(walk_con)) &&
27
+            floating->scratchpad_state != SCRATCHPAD_NONE &&
28
+            floating != con_inside_floating(focused)) {
29
+                DLOG("Found an unfocused scratchpad window on this workspace\n");
30
+                DLOG("Focusing it: %p\n", walk_con);
31
+                /* use con_descend_tiling_focused to get the last focused
32
+                 * window inside this scratch container in order to
33
+                 * keep the focus the same within this container */
34
+                con_focus(con_descend_tiling_focused(walk_con));
35
+                return;
36
+            }
37
+    }
38
+
39
+    /* If this was 'scratchpad show' without criteria, we check if there is a
40
+     * visible scratchpad window on another workspace. In this case we move it
41
+     * to the current workspace. */
42
+    focused_ws = con_get_workspace(focused);
43
     TAILQ_FOREACH(walk_con, &all_cons, all_cons) {
44
         Con *walk_ws = con_get_workspace(walk_con);
45
         if (walk_ws &&

b/testcases/t/185-scratchpad.t

50
@@ -400,6 +400,28 @@ $second = fresh_workspace;
51
 verify_scratchpad_move_with_visible_scratch_con($first, $second, 0);
52
 does_i3_live;
53
 
54
+
55
+################################################################################
56
+# 13: Test whether scratchpad show moves focus to the scratchpad window
57
+# when another window on the same workspace has focus
58
+################################################################################
59
+
60
+clear_scratchpad;
61
+my $ws = fresh_workspace;
62
+
63
+open_window;
64
+my $scratch = get_focused($ws);
65
+cmd 'move scratchpad';
66
+cmd 'scratchpad show';
67
+
68
+open_window;
69
+my $not_scratch = get_focused($ws);
70
+is(get_focused($ws), $not_scratch, 'not scratch window has focus');
71
+
72
+cmd 'scratchpad show';
73
+
74
+is(get_focused($ws), $scratch, 'scratchpad is focused');
75
+
76
 # TODO: make i3bar display *something* when a window on the scratchpad has the urgency hint
77
 
78
 done_testing;