config: Added "source=" capability to Hyprpaper .conf file (#267)

This commit is contained in:
Blake-sama 2025-07-27 12:32:49 -04:00 committed by GitHub
parent a88e0e066e
commit 6502c87e9c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 33 additions and 0 deletions

View File

@ -176,6 +176,22 @@ static Hyprlang::CParseResult handleReload(const char* C, const char* V) {
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() {
// Initialize the configuration
// Read file from default location
@ -195,6 +211,7 @@ CConfigManager::CConfigManager() {
config->registerHandler(&handlePreload, "preload", {.allowFlags = false});
config->registerHandler(&handleUnloadAll, "unloadAll", {.allowFlags = false});
config->registerHandler(&handleReload, "reload", {.allowFlags = false});
config->registerHandler(&handleSource, "source", {.allowFlags = false});
config->commence();
}
@ -227,3 +244,18 @@ std::string CConfigManager::trimPath(std::string path) {
size_t pathEndIndex = path.find_last_not_of(" \t\r\n");
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();
}

View File

@ -13,6 +13,7 @@ class CConfigManager {
std::deque<std::string> m_dRequestedPreloads;
std::string getMainConfigPath();
std::string trimPath(std::string path);
std::string absolutePath(const std::string& path);
std::unique_ptr<Hyprlang::CConfig> config;