diff --git a/src/notify.cpp b/src/notify.cpp index 233bc6a2..9ca35941 100644 --- a/src/notify.cpp +++ b/src/notify.cpp @@ -10,19 +10,24 @@ pthread_t fileChange; #define EVENT_BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) ) void *fileChanged(void *params_void){ - overlay_params *params = reinterpret_cast(params_void); + notify_thread *nt = 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; + wd = inotify_add_watch( fd, nt->params->config_file_path.c_str(), IN_MODIFY); + while (!nt->quit) { + length = read( fd, buffer, EVENT_BUF_LEN ); + while (i < length) { + struct inotify_event *event = + (struct inotify_event *) &buffer[i]; + i += EVENT_SIZE + event->len; + if (event->mask & IN_MODIFY) + parse_overlay_config(nt->params, getenv("MANGOHUD_CONFIG")); + } + i = 0; + printf("File Changed\n"); } - printf("File Changed\n"); return NULL; } \ No newline at end of file diff --git a/src/notify.h b/src/notify.h index 7fff8a89..3a735936 100644 --- a/src/notify.h +++ b/src/notify.h @@ -1,5 +1,11 @@ #include #include "overlay_params.h" +struct notify_thread +{ + overlay_params *params = nullptr; + bool quit = false; +}; + 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 7d4ccb12..8045bbe3 100644 --- a/src/overlay.cpp +++ b/src/overlay.cpp @@ -83,6 +83,8 @@ struct instance_data { /* Dumping of frame stats to a file has been enabled and started. */ bool capture_started; + + notify_thread notifier; }; /* Mapped from VkDevice */ @@ -2612,7 +2614,8 @@ 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); + instance_data->notifier.params = &instance_data->params; + pthread_create(&fileChange, NULL, &fileChanged, &instance_data->notifier); init_cpu_stats(instance_data->params); @@ -2635,6 +2638,7 @@ static void overlay_DestroyInstance( struct instance_data *instance_data = FIND(struct instance_data, instance); instance_data_map_physical_devices(instance_data, false); instance_data->vtable.DestroyInstance(instance, pAllocator); + instance_data->notifier.quit = true; destroy_instance_data(instance_data); }