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:
Orestis Floros
2019-03-21 23:57:24 +02:00
parent 351d891f4c
commit 7fc3bf660e
2 changed files with 36 additions and 14 deletions

View File

@ -1626,24 +1626,18 @@ void cmd_open(I3_CMD) {
*
*/
void cmd_focus_output(I3_CMD, const char *name) {
owindow *current;
DLOG("name = %s\n", name);
HANDLE_EMPTY_MATCH;
/* get the output */
Output *current_output = NULL;
Output *output;
if (TAILQ_EMPTY(&owindows)) {
ysuccess(true);
return;
}
TAILQ_FOREACH(current, &owindows, owindows)
current_output = get_output_for_con(current->con);
assert(current_output != NULL);
output = get_output_from_string(current_output, name);
Output *current_output = get_output_for_con(TAILQ_FIRST(&owindows)->con);
Output *output = get_output_from_string(current_output, name);
if (!output) {
yerror("No such output found.");
yerror("Output %s not found.", name);
return;
}
@ -1658,7 +1652,6 @@ void cmd_focus_output(I3_CMD, const char *name) {
workspace_show(ws);
cmd_output->needs_tree_render = true;
// XXX: default reply for now, make this a better reply
ysuccess(true);
}