diff --git a/src/commands.c b/src/commands.c index 9b5c68e3..a696ad34 100644 --- a/src/commands.c +++ b/src/commands.c @@ -1160,41 +1160,37 @@ void cmd_mode(I3_CMD, char *mode) { * */ void cmd_move_con_to_output(I3_CMD, char *name) { - owindow *current; - - DLOG("should move window to output %s\n", name); - + DLOG("Should move window to output \"%s\".\n", name); HANDLE_EMPTY_MATCH; - Output *current_output = NULL; - // TODO: fix the handling of criteria - TAILQ_FOREACH(current, &owindows, owindows) - current_output = get_output_of_con(current->con); - assert(current_output != NULL); - - Output *output = get_output_from_string(current_output, name); - if (!output) { - LOG("No such output found.\n"); - ysuccess(false); - return; - } - - /* get visible workspace on output */ - Con *ws = NULL; - GREP_FIRST(ws, output_get_content(output->con), workspace_is_visible(child)); - if (!ws) { - ysuccess(false); - return; - } - + owindow *current; + bool had_error = false; TAILQ_FOREACH(current, &owindows, owindows) { DLOG("matching: %p / %s\n", current->con, current->con->name); + + Output *current_output = get_output_of_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); } cmd_output->needs_tree_render = true; - // XXX: default reply for now, make this a better reply - ysuccess(true); + ysuccess(!had_error); } /* diff --git a/testcases/t/254-move-to-output-with-criteria.t b/testcases/t/254-move-to-output-with-criteria.t new file mode 100644 index 00000000..fb832184 --- /dev/null +++ b/testcases/t/254-move-to-output-with-criteria.t @@ -0,0 +1,50 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# +# Please read the following documents before working on tests: +# • http://build.i3wm.org/docs/testsuite.html +# (or docs/testsuite) +# +# • http://build.i3wm.org/docs/lib-i3test.html +# (alternatively: perldoc ./testcases/lib/i3test.pm) +# +# • http://build.i3wm.org/docs/ipc.html +# (or docs/ipc) +# +# • http://onyxneon.com/books/modern_perl/modern_perl_a4.pdf +# (unless you are already familiar with Perl) +# +# Verifies that "move container to output" works correctly when +# used with command criteria. +# Bug still in: 4.10.4-349-gee5db87 +use i3test i3_autostart => 0; + +my $config = < 0); +my $ws_top_right = fresh_workspace(output => 1); +my $ws_bottom_left = fresh_workspace(output => 2); +my $ws_bottom_right = fresh_workspace(output => 3); + +cmd "workspace " . $ws_top_left; +open_window(wm_class => 'moveme'); +cmd "workspace " . $ws_bottom_left; +open_window(wm_class => 'moveme'); + +cmd '[class="moveme"] move window to output right'; + +is_num_children($ws_top_left, 0, 'no containers on the upper left workspace'); +is_num_children($ws_top_right, 1, 'one container on the upper right workspace'); +is_num_children($ws_bottom_left, 0, 'no containers on the lower left workspace'); +is_num_children($ws_bottom_right, 1, 'one container on the lower right workspace'); + +exit_gracefully($pid); + +done_testing;