cmd_focus_output: Avoid assertion crash
Happened when the command criteria didn't match any windows. For example: `[con_mark=doesnotexist] focus output left`.
This commit is contained in:
parent
351d891f4c
commit
7fc3bf660e
|
@ -1626,24 +1626,18 @@ void cmd_open(I3_CMD) {
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void cmd_focus_output(I3_CMD, const char *name) {
|
void cmd_focus_output(I3_CMD, const char *name) {
|
||||||
owindow *current;
|
|
||||||
|
|
||||||
DLOG("name = %s\n", name);
|
|
||||||
|
|
||||||
HANDLE_EMPTY_MATCH;
|
HANDLE_EMPTY_MATCH;
|
||||||
|
|
||||||
/* get the output */
|
if (TAILQ_EMPTY(&owindows)) {
|
||||||
Output *current_output = NULL;
|
ysuccess(true);
|
||||||
Output *output;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
TAILQ_FOREACH(current, &owindows, owindows)
|
Output *current_output = get_output_for_con(TAILQ_FIRST(&owindows)->con);
|
||||||
current_output = get_output_for_con(current->con);
|
Output *output = get_output_from_string(current_output, name);
|
||||||
assert(current_output != NULL);
|
|
||||||
|
|
||||||
output = get_output_from_string(current_output, name);
|
|
||||||
|
|
||||||
if (!output) {
|
if (!output) {
|
||||||
yerror("No such output found.");
|
yerror("Output %s not found.", name);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1658,7 +1652,6 @@ void cmd_focus_output(I3_CMD, const char *name) {
|
||||||
workspace_show(ws);
|
workspace_show(ws);
|
||||||
|
|
||||||
cmd_output->needs_tree_render = true;
|
cmd_output->needs_tree_render = true;
|
||||||
// XXX: default reply for now, make this a better reply
|
|
||||||
ysuccess(true);
|
ysuccess(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -86,4 +86,33 @@ is(focused_output, 'fake-1', 'focus on second output');
|
||||||
cmd 'focus output fake-0';
|
cmd 'focus output fake-0';
|
||||||
is(focused_output, 'fake-0', 'focus on first output');
|
is(focused_output, 'fake-0', 'focus on first output');
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# use 'focus output' with command criteria and verify that i3 does not crash
|
||||||
|
# when they don't match any window
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
is(focused_output, 'fake-0', 'focus on first output');
|
||||||
|
|
||||||
|
cmd '[con_mark=doesnotexist] focus output right';
|
||||||
|
does_i3_live;
|
||||||
|
is(focused_output, 'fake-0', 'focus remained on first output');
|
||||||
|
|
||||||
|
################################################################################
|
||||||
|
# use 'focus output' with command criteria and verify that focus gets changed
|
||||||
|
# appropriately
|
||||||
|
################################################################################
|
||||||
|
|
||||||
|
is(focused_output, 'fake-0', 'focus on first output');
|
||||||
|
|
||||||
|
my $window = open_window;
|
||||||
|
|
||||||
|
cmd 'focus output right';
|
||||||
|
is(focused_output, 'fake-1', 'focus on second output');
|
||||||
|
|
||||||
|
cmd '[id= . ' . $window->id . '] focus output right';
|
||||||
|
is(focused_output, 'fake-1', 'focus on second output after command with criteria');
|
||||||
|
|
||||||
|
cmd 'focus output right';
|
||||||
|
is(focused_output, 'fake-0', 'focus on first output after command without criteria');
|
||||||
|
|
||||||
done_testing;
|
done_testing;
|
||||||
|
|
Loading…
Reference in New Issue