From 1a523a735f5c686a562b22195285d610e0215f4a Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Sun, 9 Feb 2020 12:10:41 +0100 Subject: [PATCH 1/9] Keybind params for toggle hud and log --- src/overlay_params.c | 21 ++++++++++++++++++++- src/overlay_params.h | 4 ++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/overlay_params.c b/src/overlay_params.c index 14272ea5..c907b80b 100644 --- a/src/overlay_params.c +++ b/src/overlay_params.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include "X11/keysym.h" #include "overlay_params.h" @@ -73,6 +75,18 @@ parse_font_size(const char *str) return strtof(str, NULL); } +static KeySym +parse_toggle_hud(const char *str) +{ + return XStringToKeysym(str); +} + +static KeySym +parse_toggle_logging(const char *str) +{ + return XStringToKeysym(str); +} + static uint32_t parse_fps_sampling_period(const char *str) { @@ -183,6 +197,8 @@ parse_overlay_env(struct overlay_params *params, params->width = 280; params->height = 140; params->control = -1; + params->toggle_hud = 65481; + params->toggle_logging = 65471; if (!env) return; @@ -208,8 +224,11 @@ parse_overlay_env(struct overlay_params *params, } // if font_size is used and height has not been changed from default // increase height as needed based on font_size - bool heightChanged = false; + // params->toggle_hud = "F12"; + + bool heightChanged = false; + if (params->height != 140) heightChanged = true; diff --git a/src/overlay_params.h b/src/overlay_params.h index fbcfe80a..fb16380a 100644 --- a/src/overlay_params.h +++ b/src/overlay_params.h @@ -53,6 +53,8 @@ extern "C" { OVERLAY_PARAM_CUSTOM(no_display) \ OVERLAY_PARAM_CUSTOM(control) \ OVERLAY_PARAM_CUSTOM(font_size) \ + OVERLAY_PARAM_CUSTOM(toggle_hud) \ + OVERLAY_PARAM_CUSTOM(toggle_logging) \ OVERLAY_PARAM_CUSTOM(help) enum overlay_param_position { @@ -82,6 +84,8 @@ struct overlay_params { unsigned width; unsigned height; float font_size; + int toggle_hud; + int toggle_logging; }; const extern char *overlay_param_names[]; From e5341dd86b30c0f04c4ed3407aa6da7cb1084f26 Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Sun, 9 Feb 2020 12:25:23 +0100 Subject: [PATCH 2/9] Use params for keybinds --- src/overlay.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/overlay.cpp b/src/overlay.cpp index 93b986f7..3b507cc0 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -876,7 +876,7 @@ static void snapshot_swapchain_frame(struct swapchain_data *data) } if (elapsedF2 >= 500000 && mangohud_output_env){ - if (key_is_pressed(XK_F2)){ + if (key_is_pressed(instance_data->params.toggle_logging)){ last_f2_press = now; log_start = now; loggingOn = !loggingOn; @@ -888,7 +888,7 @@ static void snapshot_swapchain_frame(struct swapchain_data *data) } if (elapsedF12 >= 500000){ - if (key_is_pressed(XK_F12)){ + if (key_is_pressed(instance_data->params.toggle_hud)){ displayHud = !displayHud; last_f12_press = now; } From 25f4c88175193fdd7043ce86b15df092ee5c12bf Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Sun, 9 Feb 2020 12:26:19 +0100 Subject: [PATCH 3/9] Change param keybind vars to KeySym --- src/overlay_params.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/overlay_params.h b/src/overlay_params.h index fb16380a..7e098d32 100644 --- a/src/overlay_params.h +++ b/src/overlay_params.h @@ -31,6 +31,8 @@ extern "C" { #include #include #include +#include +#include "X11/keysym.h" #define OVERLAY_PARAMS \ OVERLAY_PARAM_BOOL(fps) \ @@ -84,8 +86,8 @@ struct overlay_params { unsigned width; unsigned height; float font_size; - int toggle_hud; - int toggle_logging; + KeySym toggle_hud; + KeySym toggle_logging; }; const extern char *overlay_param_names[]; From d578d612d47b4d07e9c2e5f31390d0a02d8f7f55 Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Sun, 9 Feb 2020 14:02:40 +0100 Subject: [PATCH 4/9] Renamed overlay_param.c to .cpp --- src/meson.build | 2 +- src/overlay_params.cpp | 264 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 265 insertions(+), 1 deletion(-) create mode 100644 src/overlay_params.cpp diff --git a/src/meson.build b/src/meson.build index f7fce7b3..88824357 100644 --- a/src/meson.build +++ b/src/meson.build @@ -33,7 +33,7 @@ endforeach vklayer_files = files( 'overlay.cpp', - 'overlay_params.c', + 'overlay_params.cpp', 'font_unispace.c', 'cpu.cpp', 'loaders/loader_nvml.cpp', diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp new file mode 100644 index 00000000..c907b80b --- /dev/null +++ b/src/overlay_params.cpp @@ -0,0 +1,264 @@ +/* + * Copyright © 2019 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include +#include +#include +#include +#include +#include +#include +#include "X11/keysym.h" + +#include "overlay_params.h" + +#include "mesa/util/os_socket.h" + +static enum overlay_param_position +parse_position(const char *str) +{ + if (!str || !strcmp(str, "top-left")) + return LAYER_POSITION_TOP_LEFT; + if (!strcmp(str, "top-right")) + return LAYER_POSITION_TOP_RIGHT; + if (!strcmp(str, "bottom-left")) + return LAYER_POSITION_BOTTOM_LEFT; + if (!strcmp(str, "bottom-right")) + return LAYER_POSITION_BOTTOM_RIGHT; + return LAYER_POSITION_TOP_LEFT; +} + +static FILE * +parse_output_file(const char *str) +{ + return fopen(str, "w+"); +} + +static int +parse_control(const char *str) +{ + int ret = os_socket_listen_abstract(str, 1); + if (ret < 0) { + fprintf(stderr, "ERROR: Couldn't create socket pipe at '%s'\n", str); + fprintf(stderr, "ERROR: '%s'\n", strerror(errno)); + return ret; + } + + os_socket_block(ret, false); + + return ret; +} + +static float +parse_font_size(const char *str) +{ + return strtof(str, NULL); +} + +static KeySym +parse_toggle_hud(const char *str) +{ + return XStringToKeysym(str); +} + +static KeySym +parse_toggle_logging(const char *str) +{ + return XStringToKeysym(str); +} + +static uint32_t +parse_fps_sampling_period(const char *str) +{ + return strtol(str, NULL, 0) * 1000; +} + +static bool +parse_no_display(const char *str) +{ + return strtol(str, NULL, 0) != 0; +} + +static unsigned +parse_unsigned(const char *str) +{ + return strtol(str, NULL, 0); +} + +#define parse_width(s) parse_unsigned(s) +#define parse_height(s) parse_unsigned(s) + +static bool +parse_help(const char *str) +{ + fprintf(stderr, "Layer params using VK_LAYER_MESA_OVERLAY_CONFIG=\n"); +#define OVERLAY_PARAM_BOOL(name) \ + fprintf(stderr, "\t%s=0|1\n", #name); +#define OVERLAY_PARAM_CUSTOM(name) + OVERLAY_PARAMS +#undef OVERLAY_PARAM_BOOL +#undef OVERLAY_PARAM_CUSTOM + fprintf(stderr, "\tposition=top-left|top-right|bottom-left|bottom-right\n"); + fprintf(stderr, "\tfps_sampling_period=number-of-milliseconds\n"); + fprintf(stderr, "\tno_display=0|1\n"); + fprintf(stderr, "\toutput_file=/path/to/output.txt\n"); + fprintf(stderr, "\twidth=width-in-pixels\n"); + fprintf(stderr, "\theight=height-in-pixels\n"); + + return true; +} + +static bool is_delimiter(char c) +{ + return c == 0 || c == ',' || c == ':' || c == ';' || c == '='; +} + +static int +parse_string(const char *s, char *out_param, char *out_value) +{ + int i = 0; + + for (; !is_delimiter(*s); s++, out_param++, i++) + *out_param = *s; + + *out_param = 0; + + if (*s == '=') { + s++; + i++; + for (; !is_delimiter(*s); s++, out_value++, i++) + *out_value = *s; + } else + *(out_value++) = '1'; + *out_value = 0; + + if (*s && is_delimiter(*s)) { + s++; + i++; + } + + if (*s && !i) { + fprintf(stderr, "mesa-overlay: syntax error: unexpected '%c' (%i) while " + "parsing a string\n", *s, *s); + fflush(stderr); + } + + return i; +} + +const char *overlay_param_names[] = { +#define OVERLAY_PARAM_BOOL(name) #name, +#define OVERLAY_PARAM_CUSTOM(name) + OVERLAY_PARAMS +#undef OVERLAY_PARAM_BOOL +#undef OVERLAY_PARAM_CUSTOM +}; + +void +parse_overlay_env(struct overlay_params *params, + const char *env) +{ + uint32_t num; + char key[256], value[256]; + + memset(params, 0, sizeof(*params)); + + /* Visible by default */ + params->enabled[OVERLAY_PARAM_ENABLED_fps] = true; + params->enabled[OVERLAY_PARAM_ENABLED_frame_timing] = true; + params->enabled[OVERLAY_PARAM_ENABLED_core_load] = false; + params->enabled[OVERLAY_PARAM_ENABLED_cpu_temp] = false; + params->enabled[OVERLAY_PARAM_ENABLED_gpu_temp] = false; + params->enabled[OVERLAY_PARAM_ENABLED_cpu_stats] = true; + params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = true; + params->enabled[OVERLAY_PARAM_ENABLED_ram] = false; + params->enabled[OVERLAY_PARAM_ENABLED_vram] = false; + params->fps_sampling_period = 500000; /* 500ms */ + params->width = 280; + params->height = 140; + params->control = -1; + params->toggle_hud = 65481; + params->toggle_logging = 65471; + + if (!env) + return; + + while ((num = parse_string(env, key, value)) != 0) { + env += num; + +#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); + } + // 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) + heightChanged = true; + + if (!params->font_size) + params->font_size = 24.0f; + + int FrameTimeGraphHeight = 0; + + if (!heightChanged){ + if (params->enabled[OVERLAY_PARAM_ENABLED_frame_timing]) + FrameTimeGraphHeight = 50 + params->font_size / 2; + + if (params->font_size) + params->height = (params->font_size - 3 * 2) * 3 + FrameTimeGraphHeight; + + // Apply more hud height if cores are enabled + if (params->enabled[OVERLAY_PARAM_ENABLED_core_load]) + params->height += ((params->font_size - 3) * get_nprocs()); + + if (params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats]) + params->height += ((params->font_size) / 2); + + if (params->enabled[OVERLAY_PARAM_ENABLED_cpu_stats]) + params->height += ((params->font_size) / 2); + + if (params->enabled[OVERLAY_PARAM_ENABLED_ram]) + params->height += (params->font_size - 3); + + if (params->enabled[OVERLAY_PARAM_ENABLED_vram]) + params->height += (params->font_size - 3); + } + +} From ebc49ae8c5e318c0f9df50c2553b9efb41a9317c Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Mon, 10 Feb 2020 09:37:19 +0100 Subject: [PATCH 5/9] Basic parse config --- src/config.cpp | 52 ++++++++ src/config.h | 1 + src/meson.build | 2 +- src/overlay_params.c | 264 ----------------------------------------- src/overlay_params.cpp | 7 +- src/overlay_params.h | 1 - 6 files changed, 59 insertions(+), 268 deletions(-) create mode 100644 src/config.cpp create mode 100644 src/config.h delete mode 100644 src/overlay_params.c diff --git a/src/config.cpp b/src/config.cpp new file mode 100644 index 00000000..51eaf1f4 --- /dev/null +++ b/src/config.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include "config.h" +#include "overlay_params.h" +#include +std::vector config_params; + +void configParams(){ + config_params.push_back("height"); +} + +void parseConfigLine(std::string line, struct overlay_params *params){ + 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; + } + + std::cout << "set option " << line.substr(0,equal) << " equal to " << line.substr(equal+1) << std::endl; +} + +void parseConfigFile(struct overlay_params *params) { + configParams(); + std::string home = std::getenv("HOME"); + std::string filePath = home + "/.local/share/MangoHud/MangoHud.conf"; + std::ifstream stream(filePath); + + std::string line; + + while (std::getline(stream, line)) + { + parseConfigLine(line, params); + } +} \ No newline at end of file diff --git a/src/config.h b/src/config.h new file mode 100644 index 00000000..525b5157 --- /dev/null +++ b/src/config.h @@ -0,0 +1 @@ + void parseConfigFile(struct overlay_params *params); \ No newline at end of file diff --git a/src/meson.build b/src/meson.build index 88824357..196b810b 100644 --- a/src/meson.build +++ b/src/meson.build @@ -40,7 +40,7 @@ vklayer_files = files( '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.c deleted file mode 100644 index c907b80b..00000000 --- a/src/overlay_params.c +++ /dev/null @@ -1,264 +0,0 @@ -/* - * Copyright © 2019 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a - * copy of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, including without limitation - * the rights to use, copy, modify, merge, publish, distribute, sublicense, - * and/or sell copies of the Software, and to permit persons to whom the - * Software is furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice (including the next - * paragraph) shall be included in all copies or substantial portions of the - * Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING - * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS - * IN THE SOFTWARE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include "X11/keysym.h" - -#include "overlay_params.h" - -#include "mesa/util/os_socket.h" - -static enum overlay_param_position -parse_position(const char *str) -{ - if (!str || !strcmp(str, "top-left")) - return LAYER_POSITION_TOP_LEFT; - if (!strcmp(str, "top-right")) - return LAYER_POSITION_TOP_RIGHT; - if (!strcmp(str, "bottom-left")) - return LAYER_POSITION_BOTTOM_LEFT; - if (!strcmp(str, "bottom-right")) - return LAYER_POSITION_BOTTOM_RIGHT; - return LAYER_POSITION_TOP_LEFT; -} - -static FILE * -parse_output_file(const char *str) -{ - return fopen(str, "w+"); -} - -static int -parse_control(const char *str) -{ - int ret = os_socket_listen_abstract(str, 1); - if (ret < 0) { - fprintf(stderr, "ERROR: Couldn't create socket pipe at '%s'\n", str); - fprintf(stderr, "ERROR: '%s'\n", strerror(errno)); - return ret; - } - - os_socket_block(ret, false); - - return ret; -} - -static float -parse_font_size(const char *str) -{ - return strtof(str, NULL); -} - -static KeySym -parse_toggle_hud(const char *str) -{ - return XStringToKeysym(str); -} - -static KeySym -parse_toggle_logging(const char *str) -{ - return XStringToKeysym(str); -} - -static uint32_t -parse_fps_sampling_period(const char *str) -{ - return strtol(str, NULL, 0) * 1000; -} - -static bool -parse_no_display(const char *str) -{ - return strtol(str, NULL, 0) != 0; -} - -static unsigned -parse_unsigned(const char *str) -{ - return strtol(str, NULL, 0); -} - -#define parse_width(s) parse_unsigned(s) -#define parse_height(s) parse_unsigned(s) - -static bool -parse_help(const char *str) -{ - fprintf(stderr, "Layer params using VK_LAYER_MESA_OVERLAY_CONFIG=\n"); -#define OVERLAY_PARAM_BOOL(name) \ - fprintf(stderr, "\t%s=0|1\n", #name); -#define OVERLAY_PARAM_CUSTOM(name) - OVERLAY_PARAMS -#undef OVERLAY_PARAM_BOOL -#undef OVERLAY_PARAM_CUSTOM - fprintf(stderr, "\tposition=top-left|top-right|bottom-left|bottom-right\n"); - fprintf(stderr, "\tfps_sampling_period=number-of-milliseconds\n"); - fprintf(stderr, "\tno_display=0|1\n"); - fprintf(stderr, "\toutput_file=/path/to/output.txt\n"); - fprintf(stderr, "\twidth=width-in-pixels\n"); - fprintf(stderr, "\theight=height-in-pixels\n"); - - return true; -} - -static bool is_delimiter(char c) -{ - return c == 0 || c == ',' || c == ':' || c == ';' || c == '='; -} - -static int -parse_string(const char *s, char *out_param, char *out_value) -{ - int i = 0; - - for (; !is_delimiter(*s); s++, out_param++, i++) - *out_param = *s; - - *out_param = 0; - - if (*s == '=') { - s++; - i++; - for (; !is_delimiter(*s); s++, out_value++, i++) - *out_value = *s; - } else - *(out_value++) = '1'; - *out_value = 0; - - if (*s && is_delimiter(*s)) { - s++; - i++; - } - - if (*s && !i) { - fprintf(stderr, "mesa-overlay: syntax error: unexpected '%c' (%i) while " - "parsing a string\n", *s, *s); - fflush(stderr); - } - - return i; -} - -const char *overlay_param_names[] = { -#define OVERLAY_PARAM_BOOL(name) #name, -#define OVERLAY_PARAM_CUSTOM(name) - OVERLAY_PARAMS -#undef OVERLAY_PARAM_BOOL -#undef OVERLAY_PARAM_CUSTOM -}; - -void -parse_overlay_env(struct overlay_params *params, - const char *env) -{ - uint32_t num; - char key[256], value[256]; - - memset(params, 0, sizeof(*params)); - - /* Visible by default */ - params->enabled[OVERLAY_PARAM_ENABLED_fps] = true; - params->enabled[OVERLAY_PARAM_ENABLED_frame_timing] = true; - params->enabled[OVERLAY_PARAM_ENABLED_core_load] = false; - params->enabled[OVERLAY_PARAM_ENABLED_cpu_temp] = false; - params->enabled[OVERLAY_PARAM_ENABLED_gpu_temp] = false; - params->enabled[OVERLAY_PARAM_ENABLED_cpu_stats] = true; - params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats] = true; - params->enabled[OVERLAY_PARAM_ENABLED_ram] = false; - params->enabled[OVERLAY_PARAM_ENABLED_vram] = false; - params->fps_sampling_period = 500000; /* 500ms */ - params->width = 280; - params->height = 140; - params->control = -1; - params->toggle_hud = 65481; - params->toggle_logging = 65471; - - if (!env) - return; - - while ((num = parse_string(env, key, value)) != 0) { - env += num; - -#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); - } - // 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) - heightChanged = true; - - if (!params->font_size) - params->font_size = 24.0f; - - int FrameTimeGraphHeight = 0; - - if (!heightChanged){ - if (params->enabled[OVERLAY_PARAM_ENABLED_frame_timing]) - FrameTimeGraphHeight = 50 + params->font_size / 2; - - if (params->font_size) - params->height = (params->font_size - 3 * 2) * 3 + FrameTimeGraphHeight; - - // Apply more hud height if cores are enabled - if (params->enabled[OVERLAY_PARAM_ENABLED_core_load]) - params->height += ((params->font_size - 3) * get_nprocs()); - - if (params->enabled[OVERLAY_PARAM_ENABLED_gpu_stats]) - params->height += ((params->font_size) / 2); - - if (params->enabled[OVERLAY_PARAM_ENABLED_cpu_stats]) - params->height += ((params->font_size) / 2); - - if (params->enabled[OVERLAY_PARAM_ENABLED_ram]) - params->height += (params->font_size - 3); - - if (params->enabled[OVERLAY_PARAM_ENABLED_vram]) - params->height += (params->font_size - 3); - } - -} diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index c907b80b..ff364ea2 100644 --- a/src/overlay_params.cpp +++ 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" @@ -200,6 +201,8 @@ parse_overlay_env(struct overlay_params *params, params->toggle_hud = 65481; params->toggle_logging = 65471; + parseConfigFile(params); + if (!env) return; @@ -261,4 +264,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 7e098d32..d7b6afe0 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) \ From 33f48c91beb095537b4224e0c4b1561873aaab88 Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Mon, 10 Feb 2020 10:32:22 +0100 Subject: [PATCH 6/9] Apply params from config file --- src/config.cpp | 10 ++-------- src/config.h | 6 +++++- src/overlay_params.cpp | 20 +++++++++++++++++++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 51eaf1f4..4626c969 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -5,11 +5,7 @@ #include "config.h" #include "overlay_params.h" #include -std::vector config_params; - -void configParams(){ - config_params.push_back("height"); -} +std::unordered_map options; void parseConfigLine(std::string line, struct overlay_params *params){ if(line.find("#")!=std::string::npos) @@ -33,12 +29,10 @@ void parseConfigLine(std::string line, struct overlay_params *params){ { return; } - - std::cout << "set option " << line.substr(0,equal) << " equal to " << line.substr(equal+1) << std::endl; + options.insert({line.substr(0,equal), line.substr(equal+1)}); } void parseConfigFile(struct overlay_params *params) { - configParams(); std::string home = std::getenv("HOME"); std::string filePath = home + "/.local/share/MangoHud/MangoHud.conf"; std::ifstream stream(filePath); diff --git a/src/config.h b/src/config.h index 525b5157..21b2b799 100644 --- a/src/config.h +++ b/src/config.h @@ -1 +1,5 @@ - void parseConfigFile(struct overlay_params *params); \ No newline at end of file +#include + +extern std::unordered_map options; + +void parseConfigFile(struct overlay_params *params); \ No newline at end of file diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index ff364ea2..f8a64e82 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -201,8 +201,26 @@ parse_overlay_env(struct overlay_params *params, params->toggle_hud = 65481; params->toggle_logging = 65471; +// Get config options parseConfigFile(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", it.first.c_str()); + } + if (!env) return; From 5a62a1b0de88fa2467666c0fd5a4cbf1250d0004 Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Mon, 10 Feb 2020 11:03:39 +0100 Subject: [PATCH 7/9] Cleaning up --- src/config.cpp | 9 +++++---- src/config.h | 2 +- src/overlay_params.cpp | 4 ++-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index 4626c969..cb421da1 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -7,7 +7,7 @@ #include std::unordered_map options; -void parseConfigLine(std::string line, struct overlay_params *params){ +void parseConfigLine(std::string line){ if(line.find("#")!=std::string::npos) { line = line.erase(line.find("#"),std::string::npos); @@ -29,10 +29,11 @@ void parseConfigLine(std::string line, struct overlay_params *params){ { return; } - options.insert({line.substr(0,equal), line.substr(equal+1)}); + + options.insert({line.substr(0,equal), line.substr(equal+1)}); } -void parseConfigFile(struct overlay_params *params) { +void parseConfigFile() { std::string home = std::getenv("HOME"); std::string filePath = home + "/.local/share/MangoHud/MangoHud.conf"; std::ifstream stream(filePath); @@ -41,6 +42,6 @@ void parseConfigFile(struct overlay_params *params) { while (std::getline(stream, line)) { - parseConfigLine(line, params); + parseConfigLine(line); } } \ No newline at end of file diff --git a/src/config.h b/src/config.h index 21b2b799..4fa3f45f 100644 --- a/src/config.h +++ b/src/config.h @@ -2,4 +2,4 @@ extern std::unordered_map options; -void parseConfigFile(struct overlay_params *params); \ No newline at end of file +void parseConfigFile(void); \ No newline at end of file diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index f8a64e82..18caf2f7 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -202,7 +202,7 @@ parse_overlay_env(struct overlay_params *params, params->toggle_logging = 65471; // Get config options - parseConfigFile(params); + parseConfigFile(); for (auto& it : options) { #define OVERLAY_PARAM_BOOL(name) \ if (it.first == #name) { \ @@ -220,7 +220,7 @@ parse_overlay_env(struct overlay_params *params, #undef OVERLAY_PARAM_CUSTOM fprintf(stderr, "Unknown option '%s'\n", it.first.c_str()); } - + if (!env) return; From 2003ae93c9614dc5395892548adf78ab471950a4 Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Mon, 10 Feb 2020 14:57:22 +0100 Subject: [PATCH 8/9] Continue parsing overlay params without env --- src/config.cpp | 2 +- src/overlay_params.cpp | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/config.cpp b/src/config.cpp index cb421da1..8cbab73b 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -39,7 +39,7 @@ void parseConfigFile() { std::ifstream stream(filePath); std::string line; - + if (stream) while (std::getline(stream, line)) { parseConfigLine(line); diff --git a/src/overlay_params.cpp b/src/overlay_params.cpp index 18caf2f7..76dbf780 100644 --- a/src/overlay_params.cpp +++ b/src/overlay_params.cpp @@ -221,8 +221,7 @@ parse_overlay_env(struct overlay_params *params, fprintf(stderr, "Unknown option '%s'\n", it.first.c_str()); } - if (!env) - return; + if (env){ while ((num = parse_string(env, key, value)) != 0) { env += num; @@ -243,11 +242,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) From f56c53c152ad80883582780346b7fbf65d11608a Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Mon, 10 Feb 2020 16:59:49 +0100 Subject: [PATCH 9/9] Removed unused header --- src/config.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config.cpp b/src/config.cpp index 8cbab73b..8ca68cad 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -4,7 +4,7 @@ #include #include "config.h" #include "overlay_params.h" -#include + std::unordered_map options; void parseConfigLine(std::string line){