create_workspace_on_output: Prevent duplicate workspace nums

When going through the `binding_workspace_names` to prioritize
user-specified names, we only check if the workspace exists, not the
workspace number. If the user specified a `bindsym … workspace number X`
directive, then it is appended in `binding_workspace_names` and a
workspace is created using that number even though from the POV of a
user that uses numbers to change workspaces, that workspace already
exists.

In similar code here:
1d9160f2d2/src/workspace.c (L997)
we do the check.

Fixes #4238
This commit is contained in:
Orestis Floros 2020-11-10 10:24:15 +01:00
parent d0067077ed
commit 68258785ac
No known key found for this signature in database
GPG Key ID: A09DBD7D3222C1C3
2 changed files with 6 additions and 4 deletions

View File

@ -17,5 +17,4 @@ strongly encouraged to upgrade.
│ Bugfixes │
└────────────────────────────┘
• placeholder
• when initializing new outputs, avoid duplicating workspace numbers

View File

@ -254,12 +254,15 @@ Con *create_workspace_on_output(Output *output, Con *content) {
continue;
}
exists = (get_existing_workspace_by_name(target_name) != NULL);
const int num = ws_name_to_number(target_name);
exists = (num == -1)
? get_existing_workspace_by_name(target_name)
: get_existing_workspace_by_num(num);
if (!exists) {
ws->name = sstrdup(target_name);
/* Set ->num to the number of the workspace, if the name actually
* is a number or starts with a number */
ws->num = ws_name_to_number(ws->name);
ws->num = num;
LOG("Used number %d for workspace with name %s\n", ws->num, ws->name);
break;