From feac662e1d9dc64377dd91b35675837b26055747 Mon Sep 17 00:00:00 2001 From: AnmiTaliDev Date: Sat, 15 Aug 2026 07:08:56 +0500 Subject: [PATCH] Detect active wallpaper tool (feh/nitrogen) by state file mtime instead of WM/DE name --- binding-mri/wallpaper-binding.cpp | 64 ++++++++++++++++++++++--------- src/oneshot.cpp | 2 - 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/binding-mri/wallpaper-binding.cpp b/binding-mri/wallpaper-binding.cpp index fd0d289..836941a 100644 --- a/binding-mri/wallpaper-binding.cpp +++ b/binding-mri/wallpaper-binding.cpp @@ -39,6 +39,7 @@ #include #include #include + #include static std::string desktop = "uninitialized"; // GNOME settings static GSettings *bgsetting; @@ -58,7 +59,8 @@ static std::string originalBgMode = ""; // LXQT static std::string DBUS_SESSION_BUS_ADDRESS = ""; - // dwm (feh) + // Wallpaper utility (feh/nitrogen), used when no known DE is detected + static std::string wpTool = ""; static std::string originalFehbgCmd = ""; static bool originalFehbgExists = false; // Fallback settings @@ -71,7 +73,7 @@ printf("[desktopEnvironmentInit] desktopEnvironmentInit()\n"); if (desktop != "uninitialized") return; - + desktop = shState->oneshot().desktopEnv; if (desktop == "nope") { return; @@ -116,19 +118,6 @@ } infile.close(); } - if (desktop == "dwm"){ - const char* homeC = SDL_getenv("HOME"); - if (!homeC) return; - std::string path = std::string(homeC) + "/.fehbg"; - std::ifstream infile(path); - if (infile) { - std::stringstream buffer; - buffer << infile.rdbuf(); - originalFehbgCmd = buffer.str(); - originalFehbgExists = !originalFehbgCmd.empty(); - infile.close(); - } - } //just reuse code :3 if (desktop == "lxqt"){ DBUS_SESSION_BUS_ADDRESS = SDL_getenv("DBUS_SESSION_BUS_ADDRESS"); @@ -268,7 +257,34 @@ desktop = "kde_error"; } } else { - fallbackPath = std::string(SDL_getenv("HOME")) + "/Desktop/ONESHOT_hint.png"; + const char* homeC = SDL_getenv("HOME"); + std::string home = homeC ? homeC : ""; + std::string fehbgPath = home + "/.fehbg"; + std::string nitrogenPath = home + "/.config/nitrogen/bg-saved.cfg"; + + struct stat fehStat, nitrogenStat; + bool fehExists = !home.empty() && stat(fehbgPath.c_str(), &fehStat) == 0; + bool nitrogenExists = !home.empty() && stat(nitrogenPath.c_str(), &nitrogenStat) == 0; + + if (fehExists && (!nitrogenExists || fehStat.st_mtime >= nitrogenStat.st_mtime)) { + wpTool = "feh"; + std::ifstream infile(fehbgPath); + if (infile) { + std::stringstream buffer; + buffer << infile.rdbuf(); + originalFehbgCmd = buffer.str(); + originalFehbgExists = !originalFehbgCmd.empty(); + infile.close(); + } + } else if (nitrogenExists) { + wpTool = "nitrogen"; + } else if (std::system("command -v feh >/dev/null 2>&1") == 0) { + wpTool = "feh"; + } else if (std::system("command -v nitrogen >/dev/null 2>&1") == 0) { + wpTool = "nitrogen"; + } else { + fallbackPath = home + "/Desktop/ONESHOT_hint.png"; + } } } #endif @@ -478,13 +494,20 @@ end: if (status != 0) { Debug() << "bliat ono slomalos\n"; } - } else if (desktop == "dwm") { + } else if (wpTool == "feh") { std::string concatPath = gameDirStr + path; std::string cmd = "feh --bg-scale \"" + concatPath + "\""; int status = std::system(cmd.c_str()); if (status != 0) { Debug() << "bliat ono slomalos\n"; } + } else if (wpTool == "nitrogen") { + std::string concatPath = gameDirStr + path; + std::string cmd = "nitrogen --set-scaled \"" + concatPath + "\""; + int status = std::system(cmd.c_str()); + if (status != 0) { + Debug() << "bliat ono slomalos\n"; + } } else { std::ifstream srcHint(gameDirStr + path); std::ofstream dstHint(fallbackPath); @@ -629,12 +652,17 @@ RB_METHOD(wallpaperReset){ Debug() << "bliat ono slomalos"; } } - } else if(desktop == "dwm"){ + } else if (wpTool == "feh") { std::string cmd = originalFehbgExists ? originalFehbgCmd : "xsetroot -solid black"; int status = std::system(cmd.c_str()); if (status != 0) { Debug() << "bliat ono slomalos"; } + } else if (wpTool == "nitrogen") { + int status = std::system("nitrogen --restore"); + if (status != 0) { + Debug() << "bliat ono slomalos"; + } } else { if (remove(fallbackPath.c_str()) != 0) { #ifdef DEBUG diff --git a/src/oneshot.cpp b/src/oneshot.cpp index 409e98e..3558c78 100644 --- a/src/oneshot.cpp +++ b/src/oneshot.cpp @@ -293,8 +293,6 @@ Oneshot::Oneshot(RGSSThreadData &threadData) : threadData(threadData){ desktopEnv = "budgie"; }else if (desktop.find("pantheon") != std::string::npos){ desktopEnv = "pantheon"; - }else if (desktop.find("dwm") != std::string::npos){ - desktopEnv = "dwm"; } }