Merge branch 'config'

pull/28/head
FlightlessMango 4 years ago
commit 2590426ef6

@ -0,0 +1,47 @@
#include <fstream>
#include <sstream>
#include <iostream>
#include <string.h>
#include "config.h"
#include "overlay_params.h"
std::unordered_map<std::string,std::string> 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);
}
}

@ -0,0 +1,5 @@
#include <unordered_map>
extern std::unordered_map<std::string,std::string> options;
void parseConfigFile(void);

@ -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')

@ -24,13 +24,14 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <string.h>
#include <fstream>
#include <errno.h>
#include <sys/sysinfo.h>
#include <X11/Xlib.h>
#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);
}
}
}

@ -32,7 +32,6 @@ extern "C" {
#include <stdint.h>
#include <stdbool.h>
#include <X11/Xlib.h>
#include "X11/keysym.h"
#define OVERLAY_PARAMS \
OVERLAY_PARAM_BOOL(fps) \

Loading…
Cancel
Save