forked from external/yambar
module/i3: treat workspaces on the form N:name as numerical
This commit is contained in:
parent
a2cf05a64d
commit
ca407cd166
1 changed files with 16 additions and 0 deletions
16
modules/i3.c
16
modules/i3.c
|
@ -72,6 +72,22 @@ static int
|
|||
workspace_name_as_int(const char *name)
|
||||
{
|
||||
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++) {
|
||||
if (!(*p >= '0' && *p <= '9'))
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Reference in a new issue