Compare commits

...

5 Commits

Author SHA1 Message Date
Michael Peters
d58dfbb322 Merge branch 'main' into michael 2022-05-01 16:21:48 -05:00
Michael Peters
7f799a9b49 my blocks 2022-05-01 16:21:26 -05:00
Utkarsh Verma
65bfd0eef5
Improve UTF8 trimming algorithm 2022-05-01 15:27:30 +05:30
Utkarsh Verma
6cdd6f7ff2
Fix crashing of dwmblocks 2022-04-22 06:21:11 +05:30
Utkarsh Verma
09e72e590d
maxInterval should bet at least 1 2022-04-21 19:04:41 +05:30
2 changed files with 24 additions and 18 deletions

View File

@ -1,16 +1,16 @@
#define CMDLENGTH 45
#define DELIMITER " "
#define CLICKABLE_BLOCKS
const Block blocks[] = {
BLOCK("sb-mail", 1800, 17),
BLOCK("sb-music", 0, 18),
BLOCK("sb-disk", 1800, 19),
BLOCK("sb-memory", 10, 20),
BLOCK("sb-loadavg", 5, 21),
BLOCK("sb-mic", 0, 26),
BLOCK("sb-record", 0, 27),
BLOCK("sb-volume", 0, 22),
BLOCK("sb-battery", 5, 23),
BLOCK("sb-date", 1, 24)
/* script, refresh, signal */
BLOCK("~/scripts/blocks/net-rate.sh", 5, 23),
BLOCK("~/scripts/blocks/ram-free.sh", 5, 22),
BLOCK("~/scripts/blocks/cpu-use.sh", 5, 21),
BLOCK("~/scripts/blocks/cpu-temp.sh", 5, 20),
// TODO: Update volume in a hook rather than querying it every 2 seconds
BLOCK("~/scripts/blocks/volume.sh", 2, 19),
BLOCK("~/scripts/blocks/datetime.sh", 15, 18),
};

18
main.c
View File

@ -41,7 +41,7 @@ static Window root;
static unsigned short statusContinue = 1;
static struct epoll_event event;
static int pipes[LEN(blocks)][2];
static int timer = 0, timerTick = 0, maxInterval = 0;
static int timer = 0, timerTick = 0, maxInterval = 1;
static int signalFD;
static int epollFD;
static int execLock = 0;
@ -115,10 +115,15 @@ void updateBlock(int i) {
// Trim UTF-8 string to desired length
int count = 0, j = 0;
while (buffer[j] != '\n' && count <= CMDLENGTH) {
// Increment count for non-continuation bytes
if ((buffer[j++] & 0xc0) != 0x80)
while (buffer[j] != '\n' && count < CMDLENGTH) {
count++;
// Skip continuation bytes, if any.
char ch = buffer[j];
int skip = 1;
while ((ch & 0xc0) > 0x80)
ch <<= 1, skip++;
j += skip;
}
// Cache last character and replace it with a trailing space
@ -126,7 +131,8 @@ void updateBlock(int i) {
buffer[j] = ' ';
// Trim trailing spaces
while (j >= 0 && buffer[j] == ' ') j--;
while (j >= 0 && buffer[j] == ' ')
j--;
buffer[j + 1] = 0;
// Clear the pipe
@ -239,7 +245,7 @@ void setupSignals() {
void statusLoop() {
// Update all blocks initially
kill(0, SIGALRM);
raise(SIGALRM);
struct epoll_event events[LEN(blocks) + 1];
while (statusContinue) {