mirror of
https://github.com/mintycube/dwmblocks.git
synced 2024-10-22 14:05:47 +02:00
Add .clang-format
This commit is contained in:
parent
098184d0c3
commit
647080cbed
2
.clang-format
Normal file
2
.clang-format
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
BasedOnStyle: Google
|
||||||
|
IndentWidth: 4
|
45
main.c
45
main.c
@ -48,7 +48,10 @@ static int execLock = 0;
|
|||||||
|
|
||||||
// Longest UTF-8 character is 4 bytes long
|
// Longest UTF-8 character is 4 bytes long
|
||||||
static char outputs[LEN(blocks)][CMDLENGTH * 4 + 1 + CLICKABLE_BLOCKS];
|
static char outputs[LEN(blocks)][CMDLENGTH * 4 + 1 + CLICKABLE_BLOCKS];
|
||||||
static char statusBar[2][LEN(blocks) * (LEN(outputs[0]) - 1) + (LEN(blocks) - 1 + LEADING_DELIMITER) * (LEN(DELIMITER) - 1) + 1];
|
static char
|
||||||
|
statusBar[2]
|
||||||
|
[LEN(blocks) * (LEN(outputs[0]) - 1) +
|
||||||
|
(LEN(blocks) - 1 + LEADING_DELIMITER) * (LEN(DELIMITER) - 1) + 1];
|
||||||
|
|
||||||
void (*writeStatus)();
|
void (*writeStatus)();
|
||||||
|
|
||||||
@ -69,8 +72,7 @@ void closePipe(int* pipe) {
|
|||||||
|
|
||||||
void execBlock(int i, const char *button) {
|
void execBlock(int i, const char *button) {
|
||||||
// Ensure only one child process exists per block at an instance
|
// Ensure only one child process exists per block at an instance
|
||||||
if (execLock & 1 << i)
|
if (execLock & 1 << i) return;
|
||||||
return;
|
|
||||||
// Lock execution of block until current instance finishes execution
|
// Lock execution of block until current instance finishes execution
|
||||||
execLock |= 1 << i;
|
execLock |= 1 << i;
|
||||||
|
|
||||||
@ -79,8 +81,7 @@ void execBlock(int i, const char* button) {
|
|||||||
dup2(pipes[i][1], STDOUT_FILENO);
|
dup2(pipes[i][1], STDOUT_FILENO);
|
||||||
close(pipes[i][1]);
|
close(pipes[i][1]);
|
||||||
|
|
||||||
if (button)
|
if (button) setenv("BLOCK_BUTTON", button, 1);
|
||||||
setenv("BLOCK_BUTTON", button, 1);
|
|
||||||
execl("/bin/sh", "sh", "-c", blocks[i].command, (char *)NULL);
|
execl("/bin/sh", "sh", "-c", blocks[i].command, (char *)NULL);
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
@ -88,7 +89,8 @@ void execBlock(int i, const char* button) {
|
|||||||
|
|
||||||
void execBlocks(unsigned int time) {
|
void execBlocks(unsigned int time) {
|
||||||
for (int i = 0; i < LEN(blocks); i++)
|
for (int i = 0; i < LEN(blocks); i++)
|
||||||
if (time == 0 || (blocks[i].interval != 0 && time % blocks[i].interval == 0))
|
if (time == 0 ||
|
||||||
|
(blocks[i].interval != 0 && time % blocks[i].interval == 0))
|
||||||
execBlock(i, NULL);
|
execBlock(i, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,8 +123,7 @@ void updateBlock(int i) {
|
|||||||
// Skip continuation bytes, if any
|
// Skip continuation bytes, if any
|
||||||
char ch = buffer[j];
|
char ch = buffer[j];
|
||||||
int skip = 1;
|
int skip = 1;
|
||||||
while ((ch & 0xc0) > 0x80)
|
while ((ch & 0xc0) > 0x80) ch <<= 1, skip++;
|
||||||
ch <<= 1, skip++;
|
|
||||||
j += skip;
|
j += skip;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,8 +132,7 @@ void updateBlock(int i) {
|
|||||||
buffer[j] = ' ';
|
buffer[j] = ' ';
|
||||||
|
|
||||||
// Trim trailing spaces
|
// Trim trailing spaces
|
||||||
while (j >= 0 && buffer[j] == ' ')
|
while (j >= 0 && buffer[j] == ' ') j--;
|
||||||
j--;
|
|
||||||
buffer[j + 1] = 0;
|
buffer[j + 1] = 0;
|
||||||
|
|
||||||
// Clear the pipe
|
// Clear the pipe
|
||||||
@ -156,8 +156,7 @@ void updateBlock(int i) {
|
|||||||
|
|
||||||
void debug() {
|
void debug() {
|
||||||
// Only write out if text has changed
|
// Only write out if text has changed
|
||||||
if (!getStatus(statusBar[0], statusBar[1]))
|
if (!getStatus(statusBar[0], statusBar[1])) return;
|
||||||
return;
|
|
||||||
|
|
||||||
write(STDOUT_FILENO, statusBar[0], strlen(statusBar[0]));
|
write(STDOUT_FILENO, statusBar[0], strlen(statusBar[0]));
|
||||||
write(STDOUT_FILENO, "\n", 1);
|
write(STDOUT_FILENO, "\n", 1);
|
||||||
@ -165,8 +164,7 @@ void debug() {
|
|||||||
|
|
||||||
int setupX() {
|
int setupX() {
|
||||||
dpy = XOpenDisplay(NULL);
|
dpy = XOpenDisplay(NULL);
|
||||||
if (!dpy)
|
if (!dpy) return 1;
|
||||||
return 1;
|
|
||||||
|
|
||||||
screen = DefaultScreen(dpy);
|
screen = DefaultScreen(dpy);
|
||||||
root = RootWindow(dpy, screen);
|
root = RootWindow(dpy, screen);
|
||||||
@ -175,8 +173,7 @@ int setupX() {
|
|||||||
|
|
||||||
void setRoot() {
|
void setRoot() {
|
||||||
// Only set root if text has changed
|
// Only set root if text has changed
|
||||||
if (!getStatus(statusBar[0], statusBar[1]))
|
if (!getStatus(statusBar[0], statusBar[1])) return;
|
||||||
return;
|
|
||||||
|
|
||||||
XStoreName(dpy, root, statusBar[0]);
|
XStoreName(dpy, root, statusBar[0]);
|
||||||
XFlush(dpy);
|
XFlush(dpy);
|
||||||
@ -211,9 +208,7 @@ void signalHandler() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void termHandler() {
|
void termHandler() { statusContinue = 0; }
|
||||||
statusContinue = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void setupSignals() {
|
void setupSignals() {
|
||||||
sigset_t handledSignals;
|
sigset_t handledSignals;
|
||||||
@ -232,8 +227,7 @@ void setupSignals() {
|
|||||||
epoll_ctl(epollFD, EPOLL_CTL_ADD, signalFD, &event);
|
epoll_ctl(epollFD, EPOLL_CTL_ADD, signalFD, &event);
|
||||||
|
|
||||||
// Block all realtime and handled signals
|
// Block all realtime and handled signals
|
||||||
for (int i = SIGRTMIN; i <= SIGRTMAX; i++)
|
for (int i = SIGRTMIN; i <= SIGRTMAX; i++) sigaddset(&handledSignals, i);
|
||||||
sigaddset(&handledSignals, i);
|
|
||||||
sigprocmask(SIG_BLOCK, &handledSignals, NULL);
|
sigprocmask(SIG_BLOCK, &handledSignals, NULL);
|
||||||
|
|
||||||
// Handle termination signals
|
// Handle termination signals
|
||||||
@ -263,8 +257,7 @@ void statusLoop() {
|
|||||||
signalHandler();
|
signalHandler();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (eventCount != -1)
|
if (eventCount != -1) writeStatus();
|
||||||
writeStatus();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -296,8 +289,7 @@ int main(const int argc, const char* argv[]) {
|
|||||||
|
|
||||||
writeStatus = setRoot;
|
writeStatus = setRoot;
|
||||||
for (int i = 0; i < argc; i++)
|
for (int i = 0; i < argc; i++)
|
||||||
if (!strcmp("-d", argv[i]))
|
if (!strcmp("-d", argv[i])) writeStatus = debug;
|
||||||
writeStatus = debug;
|
|
||||||
|
|
||||||
init();
|
init();
|
||||||
statusLoop();
|
statusLoop();
|
||||||
@ -305,8 +297,7 @@ int main(const int argc, const char* argv[]) {
|
|||||||
XCloseDisplay(dpy);
|
XCloseDisplay(dpy);
|
||||||
close(epollFD);
|
close(epollFD);
|
||||||
close(signalFD);
|
close(signalFD);
|
||||||
for (int i = 0; i < LEN(pipes); i++)
|
for (int i = 0; i < LEN(pipes); i++) closePipe(pipes[i]);
|
||||||
closePipe(pipes[i]);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user