mirror of
https://github.com/mintycube/dwmblocks.git
synced 2024-10-22 14:05:47 +02:00
Refactor code and turn on compiler optimizations
This commit is contained in:
parent
a1727ce4c8
commit
65d12cf3c9
4
Makefile
4
Makefile
@ -4,9 +4,9 @@ PREFIX = /usr/local
|
||||
CC = gcc
|
||||
|
||||
dwmblocks: main.o
|
||||
$(CC) main.o -lX11 -o dwmblocks
|
||||
$(CC) main.o -lX11 -Ofast -o dwmblocks
|
||||
main.o: main.c config.h
|
||||
$(CC) -c main.c
|
||||
$(CC) -Ofast -c main.c
|
||||
clean:
|
||||
rm -f *.o *.gch dwmblocks
|
||||
install: dwmblocks
|
||||
|
2
config.h
2
config.h
@ -1,4 +1,4 @@
|
||||
#define CMDLENGTH 50 + 1 // 1 character used to encoding the signal
|
||||
#define CMDLENGTH 50
|
||||
#define DELIMITER "<"
|
||||
|
||||
const Block blocks[] = {
|
||||
|
12
main.c
12
main.c
@ -7,6 +7,7 @@
|
||||
#include <time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#define LEN(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
#define STR2(a) #a
|
||||
#define STR(a) STR2(a)
|
||||
#define BLOCK(cmd, interval, signal) { .command = "echo \"" STR(__COUNTER__) "$(" cmd ")\"", interval, signal },
|
||||
@ -17,14 +18,11 @@ typedef struct {
|
||||
} Block;
|
||||
#include "config.h"
|
||||
|
||||
#define LEN(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||
#define MIN(x, y) (x > y ? y : x)
|
||||
|
||||
static Display *dpy;
|
||||
static int screen;
|
||||
static Window root;
|
||||
static char outputs[LEN(blocks)][CMDLENGTH];
|
||||
static char statusBar[2][LEN(blocks) * (CMDLENGTH + LEN(DELIMITER) - 1) + 1];
|
||||
static char outputs[LEN(blocks)][CMDLENGTH + 2];
|
||||
static char statusBar[2][LEN(blocks) * ((LEN(outputs[0]) - 1) + (LEN(DELIMITER) - 1)) + 1];
|
||||
static int statusContinue = 1;
|
||||
void (*writeStatus)();
|
||||
static int pipeFD[2];
|
||||
@ -125,7 +123,7 @@ void childHandler() {
|
||||
i -= '0';
|
||||
|
||||
char ch;
|
||||
char buffer[LEN(outputs[0]) - 1];
|
||||
char buffer[LEN(outputs[0])];
|
||||
int j = 0;
|
||||
while (j < LEN(buffer) && read(pipeFD[0], &ch, 1) == 1) {
|
||||
buffer[j++] = ch;
|
||||
@ -136,12 +134,10 @@ void childHandler() {
|
||||
|
||||
const Block *block = blocks + i;
|
||||
char *output = outputs[i];
|
||||
|
||||
if (block->signal > 0) {
|
||||
output[0] = block->signal;
|
||||
output++;
|
||||
}
|
||||
|
||||
strcpy(output, buffer);
|
||||
writeStatus();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user