From d525eb80aefcd596c5c40750eb9fa3570e5c55ed Mon Sep 17 00:00:00 2001 From: Orestis Floros Date: Wed, 28 Mar 2018 04:05:48 +0300 Subject: [PATCH] Use get_assigned_output for numbers This prohibits the usage of workspaces assigned to other outputs in create_workspace_on_output. Eg, with config: workspace 1 output fake-0 workspace 2 output fake-0 and 2 screens workspace 2 would be used for the second screen even though it is assigned to the first one. Also introduces a test for workspace assignments that includes the case described above and some tests that don't fail in the next branch. --- src/workspace.c | 4 +- testcases/t/297-assign-workspace-to-output.t | 60 ++++++++++++++++++++ 2 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 testcases/t/297-assign-workspace-to-output.t diff --git a/src/workspace.c b/src/workspace.c index 9441042e..a27c6f4b 100644 --- a/src/workspace.c +++ b/src/workspace.c @@ -248,7 +248,9 @@ Con *create_workspace_on_output(Output *output, Con *content) { DLOG("Getting next unused workspace by number\n"); int c = 0; while (exists) { - exists = (get_existing_workspace_by_num(++c) != NULL); + c++; + Con *assigned = get_assigned_output(NULL, c); + exists = (get_existing_workspace_by_num(c) || (assigned && assigned != output->con)); DLOG("result for ws %d: exists = %d\n", c, exists); } ws->num = c; diff --git a/testcases/t/297-assign-workspace-to-output.t b/testcases/t/297-assign-workspace-to-output.t new file mode 100644 index 00000000..650efa12 --- /dev/null +++ b/testcases/t/297-assign-workspace-to-output.t @@ -0,0 +1,60 @@ +#!perl +# vim:ts=4:sw=4:expandtab +# +# Please read the following documents before working on tests: +# • https://build.i3wm.org/docs/testsuite.html +# (or docs/testsuite) +# +# • https://build.i3wm.org/docs/lib-i3test.html +# (alternatively: perldoc ./testcases/lib/i3test.pm) +# +# • https://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) +# +# Test assignments of workspaces to outputs. +use i3test i3_autostart => 0; + +################################################################################ +# Test initial workspaces. +################################################################################ + +my $config = <