Bugfix: don't focus unmapped container on manage
Patch status: merged
Patch by Tony Crisci
Long description:
A window may become unmapped on manage when an assignment command unmaps the window, such as moving it to the scratchpad or killing it. This can cause i3 focus to be an unmapped window and different than X focus which can lead to complications fixes #1283
To apply this patch, use:
curl http://cr.i3wm.org/patch/605/raw.patch | git am
b/src/manage.c
22 |
@@ -505,7 +505,7 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki |
23 |
|
24 |
/* Defer setting focus after the 'new' event has been sent to ensure the |
25 |
* proper window event sequence. */ |
26 |
- if (set_focus && !nc->window->doesnt_accept_focus) { |
27 |
+ if (set_focus && !nc->window->doesnt_accept_focus && nc->mapped) { |
28 |
DLOG("Now setting focus.\n"); |
29 |
con_focus(nc); |
30 |
} |
b/testcases/t/233-regress-manage-focus-unmapped.t
36 |
@@ -0,0 +1,58 @@ |
37 |
+#!perl |
38 |
+# vim:ts=4:sw=4:expandtab |
39 |
+# |
40 |
+# Please read the following documents before working on tests: |
41 |
+# • http://build.i3wm.org/docs/testsuite.html |
42 |
+# (or docs/testsuite) |
43 |
+# |
44 |
+# • http://build.i3wm.org/docs/lib-i3test.html |
45 |
+# (alternatively: perldoc ./testcases/lib/i3test.pm) |
46 |
+# |
47 |
+# • http://build.i3wm.org/docs/ipc.html |
48 |
+# (or docs/ipc) |
49 |
+# |
50 |
+# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf |
51 |
+# (unless you are already familiar with Perl) |
52 |
+# |
53 |
+# Test that an assignment that unmaps a window does not disturb input focus. |
54 |
+# This can cause i3 focus to be an unmapped window and different than X focus |
55 |
+# which can lead to complications |
56 |
+# Ticket: #1283 |
57 |
+# Bug still in: 4.8-24-g60070de |
58 |
+use i3test i3_autostart => 0; |
59 |
+ |
60 |
+my $config = <<'EOT'; |
61 |
+# i3 config file (v4) |
62 |
+font -misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1 |
63 |
+ |
64 |
+for_window [class="^special_kill$"] kill |
65 |
+for_window [class="^special_scratchpad$"] move scratchpad |
66 |
+EOT |
67 |
+ |
68 |
+my $pid = launch_with_config($config); |
69 |
+ |
70 |
+my $win = open_window; |
71 |
+ |
72 |
+my $scratch_window = open_window( |
73 |
+ wm_class => 'special_scratchpad', |
74 |
+ dont_map => 1 |
75 |
+); |
76 |
+$scratch_window->map; |
77 |
+sync_with_i3; |
78 |
+ |
79 |
+is($x->input_focus, $win->{id}, |
80 |
+ 'an assignment that sends a window to the scratchpad should not disturb focus'); |
81 |
+ |
82 |
+my $kill_window = open_window( |
83 |
+ wm_class => 'special_kill', |
84 |
+ dont_map => 1 |
85 |
+); |
86 |
+$kill_window->map; |
87 |
+sync_with_i3; |
88 |
+ |
89 |
+is($x->input_focus, $win->{id}, |
90 |
+ 'an assignment that kills a window should not disturb focus'); |
91 |
+ |
92 |
+exit_gracefully($pid); |
93 |
+ |
94 |
+done_testing; |