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

20
main.c
View File

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