Preload DWM plugins (dialer, calllog, xdrawer) with resident X11/Pango state and FIFO IPC
This commit is contained in:
1 parent
0a02400505
commit
996e80b095
16 files changed
+753
-407
No files matched your search
@@ -10,6 +10,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <csignal>
|
||||
#include <cstdint>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@@ -87,6 +88,103 @@ inline bool writeIntFile(const std::string& path, int value) {
|
||||
return w == len;
|
||||
}
|
||||
|
||||
inline bool isPidFileAlive(const std::string& path) {
|
||||
int pid = readIntFile(path, -1);
|
||||
return (pid > 0 && ::kill(pid, 0) == 0);
|
||||
}
|
||||
|
||||
inline std::string getPluginFifoPath(const char* name) {
|
||||
return std::string("/tmp/dwm_plugin_") + name + ".fifo";
|
||||
}
|
||||
|
||||
inline std::string getPluginDaemonPidPath(const char* name) {
|
||||
return std::string("/tmp/dwm_plugin_") + name + ".pid";
|
||||
}
|
||||
|
||||
inline bool sendPluginCommand(const char* name, const std::string& cmdLine) {
|
||||
int pid = readIntFile(getPluginDaemonPidPath(name), -1);
|
||||
if (pid <= 0 || pid == static_cast<int>(::getpid()) || ::kill(pid, 0) != 0) {
|
||||
return false;
|
||||
}
|
||||
std::string fifoPath = getPluginFifoPath(name);
|
||||
int fd = ::open(fifoPath.c_str(), O_WRONLY | O_NONBLOCK | O_CLOEXEC);
|
||||
if (fd < 0) {
|
||||
return false;
|
||||
}
|
||||
std::string msg = cmdLine + "\n";
|
||||
ssize_t w = ::write(fd, msg.data(), msg.size());
|
||||
::close(fd);
|
||||
return w == static_cast<ssize_t>(msg.size());
|
||||
}
|
||||
|
||||
inline int setupPluginDaemonFifo(const char* name) {
|
||||
std::string fifoPath = getPluginFifoPath(name);
|
||||
::mkfifo(fifoPath.c_str(), 0666);
|
||||
::chmod(fifoPath.c_str(), 0666);
|
||||
return ::open(fifoPath.c_str(), O_RDWR | O_NONBLOCK | O_CLOEXEC);
|
||||
}
|
||||
|
||||
inline std::vector<std::string> readFifoLines(int fifoFd) {
|
||||
std::vector<std::string> lines;
|
||||
if (fifoFd < 0) {
|
||||
return lines;
|
||||
}
|
||||
char buf[512];
|
||||
ssize_t n = ::read(fifoFd, buf, sizeof(buf) - 1);
|
||||
if (n <= 0) {
|
||||
return lines;
|
||||
}
|
||||
buf[n] = '\0';
|
||||
std::stringstream ss(buf);
|
||||
std::string line;
|
||||
while (std::getline(ss, line)) {
|
||||
if (!line.empty() && line.back() == '\r') {
|
||||
line.pop_back();
|
||||
}
|
||||
if (!line.empty()) {
|
||||
lines.push_back(line);
|
||||
}
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
inline bool isCallRingingFast() {
|
||||
std::string jobPath = getRuntimeFile("sxmo_jobs/ringing");
|
||||
if (::access(jobPath.c_str(), F_OK) == 0) {
|
||||
return true;
|
||||
}
|
||||
std::string ringPidFile = getRuntimeFile("sxmo.ring.pid");
|
||||
int pid = readIntFile(ringPidFile, -1);
|
||||
return (pid > 0 && ::kill(pid, 0) == 0);
|
||||
}
|
||||
|
||||
struct FileStamp {
|
||||
time_t sec = -1;
|
||||
long nsec = -1;
|
||||
off_t size = -1;
|
||||
|
||||
bool checkAndUpdate(const std::string& path) {
|
||||
struct stat st {};
|
||||
if (::stat(path.c_str(), &st) != 0) {
|
||||
if (sec != 0 || size != 0) {
|
||||
sec = 0;
|
||||
nsec = 0;
|
||||
size = 0;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (st.st_mtim.tv_sec != sec || st.st_mtim.tv_nsec != nsec ||
|
||||
st.st_size != size) {
|
||||
sec = st.st_mtim.tv_sec;
|
||||
nsec = st.st_mtim.tv_nsec;
|
||||
size = st.st_size;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
inline void writeSoftkeySuppress(int64_t untilMs) {
|
||||
int fd = ::open("/tmp/sxmo_softkey_suppress",
|
||||
O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC, 0644);
|
||||
|
||||
Reference in new issue
Block a user