i3 - improved tiling WM


Command `focus [direc]` raises floating windows

Patch status: superseded

Patch by Tony Crisci

Long description:

When floating windows are cycled through using the command `focus
[direction]` the newly focused window will be rendered on top of other
windows. The focused window will be placed last in the floating nodes of
the parent with the relative order of the floating nodes being
preserved.

fixes #1322

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

b/src/tree.c

22
@@ -621,6 +621,14 @@ static bool _tree_next(Con *con, char way, orientation_t orientation, bool wrap)
23
         if (!next)
24
             return false;
25
 
26
+        /* Raise the floating window on top of other windows preserving
27
+         * relative stack order */
28
+        while (TAILQ_LAST(&(parent->floating_head), floating_head) != next) {
29
+            Con *last = TAILQ_LAST(&(parent->floating_head), floating_head);
30
+            TAILQ_REMOVE(&(parent->floating_head), last, floating_windows);
31
+            TAILQ_INSERT_HEAD(&(parent->floating_head), last, floating_windows);
32
+        }
33
+
34
         con_focus(con_descend_focused(next));
35
         return true;
36
     }

b/testcases/t/236-floating-focus-raise.t

42
@@ -0,0 +1,44 @@
43
+#!perl
44
+# vim:ts=4:sw=4:expandtab
45
+#
46
+# Please read the following documents before working on tests:
47
+# • http://build.i3wm.org/docs/testsuite.html
48
+#   (or docs/testsuite)
49
+#
50
+# • http://build.i3wm.org/docs/lib-i3test.html
51
+#   (alternatively: perldoc ./testcases/lib/i3test.pm)
52
+#
53
+# • http://build.i3wm.org/docs/ipc.html
54
+#   (or docs/ipc)
55
+#
56
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf
57
+#   (unless you are already familiar with Perl)
58
+#
59
+# Test that focusing floating windows with the command `focus [direction]`
60
+# promotes the focused window to the top of the rendering stack.
61
+# Ticket: #1322
62
+# Bug still in: 4.8-88-gcc09348
63
+use i3test;
64
+
65
+my $ws = fresh_workspace;
66
+
67
+my $win1 = open_floating_window;
68
+my $win2 = open_floating_window;
69
+my $win3 = open_floating_window;
70
+
71
+# it's a good idea to do this a few times because of the implementation
72
+for my $i (1 .. 3) {
73
+    cmd 'focus left';
74
+    my $ws_con = get_ws($ws);
75
+    is($ws_con->{floating_nodes}[-1]->{nodes}[0]->{id}, get_focused($ws),
76
+        "focus left put the focused window on top of the floating windows (try $i)");
77
+}
78
+
79
+for my $i (1 .. 3) {
80
+    cmd 'focus right';
81
+    my $ws_con = get_ws($ws);
82
+    is($ws_con->{floating_nodes}[-1]->{nodes}[0]->{id}, get_focused($ws),
83
+        "focus right put the focused window on top of the floating windows (try $i)");
84
+}
85
+
86
+done_testing;