Skip to content

Commit b931773

Browse files
committed
WM: support CTWM version detection
1 parent 4df4a1d commit b931773

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ elseif(NetBSD)
802802
src/detection/users/users_linux.c
803803
src/detection/wallpaper/wallpaper_linux.c
804804
src/detection/wifi/wifi_nbsd.c
805-
src/detection/wm/wm_nosupport.c
805+
src/detection/wm/wm_linux.c
806806
src/detection/de/de_linux.c
807807
src/detection/wmtheme/wmtheme_linux.c
808808
src/detection/camera/camera_linux.c

src/detection/wm/wm_linux.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,39 @@ static const char* getWslg(FFstrbuf* result)
143143
return NULL;
144144
}
145145

146+
static bool extractCtwmVersion(const char* line, FF_MAYBE_UNUSED uint32_t len, void *userdata)
147+
{
148+
int count = 0;
149+
sscanf(line, "%*d.%*d.%*d%n", &count);
150+
if (count == 0) return true;
151+
152+
ffStrbufSetNS((FFstrbuf*) userdata, len, line);
153+
return false;
154+
}
155+
156+
static const char* getCtwm(FFstrbuf* result)
157+
{
158+
FF_STRBUF_AUTO_DESTROY path = ffStrbufCreate();
159+
const char* error = ffFindExecutableInPath("ctwm", &path);
160+
if (error) return "Failed to find ctwm executable path";
161+
162+
ffBinaryExtractStrings(path.chars, extractCtwmVersion, result, (uint32_t) strlen("0.0.0"));
163+
if (result->length > 0) return NULL;
164+
165+
if (ffProcessAppendStdOut(result, (char* const[]){
166+
path.chars,
167+
"--version",
168+
NULL
169+
}) == NULL)
170+
{ // ctwm version 4.0.1\n...
171+
ffStrbufSubstrBeforeFirstC(result, '\n');
172+
ffStrbufSubstrAfterLastC(result, ' ');
173+
return NULL;
174+
}
175+
176+
return "Failed to run command `ctwm --version`";
177+
}
178+
146179
const char* ffDetectWMVersion(const FFstrbuf* wmName, FFstrbuf* result, FF_MAYBE_UNUSED FFWMOptions* options)
147180
{
148181
if (!wmName)
@@ -157,5 +190,8 @@ const char* ffDetectWMVersion(const FFstrbuf* wmName, FFstrbuf* result, FF_MAYBE
157190
if (ffStrbufEqualS(wmName, "WSLg"))
158191
return getWslg(result);
159192

193+
if (ffStrbufEqualS(wmName, "ctwm"))
194+
return getCtwm(result);
195+
160196
return "Unsupported WM";
161197
}

0 commit comments

Comments
 (0)