From b6100dd7274a56b473927de9848bcff0e10b77d9 Mon Sep 17 00:00:00 2001 From: jj Date: Tue, 22 Oct 2013 13:17:23 +0200 Subject: [PATCH] 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. --- src/commands.c | 18 ++++++++++++++---- testcases/t/502-focus-output.t | 17 +++++++++++++++++ 2 files changed, 31 insertions(+), 4 deletions(-) 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; -- 2.39.5