|
|
|
@ -21,14 +21,19 @@ static void fileChanged(void *params_void) {
|
|
|
|
|
struct inotify_event *event =
|
|
|
|
|
(struct inotify_event *) &buffer[i];
|
|
|
|
|
i += EVENT_SIZE + event->len;
|
|
|
|
|
if (event->mask & IN_MODIFY /*|| event->mask & IN_IGNORED*/) {
|
|
|
|
|
if (event->mask & IN_MODIFY || event->mask & IN_DELETE_SELF) {
|
|
|
|
|
// In the case of IN_DELETE_SELF, some editors may to a save-to-temp-file/delete-original/move-temp-file
|
|
|
|
|
// so sleep a little to let file to be replaced
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
|
|
parse_overlay_config(&local_params, getenv("MANGOHUD_CONFIG"));
|
|
|
|
|
std::lock_guard<std::mutex> lk(nt->mutex);
|
|
|
|
|
/*if (nt->params->config_file_path != local_params.config_file_path) {
|
|
|
|
|
if ((event->mask & IN_DELETE_SELF) || (nt->params->config_file_path != local_params.config_file_path)) {
|
|
|
|
|
#ifndef NDEBUG
|
|
|
|
|
fprintf(stderr, "MANGOHUD: watching config file: %s\n", local_params.config_file_path.c_str());
|
|
|
|
|
#endif
|
|
|
|
|
inotify_rm_watch(nt->fd, nt->wd);
|
|
|
|
|
nt->wd = inotify_add_watch(nt->fd, local_params.config_file_path.c_str(), IN_MODIFY | IN_DELETE | IN_DELETE_SELF);
|
|
|
|
|
}*/
|
|
|
|
|
nt->wd = inotify_add_watch(nt->fd, local_params.config_file_path.c_str(), IN_MODIFY | IN_DELETE_SELF);
|
|
|
|
|
}
|
|
|
|
|
std::lock_guard<std::mutex> lk(nt->mutex);
|
|
|
|
|
*nt->params = local_params;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -39,13 +44,13 @@ static void fileChanged(void *params_void) {
|
|
|
|
|
|
|
|
|
|
bool start_notifier(notify_thread& nt)
|
|
|
|
|
{
|
|
|
|
|
nt.fd = inotify_init();
|
|
|
|
|
nt.wd = inotify_add_watch( nt.fd, nt.params->config_file_path.c_str(), IN_MODIFY);
|
|
|
|
|
|
|
|
|
|
int flags = fcntl(nt.fd, F_GETFL, 0);
|
|
|
|
|
if (fcntl(nt.fd, F_SETFL, flags | O_NONBLOCK))
|
|
|
|
|
perror("Set non-blocking failed");
|
|
|
|
|
nt.fd = inotify_init1(IN_NONBLOCK);
|
|
|
|
|
if (nt.fd < 0) {
|
|
|
|
|
perror("MANGOHUD: inotify_init1");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
nt.wd = inotify_add_watch(nt.fd, nt.params->config_file_path.c_str(), IN_MODIFY | IN_DELETE_SELF);
|
|
|
|
|
if (nt.wd < 0) {
|
|
|
|
|
close(nt.fd);
|
|
|
|
|
nt.fd = -1;
|
|
|
|
|