1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-11 13:50:56 -05:00

fix(battery): Ignore the fake inotify event

Assume fake event if polling flag is set.

Fixes jaagr/lemonbuddy#140
This commit is contained in:
Michael Carlberg 2016-11-03 14:39:23 +01:00
parent b9e4ee9b92
commit 52c08675e6
2 changed files with 9 additions and 1 deletions

View file

@ -62,6 +62,7 @@ namespace modules {
chrono::system_clock::time_point m_lastpoll; chrono::system_clock::time_point m_lastpoll;
stateflag m_notified{false}; stateflag m_notified{false};
stateflag m_polling{false};
int m_fullat = 100; int m_fullat = 100;
}; };

View file

@ -80,8 +80,10 @@ namespace modules {
// doesn't report inotify events for files on sysfs // doesn't report inotify events for files on sysfs
if (m_interval.count() > 0 && !m_notified.load(std::memory_order_relaxed)) { if (m_interval.count() > 0 && !m_notified.load(std::memory_order_relaxed)) {
auto now = chrono::system_clock::now(); auto now = chrono::system_clock::now();
if (now - m_lastpoll > m_interval) { if (now - m_lastpoll > m_interval) {
m_log.info("%s: Polling values (inotify fallback)", name()); m_log.info("%s: Polling values (inotify fallback)", name());
m_polling.store(true, std::memory_order_relaxed);
m_lastpoll = now; m_lastpoll = now;
on_event(nullptr); on_event(nullptr);
broadcast(); broadcast();
@ -95,9 +97,14 @@ namespace modules {
if (event != nullptr) { if (event != nullptr) {
m_log.trace("%s: %s", name(), event->filename); m_log.trace("%s: %s", name(), event->filename);
if (!m_notified.load(std::memory_order_relaxed)) { if (m_polling.load(std::memory_order_relaxed)) {
m_log.info("%s: Inotify event reported, assuming fake...", name());
m_polling.store(false, std::memory_order_relaxed);
} else if (!m_notified.load(std::memory_order_relaxed)) {
m_log.info("%s: Inotify event reported, disable polling fallback...", name()); m_log.info("%s: Inotify event reported, disable polling fallback...", name());
m_notified.store(true, std::memory_order_relaxed); m_notified.store(true, std::memory_order_relaxed);
} else {
m_log.info("%s: Inotify event reported", name());
} }
} }