Fix problem with floating container when switching outputs
Patch status: rejected
Patch by jj
Long description:
When the top left corner of a floating container is outside of the screen and the command 'focus output <direction>' is used, i3 fails to find the currently focused output and crashes. With this patch, the 'focus output' command checks for both, the top left and down right corner of the focused container, to detect the current output.
To apply this patch, use:
curl http://cr.i3wm.org/patch/188/raw.patch | git am
b/src/commands.c
19 |
@@ -1677,8 +1677,6 @@ void cmd_open(I3_CMD) { |
20 |
* |
21 |
*/ |
22 |
void cmd_focus_output(I3_CMD, char *name) { |
23 |
- owindow *current; |
24 |
- |
25 |
DLOG("name = %s\n", name); |
26 |
|
27 |
HANDLE_EMPTY_MATCH; |
28 |
@@ -1687,8 +1685,13 @@ void cmd_focus_output(I3_CMD, char *name) { |
29 |
Output *current_output = NULL; |
30 |
Output *output; |
31 |
|
32 |
- TAILQ_FOREACH(current, &owindows, owindows) |
33 |
- current_output = get_output_containing(current->con->rect.x, current->con->rect.y); |
34 |
+ current_output = get_output_containing(focused->rect.x, focused->rect.y); |
35 |
+ /* Check whether the current_output is null, i.e. the top left corner of the focused window |
36 |
+ * is placed outside of the visible output screen. In this case, the bottom right corner |
37 |
+ * must be contained in some output. */ |
38 |
+ if (!current_output) |
39 |
+ current_output = get_output_containing(focused->rect.x + focused->rect.width, focused->rect.y + focused->rect.height); |
40 |
+ |
41 |
assert(current_output != NULL); |
42 |
|
43 |
output = get_output_from_string(current_output, name); |
b/testcases/t/502-focus-output.t
48 |
@@ -71,6 +71,22 @@ is(focused_output, 'fake-1', 'focus on second output'); |
49 |
cmd 'focus output fake-0'; |
50 |
is(focused_output, 'fake-0', 'focus on first output'); |
51 |
|
52 |
+################################################################################ |
53 |
+# assure 'focus output' works correctly when a floating window has (partially) moved |
54 |
+# out of screen |
55 |
+################################################################################ |
56 |
+ |
57 |
+# open floating window |
58 |
+open_window; |
59 |
+cmd 'floating toggle'; |
60 |
+ |
61 |
+# move the top left corner over the left border of the current screen |
62 |
+cmd 'move left 500'; |
63 |
+ |
64 |
+# focus right output |
65 |
+cmd 'focus output right'; |
66 |
+is(focused_output, 'fake-1', 'focus on second output'); |
67 |
+ |
68 |
exit_gracefully($pid); |
69 |
|
70 |
done_testing; |