From e2bacc7df8ba09a552ddd3555f3c730ed5205664 Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Sat, 16 Sep 2017 20:14:35 +0300 Subject: [PATCH] Add con_move_to_output_name function --- include/con.h | 11 ++++++++++- src/commands.c | 20 +------------------- src/con.c | 25 +++++++++++++++++++++++-- src/manage.c | 2 +- 4 files changed, 35 insertions(+), 23 deletions(-) diff --git a/include/con.h b/include/con.h index 6cd1ef3e..69292411 100644 --- a/include/con.h +++ b/include/con.h @@ -307,7 +307,16 @@ void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, * visible workspace on the given output. * */ -void con_move_to_output(Con *con, Output *output); +void con_move_to_output(Con *con, Output *output, bool fix_coordinates); + +/** + * Moves the given container to the currently focused container on the + * visible workspace on the output specified by the given name. + * The current output for the container is used to resolve relative names + * such as left, right, up, down. + * + */ +bool con_move_to_output_name(Con *con, const char *name, bool fix_coordinates); /** * Moves the given container to the given mark. diff --git a/src/commands.c b/src/commands.c index 2697d6e1..d7cdf219 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1044,25 +1044,7 @@ void cmd_move_con_to_output(I3_CMD, const char *name) { TAILQ_FOREACH(current, &owindows, owindows) { DLOG("matching: %p / %s\n", current->con, current->con->name); - Output *current_output = get_output_for_con(current->con); - assert(current_output != NULL); - - Output *output = get_output_from_string(current_output, name); - if (output == NULL) { - ELOG("Could not find output \"%s\", skipping.\n", name); - had_error = true; - continue; - } - - Con *ws = NULL; - GREP_FIRST(ws, output_get_content(output->con), workspace_is_visible(child)); - if (ws == NULL) { - ELOG("Could not find a visible workspace on output %p.\n", output); - had_error = true; - continue; - } - - con_move_to_workspace(current->con, ws, true, false, false); + had_error |= !con_move_to_output_name(current->con, name, true); } cmd_output->needs_tree_render = true; diff --git a/src/con.c b/src/con.c index a663db31..8254672f 100644 --- a/src/con.c +++ b/src/con.c @@ -1284,12 +1284,33 @@ void con_move_to_workspace(Con *con, Con *workspace, bool fix_coordinates, bool * visible workspace on the given output. * */ -void con_move_to_output(Con *con, Output *output) { +void con_move_to_output(Con *con, Output *output, bool fix_coordinates) { Con *ws = NULL; GREP_FIRST(ws, output_get_content(output->con), workspace_is_visible(child)); assert(ws != NULL); DLOG("Moving con %p to output %s\n", con, output_primary_name(output)); - con_move_to_workspace(con, ws, false, false, false); + con_move_to_workspace(con, ws, fix_coordinates, false, false); +} + +/* + * Moves the given container to the currently focused container on the + * visible workspace on the output specified by the given name. + * The current output for the container is used to resolve relative names + * such as left, right, up, down. + * + */ +bool con_move_to_output_name(Con *con, const char *name, bool fix_coordinates) { + Output *current_output = get_output_for_con(con); + assert(current_output != NULL); + + Output *output = get_output_from_string(current_output, name); + if (output == NULL) { + ELOG("Could not find output \"%s\"\n", name); + return false; + } + + con_move_to_output(con, output, fix_coordinates); + return true; } /* diff --git a/src/manage.c b/src/manage.c index f155603d..8087d563 100644 --- a/src/manage.c +++ b/src/manage.c @@ -384,7 +384,7 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki * needed e.g. for LibreOffice Impress multi-monitor * presentations to work out of the box. */ if (output != NULL) - con_move_to_output(nc, output); + con_move_to_output(nc, output, false); con_toggle_fullscreen(nc, CF_OUTPUT); } fs = NULL; -- 2.39.2