@@ -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+
146179const 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