mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 17:41:41 +01:00
WMTheme: support macOS
This commit is contained in:
@@ -229,6 +229,87 @@ static void printOpenbox(FFinstance* instance, const FFstrbuf* dePrettyName)
|
||||
ffStrbufDestroy(&absolutePath);
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_LIBPLIST
|
||||
#include "common/library.h"
|
||||
#include "common/io.h"
|
||||
#include <plist/plist.h>
|
||||
|
||||
static const char* quartzCompositorParsePlist(FFinstance* instance, const FFstrbuf* content, FFstrbuf* theme) {
|
||||
FF_LIBRARY_LOAD(libplist, &instance->config.libplist, "dlopen libplist failed", "libplist-2.0"FF_LIBRARY_EXTENSION, 2);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libplist, plist_is_binary);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libplist, plist_from_bin);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libplist, plist_from_xml);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libplist, plist_dict_get_item);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libplist, plist_get_string_ptr);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libplist, plist_get_uint_val);
|
||||
FF_LIBRARY_LOAD_SYMBOL_MESSAGE(libplist, plist_free);
|
||||
|
||||
plist_t root_node = NULL;
|
||||
if (ffplist_is_binary(content->chars, content->length))
|
||||
ffplist_from_bin(content->chars, content->length, &root_node);
|
||||
else
|
||||
ffplist_from_xml(content->chars, content->length, &root_node);
|
||||
|
||||
if(root_node == NULL)
|
||||
return "parsing Quartz Compositor preference file failed";
|
||||
|
||||
plist_t pWmThemeColor = ffplist_dict_get_item(root_node, "AppleAccentColor");
|
||||
uint64_t wmThemeColor = 100;
|
||||
if (pWmThemeColor != NULL)
|
||||
ffplist_get_uint_val(pWmThemeColor, &wmThemeColor);
|
||||
switch (wmThemeColor)
|
||||
{
|
||||
case (uint64_t)-1: ffStrbufAppendS(theme, " (Graphite)");
|
||||
case 0: ffStrbufAppendS(theme, "Red"); break;
|
||||
case 1: ffStrbufAppendS(theme, "Orange"); break;
|
||||
case 2: ffStrbufAppendS(theme, "Yellow"); break;
|
||||
case 3: ffStrbufAppendS(theme, "Green"); break;
|
||||
case 5: ffStrbufAppendS(theme, "Purple"); break;
|
||||
case 6: ffStrbufAppendS(theme, "Pink"); break;
|
||||
default: ffStrbufAppendS(theme, "Blue"); break;
|
||||
}
|
||||
|
||||
plist_t pWmTheme = ffplist_dict_get_item(root_node, "AppleInterfaceStyle");
|
||||
ffStrbufAppendF(theme, " (%s)", pWmTheme != NULL ? ffplist_get_string_ptr(pWmTheme, NULL) : "Light");
|
||||
|
||||
ffplist_free(root_node);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void printQuartzCompositor(FFinstance* instance) {
|
||||
FFstrbuf fileName;
|
||||
ffStrbufInitS(&fileName, instance->state.passwd->pw_dir);
|
||||
ffStrbufAppendS(&fileName, "/Library/Preferences/.GlobalPreferences.plist");
|
||||
|
||||
FFstrbuf content;
|
||||
ffStrbufInit(&content);
|
||||
ffAppendFileBuffer(fileName.chars, &content);
|
||||
ffStrbufDestroy(&fileName);
|
||||
if(content.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "reading Quartz Compositor preference file failed");
|
||||
ffStrbufDestroy(&content);
|
||||
return;
|
||||
}
|
||||
|
||||
FFstrbuf theme;
|
||||
ffStrbufInit(&theme);
|
||||
const char* error = quartzCompositorParsePlist(instance, &content, &theme);
|
||||
ffStrbufDestroy(&content);
|
||||
|
||||
if(error != NULL)
|
||||
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "%s", error);
|
||||
else
|
||||
printWMTheme(instance, theme.chars);
|
||||
}
|
||||
#else
|
||||
static void printQuartzCompositor(FFinstance* instance)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Fastfetch was compiled without libplist support");
|
||||
}
|
||||
#endif
|
||||
|
||||
void ffPrintWMTheme(FFinstance* instance)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
@@ -261,6 +342,8 @@ void ffPrintWMTheme(FFinstance* instance)
|
||||
printWMThemeFromSettings(instance, "/org/mate/Marco/general/theme", "org.mate.Marco.general", NULL, "theme");
|
||||
else if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "Openbox") == 0)
|
||||
printOpenbox(instance, &result->dePrettyName);
|
||||
else if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "Quartz Compositor") == 0)
|
||||
printQuartzCompositor(instance);
|
||||
else
|
||||
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Unknown WM: %s", result->wmPrettyName.chars);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user