From ca407cd1669e6c871a25c86db92ea8e121fda46d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Ekl=C3=B6f?= Date: Mon, 14 Feb 2022 18:33:14 +0100 Subject: [PATCH] module/i3: treat workspaces on the form N:name as numerical --- modules/i3.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/modules/i3.c b/modules/i3.c index fcd9395..bb51794 100644 --- a/modules/i3.c +++ b/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;