summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrestis Floros <orestisflo@gmail.com>2020-04-16 22:31:44 +0200
committerOrestis Floros <orestisflo@gmail.com>2020-10-18 17:28:55 +0200
commitb6024122dc2e861ad399892cf21e580b70b90ec7 (patch)
tree36121a263c249d9c0295f9e4ac3f7d8586bd3df7
parent0d5a7eeff8e95277256fb191f80112296e0aba6f (diff)
downloadi3-b6024122dc2e861ad399892cf21e580b70b90ec7.tar.gz
i3-b6024122dc2e861ad399892cf21e580b70b90ec7.zip
Fix conflicting workspace assignments when renaming
The bug here is that workspace assignments with numbers are triggered even if a named argument matches later on. With this commit, get_assigned_output is called to correctly iterate the workspace assignments. Fixes #4021
-rw-r--r--RELEASE-NOTES-next1
-rw-r--r--src/commands.c23
-rw-r--r--testcases/t/297-assign-workspace-to-output.t22
3 files changed, 23 insertions, 23 deletions
diff --git a/RELEASE-NOTES-next b/RELEASE-NOTES-next
index 76a7354e..2da81372 100644
--- a/RELEASE-NOTES-next
+++ b/RELEASE-NOTES-next
@@ -47,3 +47,4 @@ working. Please reach out to us in that case!
• fix conflict when moving parent of fullscreen window to workspace
• fix Xorg memory leak with i3bar
• fix named workspace assignments on output changes
+ • fix named workspace assignment precedence on workspace renames
diff --git a/src/commands.c b/src/commands.c
index a9c90b9a..5bf4cef6 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -2026,26 +2026,9 @@ void cmd_rename_workspace(I3_CMD, const char *old_name, const char *new_name) {
con_attach(workspace, parent, false);
ipc_send_workspace_event("rename", workspace, NULL);
- /* Move the workspace to the correct output if it has an assignment */
- struct Workspace_Assignment *assignment = NULL;
- TAILQ_FOREACH (assignment, &ws_assignments, ws_assignments) {
- if (assignment->output == NULL)
- continue;
- if (strcmp(assignment->name, workspace->name) != 0 && (!name_is_digits(assignment->name) || ws_name_to_number(assignment->name) != workspace->num)) {
- continue;
- }
-
- Output *target_output = get_output_by_name(assignment->output, true);
- if (!target_output) {
- LOG("Could not get output named \"%s\"\n", assignment->output);
- continue;
- }
- if (!output_triggers_assignment(target_output, assignment)) {
- continue;
- }
- workspace_move_to_output(workspace, target_output);
-
- break;
+ Con *assigned = get_assigned_output(workspace->name, workspace->num);
+ if (assigned) {
+ workspace_move_to_output(workspace, get_output_for_con(assigned));
}
bool can_restore_focus = previously_focused != NULL;
diff --git a/testcases/t/297-assign-workspace-to-output.t b/testcases/t/297-assign-workspace-to-output.t
index eb8f24b2..4e251e5d 100644
--- a/testcases/t/297-assign-workspace-to-output.t
+++ b/testcases/t/297-assign-workspace-to-output.t
@@ -41,7 +41,7 @@ my $pid = launch_with_config($config);
sub check_output {
my ($workspace, $output, $msg) = @_;
- is(get_output_for_workspace($workspace), $output, $msg);
+ is(get_output_for_workspace($workspace), $output, "[$workspace->$output] " . $msg);
}
check_output('9', '', 'Numbered workspace with a big number that is assigned to output that does not exist is not used');
@@ -82,6 +82,10 @@ workspace 4 output whitespace fake-0
workspace foo output doesnotexist1 doesnotexist2 doesnotexist3
workspace bar output doesnotexist
workspace bar output fake-0
+workspace 5 output fake-0
+workspace 5:xxx output fake-1
+workspace 6:xxx output fake-0
+workspace 6 output fake-1
EOT
$pid = launch_with_config($config);
@@ -90,8 +94,11 @@ do_test('1', 'fake-0', 'Multiple assignments do not override a single one');
do_test('2', 'fake-3', 'First output out of multiple assignments is used');
do_test('3', 'fake-0', 'First existing output is used');
do_test('4', 'fake-0', 'Excessive whitespace is ok');
-do_test('5', 'fake-1', 'Numbered initialization for fake-1');
-do_test('6', 'fake-2', 'Numbered initialization for fake-2');
+do_test('5', 'fake-0', 'Numbered assignment ok');
+do_test('5:xxx', 'fake-1', 'Named assignment overrides number');
+do_test('6', 'fake-1', 'Numbered assignment ok');
+do_test('6:xxx', 'fake-0', 'Named assignment overrides number');
+do_test('7', 'fake-2', 'Numbered initialization for fake-2');
cmd 'focus output fake-0, workspace foo';
check_output('foo', 'fake-0', 'Workspace with only non-existing assigned outputs opened in current output');
@@ -103,5 +110,14 @@ check_output('bar', 'fake-0', 'Second workspace assignment line ignored');
cmd 'workspace 2, move workspace to output left';
check_output('2', 'fake-2', 'Moved assigned workspace up');
+# Specific name overrides assignment by number after renaming
+# See #4021
+cmd 'workspace 5, rename workspace to 5:xxx';
+check_output('5:xxx', 'fake-1', 'workspace triggered correct, specific assignment after renaming');
+
+# Same but opposite order
+cmd 'workspace 6, rename workspace to 6:xxx';
+check_output('6:xxx', 'fake-0', 'workspace triggered correct, specific assignment after renaming');
+
exit_gracefully($pid);
done_testing;