Optimize kernel-to-userspace battery life across CAMSS, SPI runtime PM, dwm, NeoUI, and plugins
This commit is contained in:
1 parent
f112b6ae72
commit
456d3fbc42
61 files changed
+466
-148
No files matched your search
@@ -6,6 +6,7 @@
|
||||
#include <X11/Xutil.h>
|
||||
#include <pango/pangoxft.h>
|
||||
#include <poll.h>
|
||||
#include <sys/inotify.h>
|
||||
#include <sys/wait.h>
|
||||
#include <clocale>
|
||||
#include <mutex>
|
||||
@@ -234,7 +235,7 @@ int runSmsApp(int argc, char** argv) {
|
||||
}
|
||||
};
|
||||
|
||||
auto reloadAllData = [&](bool force = false) {
|
||||
auto reloadAllData = [&](bool force = false) -> bool {
|
||||
bool cChanged = contactsStamp.checkAndUpdate(getContactsFilePath());
|
||||
bool lChanged = modemLogStamp.checkAndUpdate(getModemLogFilePath());
|
||||
bool bChanged = blockFileStamp.checkAndUpdate(getBlockFilePath());
|
||||
@@ -258,7 +259,9 @@ int runSmsApp(int argc, char** argv) {
|
||||
std::max(0, static_cast<int>(threadMessages.size()) - 1);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
reloadAllData(true);
|
||||
@@ -1337,10 +1340,21 @@ int runSmsApp(int argc, char** argv) {
|
||||
}
|
||||
|
||||
int xfd = ConnectionNumber(dpy);
|
||||
int inotifyFd = ::inotify_init1(IN_NONBLOCK | IN_CLOEXEC);
|
||||
if (inotifyFd >= 0) {
|
||||
ContactBook::ensureParentDir(getModemLogFilePath());
|
||||
ContactBook::ensureParentDir(getBlockedModemLogFilePath());
|
||||
::inotify_add_watch(inotifyFd, getModemLogDirPath().c_str(),
|
||||
IN_MODIFY | IN_CLOSE_WRITE | IN_MOVED_TO | IN_CREATE | IN_DELETE);
|
||||
::inotify_add_watch(inotifyFd, getBlockDirPath().c_str(),
|
||||
IN_MODIFY | IN_CLOSE_WRITE | IN_MOVED_TO | IN_CREATE | IN_DELETE);
|
||||
}
|
||||
while (gRunning) {
|
||||
for (const auto& cmd : readFifoLines(fifoFd)) {
|
||||
if (cmd == "NOP") {
|
||||
continue;
|
||||
} else if (cmd == "REFRESH") {
|
||||
if (reloadAllData(false) && visible) drawUI();
|
||||
} else if (cmd == "RELOAD_THEME") {
|
||||
pt.reload();
|
||||
reloadAllData(true);
|
||||
@@ -1721,26 +1735,48 @@ int runSmsApp(int argc, char** argv) {
|
||||
drawUI();
|
||||
}
|
||||
|
||||
int64_t bannerDeadline = 0;
|
||||
bool bannerExpired = false;
|
||||
{
|
||||
std::lock_guard<std::mutex> lk(sendMutex);
|
||||
if (!statusBanner.empty() && statusBannerUntilMs > 0) {
|
||||
if (tNow >= statusBannerUntilMs) {
|
||||
statusBanner.clear();
|
||||
statusBannerUntilMs = 0;
|
||||
bannerExpired = true;
|
||||
} else {
|
||||
bannerDeadline = statusBannerUntilMs;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (visible && bannerExpired) {
|
||||
drawUI();
|
||||
}
|
||||
|
||||
int timeoutMs = -1;
|
||||
if (visible) {
|
||||
timeoutMs = 250;
|
||||
if (!initialSoftkeysReleased) {
|
||||
timeoutMs = 40;
|
||||
}
|
||||
if (softkeyPending != 0) {
|
||||
timeoutMs = std::min(timeoutMs,
|
||||
std::max(1, static_cast<int>(softkeyDeadlineMs - tNow)));
|
||||
int rem = std::max(1, static_cast<int>(softkeyDeadlineMs - tNow));
|
||||
timeoutMs = (timeoutMs < 0) ? rem : std::min(timeoutMs, rem);
|
||||
}
|
||||
if (zeroHeld) {
|
||||
timeoutMs = std::min(
|
||||
timeoutMs,
|
||||
std::max(1, static_cast<int>((zeroPressMs + 420) - tNow)));
|
||||
int rem = std::max(1, static_cast<int>((zeroPressMs + 420) - tNow));
|
||||
timeoutMs = (timeoutMs < 0) ? rem : std::min(timeoutMs, rem);
|
||||
}
|
||||
if (mode == ViewMode::Compose && lastTapDigit != -1) {
|
||||
timeoutMs = std::min(
|
||||
timeoutMs,
|
||||
std::max(1, static_cast<int>(851 - (tNow - lastTapMs))));
|
||||
int rem = std::max(1, static_cast<int>(851 - (tNow - lastTapMs)));
|
||||
timeoutMs = (timeoutMs < 0) ? rem : std::min(timeoutMs, rem);
|
||||
}
|
||||
if (bannerDeadline > 0) {
|
||||
int rem = std::max(1, static_cast<int>(bannerDeadline - tNow));
|
||||
timeoutMs = (timeoutMs < 0) ? rem : std::min(timeoutMs, rem);
|
||||
}
|
||||
}
|
||||
|
||||
struct pollfd pfds[3];
|
||||
struct pollfd pfds[4];
|
||||
int nfds = 0;
|
||||
pfds[nfds++] = {xfd, POLLIN, 0};
|
||||
int fifoIdx = -1;
|
||||
@@ -1753,12 +1789,19 @@ int runSmsApp(int argc, char** argv) {
|
||||
pipeIdx = nfds;
|
||||
pfds[nfds++] = {notifyPipe[0], POLLIN, 0};
|
||||
}
|
||||
int inotifyIdx = -1;
|
||||
if (inotifyFd >= 0 && visible) {
|
||||
inotifyIdx = nfds;
|
||||
pfds[nfds++] = {inotifyFd, POLLIN, 0};
|
||||
}
|
||||
|
||||
int pr = ::poll(pfds, nfds, timeoutMs);
|
||||
if (pr > 0) {
|
||||
if (fifoIdx >= 0 && (pfds[fifoIdx].revents & POLLIN)) {
|
||||
for (const auto& cmd : readFifoLines(fifoFd)) {
|
||||
if (cmd == "RELOAD_THEME") {
|
||||
if (cmd == "REFRESH") {
|
||||
if (reloadAllData(false) && visible) drawUI();
|
||||
} else if (cmd == "RELOAD_THEME") {
|
||||
pt.reload();
|
||||
reloadAllData(true);
|
||||
if (visible) drawUI();
|
||||
@@ -1782,12 +1825,19 @@ int runSmsApp(int argc, char** argv) {
|
||||
}
|
||||
drawUI();
|
||||
}
|
||||
} else if (pr == 0 && visible) {
|
||||
reloadAllData(false);
|
||||
if (inotifyIdx >= 0 && (pfds[inotifyIdx].revents & POLLIN)) {
|
||||
char ibuf[512];
|
||||
while (::read(inotifyFd, ibuf, sizeof(ibuf)) > 0) {
|
||||
}
|
||||
if (reloadAllData(false) && visible) {
|
||||
drawUI();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
hideWindow();
|
||||
if (inotifyFd >= 0) ::close(inotifyFd);
|
||||
if (fifoFd >= 0) ::close(fifoFd);
|
||||
if (notifyPipe[0] >= 0) ::close(notifyPipe[0]);
|
||||
if (notifyPipe[1] >= 0) ::close(notifyPipe[1]);
|
||||
|
||||
Reference in new issue
Block a user