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
|
CC = gcc
|
||||||
|
|
||||||
dwmblocks: main.o
|
dwmblocks: main.o
|
||||||
$(CC) main.o -lX11 -o dwmblocks
|
$(CC) main.o -lX11 -Ofast -o dwmblocks
|
||||||
main.o: main.c config.h
|
main.o: main.c config.h
|
||||||
$(CC) -c main.c
|
$(CC) -Ofast -c main.c
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o *.gch dwmblocks
|
rm -f *.o *.gch dwmblocks
|
||||||
install: 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 "<"
|
#define DELIMITER "<"
|
||||||
|
|
||||||
const Block blocks[] = {
|
const Block blocks[] = {
|
||||||
|
|
12
main.c
12
main.c
|
@ -7,6 +7,7 @@
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define LEN(arr) (sizeof(arr) / sizeof(arr[0]))
|
||||||
#define STR2(a) #a
|
#define STR2(a) #a
|
||||||
#define STR(a) STR2(a)
|
#define STR(a) STR2(a)
|
||||||
#define BLOCK(cmd, interval, signal) { .command = "echo \"" STR(__COUNTER__) "$(" cmd ")\"", interval, signal },
|
#define BLOCK(cmd, interval, signal) { .command = "echo \"" STR(__COUNTER__) "$(" cmd ")\"", interval, signal },
|
||||||
|
@ -17,14 +18,11 @@ typedef struct {
|
||||||
} Block;
|
} Block;
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#define LEN(arr) (sizeof(arr) / sizeof(arr[0]))
|
|
||||||
#define MIN(x, y) (x > y ? y : x)
|
|
||||||
|
|
||||||
static Display *dpy;
|
static Display *dpy;
|
||||||
static int screen;
|
static int screen;
|
||||||
static Window root;
|
static Window root;
|
||||||
static char outputs[LEN(blocks)][CMDLENGTH];
|
static char outputs[LEN(blocks)][CMDLENGTH + 2];
|
||||||
static char statusBar[2][LEN(blocks) * (CMDLENGTH + LEN(DELIMITER) - 1) + 1];
|
static char statusBar[2][LEN(blocks) * ((LEN(outputs[0]) - 1) + (LEN(DELIMITER) - 1)) + 1];
|
||||||
static int statusContinue = 1;
|
static int statusContinue = 1;
|
||||||
void (*writeStatus)();
|
void (*writeStatus)();
|
||||||
static int pipeFD[2];
|
static int pipeFD[2];
|
||||||
|
@ -125,7 +123,7 @@ void childHandler() {
|
||||||
i -= '0';
|
i -= '0';
|
||||||
|
|
||||||
char ch;
|
char ch;
|
||||||
char buffer[LEN(outputs[0]) - 1];
|
char buffer[LEN(outputs[0])];
|
||||||
int j = 0;
|
int j = 0;
|
||||||
while (j < LEN(buffer) && read(pipeFD[0], &ch, 1) == 1) {
|
while (j < LEN(buffer) && read(pipeFD[0], &ch, 1) == 1) {
|
||||||
buffer[j++] = ch;
|
buffer[j++] = ch;
|
||||||
|
@ -136,12 +134,10 @@ void childHandler() {
|
||||||
|
|
||||||
const Block *block = blocks + i;
|
const Block *block = blocks + i;
|
||||||
char *output = outputs[i];
|
char *output = outputs[i];
|
||||||
|
|
||||||
if (block->signal > 0) {
|
if (block->signal > 0) {
|
||||||
output[0] = block->signal;
|
output[0] = block->signal;
|
||||||
output++;
|
output++;
|
||||||
}
|
}
|
||||||
|
|
||||||
strcpy(output, buffer);
|
strcpy(output, buffer);
|
||||||
writeStatus();
|
writeStatus();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue