i3 - improved tiling WM


scratchpad_show focus unfocused scratchpad window

Patch status: rejected

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/23/raw.patch | git am

b/src/scratchpad.c

16
@@ -89,20 +89,31 @@ 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
+     * visible scratchpad window. If there is one and it's on another workspace
23
+     * we move it to the current workspace. If there is one on the current workspace
24
+     * but unfocused we focus it */
25
     Con *walk_con;
26
     Con *focused_ws = con_get_workspace(focused);
27
     TAILQ_FOREACH(walk_con, &all_cons, all_cons) {
28
         Con *walk_ws = con_get_workspace(walk_con);
29
         if (walk_ws &&
30
-            !con_is_internal(walk_ws) && focused_ws != walk_ws &&
31
+            !con_is_internal(walk_ws) &&
32
             (floating = con_inside_floating(walk_con)) &&
33
             floating->scratchpad_state != SCRATCHPAD_NONE) {
34
-            DLOG("Found a visible scratchpad window on another workspace,\n");
35
-            DLOG("moving it to this workspace: con = %p\n", walk_con);
36
-            con_move_to_workspace(walk_con, focused_ws, true, false);
37
-            return;
38
+            if (focused_ws != walk_ws) {
39
+                DLOG("Found a visible scratchpad window on another workspace,\n");
40
+                DLOG("moving it to this workspace: con = %p\n", walk_con);
41
+                con_move_to_workspace(walk_con, focused_ws, true, false);
42
+                return;
43
+            } else if (floating != con_inside_floating(focused)) {
44
+                DLOG("Found an unfocused scratchpad window on this workspace\n");
45
+                DLOG("Focusing it: %p\n", walk_con);
46
+                /* use con_descend_tiling_focused to get the last focused
47
+                 * window inside this scratch container in order to
48
+                 * keep the focus the same within this container */
49
+                con_focus(con_descend_tiling_focused(walk_con));
50
+                return;
51
+            }
52
         }
53
     }
54
 

b/testcases/t/185-scratchpad.t

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