Remove unnecessary background services and polling loops to improve battery life

This commit is contained in:
Luxferre committed 2026-10-27 08:08:05 +02:00
1 parent 726500085a
commit 68cf9c515b
17 files changed
+159 -22

No files matched your search

+66
View File
@@ -10,8 +10,13 @@
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <dirent.h>
#include <dlfcn.h>
#include <string>
#include <string_view>
#include <sys/stat.h>
#include <vector>
namespace {
@@ -233,6 +238,67 @@ void writeStatusIndicator(const std::string& badge) {
std::fprintf(fp, "%s\n", badge.c_str());
std::fclose(fp);
}
DIR* dir = ::opendir(statusDir.c_str());
if (!dir) {
return;
}
std::vector<std::string> names;
while (struct dirent* ent = ::readdir(dir)) {
if (ent->d_name[0] == '.') {
continue;
}
names.emplace_back(ent->d_name);
}
::closedir(dir);
std::sort(names.begin(), names.end());
std::string statusLine;
char lineBuf[256];
for (const auto& name : names) {
std::string fpath = statusDir + "/" + name;
FILE* fp = std::fopen(fpath.c_str(), "r");
if (!fp) {
continue;
}
if (std::fgets(lineBuf, sizeof(lineBuf), fp)) {
size_t len = std::strlen(lineBuf);
while (len > 0 && (lineBuf[len - 1] == '\n' || lineBuf[len - 1] == '\r')) {
lineBuf[--len] = '\0';
}
if (len > 0) {
if (!statusLine.empty()) {
statusLine.push_back(' ');
}
statusLine.append(lineBuf, len);
}
}
std::fclose(fp);
}
if (statusLine.empty()) {
return;
}
using OpenDisplayFn = void* (*)(const char*);
using DefaultRootWindowFn = unsigned long (*)(void*);
using StoreNameFn = int (*)(void*, unsigned long, const char*);
using CloseDisplayFn = int (*)(void*);
static void* x11Handle = ::dlopen("libX11.so.6", RTLD_LAZY | RTLD_LOCAL);
static auto fnOpenDisplay = x11Handle ? reinterpret_cast<OpenDisplayFn>(::dlsym(x11Handle, "XOpenDisplay")) : nullptr;
static auto fnDefaultRoot = x11Handle ? reinterpret_cast<DefaultRootWindowFn>(::dlsym(x11Handle, "XDefaultRootWindow")) : nullptr;
static auto fnStoreName = x11Handle ? reinterpret_cast<StoreNameFn>(::dlsym(x11Handle, "XStoreName")) : nullptr;
static auto fnCloseDisplay = x11Handle ? reinterpret_cast<CloseDisplayFn>(::dlsym(x11Handle, "XCloseDisplay")) : nullptr;
if (fnOpenDisplay && fnDefaultRoot && fnStoreName && fnCloseDisplay) {
const char* disp = std::getenv("DISPLAY");
void* x11Dpy = fnOpenDisplay((disp && disp[0]) ? disp : ":0");
if (x11Dpy) {
fnStoreName(x11Dpy, fnDefaultRoot(x11Dpy), statusLine.c_str());
fnCloseDisplay(x11Dpy);
}
}
}
} // namespace
+56
View File
@@ -278,6 +278,62 @@ update_t9_status_indicator(void)
fprintf(fp, "%s\n", badge);
fclose(fp);
}
if (dpy && root) {
char status_dir[256];
snprintf(status_dir, sizeof(status_dir), "%s/sxmo_status/default", base);
DIR *dir = opendir(status_dir);
if (dir) {
char names[32][64];
int count = 0;
struct dirent *ent;
while ((ent = readdir(dir)) != NULL && count < 32) {
if (ent->d_name[0] == '.')
continue;
snprintf(names[count], sizeof(names[count]), "%s", ent->d_name);
count++;
}
closedir(dir);
for (int i = 0; i < count - 1; i++) {
for (int j = i + 1; j < count; j++) {
if (strcmp(names[i], names[j]) > 0) {
char tmp[64];
memcpy(tmp, names[i], sizeof(tmp));
memcpy(names[i], names[j], sizeof(names[i]));
memcpy(names[j], tmp, sizeof(names[j]));
}
}
}
char status_line[512];
size_t pos = 0;
status_line[0] = '\0';
for (int i = 0; i < count; i++) {
char fpath[320];
snprintf(fpath, sizeof(fpath), "%s/%s", status_dir, names[i]);
FILE *sfp = fopen(fpath, "r");
if (!sfp)
continue;
char lbuf[128];
if (fgets(lbuf, sizeof(lbuf), sfp)) {
size_t len = strlen(lbuf);
while (len > 0 && (lbuf[len - 1] == '\n' || lbuf[len - 1] == '\r'))
lbuf[--len] = '\0';
if (len > 0 && pos + len + 2 < sizeof(status_line)) {
if (pos > 0)
status_line[pos++] = ' ';
memcpy(status_line + pos, lbuf, len);
pos += len;
status_line[pos] = '\0';
}
}
fclose(sfp);
}
if (pos > 0) {
XStoreName(dpy, root, status_line);
XFlush(dpy);
}
}
}
}
static void