Skip to content
This repository has been archived by the owner on Apr 18, 2023. It is now read-only.

Commit

Permalink
Fix conflicting workspace assignments when renaming
Browse files Browse the repository at this point in the history
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
  • Loading branch information
orestisfl committed Oct 18, 2020
1 parent 0d5a7ee commit b602412
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 23 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES-next
Expand Up @@ -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
23 changes: 3 additions & 20 deletions src/commands.c
Expand Up @@ -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;
Expand Down
22 changes: 19 additions & 3 deletions testcases/t/297-assign-workspace-to-output.t
Expand Up @@ -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');
Expand Down Expand Up @@ -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);
Expand All @@ -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');
Expand All @@ -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;

0 comments on commit b602412

Please sign in to comment.