Raise floating windows on `focus [direction]`
Patch status: merged
Patch by Tony Crisci
Long description:
Raise a window when cycling focus between floating windows with `focus [direction]` command so that newly focused windows are rendered on top of other windows. This is done by placing the window last in the floating nodes of the parent and reordering the stack so the relative order is preserved. fixes #1322
To apply this patch, use:
curl http://cr.i3wm.org/patch/632/raw.patch | git am
b/src/tree.c
23 |
@@ -621,6 +621,14 @@ static bool _tree_next(Con *con, char way, orientation_t orientation, bool wrap) |
24 |
if (!next) |
25 |
return false; |
26 |
|
27 |
+ /* Raise the floating window on top of other windows preserving |
28 |
+ * relative stack order */ |
29 |
+ while (TAILQ_LAST(&(parent->floating_head), floating_head) != next) { |
30 |
+ Con *last = TAILQ_LAST(&(parent->floating_head), floating_head); |
31 |
+ TAILQ_REMOVE(&(parent->floating_head), last, floating_windows); |
32 |
+ TAILQ_INSERT_HEAD(&(parent->floating_head), last, floating_windows); |
33 |
+ } |
34 |
+ |
35 |
con_focus(con_descend_focused(next)); |
36 |
return true; |
37 |
} |
b/testcases/t/236-floating-focus-raise.t
43 |
@@ -0,0 +1,44 @@ |
44 |
+#!perl |
45 |
+# vim:ts=4:sw=4:expandtab |
46 |
+# |
47 |
+# Please read the following documents before working on tests: |
48 |
+# • http://build.i3wm.org/docs/testsuite.html |
49 |
+# (or docs/testsuite) |
50 |
+# |
51 |
+# • http://build.i3wm.org/docs/lib-i3test.html |
52 |
+# (alternatively: perldoc ./testcases/lib/i3test.pm) |
53 |
+# |
54 |
+# • http://build.i3wm.org/docs/ipc.html |
55 |
+# (or docs/ipc) |
56 |
+# |
57 |
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf |
58 |
+# (unless you are already familiar with Perl) |
59 |
+# |
60 |
+# Test that focusing floating windows with the command `focus [direction]` |
61 |
+# promotes the focused window to the top of the rendering stack. |
62 |
+# Ticket: #1322 |
63 |
+# Bug still in: 4.8-88-gcc09348 |
64 |
+use i3test; |
65 |
+ |
66 |
+my $ws = fresh_workspace; |
67 |
+ |
68 |
+my $win1 = open_floating_window; |
69 |
+my $win2 = open_floating_window; |
70 |
+my $win3 = open_floating_window; |
71 |
+ |
72 |
+# it's a good idea to do this a few times because of the implementation |
73 |
+for my $i (1 .. 3) { |
74 |
+ cmd 'focus left'; |
75 |
+ my $ws_con = get_ws($ws); |
76 |
+ is($ws_con->{floating_nodes}[-1]->{nodes}[0]->{id}, get_focused($ws), |
77 |
+ "focus left put the focused window on top of the floating windows (try $i)"); |
78 |
+} |
79 |
+ |
80 |
+for my $i (1 .. 3) { |
81 |
+ cmd 'focus right'; |
82 |
+ my $ws_con = get_ws($ws); |
83 |
+ is($ws_con->{floating_nodes}[-1]->{nodes}[0]->{id}, get_focused($ws), |
84 |
+ "focus right put the focused window on top of the floating windows (try $i)"); |
85 |
+} |
86 |
+ |
87 |
+done_testing; |