From: jj Date: Tue, 22 Oct 2013 11:17:23 +0000 (+0200) Subject: Fix output retrieval for floating cons X-Git-Tag: 4.7~29 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=b6100dd7274a56b473927de9848bcff0e10b77d9;p=i3%2Fi3 Fix output retrieval for floating cons When focusing/moving to outputs, the method of getting the correct output for a given container fails if the container in question is floating and only partially mapped on an output screen. This patch introduces a fail-safe retrieval of the output for any container. --- diff --git a/src/commands.c b/src/commands.c index 9631923d..32fdc7f1 100644 --- a/src/commands.c +++ b/src/commands.c @@ -77,6 +77,17 @@ static Output *get_output_from_string(Output *current_output, const char *output return output; } +/* + * Returns the output containing the given container. + */ +static Output *get_output_of_con(Con *con) { + Con *output_con = con_get_output(con); + Output *output = get_output_by_name(output_con->name); + assert(output != NULL); + + return output; +} + /* * Checks whether we switched to a new workspace and returns false in that case, * signaling that further workspace switching should be done by the calling function @@ -1049,7 +1060,7 @@ void cmd_move_con_to_output(I3_CMD, char *name) { // TODO: fix the handling of criteria TAILQ_FOREACH(current, &owindows, owindows) - current_output = get_output_containing(current->con->rect.x, current->con->rect.y); + current_output = get_output_of_con(current->con); assert(current_output != NULL); @@ -1131,8 +1142,7 @@ void cmd_move_workspace_to_output(I3_CMD, char *name) { owindow *current; TAILQ_FOREACH(current, &owindows, owindows) { - Output *current_output = get_output_containing(current->con->rect.x, - current->con->rect.y); + Output *current_output = get_output_of_con(current->con); if (!current_output) { ELOG("Cannot get current output. This is a bug in i3.\n"); ysuccess(false); @@ -1672,7 +1682,7 @@ void cmd_focus_output(I3_CMD, char *name) { Output *output; TAILQ_FOREACH(current, &owindows, owindows) - current_output = get_output_containing(current->con->rect.x, current->con->rect.y); + current_output = get_output_of_con(current->con); assert(current_output != NULL); output = get_output_from_string(current_output, name); diff --git a/testcases/t/502-focus-output.t b/testcases/t/502-focus-output.t index a6c5583f..8c1c36c5 100644 --- a/testcases/t/502-focus-output.t +++ b/testcases/t/502-focus-output.t @@ -71,6 +71,23 @@ is(focused_output, 'fake-1', 'focus on second output'); cmd 'focus output fake-0'; is(focused_output, 'fake-0', 'focus on first output'); +################################################################################ +# use 'focus output' and verify that i3 does not crash when the currently +# focused window is floating and is only partially mapped on an output screen +################################################################################ + +is(focused_output, 'fake-0', 'focus on first output'); + +my $floating_win = open_window; +cmd 'floating toggle'; +cmd 'move to absolute position -10 -10'; + +cmd 'focus output right'; +is(focused_output, 'fake-1', 'focus on second output'); + +cmd 'focus output fake-0'; +is(focused_output, 'fake-0', 'focus on first output'); + exit_gracefully($pid); done_testing;