Listen for modify on config file

This commit is contained in:
FlightlessMango 2020-03-16 16:48:12 +01:00
parent 32c45150bc
commit c5dad16612
7 changed files with 43 additions and 0 deletions

View File

@ -2,11 +2,13 @@
#include <sstream>
#include <iostream>
#include <string.h>
#include <thread>
#include "config.h"
#include "overlay_params.h"
#include "file_utils.h"
#include "string_utils.h"
std::string config_file_path;
std::unordered_map<std::string,std::string> options;
void parseConfigLine(std::string line) {
@ -91,6 +93,7 @@ void parseConfigFile() {
parseConfigLine(line);
}
std::cerr << " [ ok ]" << std::endl;
config_file_path = *p;
return;
}
}

View File

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

View File

@ -17,6 +17,7 @@
#include "mesa/util/macros.h"
#include "mesa/util/os_time.h"
#include "file_utils.h"
#include "notify.h"
#include <chrono>
#include <iomanip>
@ -48,6 +49,7 @@ void imgui_init()
if (cfg_inited)
return;
parse_overlay_config(&params, getenv("MANGOHUD_CONFIG"));
pthread_create(&fileChange, NULL, &fileChanged, &params);
window_size = ImVec2(params.width, params.height);
init_system_info();
cfg_inited = true;

View File

@ -50,6 +50,7 @@ vklayer_files = files(
'config.cpp',
'iostats.cpp',
'gpu.cpp',
'notify.cpp',
)
opengl_files = files(

28
src/notify.cpp Normal file
View File

@ -0,0 +1,28 @@
#include <unistd.h>
#include <sys/types.h>
#include <sys/inotify.h>
#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<overlay_params *>(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;
}

5
src/notify.h Normal file
View File

@ -0,0 +1,5 @@
#include <thread>
#include "overlay_params.h"
extern pthread_t fileChange;
extern void *fileChanged(void *params_void);

View File

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