Allow MANGOHUD_CONFIG to override configuration files' settings.

Use `MANGOHUD_CONFIG=some_setting=1` to skip reading the configuration files
and just use the settings specified with MANGOHUD_CONFIG.

Use `MANGOHUD_CONFIG=read_configs,...` to read configuration files too and
add other settings that you would like to override.
pull/43/head
jackun 4 years ago
parent f7e7146883
commit 80f29aad9d
No known key found for this signature in database
GPG Key ID: 119DB3F1D05A9ED3

@ -2592,7 +2592,7 @@ static VkResult overlay_CreateInstance(
&instance_data->vtable);
instance_data_map_physical_devices(instance_data, true);
parse_overlay_env(&instance_data->params, getenv("MANGOHUD_CONFIG"));
parse_overlay_config(&instance_data->params, getenv("MANGOHUD_CONFIG"));
if (instance_data->params.fps_limit > 0)
targetFrameTime = int64_t(1000000000.0 / instance_data->params.fps_limit);

@ -212,6 +212,39 @@ parse_overlay_env(struct overlay_params *params,
{
uint32_t num;
char key[256], value[256];
while ((num = parse_string(env, key, value)) != 0) {
env += num;
if (!strcmp("full", key)) {
#define OVERLAY_PARAM_BOOL(name) \
params->enabled[OVERLAY_PARAM_ENABLED_##name] = 1;
#define OVERLAY_PARAM_CUSTOM(name)
OVERLAY_PARAMS
#undef OVERLAY_PARAM_BOOL
#undef OVERLAY_PARAM_CUSTOM
params->enabled[OVERLAY_PARAM_ENABLED_crosshair] = 0;
}
#define OVERLAY_PARAM_BOOL(name) \
if (!strcmp(#name, key)) { \
params->enabled[OVERLAY_PARAM_ENABLED_##name] = \
strtol(value, NULL, 0); \
continue; \
}
#define OVERLAY_PARAM_CUSTOM(name) \
if (!strcmp(#name, key)) { \
params->name = parse_##name(value); \
continue; \
}
OVERLAY_PARAMS
#undef OVERLAY_PARAM_BOOL
#undef OVERLAY_PARAM_CUSTOM
fprintf(stderr, "Unknown option '%s'\n", key);
}
}
void
parse_overlay_config(struct overlay_params *params,
const char *env)
{
memset(params, 0, sizeof(*params));
@ -225,6 +258,7 @@ parse_overlay_env(struct overlay_params *params,
params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = true;
params->enabled[OVERLAY_PARAM_ENABLED_ram] = false;
params->enabled[OVERLAY_PARAM_ENABLED_vram] = false;
params->enabled[OVERLAY_PARAM_ENABLED_read_configs] = false;
params->fps_sampling_period = 500000; /* 500ms */
params->width = 280;
params->height = 140;
@ -238,67 +272,50 @@ parse_overlay_env(struct overlay_params *params,
params->offset_y = 0;
params->background_alpha = 0.5;
// Get config options
parseConfigFile();
if (options.find("full") != options.end() && options.find("full")->second != "0") {
#define OVERLAY_PARAM_BOOL(name) \
params->enabled[OVERLAY_PARAM_ENABLED_##name] = 1;
#define OVERLAY_PARAM_CUSTOM(name) //define _CUSTOM to nothing so they are left alone
OVERLAY_PARAMS
#undef OVERLAY_PARAM_BOOL
#undef OVERLAY_PARAM_CUSTOM
params->enabled[OVERLAY_PARAM_ENABLED_crosshair] = 0;
options.erase("full");
}
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());
}
// first pass with env var
if (env)
parse_overlay_env(params, env);
if (env){
bool rc = params->enabled[OVERLAY_PARAM_ENABLED_read_configs];
if (!env || rc) {
while ((num = parse_string(env, key, value)) != 0) {
env += num;
if (!strcmp("full", key)) {
#define OVERLAY_PARAM_BOOL(name) \
// Get config options
parseConfigFile();
if (options.find("full") != options.end() && options.find("full")->second != "0") {
#define OVERLAY_PARAM_BOOL(name) \
params->enabled[OVERLAY_PARAM_ENABLED_##name] = 1;
#define OVERLAY_PARAM_CUSTOM(name) //define _CUSTOM to nothing so they are left alone
OVERLAY_PARAMS
#undef OVERLAY_PARAM_BOOL
#undef OVERLAY_PARAM_CUSTOM
params->enabled[OVERLAY_PARAM_ENABLED_crosshair] = 0;
}
#define OVERLAY_PARAM_BOOL(name) \
if (!strcmp(#name, key)) { \
params->enabled[OVERLAY_PARAM_ENABLED_##name] = \
strtol(value, NULL, 0); \
continue; \
}
#define OVERLAY_PARAM_CUSTOM(name) \
if (!strcmp(#name, key)) { \
params->name = parse_##name(value); \
continue; \
#define OVERLAY_PARAM_CUSTOM(name)
OVERLAY_PARAMS
#undef OVERLAY_PARAM_BOOL
#undef OVERLAY_PARAM_CUSTOM
params->enabled[OVERLAY_PARAM_ENABLED_crosshair] = 0;
options.erase("full");
}
OVERLAY_PARAMS
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", key);
fprintf(stderr, "Unknown option '%s'\n", it.first.c_str());
}
}
}
// second pass, override config file settings with MANGOHUD_CONFIG
if (env && rc)
parse_overlay_env(params, env);
// if font_size is used and height has not been changed from default
// increase height as needed based on font_size

@ -49,6 +49,7 @@ extern "C" {
OVERLAY_PARAM_BOOL(crosshair) \
OVERLAY_PARAM_BOOL(time) \
OVERLAY_PARAM_BOOL(full) \
OVERLAY_PARAM_BOOL(read_configs) \
OVERLAY_PARAM_CUSTOM(fps_sampling_period) \
OVERLAY_PARAM_CUSTOM(output_file) \
OVERLAY_PARAM_CUSTOM(position) \
@ -111,6 +112,8 @@ const extern char *overlay_param_names[];
void parse_overlay_env(struct overlay_params *params,
const char *env);
void parse_overlay_config(struct overlay_params *params,
const char *env);
#ifdef __cplusplus
}

Loading…
Cancel
Save