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
This commit is contained in:
Orestis Floros 2020-04-16 22:31:44 +02:00
parent 0d5a7eeff8
commit b6024122dc
No known key found for this signature in database
GPG Key ID: A09DBD7D3222C1C3
3 changed files with 23 additions and 23 deletions

View File

@ -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

View File

@ -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;

View File

@ -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;