diff options
| author | BossCode45 <human.cyborg42@gmail.com> | 2025-01-04 20:50:44 +1300 |
|---|---|---|
| committer | BossCode45 <human.cyborg42@gmail.com> | 2025-01-04 20:50:44 +1300 |
| commit | 63005f5fc81e9b641f07eadb5f07bc7c532d40c7 (patch) | |
| tree | 235fed0b412d26030ee0dcf1ca145909c92e5ef9 | |
| parent | e9c351d109439ca27c472f0d8d5f8a530ce24033 (diff) | |
| download | YATwm-63005f5fc81e9b641f07eadb5f07bc7c532d40c7.tar.gz YATwm-63005f5fc81e9b641f07eadb5f07bc7c532d40c7.zip | |
feat: Added new command line option --config (-c)
The new options allows you to specify the location of the config file
in the arguments to the program.
| -rw-r--r-- | config | 5 | ||||
| -rw-r--r-- | src/main.cpp | 32 | ||||
| -rw-r--r-- | test | 2 |
3 files changed, 24 insertions, 15 deletions
@@ -1,10 +1,13 @@ # This is a comment # Mainly used for testing -# swapmods +swapmods + +quitkey mod+g bind mod+shift+e exit bind mod+Return spawn alacritty +bind "mod+r k" spawn kitty bind mod+c spawn firefox bind mod+x spawn loginctl lock-session bind mod+shift+x bashSpawn loginctl lock-session && systemctl suspend diff --git a/src/main.cpp b/src/main.cpp index 3e01b4d..291151f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -5,7 +5,6 @@ #include <X11/Xutil.h> #include <X11/extensions/Xrandr.h> -#include <bits/getopt_core.h> #include <libnotify/notification.h> #include <libnotify/notify.h> @@ -36,8 +35,7 @@ #include "config.h" #include "util.h" #include "ewmh.h" -//TODO: FIX THIS -#include <error.h> +#include "error.h" using std::cout; using std::string; @@ -1030,13 +1028,15 @@ int main(int argc, char** argv) { int versionFlag = 0; bool immediateExit = false; + string configLocation = ""; while(1) { static option long_options[] = {{"version", no_argument, &versionFlag, 1}, + {"config", required_argument, NULL, 'c'}, {0, 0, 0, 0}}; int optionIndex; - char c = getopt_long(argc, argv, "v", long_options, &optionIndex); + char c = getopt_long(argc, argv, "c:v", long_options, &optionIndex); if(c == -1) break; @@ -1048,8 +1048,12 @@ int main(int argc, char** argv) break; //Option had arg break; + case 'c': + configLocation = string(optarg); + break; case 'v': versionFlag = 1; + break; case '?': //Error?? break; @@ -1124,16 +1128,19 @@ int main(int argc, char** argv) std::vector<Err> cfgErr; cout << "Registered commands" << endl; - - char* confDir = getenv("XDG_CONFIG_HOME"); - if(confDir != NULL) - { - cfgErr = cfg.loadFromFile(string(confDir) + "/YATwm/config"); - } + + if(configLocation != "") + cfgErr = cfg.loadFromFile(configLocation); else { - string home = getenv("HOME"); - cfgErr = cfg.loadFromFile(home + "/.config/YATwm/config"); + char* confDir = getenv("XDG_CONFIG_HOME"); + if(confDir != NULL) + cfgErr = cfg.loadFromFile(string(confDir) + "/YATwm/config"); + else + { + string home = getenv("HOME"); + cfgErr = cfg.loadFromFile(home + "/.config/YATwm/config"); + } } cout << "Done config" << endl; @@ -1234,7 +1241,6 @@ int main(int argc, char** argv) } if(ready == -1) { - cout << "E" << endl; log("ERROR"); } } @@ -7,6 +7,6 @@ Xephyr -screen 1600x900+2080+90 :1 & sleep 0.1 -DISPLAY=:1 ./YATwm +DISPLAY=:1 ./YATwm -c config pkill Xephyr |
