module/i3: treat workspaces on the form N:name as numerical

This commit is contained in:
Daniel Eklöf 2022-02-14 18:33:14 +01:00
parent a2cf05a64d
commit ca407cd166
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F

View file

@ -72,6 +72,22 @@ static int
workspace_name_as_int(const char *name) workspace_name_as_int(const char *name)
{ {
int name_as_int = 0; int name_as_int = 0;
/* First check for N:name pattern (set $ws1 “1:foobar”) */
const char *colon = strchr(name, ':');
if (colon != NULL) {
for (const char *p = name; p < colon; p++) {
if (!(*p >= '0' && *p < '9'))
return -1;
name_as_int *= 10;
name_as_int += *p - '0';
}
return name_as_int;
}
/* Then, if the name is a number *only* (set $ws1 1) */
for (const char *p = name; *p != '\0'; p++) { for (const char *p = name; *p != '\0'; p++) {
if (!(*p >= '0' && *p <= '9')) if (!(*p >= '0' && *p <= '9'))
return -1; return -1;