diff --git a/CMakeLists.txt b/CMakeLists.txt index 99db5c69..4c6bc1ad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -200,6 +200,7 @@ set(LIBFASTFETCH_SRC src/detection/cpu/cpu.c src/detection/gpu/gpu.c src/detection/memory/memory.c + src/detection/font/font.c src/detection/displayserver/displayserver.c src/detection/terminalfont/terminalfont.c src/detection/media/media.c diff --git a/completions/bash b/completions/bash index 2a3822ea..a27172df 100644 --- a/completions/bash +++ b/completions/bash @@ -180,7 +180,6 @@ __fastfetch_completion() "--cpu-temp" "--gpu-temp" "--battery-temp" - "--font-inline" "--localip-show-ipv4" "--localip-show-ipv6" "--localip-show-loop" diff --git a/presets/examples/5 b/presets/examples/5 index 349257b7..27180ca9 100644 --- a/presets/examples/5 +++ b/presets/examples/5 @@ -8,5 +8,4 @@ --icons-key I --icons-format {5} --font-key F ---font-format {21} --cursor-key C diff --git a/presets/verbose b/presets/verbose index 6109baa1..9b7713ea 100644 --- a/presets/verbose +++ b/presets/verbose @@ -11,7 +11,7 @@ --wm-theme-format Name: {} --theme-format Plasma: {}; Plasma colors: {}; Plasma colors pretty: {}; GTK2: {}; GTK3: {}; GTK4: {}; GTK: {} --icons-format Plasma: {}; GTK2: {}; GTK3: {}; GTK4: {}; GTK: {} ---font-format Type: {}; Font: {} +--font-format Font1: {}; Font2: {}; Font3: {}; Font4: {} --cursor-format Theme: {}; Size: {} --terminal-format Process: {}; Path: {}; Exe: {} --terminal-font-format Pretty: {}; Name: {}; Size: {}; Styles: {} diff --git a/src/common/init.c b/src/common/init.c index 0c467475..49548044 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -236,8 +236,6 @@ static void defaultConfig(FFinstance* instance) ffStrbufInitA(&instance->config.separatorString, 0); - instance->config.fontInline = true; - instance->config.localIpShowIpV4 = true; instance->config.localIpShowIpV6 = false; instance->config.localIpShowLoop = false; diff --git a/src/data/help.txt b/src/data/help.txt index c5b2c007..1e59db56 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -97,7 +97,6 @@ Module specific options: --cpu-temp : Detect and display CPU temperature if supported. Default is false --gpu-temp : Detect and display GPU temperature if supported. Default is false --battery-temp : Detect and display Battery temperature if supported. Default is false - --font-inline : Display fonts of different DE in one line --localip-show-ipv4 : Show ipv4 addresses in local ip module. Default is true --localip-show-ipv6 : Show ipv6 addresses in local ip module. Default is false --localip-show-loop : Show loop back addresses (127.0.0.1) in local ip module. Default is false diff --git a/src/detection/font/font.c b/src/detection/font/font.c new file mode 100644 index 00000000..253e4624 --- /dev/null +++ b/src/detection/font/font.c @@ -0,0 +1,32 @@ +#include "font.h" +#include "detection/internal.h" + +void ffDetectFontImpl(const FFinstance* instance, FFFontResult* font); + +static void detectFont(const FFinstance* instance, FFFontResult* font) +{ + ffStrbufInit(&font->error); + + for(uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i) + ffStrbufInit(&font->fonts[i]); + + ffDetectFontImpl(instance, font); + + if(font->error.length > 0) + return; + + for(uint32_t i = 0; i < FF_DETECT_FONT_NUM_FONTS; ++i) + { + if(font->fonts[i].length > 0) + return; + } + + ffStrbufAppendS(&font->error, "No fonts found"); +} + +const FFFontResult* ffDetectFont(const FFinstance* instance) +{ + FF_DETECTION_INTERNAL_GUARD(FFFontResult, + detectFont(instance, &result); + ); +} diff --git a/src/detection/font/font.h b/src/detection/font/font.h index f1d36a5b..400ff479 100644 --- a/src/detection/font/font.h +++ b/src/detection/font/font.h @@ -4,15 +4,21 @@ #define FF_INCLUDED_detection_font_font #include "fastfetch.h" -#include "util/FFstrbuf.h" -#include "util/FFlist.h" + +#define FF_DETECT_FONT_NUM_FONTS 4 typedef struct FFFontResult { - const char* type; - FFstrbuf fontPretty; + FFstrbuf error; + + /** + * Linux / BSD: QT, GTK2, GTK3, GTK4 + * MacOS: System, User, Unset, Unset + * Other: Unset, Unset, Unset, Unset + */ + FFstrbuf fonts[FF_DETECT_FONT_NUM_FONTS]; } FFFontResult; -const char* ffDetectFontImpl(FFinstance* instance, FFlist* result); +const FFFontResult* ffDetectFont(const FFinstance* instance); #endif diff --git a/src/detection/font/font_android.c b/src/detection/font/font_android.c index 3f8578b8..f6bfa81e 100644 --- a/src/detection/font/font_android.c +++ b/src/detection/font/font_android.c @@ -1,8 +1,7 @@ #include "fastfetch.h" -#include "common/font.h" -const char* ffDetectFontImpl(FFinstance* instance, FFlist* result) +void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result) { - FF_UNUSED(instance, result); - return "Font detection is not supported on Android"; + FF_UNUSED(instance); + ffStrbufAppendS(&result->error, "Not implemented"); } diff --git a/src/detection/font/font_apple.m b/src/detection/font/font_apple.m index 974c1c07..41dd5b8d 100644 --- a/src/detection/font/font_apple.m +++ b/src/detection/font/font_apple.m @@ -4,38 +4,27 @@ #import -#define FF_FONT_MODULE_NAME "Font" - -static void detectFontForType(CTFontUIFontType uiType, FFFontResult* result) +static void detectFontForType(CTFontUIFontType uiType, FFstrbuf* font) { CTFontRef ctFont = CTFontCreateUIFontForLanguage(uiType, 12, NULL); + ffCfStrGetString(CTFontCopyFullName(ctFont), font); - ffStrbufInit(&result->fontPretty); - ffCfStrGetString(CTFontCopyFullName(ctFont), &result->fontPretty); + if(font->length == 0) + return; FFstrbuf familyName; ffStrbufInit(&familyName); ffCfStrGetString(CTFontCopyFamilyName(ctFont), &familyName); - if (ffStrbufComp(&familyName, &result->fontPretty) != 0) - { - ffStrbufAppendF(&result->fontPretty, " (%*s)", familyName.length, familyName.chars); - } + if (ffStrbufComp(&familyName, font) != 0) + ffStrbufAppendF(font, " (%*s)", familyName.length, familyName.chars); ffStrbufDestroy(&familyName); } -const char* ffDetectFontImpl(FFinstance* instance, FFlist* result) +void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result) { FF_UNUSED(instance); - - FFFontResult* resultSystem = (FFFontResult*)ffListAdd(result); - resultSystem->type = "SYS"; - detectFontForType(kCTFontUIFontSystem, resultSystem); - - FFFontResult* resultUser = (FFFontResult*)ffListAdd(result); - resultUser->type = "USER"; - detectFontForType(kCTFontUIFontUser, resultUser); - - return NULL; + detectFontForType(kCTFontUIFontSystem, &result->fonts[0]); + detectFontForType(kCTFontUIFontUser, &result->fonts[1]); } diff --git a/src/detection/font/font_linux.c b/src/detection/font/font_linux.c index eb57cdd4..62c66445 100644 --- a/src/detection/font/font_linux.c +++ b/src/detection/font/font_linux.c @@ -1,51 +1,27 @@ #include "detection/qt.h" #include "detection/gtk.h" -#include "common/parsing.h" #include "common/font.h" #include "font.h" -const char* ffDetectFontImpl(FFinstance* instance, FFlist* result) +void ffDetectFontImpl(const FFinstance* instance, FFFontResult* result) { - const FFstrbuf* qtRaw = &ffDetectQt(instance)->font; - const FFstrbuf* gtk2Raw = &ffDetectGTK2(instance)->font; - const FFstrbuf* gtk3Raw = &ffDetectGTK3(instance)->font; - const FFstrbuf* gtk4Raw = &ffDetectGTK4(instance)->font; + FFfont qt; + ffFontInitQt(&qt, ffDetectQt(instance)->font.chars); + ffStrbufAppend(&result->fonts[0], &qt.pretty); + ffFontDestroy(&qt); - if(qtRaw->length > 0) - { - FFfont qt; - ffFontInitQt(&qt, qtRaw->chars); + FFfont gtk2; + ffFontInitPango(>k2, ffDetectGTK2(instance)->font.chars); + ffStrbufAppend(&result->fonts[1], >k2.pretty); + ffFontDestroy(>k2); - FFFontResult* resultQt = (FFFontResult *)ffListAdd(result); - resultQt->type = "QT"; - ffStrbufInitCopy(&resultQt->fontPretty, &qt.pretty); + FFfont gtk3; + ffFontInitPango(>k3, ffDetectGTK3(instance)->font.chars); + ffStrbufAppend(&result->fonts[2], >k3.pretty); + ffFontDestroy(>k3); - ffFontDestroy(&qt); - } - - if(gtk2Raw->length > 0 || gtk3Raw->length > 0 || gtk4Raw->length > 0) - { - FFfont gtk2; - ffFontInitPango(>k2, gtk2Raw->chars); - - FFfont gtk3; - ffFontInitPango(>k3, gtk3Raw->chars); - - FFfont gtk4; - ffFontInitPango(>k4, gtk4Raw->chars); - - FFFontResult* resultGtk = (FFFontResult *)ffListAdd(result); - resultGtk->type = "GTK"; - ffStrbufInit(&resultGtk->fontPretty); - ffParseGTK(&resultGtk->fontPretty, >k2.pretty, >k3.pretty, >k4.pretty); - - ffFontDestroy(>k2); - ffFontDestroy(>k3); - ffFontDestroy(>k4); - } - - if(result->length == 0) - return "No fonts found"; - - return NULL; + FFfont gtk4; + ffFontInitPango(>k4, ffDetectGTK4(instance)->font.chars); + ffStrbufAppend(&result->fonts[3], >k4.pretty); + ffFontDestroy(>k4); } diff --git a/src/detection/gtk.c b/src/detection/gtk.c index c404420e..3855f799 100644 --- a/src/detection/gtk.c +++ b/src/detection/gtk.c @@ -32,7 +32,7 @@ static inline void applyGTKSettings(FFGTKResult* result, const char* themeName, ffStrbufAppendF(&result->cursorSize, "%i", cursorSize); } -static void detectGTKFromSettings(FFinstance* instance, FFGTKResult* result) +static void detectGTKFromSettings(const FFinstance* instance, FFGTKResult* result) { static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -144,7 +144,7 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG ffStrbufSubstrBefore(configDir, configDirLength); } -static void detectGTK(FFinstance* instance, const char* version, FFGTKResult* result) +static void detectGTK(const FFinstance* instance, const char* version, FFGTKResult* result) { //Mate, Cinnamon and Gnome use dconf to save theme config //On other DEs, this will do nothing @@ -186,17 +186,17 @@ static void detectGTK(FFinstance* instance, const char* version, FFGTKResult* re pthread_mutex_unlock(&mutex); \ return &result; -const FFGTKResult* ffDetectGTK2(FFinstance* instance) +const FFGTKResult* ffDetectGTK2(const FFinstance* instance) { FF_DETECT_GTK_IMPL(2) } -const FFGTKResult* ffDetectGTK3(FFinstance* instance) +const FFGTKResult* ffDetectGTK3(const FFinstance* instance) { FF_DETECT_GTK_IMPL(3) } -const FFGTKResult* ffDetectGTK4(FFinstance* instance) +const FFGTKResult* ffDetectGTK4(const FFinstance* instance) { FF_DETECT_GTK_IMPL(4) } diff --git a/src/detection/gtk.h b/src/detection/gtk.h index cd726c39..68398435 100644 --- a/src/detection/gtk.h +++ b/src/detection/gtk.h @@ -14,8 +14,8 @@ typedef struct FFGTKResult FFstrbuf cursorSize; } FFGTKResult; -const FFGTKResult* ffDetectGTK2(FFinstance* instance); -const FFGTKResult* ffDetectGTK4(FFinstance* instance); -const FFGTKResult* ffDetectGTK3(FFinstance* instance); +const FFGTKResult* ffDetectGTK2(const FFinstance* instance); +const FFGTKResult* ffDetectGTK4(const FFinstance* instance); +const FFGTKResult* ffDetectGTK3(const FFinstance* instance); #endif diff --git a/src/detection/qt.c b/src/detection/qt.c index ec089325..5bd9b240 100644 --- a/src/detection/qt.c +++ b/src/detection/qt.c @@ -131,7 +131,7 @@ static void detectLXQt(const FFinstance* instance, FFQtResult* result) }); } -const FFQtResult* ffDetectQt(FFinstance* instance) +const FFQtResult* ffDetectQt(const FFinstance* instance) { static FFQtResult result; diff --git a/src/detection/qt.h b/src/detection/qt.h index 49dd9312..a23b29db 100644 --- a/src/detection/qt.h +++ b/src/detection/qt.h @@ -13,6 +13,6 @@ typedef struct FFQtResult FFstrbuf font; } FFQtResult; -const FFQtResult* ffDetectQt(FFinstance* instance); +const FFQtResult* ffDetectQt(const FFinstance* instance); #endif diff --git a/src/fastfetch.c b/src/fastfetch.c index a42c0d80..f436c84e 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -199,28 +199,11 @@ static inline void printCommandHelp(const char* command) } else if(strcasecmp(command, "font-format") == 0) { - constructAndPrintCommandHelpFormat("font", "{5} [Plasma], {21}", 21, - "Plasma raw", - "Plasma name", - "Plasma size", - "Plasma styles", - "Plasma pretty", - "GTK2 raw", - "GTK2 name", - "GTK2 size", - "GTK2 styles", - "GTK2 pretty", - "GTK3 raw", - "GTK3 name", - "GTK3 size", - "GTK3 styles", - "GTK3 pretty", - "GTK4 raw", - "GTK4 name", - "GTK4 size", - "GTK4 styles", - "GTK4 pretty", - "GTK2/3/4 pretty" + constructAndPrintCommandHelpFormat("font", "{} [QT], {} [GTK2], {} [GTK3], {} [GTK4]", 4, + "Font 1", + "Font 2", + "Font 3", + "Font 4" ); } else if(strcasecmp(command, "cursor-format") == 0) @@ -1283,8 +1266,6 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con optionParseString(key, value, &instance->config.batteryDir); else if(strcasecmp(key, "--separator-string") == 0) optionParseString(key, value, &instance->config.separatorString); - else if(strcasecmp(key, "--font-inline") == 0) - instance->config.fontInline = optionParseBoolean(value); else if(strcasecmp(key, "--localip-show-ipv4") == 0) instance->config.localIpShowIpV4 = optionParseBoolean(value); else if(strcasecmp(key, "--localip-show-ipv6") == 0) diff --git a/src/fastfetch.h b/src/fastfetch.h index 085d9b82..7033d378 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -168,8 +168,6 @@ typedef struct FFconfig FFstrbuf separatorString; - bool fontInline; - bool localIpShowLoop; bool localIpShowIpV4; bool localIpShowIpV6; diff --git a/src/modules/font.c b/src/modules/font.c index fff39939..bcf8fd14 100644 --- a/src/modules/font.c +++ b/src/modules/font.c @@ -4,10 +4,55 @@ #include "detection/displayserver/displayserver.h" #define FF_FONT_MODULE_NAME "Font" -#define FF_FONT_NUM_FORMAT_ARGS 2 +#define FF_FONT_NUM_FORMAT_ARGS 4 + +#if defined(__linux__) || defined(__FreeBSD__) +#include "common/parsing.h" + +static void printFont(const FFFontResult* font) +{ + FFstrbuf gtk; + ffStrbufInit(>k); + ffParseGTK(>k, &font->fonts[1], &font->fonts[2], &font->fonts[3]); + + if(font->fonts[0].length > 0) + { + printf("%s [QT]", font->fonts[0].chars); + if(gtk.length > 0) + fputs(", ", stdout); + } + + ffStrbufWriteTo(>k, stdout); +} + +#elif defined(__APPLE__) + +static void printFont(const FFFontResult* font) +{ + if(font->fonts[0].length > 0) + { + printf("%s [System]", font->fonts[0].chars); + if(font->fonts[1].length > 0) + fputs(", ", stdout); + } + + if(font->fonts[1].length > 0) + printf("%s [User]", font->fonts[1].chars); +} + +#else + +static void printFont(const FFFontResult* font) +{ + FF_UNUSED(font); +} + +#endif void ffPrintFont(FFinstance* instance) { + assert(FF_DETECT_FONT_NUM_FONTS == FF_FONT_NUM_FORMAT_ARGS); + const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance); if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0) @@ -16,47 +61,27 @@ void ffPrintFont(FFinstance* instance) return; } - FFlist list; - ffListInit(&list, sizeof(FFFontResult)); - const char* error = ffDetectFontImpl(instance, &list); - if(error) + const FFFontResult* font = ffDetectFont(instance); + + if(font->error.length > 0) { - ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "%s", error); + ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "%s", font->error.chars); return; } - if (instance->config.font.outputFormat.length == 0 && instance->config.fontInline) + if(instance->config.font.outputFormat.length == 0) { ffPrintLogoAndKey(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font.key); - for(uint32_t i = 0; i < list.length; ++i) - { - FFFontResult* font = (FFFontResult*)ffListGet(&list, i); - printf("[%s] %*s%s", font->type, font->fontPretty.length, font->fontPretty.chars, i < list.length - 1 ? ", " : ""); - ffStrbufDestroy(&font->fontPretty); - } + printFont(font); putchar('\n'); } else { - for(uint32_t i = 0; i < list.length; ++i) - { - FFFontResult* font = (FFFontResult*)ffListGet(&list, i); - if(instance->config.font.outputFormat.length == 0) - { - char keyChars[32]; - snprintf(keyChars, sizeof(keyChars), "%s (%s)", FF_FONT_MODULE_NAME, font->type); - ffPrintLogoAndKey(instance, keyChars, 0, &instance->config.font.key); - puts(font->fontPretty.chars); - } - else - { - ffPrintFormat(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRING, font->type}, - {FF_FORMAT_ARG_TYPE_STRBUF, &font->fontPretty} - }); - } - ffStrbufDestroy(&font->fontPretty); - } + ffPrintFormat(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]) { + {FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[0]}, + {FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[1]}, + {FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[2]}, + {FF_FORMAT_ARG_TYPE_STRBUF, &font->fonts[3]} + }); } - ffListDestroy(&list); }