@@ -229,6 +229,87 @@ static void printOpenbox(FFinstance* instance, const FFstrbuf* dePrettyName)
229229 ffStrbufDestroy (& absolutePath );
230230}
231231
232+ #ifdef FF_HAVE_LIBPLIST
233+ #include "common/library.h"
234+ #include "common/io.h"
235+ #include <plist/plist.h>
236+
237+ static const char * quartzCompositorParsePlist (FFinstance * instance , const FFstrbuf * content , FFstrbuf * theme ) {
238+ FF_LIBRARY_LOAD (libplist , & instance -> config .libplist , "dlopen libplist failed" , "libplist-2.0" FF_LIBRARY_EXTENSION , 2 );
239+ FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libplist , plist_is_binary );
240+ FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libplist , plist_from_bin );
241+ FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libplist , plist_from_xml );
242+ FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libplist , plist_dict_get_item );
243+ FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libplist , plist_get_string_ptr );
244+ FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libplist , plist_get_uint_val );
245+ FF_LIBRARY_LOAD_SYMBOL_MESSAGE (libplist , plist_free );
246+
247+ plist_t root_node = NULL ;
248+ if (ffplist_is_binary (content -> chars , content -> length ))
249+ ffplist_from_bin (content -> chars , content -> length , & root_node );
250+ else
251+ ffplist_from_xml (content -> chars , content -> length , & root_node );
252+
253+ if (root_node == NULL )
254+ return "parsing Quartz Compositor preference file failed" ;
255+
256+ plist_t pWmThemeColor = ffplist_dict_get_item (root_node , "AppleAccentColor" );
257+ uint64_t wmThemeColor = 100 ;
258+ if (pWmThemeColor != NULL )
259+ ffplist_get_uint_val (pWmThemeColor , & wmThemeColor );
260+ switch (wmThemeColor )
261+ {
262+ case (uint64_t )-1 : ffStrbufAppendS (theme , " (Graphite)" );
263+ case 0 : ffStrbufAppendS (theme , "Red" ); break ;
264+ case 1 : ffStrbufAppendS (theme , "Orange" ); break ;
265+ case 2 : ffStrbufAppendS (theme , "Yellow" ); break ;
266+ case 3 : ffStrbufAppendS (theme , "Green" ); break ;
267+ case 5 : ffStrbufAppendS (theme , "Purple" ); break ;
268+ case 6 : ffStrbufAppendS (theme , "Pink" ); break ;
269+ default : ffStrbufAppendS (theme , "Blue" ); break ;
270+ }
271+
272+ plist_t pWmTheme = ffplist_dict_get_item (root_node , "AppleInterfaceStyle" );
273+ ffStrbufAppendF (theme , " (%s)" , pWmTheme != NULL ? ffplist_get_string_ptr (pWmTheme , NULL ) : "Light" );
274+
275+ ffplist_free (root_node );
276+ return NULL ;
277+ }
278+
279+ static void printQuartzCompositor (FFinstance * instance ) {
280+ FFstrbuf fileName ;
281+ ffStrbufInitS (& fileName , instance -> state .passwd -> pw_dir );
282+ ffStrbufAppendS (& fileName , "/Library/Preferences/.GlobalPreferences.plist" );
283+
284+ FFstrbuf content ;
285+ ffStrbufInit (& content );
286+ ffAppendFileBuffer (fileName .chars , & content );
287+ ffStrbufDestroy (& fileName );
288+ if (content .length == 0 )
289+ {
290+ ffPrintError (instance , FF_WMTHEME_MODULE_NAME , 0 , & instance -> config .wmTheme , "reading Quartz Compositor preference file failed" );
291+ ffStrbufDestroy (& content );
292+ return ;
293+ }
294+
295+ FFstrbuf theme ;
296+ ffStrbufInit (& theme );
297+ const char * error = quartzCompositorParsePlist (instance , & content , & theme );
298+ ffStrbufDestroy (& content );
299+
300+ if (error != NULL )
301+ ffPrintError (instance , FF_WMTHEME_MODULE_NAME , 0 , & instance -> config .wmTheme , "%s" , error );
302+ else
303+ printWMTheme (instance , theme .chars );
304+ }
305+ #else
306+ static void printQuartzCompositor (FFinstance * instance )
307+ {
308+ FF_UNUSED (instance );
309+ ffPrintError (instance , FF_WMTHEME_MODULE_NAME , 0 , & instance -> config .wmTheme , "Fastfetch was compiled without libplist support" );
310+ }
311+ #endif
312+
232313void ffPrintWMTheme (FFinstance * instance )
233314{
234315 #ifdef __ANDROID__
@@ -261,6 +342,8 @@ void ffPrintWMTheme(FFinstance* instance)
261342 printWMThemeFromSettings (instance , "/org/mate/Marco/general/theme" , "org.mate.Marco.general" , NULL , "theme" );
262343 else if (ffStrbufIgnCaseCompS (& result -> wmPrettyName , "Openbox" ) == 0 )
263344 printOpenbox (instance , & result -> dePrettyName );
345+ else if (ffStrbufIgnCaseCompS (& result -> wmPrettyName , "Quartz Compositor" ) == 0 )
346+ printQuartzCompositor (instance );
264347 else
265348 ffPrintError (instance , FF_WMTHEME_MODULE_NAME , 0 , & instance -> config .wmTheme , "Unknown WM: %s" , result -> wmPrettyName .chars );
266349}
0 commit comments