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.
This commit is contained in:
jj 2013-10-22 13:17:23 +02:00 committed by Michael Stapelberg
parent 1110a1bed6
commit b6100dd727
2 changed files with 31 additions and 4 deletions

View File

@ -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);

View File

@ -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;