From c5dad16612beccdc99a8b79334cd6e563052b631 Mon Sep 17 00:00:00 2001 From: FlightlessMango Date: Mon, 16 Mar 2020 16:48:12 +0100 Subject: [PATCH] Listen for modify on config file --- src/config.cpp | 3 +++ src/config.h | 2 ++ src/gl/inject.cpp | 2 ++ src/meson.build | 1 + src/notify.cpp | 28 ++++++++++++++++++++++++++++ src/notify.h | 5 +++++ src/overlay.cpp | 2 ++ 7 files changed, 43 insertions(+) create mode 100644 src/notify.cpp create mode 100644 src/notify.h diff --git a/src/config.cpp b/src/config.cpp index 9c286c0..22b016b 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -2,11 +2,13 @@ #include #include #include +#include #include "config.h" #include "overlay_params.h" #include "file_utils.h" #include "string_utils.h" +std::string config_file_path; std::unordered_map options; void parseConfigLine(std::string line) { @@ -91,6 +93,7 @@ void parseConfigFile() { parseConfigLine(line); } std::cerr << " [ ok ]" << std::endl; + config_file_path = *p; return; } } diff --git a/src/config.h b/src/config.h index 4fa3f45..35d45b7 100644 --- a/src/config.h +++ b/src/config.h @@ -1,5 +1,7 @@ #include +#include extern std::unordered_map options; +extern std::string config_file_path; void parseConfigFile(void); \ No newline at end of file diff --git a/src/gl/inject.cpp b/src/gl/inject.cpp index 88d0f17..0514393 100644 --- a/src/gl/inject.cpp +++ b/src/gl/inject.cpp @@ -17,6 +17,7 @@ #include "mesa/util/macros.h" #include "mesa/util/os_time.h" #include "file_utils.h" +#include "notify.h" #include #include @@ -48,6 +49,7 @@ void imgui_init() if (cfg_inited) return; parse_overlay_config(¶ms, getenv("MANGOHUD_CONFIG")); + pthread_create(&fileChange, NULL, &fileChanged, ¶ms); window_size = ImVec2(params.width, params.height); init_system_info(); cfg_inited = true; diff --git a/src/meson.build b/src/meson.build index b2bfb61..cb91803 100644 --- a/src/meson.build +++ b/src/meson.build @@ -50,6 +50,7 @@ vklayer_files = files( 'config.cpp', 'iostats.cpp', 'gpu.cpp', + 'notify.cpp', ) opengl_files = files( diff --git a/src/notify.cpp b/src/notify.cpp new file mode 100644 index 0000000..233bc6a --- /dev/null +++ b/src/notify.cpp @@ -0,0 +1,28 @@ +#include +#include +#include +#include "config.h" +#include "notify.h" + +pthread_t fileChange; + +#define EVENT_SIZE ( sizeof (struct inotify_event) ) +#define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) ) + +void *fileChanged(void *params_void){ + overlay_params *params = reinterpret_cast(params_void); + int length, i = 0; + int fd; + int wd; + char buffer[EVENT_BUF_LEN]; + fd = inotify_init(); + wd = inotify_add_watch( fd, config_file_path.c_str(), IN_MODIFY); + length = read( fd, buffer, EVENT_BUF_LEN ); + while (i < length) { + struct inotify_event *event = + (struct inotify_event *) &buffer[i]; + i += EVENT_SIZE + event->len; + } + printf("File Changed\n"); + return NULL; +} \ No newline at end of file diff --git a/src/notify.h b/src/notify.h new file mode 100644 index 0000000..7fff8a8 --- /dev/null +++ b/src/notify.h @@ -0,0 +1,5 @@ +#include +#include "overlay_params.h" + +extern pthread_t fileChange; +extern void *fileChanged(void *params_void); \ No newline at end of file diff --git a/src/overlay.cpp b/src/overlay.cpp index 6bd34d8..7d4ccb1 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -56,6 +56,7 @@ #include "cpu.h" #include "loaders/loader_nvml.h" #include "memory.h" +#include "notify.h" bool open = false; string gpuString; @@ -2611,6 +2612,7 @@ static VkResult overlay_CreateInstance( instance_data_map_physical_devices(instance_data, true); parse_overlay_config(&instance_data->params, getenv("MANGOHUD_CONFIG")); + pthread_create(&fileChange, NULL, &fileChanged, &instance_data->params); init_cpu_stats(instance_data->params);