diff --git a/src/config.cpp b/src/config.cpp new file mode 100644 index 00000000..8ca68cad --- /dev/null +++ b/src/config.cpp @@ -0,0 +1,47 @@ +#include +#include +#include +#include +#include "config.h" +#include "overlay_params.h" + +std::unordered_map options; + +void parseConfigLine(std::string line){ + if(line.find("#")!=std::string::npos) + { + line = line.erase(line.find("#"),std::string::npos); + } + size_t space = line.find(" "); + while(space!=std::string::npos) + { + line = line.erase(space,1); + space = line.find(" "); + } + space = line.find("\t"); + while(space!=std::string::npos) + { + line = line.erase(space,1); + space = line.find("\t"); + } + size_t equal = line.find("="); + if(equal==std::string::npos) + { + return; + } + + options.insert({line.substr(0,equal), line.substr(equal+1)}); +} + +void parseConfigFile() { + std::string home = std::getenv("HOME"); + std::string filePath = home + "/.local/share/MangoHud/MangoHud.conf"; + std::ifstream stream(filePath); + + std::string line; + if (stream) + while (std::getline(stream, line)) + { + parseConfigLine(line); + } +} \ No newline at end of file diff --git a/src/config.h b/src/config.h new file mode 100644 index 00000000..4fa3f45f --- /dev/null +++ b/src/config.h @@ -0,0 +1,5 @@ +#include + +extern std::unordered_map options; + +void parseConfigFile(void); \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index f7fce7b3..196b810b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -33,14 +33,14 @@ endforeach vklayer_files = files( 'overlay.cpp', - 'overlay_params.c', + 'overlay_params.cpp', 'font_unispace.c', 'cpu.cpp', 'loaders/loader_nvml.cpp', 'nvml.cpp', 'file_utils.cpp', 'memory.cpp', - # 'nvctrl.cpp', + 'config.cpp', ) # lib_xnvctrl = cc.find_library('XNVCtrl') diff --git a/src/overlay_params.c b/src/overlay_params.cpp similarity index 89% rename from src/overlay_params.c rename to src/overlay_params.cpp index afa6a47c..9d134f82 100644 --- a/src/overlay_params.c +++ b/src/overlay_params.cpp @@ -24,13 +24,14 @@ #include #include #include -#include +#include #include #include #include #include "X11/keysym.h" #include "overlay_params.h" +#include "config.h" #include "mesa/util/os_socket.h" @@ -222,8 +223,27 @@ parse_overlay_env(struct overlay_params *params, params->vsync = -1; params->crosshair_size = 30; - if (!env) - return; +// Get config options + parseConfigFile(); + for (auto& it : options) { +#define OVERLAY_PARAM_BOOL(name) \ + if (it.first == #name) { \ + params->enabled[OVERLAY_PARAM_ENABLED_##name] = \ + strtol(it.second.c_str(), NULL, 0); \ + continue; \ + } +#define OVERLAY_PARAM_CUSTOM(name) \ + if (it.first == #name) { \ + params->name = parse_##name(it.second.c_str()); \ + continue; \ + } + OVERLAY_PARAMS +#undef OVERLAY_PARAM_BOOL +#undef OVERLAY_PARAM_CUSTOM + fprintf(stderr, "Unknown option '%s'\n", it.first.c_str()); + } + + if (env){ while ((num = parse_string(env, key, value)) != 0) { env += num; @@ -244,11 +264,11 @@ parse_overlay_env(struct overlay_params *params, #undef OVERLAY_PARAM_CUSTOM fprintf(stderr, "Unknown option '%s'\n", key); } +} // if font_size is used and height has not been changed from default // increase height as needed based on font_size // params->toggle_hud = "F12"; - bool heightChanged = false; if (params->height != 140) @@ -283,4 +303,4 @@ parse_overlay_env(struct overlay_params *params, params->height += (params->font_size - 3); } -} +} \ No newline at end of file diff --git a/src/overlay_params.h b/src/overlay_params.h index d0f2b031..09653bd9 100644 --- a/src/overlay_params.h +++ b/src/overlay_params.h @@ -32,7 +32,6 @@ extern "C" { #include #include #include -#include "X11/keysym.h" #define OVERLAY_PARAMS \ OVERLAY_PARAM_BOOL(fps) \