Skip to content

Commit 1875c78

Browse files
committed
WM: support I3 version detection
1 parent f389864 commit 1875c78

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/detection/wm/wm_linux.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,39 @@ static const char* getSway(FFstrbuf* result)
128128
return "Failed to run command `sway --version`";
129129
}
130130

131+
static bool extractI3Version(const char* line, FF_MAYBE_UNUSED uint32_t len, void *userdata)
132+
{
133+
int count = 0;
134+
sscanf(line, "%*d.%*d%n", &count);
135+
if (count == 0) return true;
136+
137+
ffStrbufSetNS((FFstrbuf*) userdata, len, line);
138+
return false;
139+
}
140+
141+
static const char* getI3(FFstrbuf* result)
142+
{
143+
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
144+
const char* error = ffFindExecutableInPath("i3", &path);
145+
if (error) return "Failed to find i3 executable path";
146+
147+
ffBinaryExtractStrings(path.chars, extractI3Version, result, (uint32_t) strlen("0.0"));
148+
if (result->length > 0) return NULL;
149+
150+
if (ffProcessAppendStdOut(result, (char* const[]){
151+
path.chars,
152+
"--version",
153+
NULL
154+
}) == NULL)
155+
{ // i3 version 1.10 C 2009...
156+
ffStrbufSubstrAfterFirstS(result, "version ");
157+
ffStrbufSubstrBeforeFirstC(result, ' ');
158+
return NULL;
159+
}
160+
161+
return "Failed to run command `i3 --version`";
162+
}
163+
131164
static const char* getWslg(FFstrbuf* result)
132165
{
133166
if (!ffAppendFileBuffer("/mnt/wslg/versions.txt", result))
@@ -210,6 +243,9 @@ const char* ffDetectWMVersion(const FFstrbuf* wmName, FFstrbuf* result, FF_MAYBE
210243
if (ffStrbufEqualS(wmName, "sway"))
211244
return getSway(result);
212245

246+
if (ffStrbufEqualS(wmName, "i3"))
247+
return getI3(result);
248+
213249
if (ffStrbufEqualS(wmName, "WSLg"))
214250
return getWslg(result);
215251

0 commit comments

Comments
 (0)