From ec1981c5454d436f3e19565a2aa0db43fb9f052b Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Fri, 22 Jul 2022 17:18:36 +0200 Subject: [PATCH] Use [QT] instead of [Plasma] #198 #199 --- CMakeLists.txt | 2 +- src/common/threading.c | 2 +- src/detection/{plasma.c => qt.c} | 119 ++++++++++++++++++------------- src/fastfetch.h | 6 +- src/modules/font.c | 4 +- src/modules/icons.c | 4 +- src/modules/theme.c | 4 +- 7 files changed, 79 insertions(+), 62 deletions(-) rename src/detection/{plasma.c => qt.c} (67%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3a1a3a198..b72ff5140 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -156,7 +156,7 @@ add_library(libfastfetch OBJECT src/logo/image/im7.c src/logo/image/im6.c src/detection/os.c - src/detection/plasma.c + src/detection/qt.c src/detection/gtk.c src/detection/terminalShell.c src/detection/vulkan.c diff --git a/src/common/threading.c b/src/common/threading.c index 51c13849a..636885c2a 100644 --- a/src/common/threading.c +++ b/src/common/threading.c @@ -4,7 +4,7 @@ static inline void* detectPlasmaThreadMain(void* instance) { - ffDetectPlasma((FFinstance*)instance); + ffDetectQt((FFinstance*)instance); return NULL; } diff --git a/src/detection/plasma.c b/src/detection/qt.c similarity index 67% rename from src/detection/plasma.c rename to src/detection/qt.c index b0a6ee13b..2b8f8afae 100644 --- a/src/detection/plasma.c +++ b/src/detection/qt.c @@ -4,6 +4,15 @@ #include #include +static inline bool allValuesSet(const FFQtResult* result) +{ + return + result->widgetStyle.length > 0 && + result->colorScheme.length > 0 && + result->icons.length > 0 && + result->font.length > 0; +} + typedef enum PlasmaCategory { PLASMA_CATEGORY_GENERAL, @@ -12,7 +21,7 @@ typedef enum PlasmaCategory PLASMA_CATEGORY_OTHER } PlasmaCategory; -static bool detectFromConfigFile(const char* filename, FFPlasmaResult* result) +static bool detectPlasmaFromFile(const char* filename, FFQtResult* result) { FILE* kdeglobals = fopen(filename, "r"); if(kdeglobals == NULL) @@ -68,10 +77,62 @@ static bool detectFromConfigFile(const char* filename, FFPlasmaResult* result) return true; } -const FFPlasmaResult* ffDetectPlasma(FFinstance* instance) +static void detectPlasma(const FFinstance* instance, FFQtResult* result) { + bool foundAFile = false; + + //We need to do this because we use multiple threads on configDirs + FFstrbuf baseDir; + ffStrbufInitA(&baseDir, 64); + + for(uint32_t i = 0; i < instance->state.configDirs.length; i++) + { + ffStrbufSet(&baseDir, ffListGet(&instance->state.configDirs, i)); + ffStrbufAppendS(&baseDir, "kdeglobals"); + + if(detectPlasmaFromFile(baseDir.chars, result)) + foundAFile = true; + + if(allValuesSet(result)) + { + ffStrbufDestroy(&baseDir); + return; + } + } + + ffStrbufDestroy(&baseDir); + if(!foundAFile) + return; + + //In Plasma the default value is never set in the config file, but the whole key-value is discarded. + ///We must set these values by our self if the file exists (it always does here) + if(result->widgetStyle.length == 0) + ffStrbufAppendS(&result->widgetStyle, "Breeze"); + + if(result->colorScheme.length == 0) + ffStrbufAppendS(&result->colorScheme, "BreezeLight"); + + if(result->icons.length == 0) + ffStrbufAppendS(&result->icons, "Breeze"); + + if(result->font.length == 0) + ffStrbufAppendS(&result->font, "Noto Sans, 10"); +} + +static void detectLXQt(const FFinstance* instance, FFQtResult* result) +{ + ffParsePropFileConfigValues(instance, "lxqt/lxqt.conf", 3, (FFpropquery[]) { + {"style = ", &result->widgetStyle}, + {"icon_theme = ", &result->icons}, + {"font = ", &result->font} + }); +} + +const FFQtResult* ffDetectQt(FFinstance* instance) +{ + static FFQtResult result; + static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; - static FFPlasmaResult result; static bool init = false; pthread_mutex_lock(&mutex); if(init) @@ -87,55 +148,11 @@ const FFPlasmaResult* ffDetectPlasma(FFinstance* instance) ffStrbufInit(&result.font); const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance); - if(ffStrbufIgnCaseCompS(&wmde->deProcessName, "plasmashell") != 0) - { - pthread_mutex_unlock(&mutex); - return &result; - } - bool foundAFile = false; - - //We need to do this because we use multiple threads on configDirs - FFstrbuf baseDir; - ffStrbufInitA(&baseDir, 64); - - for(uint32_t i = 0; i < instance->state.configDirs.length; i++) - { - ffStrbufSet(&baseDir, ffListGet(&instance->state.configDirs, i)); - ffStrbufAppendS(&baseDir, "kdeglobals"); - - if(detectFromConfigFile(baseDir.chars, &result)) - foundAFile = true; - - if( - result.widgetStyle.length > 0 && - result.colorScheme.length > 0 && - result.icons.length > 0 && - result.font.length > 0 - ) break; - } - - ffStrbufDestroy(&baseDir); - - if(!foundAFile) - { - pthread_mutex_unlock(&mutex); - return &result; - } - - //In Plasma the default value is never set in the config file, but the whole key-value is discarded. - ///We must set these values by our self if the file exists (it always does here) - if(result.widgetStyle.length == 0) - ffStrbufAppendS(&result.widgetStyle, "Breeze"); - - if(result.colorScheme.length == 0) - ffStrbufAppendS(&result.colorScheme, "BreezeLight"); - - if(result.icons.length == 0) - ffStrbufAppendS(&result.icons, "Breeze"); - - if(result.font.length == 0) - ffStrbufAppendS(&result.font, "Noto Sans, 10"); + if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, "KDE Plasma") == 0) + detectPlasma(instance, &result); + else if(ffStrbufIgnCaseCompS(&wmde->dePrettyName, "LXQt") == 0) + detectLXQt(instance, &result); pthread_mutex_unlock(&mutex); return &result; diff --git a/src/fastfetch.h b/src/fastfetch.h index 7492d2595..bde1aa5a7 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -202,13 +202,13 @@ typedef struct FFOSResult FFstrbuf architecture; } FFOSResult; -typedef struct FFPlasmaResult +typedef struct FFQtResult { FFstrbuf widgetStyle; FFstrbuf colorScheme; FFstrbuf icons; FFstrbuf font; -} FFPlasmaResult; +} FFQtResult; typedef struct FFGTKResult { @@ -522,7 +522,7 @@ void ffLogoBuiltinListAutocompletion(); const FFOSResult* ffDetectOS(const FFinstance* instance); //detection/plasma.c -const FFPlasmaResult* ffDetectPlasma(FFinstance* instance); +const FFQtResult* ffDetectQt(FFinstance* instance); //detection/gtk.c const FFGTKResult* ffDetectGTK2(FFinstance* instance); diff --git a/src/modules/font.c b/src/modules/font.c index 173aa0569..f32063529 100644 --- a/src/modules/font.c +++ b/src/modules/font.c @@ -18,7 +18,7 @@ void ffPrintFont(FFinstance* instance) return; } - const FFstrbuf* plasmaRaw = &ffDetectPlasma(instance)->font; + const FFstrbuf* plasmaRaw = &ffDetectQt(instance)->font; const FFstrbuf* gtk2Raw = &ffDetectGTK2(instance)->font; const FFstrbuf* gtk3Raw = &ffDetectGTK3(instance)->font; const FFstrbuf* gtk4Raw = &ffDetectGTK4(instance)->font; @@ -51,7 +51,7 @@ void ffPrintFont(FFinstance* instance) if(plasma.pretty.length > 0) { ffStrbufWriteTo(&plasma.pretty, stdout); - fputs(" [Plasma]", stdout); + fputs(" [QT]", stdout); if(gtk.length > 0) fputs(", ", stdout); diff --git a/src/modules/icons.c b/src/modules/icons.c index d1908a6c4..9dfd652be 100644 --- a/src/modules/icons.c +++ b/src/modules/icons.c @@ -18,7 +18,7 @@ void ffPrintIcons(FFinstance* instance) return; } - const FFstrbuf* plasma = &ffDetectPlasma(instance)->icons; + const FFstrbuf* plasma = &ffDetectQt(instance)->icons; const FFstrbuf* gtk2 = &ffDetectGTK2(instance)->icons; const FFstrbuf* gtk3 = &ffDetectGTK3(instance)->icons; const FFstrbuf* gtk4 = &ffDetectGTK4(instance)->icons; @@ -39,7 +39,7 @@ void ffPrintIcons(FFinstance* instance) if(plasma->length > 0) { ffStrbufWriteTo(plasma, stdout); - fputs(" [Plasma]", stdout); + fputs(" [QT]", stdout); if(gtkPretty.length > 0) fputs(", ", stdout); diff --git a/src/modules/theme.c b/src/modules/theme.c index b05ba0a3d..4f8184115 100644 --- a/src/modules/theme.c +++ b/src/modules/theme.c @@ -18,7 +18,7 @@ void ffPrintTheme(FFinstance* instance) return; } - const FFPlasmaResult* plasma = ffDetectPlasma(instance); + const FFQtResult* plasma = ffDetectQt(instance); const FFstrbuf* gtk2 = &ffDetectGTK2(instance)->theme; const FFstrbuf* gtk3 = &ffDetectGTK3(instance)->theme; const FFstrbuf* gtk4 = &ffDetectGTK4(instance)->theme; @@ -70,7 +70,7 @@ void ffPrintTheme(FFinstance* instance) if(plasma->widgetStyle.length > 0 || plasma->colorScheme.length > 0) { - fputs(" [Plasma]", stdout); + fputs(" [QT]", stdout); if(gtkPretty.length > 0) fputs(", ", stdout);