From f65a3d1e75fbd15cf5c3295747873143af187cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Sun, 11 Jun 2023 12:16:54 +0800 Subject: [PATCH] Wallpaper (Linux): support KDE --- CHANGELOG.md | 3 +++ src/detection/gtk_qt/gtk_qt.h | 1 + src/detection/gtk_qt/qt.c | 9 ++++++++- src/detection/users/users_linux.c | 4 ++-- src/detection/wallpaper/wallpaper_linux.c | 19 ++++++++++++++----- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5888b1abd..387e2bf18 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ This release introduces a new configuration file format: JSON config Changes: * Drop the dependency of cJSON. We now use [yyjson](https://ibireme.github.io/yyjson/doc/doxygen/html/index.html) to parse JSON documents. +Features: +* Support KDE wallpaper detection (Wallpaper, Linux) + # 1.11.3 Bugfixes: diff --git a/src/detection/gtk_qt/gtk_qt.h b/src/detection/gtk_qt/gtk_qt.h index 6e890fa97..8a115e5b0 100644 --- a/src/detection/gtk_qt/gtk_qt.h +++ b/src/detection/gtk_qt/gtk_qt.h @@ -21,6 +21,7 @@ typedef struct FFQtResult FFstrbuf colorScheme; FFstrbuf icons; FFstrbuf font; + FFstrbuf wallpaper; } FFQtResult; const FFGTKResult* ffDetectGTK2(const FFinstance* instance); diff --git a/src/detection/gtk_qt/qt.c b/src/detection/gtk_qt/qt.c index ebf36fbb9..2a29f9f46 100644 --- a/src/detection/gtk_qt/qt.c +++ b/src/detection/gtk_qt/qt.c @@ -13,7 +13,8 @@ static inline bool allValuesSet(const FFQtResult* result) result->widgetStyle.length > 0 && result->colorScheme.length > 0 && result->icons.length > 0 && - result->font.length > 0; + result->font.length > 0 && + result->wallpaper.length > 0; } typedef enum PlasmaCategory @@ -95,6 +96,11 @@ static void detectPlasma(const FFinstance* instance, FFQtResult* result) if(detectPlasmaFromFile(baseDir.chars, result)) foundAFile = true; + ffStrbufSet(&baseDir, configDir); + ffStrbufAppendS(&baseDir, "plasma-org.kde.plasma.desktop-appletsrc"); + + ffParsePropFile(baseDir.chars, "Image=", &result->wallpaper); + if(allValuesSet(result)) return; } @@ -144,6 +150,7 @@ const FFQtResult* ffDetectQt(const FFinstance* instance) ffStrbufInit(&result.colorScheme); ffStrbufInit(&result.icons); ffStrbufInit(&result.font); + ffStrbufInit(&result.wallpaper); const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance); diff --git a/src/detection/users/users_linux.c b/src/detection/users/users_linux.c index b1dcee8ed..421a6d5d2 100644 --- a/src/detection/users/users_linux.c +++ b/src/detection/users/users_linux.c @@ -22,9 +22,9 @@ next: if(n->ut_type != USER_PROCESS) continue; - for(uint32_t i = 0; i < users->length; ++i) + FF_LIST_FOR_EACH(FFstrbuf, user, *users) { - if(ffStrbufCompS((FFstrbuf*)ffListGet(users, i), n->ut_user) == 0) + if(ffStrbufCompS(user, n->ut_user) == 0) goto next; } diff --git a/src/detection/wallpaper/wallpaper_linux.c b/src/detection/wallpaper/wallpaper_linux.c index b1876f878..7ae5b480d 100644 --- a/src/detection/wallpaper/wallpaper_linux.c +++ b/src/detection/wallpaper/wallpaper_linux.c @@ -4,14 +4,23 @@ const char* ffDetectWallpaper(const FFinstance* instance, FFstrbuf* result) { + const FFstrbuf* wallpaper = NULL; const FFGTKResult* gtk = ffDetectGTK4(instance); - if (!gtk->wallpaper.length) + if (gtk->wallpaper.length) + wallpaper = >k->wallpaper; + else + { + const FFQtResult* qt = ffDetectQt(instance); + if (qt->wallpaper.length) + wallpaper = &qt->wallpaper; + } + + if (!wallpaper) return "Failed to detect the current wallpaper path"; - if (ffStrbufStartsWithS(>k->wallpaper, "file:///")) - ffStrbufAppendS(result, gtk->wallpaper.chars + strlen("file://")); + if (ffStrbufStartsWithS(wallpaper, "file:///")) + ffStrbufAppendS(result, wallpaper->chars + strlen("file://")); else - ffStrbufAppend(result, >k->wallpaper); - + ffStrbufAppend(result, wallpaper); return NULL; }