mirror of
https://github.com/flightlessmango/MangoHud.git
synced 2024-11-10 01:10:27 +00:00
Listen for modify on config file
This commit is contained in:
parent
32c45150bc
commit
c5dad16612
@ -2,11 +2,13 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <thread>
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
#include "overlay_params.h"
|
#include "overlay_params.h"
|
||||||
#include "file_utils.h"
|
#include "file_utils.h"
|
||||||
#include "string_utils.h"
|
#include "string_utils.h"
|
||||||
|
|
||||||
|
std::string config_file_path;
|
||||||
std::unordered_map<std::string,std::string> options;
|
std::unordered_map<std::string,std::string> options;
|
||||||
|
|
||||||
void parseConfigLine(std::string line) {
|
void parseConfigLine(std::string line) {
|
||||||
@ -91,6 +93,7 @@ void parseConfigFile() {
|
|||||||
parseConfigLine(line);
|
parseConfigLine(line);
|
||||||
}
|
}
|
||||||
std::cerr << " [ ok ]" << std::endl;
|
std::cerr << " [ ok ]" << std::endl;
|
||||||
|
config_file_path = *p;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
extern std::unordered_map<std::string,std::string> options;
|
extern std::unordered_map<std::string,std::string> options;
|
||||||
|
extern std::string config_file_path;
|
||||||
|
|
||||||
void parseConfigFile(void);
|
void parseConfigFile(void);
|
@ -17,6 +17,7 @@
|
|||||||
#include "mesa/util/macros.h"
|
#include "mesa/util/macros.h"
|
||||||
#include "mesa/util/os_time.h"
|
#include "mesa/util/os_time.h"
|
||||||
#include "file_utils.h"
|
#include "file_utils.h"
|
||||||
|
#include "notify.h"
|
||||||
|
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
@ -48,6 +49,7 @@ void imgui_init()
|
|||||||
if (cfg_inited)
|
if (cfg_inited)
|
||||||
return;
|
return;
|
||||||
parse_overlay_config(¶ms, getenv("MANGOHUD_CONFIG"));
|
parse_overlay_config(¶ms, getenv("MANGOHUD_CONFIG"));
|
||||||
|
pthread_create(&fileChange, NULL, &fileChanged, ¶ms);
|
||||||
window_size = ImVec2(params.width, params.height);
|
window_size = ImVec2(params.width, params.height);
|
||||||
init_system_info();
|
init_system_info();
|
||||||
cfg_inited = true;
|
cfg_inited = true;
|
||||||
|
@ -50,6 +50,7 @@ vklayer_files = files(
|
|||||||
'config.cpp',
|
'config.cpp',
|
||||||
'iostats.cpp',
|
'iostats.cpp',
|
||||||
'gpu.cpp',
|
'gpu.cpp',
|
||||||
|
'notify.cpp',
|
||||||
)
|
)
|
||||||
|
|
||||||
opengl_files = files(
|
opengl_files = files(
|
||||||
|
28
src/notify.cpp
Normal file
28
src/notify.cpp
Normal 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
5
src/notify.h
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#include <thread>
|
||||||
|
#include "overlay_params.h"
|
||||||
|
|
||||||
|
extern pthread_t fileChange;
|
||||||
|
extern void *fileChanged(void *params_void);
|
@ -56,6 +56,7 @@
|
|||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "loaders/loader_nvml.h"
|
#include "loaders/loader_nvml.h"
|
||||||
#include "memory.h"
|
#include "memory.h"
|
||||||
|
#include "notify.h"
|
||||||
|
|
||||||
bool open = false;
|
bool open = false;
|
||||||
string gpuString;
|
string gpuString;
|
||||||
@ -2611,6 +2612,7 @@ static VkResult overlay_CreateInstance(
|
|||||||
instance_data_map_physical_devices(instance_data, true);
|
instance_data_map_physical_devices(instance_data, true);
|
||||||
|
|
||||||
parse_overlay_config(&instance_data->params, getenv("MANGOHUD_CONFIG"));
|
parse_overlay_config(&instance_data->params, getenv("MANGOHUD_CONFIG"));
|
||||||
|
pthread_create(&fileChange, NULL, &fileChanged, &instance_data->params);
|
||||||
|
|
||||||
init_cpu_stats(instance_data->params);
|
init_cpu_stats(instance_data->params);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user