From e159082a57dbce57d13ec70febc96386c649f96d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Revol?= Date: Sat, 9 May 2026 20:10:37 +0200 Subject: [PATCH 1/2] Wallpaper (Haiku): Add support --- CMakeLists.txt | 2 +- src/detection/wallpaper/wallpaper_haiku.cpp | 64 +++++++++++++++++++++ 2 files changed, 65 insertions(+), 1 deletion(-) create mode 100644 src/detection/wallpaper/wallpaper_haiku.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index b671ea527e..eca8868449 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1240,7 +1240,7 @@ elseif(Haiku) src/detection/tpm/tpm_nosupport.c src/detection/uptime/uptime_haiku.c src/detection/users/users_linux.c - src/detection/wallpaper/wallpaper_nosupport.c + src/detection/wallpaper/wallpaper_haiku.cpp src/detection/wifi/wifi_nosupport.c src/detection/wm/wm_nosupport.c src/detection/de/de_nosupport.c diff --git a/src/detection/wallpaper/wallpaper_haiku.cpp b/src/detection/wallpaper/wallpaper_haiku.cpp new file mode 100644 index 0000000000..7694a624a6 --- /dev/null +++ b/src/detection/wallpaper/wallpaper_haiku.cpp @@ -0,0 +1,64 @@ +extern "C" { + #include "wallpaper.h" + #include "common/settings.h" +} + +#include +#include +#include +#include +#include +#include +#include +#include + +const char* ffDetectWallpaper(FFstrbuf* result) { + BMessage backgrounds; + status_t err = B_OK; + BPath pDesktop; + struct attr_info ai; + BScreen bs; + BString path; + + //ssize_t flatSize; + char *pAttr; + + if (find_directory(B_DESKTOP_DIRECTORY, &pDesktop) < B_OK) + return "find_directory(B_DESKTOP_DIRECTORY) failed"; + + // We need a valid be_app to query the app_server here. + BApplication app("application/x-vnd.fastfetch-cli-fastfetch"); + + BNode nDesktop(pDesktop.Path()); + if (nDesktop.InitCheck() == B_OK) { + err = nDesktop.GetAttrInfo(B_BACKGROUND_INFO, &ai); + if (err == B_OK) { + pAttr = new char[ai.size]; + if (pAttr) { + err = nDesktop.ReadAttr(B_BACKGROUND_INFO, ai.type, 0LL, pAttr, (size_t)ai.size); + if (err >= B_OK) { + err = backgrounds.Unflatten(pAttr); + if (err == B_OK) { + int32 ws; + for (int i = 0; backgrounds.FindString(B_BACKGROUND_IMAGE, i, &path) == B_OK; i++) { + if (backgrounds.FindInt32(B_BACKGROUND_WORKSPACES, i, &ws) == B_OK) { + if (ws & (1 << current_workspace())) { + // We try to match the one for the current workspace + break; + } + } + } + } + } + delete [] pAttr; + } + } + } + + if (path.Length() < 1) { + return "Failed to detect the current wallpaper path"; + } + + ffStrbufAppendS(result, path.String()); + return NULL; +} From b4f896bde78eebe11c6043d95556af4def80863c Mon Sep 17 00:00:00 2001 From: Carter Li Date: Sun, 10 May 2026 08:46:33 +0800 Subject: [PATCH 2/2] Refactor wallpaper detection logic and memory handling --- src/detection/wallpaper/wallpaper_haiku.cpp | 72 +++++++++------------ 1 file changed, 31 insertions(+), 41 deletions(-) diff --git a/src/detection/wallpaper/wallpaper_haiku.cpp b/src/detection/wallpaper/wallpaper_haiku.cpp index 7694a624a6..0bfad62bb7 100644 --- a/src/detection/wallpaper/wallpaper_haiku.cpp +++ b/src/detection/wallpaper/wallpaper_haiku.cpp @@ -1,6 +1,6 @@ extern "C" { - #include "wallpaper.h" - #include "common/settings.h" +#include "wallpaper.h" +#include "common/mallocHelper.h" } #include @@ -14,51 +14,41 @@ extern "C" { const char* ffDetectWallpaper(FFstrbuf* result) { BMessage backgrounds; - status_t err = B_OK; - BPath pDesktop; - struct attr_info ai; - BScreen bs; - BString path; + BPath pDesktop; + BString path; - //ssize_t flatSize; - char *pAttr; - - if (find_directory(B_DESKTOP_DIRECTORY, &pDesktop) < B_OK) - return "find_directory(B_DESKTOP_DIRECTORY) failed"; + if (find_directory(B_DESKTOP_DIRECTORY, &pDesktop) < B_OK) { + return "find_directory(B_DESKTOP_DIRECTORY) failed"; + } // We need a valid be_app to query the app_server here. BApplication app("application/x-vnd.fastfetch-cli-fastfetch"); - BNode nDesktop(pDesktop.Path()); - if (nDesktop.InitCheck() == B_OK) { - err = nDesktop.GetAttrInfo(B_BACKGROUND_INFO, &ai); - if (err == B_OK) { - pAttr = new char[ai.size]; - if (pAttr) { - err = nDesktop.ReadAttr(B_BACKGROUND_INFO, ai.type, 0LL, pAttr, (size_t)ai.size); - if (err >= B_OK) { - err = backgrounds.Unflatten(pAttr); - if (err == B_OK) { - int32 ws; - for (int i = 0; backgrounds.FindString(B_BACKGROUND_IMAGE, i, &path) == B_OK; i++) { - if (backgrounds.FindInt32(B_BACKGROUND_WORKSPACES, i, &ws) == B_OK) { - if (ws & (1 << current_workspace())) { - // We try to match the one for the current workspace - break; - } - } - } - } - } - delete [] pAttr; - } - } - } - - if (path.Length() < 1) { + BNode nDesktop(pDesktop.Path()); + if (nDesktop.InitCheck() == B_OK) { + struct attr_info ai; + if (nDesktop.GetAttrInfo(B_BACKGROUND_INFO, &ai) == B_OK && ai.size > 0) { + FF_AUTO_FREE char* pAttr = (char*) malloc(ai.size); + if (nDesktop.ReadAttr(B_BACKGROUND_INFO, ai.type, 0LL, pAttr, (size_t) ai.size) >= B_OK) { + if (backgrounds.Unflatten(pAttr) == B_OK) { + for (int i = 0; backgrounds.FindString(B_BACKGROUND_IMAGE, i, &path) == B_OK; i++) { + int32 ws; + if (backgrounds.FindInt32(B_BACKGROUND_WORKSPACES, i, &ws) == B_OK) { + if (ws & (1 << current_workspace())) { + // We try to match the one for the current workspace + break; + } + } + } + } + } + } + } + + if (path.Length() < 1) { return "Failed to detect the current wallpaper path"; - } + } - ffStrbufAppendS(result, path.String()); + ffStrbufAppendS(result, path.String()); return NULL; }