Testing reset functionality on KDE, expose DE to Ruby, add fallback wallpaper for unsupported DEs

This commit is contained in:
KockaAdmiralac 2018-08-02 21:52:55 +02:00
parent de433f54b6
commit a59e26595d
No known key found for this signature in database
GPG Key ID: A6007A5107D8CFBD
4 changed files with 71 additions and 4 deletions

View File

@ -111,9 +111,9 @@ RB_METHOD(nikoPrepare)
} }
#ifdef OS_OSX #ifdef OS_OSX
journal = std::string(path) + std::string("/_______.app/Contents/MacOS/_______"); journal = std::string(path) + "/_______.app/Contents/MacOS/_______";
#else #else
journal = std::string(path) + std::string("_______"); journal = std::string(path) + "_______";
#endif #endif
// Run the binary // Run the binary

View File

@ -108,6 +108,9 @@ void oneshotBindingInit()
// Constants // Constants
rb_const_set(module, rb_intern("OS"), rb_str_new2(shState->oneshot().os().c_str())); rb_const_set(module, rb_intern("OS"), rb_str_new2(shState->oneshot().os().c_str()));
#ifdef __linux__
rb_const_set(module, rb_intern("DE"), rb_str_new2(shState->oneshot().desktopEnv.c_str()));
#endif
rb_const_set(module, rb_intern("USER_NAME"), rb_str_new2(shState->oneshot().userName().c_str())); rb_const_set(module, rb_intern("USER_NAME"), rb_str_new2(shState->oneshot().userName().c_str()));
rb_const_set(module, rb_intern("SAVE_PATH"), rb_str_new2(shState->oneshot().savePath().c_str())); rb_const_set(module, rb_intern("SAVE_PATH"), rb_str_new2(shState->oneshot().savePath().c_str()));
rb_const_set(module, rb_intern("DOCS_PATH"), rb_str_new2(shState->oneshot().docsPath().c_str())); rb_const_set(module, rb_intern("DOCS_PATH"), rb_str_new2(shState->oneshot().docsPath().c_str()));

View File

@ -1,3 +1,4 @@
#include <cstdio>
#include <iostream> #include <iostream>
#include <fstream> #include <fstream>
#include <vector> #include <vector>
@ -50,6 +51,8 @@
// KDE settings // KDE settings
static std::map<std::string, std::string> defPlugins, defPictures, defColors, defModes; static std::map<std::string, std::string> defPlugins, defPictures, defColors, defModes;
static std::map<std::string, bool> defBlurs; static std::map<std::string, bool> defBlurs;
// Fallback settings
static std::string fallbackPath;
#endif #endif
#endif #endif
@ -154,7 +157,10 @@
configFile.close(); configFile.close();
} else { } else {
Debug() << "FATAL: Cannot find desktop configuration!"; Debug() << "FATAL: Cannot find desktop configuration!";
desktop = "kde_error";
} }
} else {
fallbackPath = std::string(getenv("HOME")) + "/Desktop/hint.png";
} }
} }
#endif #endif
@ -243,7 +249,7 @@ end:
} }
path = "/Wallpaper/" + nameFix + ".png"; path = "/Wallpaper/" + nameFix + ".png";
Debug() << "Setting wallpaper to" << path; Debug() << "Setting wallpaper to " << path;
#ifdef __APPLE__ #ifdef __APPLE__
if (!isCached) { if (!isCached) {
@ -342,6 +348,10 @@ end:
Debug() << "Wallpaper command:" << command.str(); Debug() << "Wallpaper command:" << command.str();
int result = system(command.str().c_str()); int result = system(command.str().c_str());
Debug() << "Result:" << result; Debug() << "Result:" << result;
} else {
std::ifstream srcHint(gameDirStr + path);
std::ofstream dstHint(fallbackPath);
dstHint << srcHint.rdbuf();
} }
#endif #endif
#endif #endif
@ -411,6 +421,60 @@ RB_METHOD(wallpaperReset)
} else { } else {
xfconf_channel_set_int(bgchannel, optionColorStyle.c_str(), defColorStyle); xfconf_channel_set_int(bgchannel, optionColorStyle.c_str(), defColorStyle);
} }
} else if (desktop == "kde") {
std::stringstream command;
command << "qdbus org.kde.plasmashell /PlasmaShell org.kde.PlasmaShell.evaluateScript 'string:" <<
"var allDesktops = desktops();" <<
"var data = {";
// Plugin, picture, color, mode, blur
for (auto const& x : defPlugins) {
command << "\"" + x.first + "\": {"
<< "plugin: \"" << x.second << "\"";
if (defPictures.find(x.first) != defPictures.end()) {
std::string picture = defPictures[x.first];
boost::replace_all(picture, "\\", "\\\\");
boost::replace_all(picture, "\"", "\\\"");
boost::replace_all(picture, "'", "\\x27");
command << ", picture: \"" << picture << "\"";
}
if (defColors.find(x.first) != defColors.end()) {
command << ", color: \"" << defColors[x.first] << "\"";
}
if (defModes.find(x.first) != defModes.end()) {
command << ", mode: \"" << defModes[x.first] << "\"";
}
if (defBlurs.find(x.first) != defBlurs.end() && defBlurs[x.first]) {
command << ", blur: true";
}
command << "},";
}
command << "\"no\": {}};" <<
"for (var i = 0, l = allDesktops.length; i < l; ++i) {" <<
"var d = allDesktops[i];" <<
"var dat = data[d.id];" <<
"d.wallpaperPlugin = dat.plugin;" <<
"d.currentConfigGroup = [\"Wallpaper\", \"org.kde.image\", \"General\"];" <<
"if (dat.picture) {" <<
"d.writeConfig(\"Image\", dat.picture);" <<
"}" <<
"if (dat.color) {" <<
"d.writeConfig(\"Color\", dat.color);" <<
"}" <<
"if (dat.mode) {" <<
"d.writeConfig(\"FillMode\", dat.mode);" <<
"}" <<
"if (dat.blur) {" <<
"d.writeConfig(\"Blur\", dat.blur);" <<
"}" <<
"}" <<
"'";
Debug() << "Reset wallpaper command:" << command.str();
int result = system(command.str().c_str());
Debug() << "Reset result:" << result;
} else {
if (remove(fallbackPath.c_str()) != 0) {
Debug() << "Failed to delete hint.png!";
}
} }
#endif #endif
#endif #endif

View File

@ -269,7 +269,7 @@ Oneshot::Oneshot(RGSSThreadData &threadData) :
} }
// Get documents path // Get documents path
std::string path = std::string(getenv("HOME")) + std::string("/Documents"); std::string path = std::string(getenv("HOME")) + "/Documents";
p->docsPath = path.c_str(); p->docsPath = path.c_str();
p->gamePath = path.c_str(); p->gamePath = path.c_str();
#ifdef OS_OSX #ifdef OS_OSX