summaryrefslogtreecommitdiffstats
path: root/src/detection/wallpaper/wallpaper_haiku.cpp
diff options
context:
space:
mode:
authorsumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
committersumuel <samuel@yakubos.org>2026-08-17 20:44:55 +0000
commit76424950e373d3b04ac3dd13019151bfba3e8423 (patch)
tree4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/detection/wallpaper/wallpaper_haiku.cpp
Add the files
Diffstat (limited to 'src/detection/wallpaper/wallpaper_haiku.cpp')
-rw-r--r--src/detection/wallpaper/wallpaper_haiku.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/detection/wallpaper/wallpaper_haiku.cpp b/src/detection/wallpaper/wallpaper_haiku.cpp
new file mode 100644
index 0000000..0bfad62
--- /dev/null
+++ b/src/detection/wallpaper/wallpaper_haiku.cpp
@@ -0,0 +1,54 @@
+extern "C" {
+#include "wallpaper.h"
+#include "common/mallocHelper.h"
+}
+
+#include <Application.h>
+#include <FindDirectory.h>
+#include <InterfaceDefs.h>
+#include <Node.h>
+#include <Path.h>
+#include <Screen.h>
+#include <fs_attr.h>
+#include <be_apps/Tracker/Background.h>
+
+const char* ffDetectWallpaper(FFstrbuf* result) {
+ BMessage backgrounds;
+ BPath pDesktop;
+ BString path;
+
+ 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) {
+ 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());
+ return NULL;
+}