summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2022-07-15 12:03:50 +0200
committerGitHub <noreply@github.com>2022-07-15 12:03:50 +0200
commit5af26a451a98288178843e5b249694c6ffc41520 (patch)
tree3a613792fc51775cc935fa8a79a2c7dba193d6cc /src
parentba48e7ceea01a6dbb20d5c29d26de609c6020a28 (diff)
parent202fb4d8d45329477870874cec2fcb9c0b42a1eb (diff)
Merge pull request #373 from fufexan/configpath
Add config flag
Diffstat (limited to 'src')
-rw-r--r--src/Compositor.hpp2
-rw-r--r--src/config/ConfigManager.cpp46
-rw-r--r--src/main.cpp11
3 files changed, 44 insertions, 15 deletions
diff --git a/src/Compositor.hpp b/src/Compositor.hpp
index 3ea1711a..0500387c 100644
--- a/src/Compositor.hpp
+++ b/src/Compositor.hpp
@@ -147,6 +147,8 @@ public:
CWindow* getX11Parent(CWindow*);
void scheduleFrameForMonitor(SMonitor*);
+ std::string explicitConfigPath;
+
private:
void initAllSignals();
void setRandomSplash();
diff --git a/src/config/ConfigManager.cpp b/src/config/ConfigManager.cpp
index f01f9b40..ba73b777 100644
--- a/src/config/ConfigManager.cpp
+++ b/src/config/ConfigManager.cpp
@@ -12,8 +12,15 @@
CConfigManager::CConfigManager() {
setDefaultVars();
- static const char* const ENVHOME = getenv("HOME");
- const std::string CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf");
+
+ std::string CONFIGPATH;
+ if (g_pCompositor->explicitConfigPath == "") {
+ static const char* const ENVHOME = getenv("HOME");
+ CONFIGPATH = ENVHOME + (ISDEBUG ? (std::string) "/.config/hypr/hyprlandd.conf" : (std::string) "/.config/hypr/hyprland.conf");
+ } else {
+ CONFIGPATH = g_pCompositor->explicitConfigPath;
+ }
+
configPaths.emplace_back(CONFIGPATH);
Debug::disableLogs = &configValues["debug:disable_logs"].intValue;
@@ -801,28 +808,37 @@ void CConfigManager::loadConfigLoadVars() {
// paths
configPaths.clear();
+ std::string CONFIGPATH;
+
static const char* const ENVHOME = getenv("HOME");
const std::string CONFIGPARENTPATH = ENVHOME + (std::string) "/.config/hypr/";
- const std::string CONFIGPATH = CONFIGPARENTPATH + (ISDEBUG ? "hyprlandd.conf" : "hyprland.conf");
- configPaths.push_back(CONFIGPATH);
+ if (g_pCompositor->explicitConfigPath == "") {
+ CONFIGPATH = CONFIGPARENTPATH + (ISDEBUG ? "hyprlandd.conf" : "hyprland.conf");
+ } else {
+ CONFIGPATH = g_pCompositor->explicitConfigPath;
+ }
+ configPaths.push_back(CONFIGPATH);
+
std::ifstream ifs;
ifs.open(CONFIGPATH);
if (!ifs.good()) {
- Debug::log(WARN, "Config reading error. (No file? Attempting to generate, backing up old one if exists)");
- try {
- std::filesystem::rename(CONFIGPATH, CONFIGPATH + ".backup");
- } catch(...) { /* Probably doesn't exist */}
+ if(g_pCompositor->explicitConfigPath == "") {
+ Debug::log(WARN, "Config reading error. (No file? Attempting to generate, backing up old one if exists)");
+ try {
+ std::filesystem::rename(CONFIGPATH, CONFIGPATH + ".backup");
+ } catch(...) { /* Probably doesn't exist */}
- try {
- if (!std::filesystem::is_directory(CONFIGPARENTPATH))
- std::filesystem::create_directories(CONFIGPARENTPATH);
- }
- catch (...) {
- parseError = "Broken config file! (Could not create directory)";
- return;
+ try {
+ if (!std::filesystem::is_directory(CONFIGPARENTPATH))
+ std::filesystem::create_directories(CONFIGPARENTPATH);
+ }
+ catch (...) {
+ parseError = "Broken config file! (Could not create directory)";
+ return;
+ }
}
std::ofstream ofs;
diff --git a/src/main.cpp b/src/main.cpp
index 3f68fa8f..9367d870 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -15,9 +15,19 @@ int main(int argc, char** argv) {
throw std::runtime_error("XDG_RUNTIME_DIR is not set!");
// parse some args
+ std::string configPath;
for (int i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "--i-am-really-stupid"))
ignoreSudo = true;
+ else if ((!strcmp(argv[i], "-c") || !strcmp(argv[i], "--config")) && argc >= i + 2) {
+ configPath = std::string(argv[++i]);
+ Debug::log(LOG, "Using config location %s.", configPath.c_str());
+ } else {
+ std::cout << "Hyprland usage: Hyprland [arg [...]].\n\nArguments:\n" <<
+ "--help -h | Show this help message\n" <<
+ "--config -c | Specify config file to use\n";
+ return 1;
+ }
}
system("mkdir -p /tmp/hypr");
@@ -37,6 +47,7 @@ int main(int argc, char** argv) {
// let's init the compositor.
// it initializes basic Wayland stuff in the constructor.
g_pCompositor = std::make_unique<CCompositor>();
+ g_pCompositor->explicitConfigPath = configPath;
Debug::log(LOG, "Hyprland init finished.");