mirror of
https://github.com/hyprwm/hyprpaper.git
synced 2025-12-19 20:20:02 +01:00
config: Added "source=" capability to Hyprpaper .conf file (#267)
This commit is contained in:
parent
a88e0e066e
commit
6502c87e9c
2 changed files with 33 additions and 0 deletions
|
|
@ -176,6 +176,22 @@ static Hyprlang::CParseResult handleReload(const char* C, const char* V) {
|
||||||
return Hyprlang::CParseResult{};
|
return Hyprlang::CParseResult{};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Hyprlang::CParseResult handleSource(const char* C, const char* V) {
|
||||||
|
Hyprlang::CParseResult result;
|
||||||
|
|
||||||
|
const std::string path = g_pConfigManager->absolutePath(V);
|
||||||
|
|
||||||
|
std::error_code ec;
|
||||||
|
if (!std::filesystem::exists(path, ec)) {
|
||||||
|
result.setError((ec ? ec.message() : "no such file").c_str());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
g_pConfigManager->config->parseFile(path.c_str());
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
CConfigManager::CConfigManager() {
|
CConfigManager::CConfigManager() {
|
||||||
// Initialize the configuration
|
// Initialize the configuration
|
||||||
// Read file from default location
|
// Read file from default location
|
||||||
|
|
@ -195,6 +211,7 @@ CConfigManager::CConfigManager() {
|
||||||
config->registerHandler(&handlePreload, "preload", {.allowFlags = false});
|
config->registerHandler(&handlePreload, "preload", {.allowFlags = false});
|
||||||
config->registerHandler(&handleUnloadAll, "unloadAll", {.allowFlags = false});
|
config->registerHandler(&handleUnloadAll, "unloadAll", {.allowFlags = false});
|
||||||
config->registerHandler(&handleReload, "reload", {.allowFlags = false});
|
config->registerHandler(&handleReload, "reload", {.allowFlags = false});
|
||||||
|
config->registerHandler(&handleSource, "source", {.allowFlags = false});
|
||||||
|
|
||||||
config->commence();
|
config->commence();
|
||||||
}
|
}
|
||||||
|
|
@ -227,3 +244,18 @@ std::string CConfigManager::trimPath(std::string path) {
|
||||||
size_t pathEndIndex = path.find_last_not_of(" \t\r\n");
|
size_t pathEndIndex = path.find_last_not_of(" \t\r\n");
|
||||||
return path.substr(pathStartIndex, pathEndIndex - pathStartIndex + 1);
|
return path.substr(pathStartIndex, pathEndIndex - pathStartIndex + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string CConfigManager::absolutePath(const std::string& path) {
|
||||||
|
if (path.empty())
|
||||||
|
return "";
|
||||||
|
|
||||||
|
std::string result = path;
|
||||||
|
|
||||||
|
if (result[0] == '~') {
|
||||||
|
const char* home = getenv("HOME");
|
||||||
|
if (home)
|
||||||
|
result = std::string(home) + result.substr(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return std::filesystem::absolute(result).string();
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ class CConfigManager {
|
||||||
std::deque<std::string> m_dRequestedPreloads;
|
std::deque<std::string> m_dRequestedPreloads;
|
||||||
std::string getMainConfigPath();
|
std::string getMainConfigPath();
|
||||||
std::string trimPath(std::string path);
|
std::string trimPath(std::string path);
|
||||||
|
std::string absolutePath(const std::string& path);
|
||||||
|
|
||||||
std::unique_ptr<Hyprlang::CConfig> config;
|
std::unique_ptr<Hyprlang::CConfig> config;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue