Detect active wallpaper tool (feh/nitrogen) by state file mtime instead

of WM/DE name
This commit is contained in:
AnmiTaliDev 2026-08-15 07:08:56 +05:00
parent 7690881a36
commit feac662e1d
No known key found for this signature in database
GPG key ID: C15CE1C091FF3004
2 changed files with 46 additions and 20 deletions

View file

@ -39,6 +39,7 @@
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <cstdlib> #include <cstdlib>
#include <sys/stat.h>
static std::string desktop = "uninitialized"; static std::string desktop = "uninitialized";
// GNOME settings // GNOME settings
static GSettings *bgsetting; static GSettings *bgsetting;
@ -58,7 +59,8 @@
static std::string originalBgMode = ""; static std::string originalBgMode = "";
// LXQT // LXQT
static std::string DBUS_SESSION_BUS_ADDRESS = ""; 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 std::string originalFehbgCmd = "";
static bool originalFehbgExists = false; static bool originalFehbgExists = false;
// Fallback settings // Fallback settings
@ -116,19 +118,6 @@
} }
infile.close(); 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 //just reuse code :3
if (desktop == "lxqt"){ if (desktop == "lxqt"){
DBUS_SESSION_BUS_ADDRESS = SDL_getenv("DBUS_SESSION_BUS_ADDRESS"); DBUS_SESSION_BUS_ADDRESS = SDL_getenv("DBUS_SESSION_BUS_ADDRESS");
@ -268,7 +257,34 @@
desktop = "kde_error"; desktop = "kde_error";
} }
} else { } 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 #endif
@ -478,13 +494,20 @@ end:
if (status != 0) { if (status != 0) {
Debug() << "bliat ono slomalos\n"; Debug() << "bliat ono slomalos\n";
} }
} else if (desktop == "dwm") { } else if (wpTool == "feh") {
std::string concatPath = gameDirStr + path; std::string concatPath = gameDirStr + path;
std::string cmd = "feh --bg-scale \"" + concatPath + "\""; std::string cmd = "feh --bg-scale \"" + concatPath + "\"";
int status = std::system(cmd.c_str()); int status = std::system(cmd.c_str());
if (status != 0) { if (status != 0) {
Debug() << "bliat ono slomalos\n"; 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 { } else {
std::ifstream srcHint(gameDirStr + path); std::ifstream srcHint(gameDirStr + path);
std::ofstream dstHint(fallbackPath); std::ofstream dstHint(fallbackPath);
@ -629,12 +652,17 @@ RB_METHOD(wallpaperReset){
Debug() << "bliat ono slomalos"; Debug() << "bliat ono slomalos";
} }
} }
} else if(desktop == "dwm"){ } else if (wpTool == "feh") {
std::string cmd = originalFehbgExists ? originalFehbgCmd : "xsetroot -solid black"; std::string cmd = originalFehbgExists ? originalFehbgCmd : "xsetroot -solid black";
int status = std::system(cmd.c_str()); int status = std::system(cmd.c_str());
if (status != 0) { if (status != 0) {
Debug() << "bliat ono slomalos"; Debug() << "bliat ono slomalos";
} }
} else if (wpTool == "nitrogen") {
int status = std::system("nitrogen --restore");
if (status != 0) {
Debug() << "bliat ono slomalos";
}
} else { } else {
if (remove(fallbackPath.c_str()) != 0) { if (remove(fallbackPath.c_str()) != 0) {
#ifdef DEBUG #ifdef DEBUG

View file

@ -293,8 +293,6 @@ Oneshot::Oneshot(RGSSThreadData &threadData) : threadData(threadData){
desktopEnv = "budgie"; desktopEnv = "budgie";
}else if (desktop.find("pantheon") != std::string::npos){ }else if (desktop.find("pantheon") != std::string::npos){
desktopEnv = "pantheon"; desktopEnv = "pantheon";
}else if (desktop.find("dwm") != std::string::npos){
desktopEnv = "dwm";
} }
} }