Compare commits
10 commits
d432a2a0fe
...
ef12a93743
Author | SHA1 | Date | |
---|---|---|---|
ef12a93743 | |||
|
28d7e79d47 | ||
|
d575da7a3c | ||
|
221daf2f5d | ||
|
e7214b60fa | ||
|
d072368de0 | ||
|
ed1e85d804 | ||
|
c6d81febf6 | ||
|
bf9cbfbf2b | ||
|
968842909e |
6 changed files with 75 additions and 30 deletions
6
CHANGELOG.md
Normal file
6
CHANGELOG.md
Normal file
|
@ -0,0 +1,6 @@
|
|||
## [1.0.1] - 2022-12-11
|
||||
### Fixed
|
||||
- Fixed crashes due to bad signal handling
|
||||
|
||||
## [1.0.0] - 2022-04-20
|
||||
Initial release
|
4
Makefile
4
Makefile
|
@ -1,4 +1,5 @@
|
|||
PREFIX ?= /usr/local
|
||||
MANPREFIX ?= $(PREFIX)/share/man
|
||||
CC ?= cc
|
||||
|
||||
output: someblocks.c blocks.def.h blocks.h
|
||||
|
@ -12,5 +13,8 @@ clean:
|
|||
install: output
|
||||
mkdir -p $(DESTDIR)$(PREFIX)/bin
|
||||
install -m 0755 someblocks $(DESTDIR)$(PREFIX)/bin/someblocks
|
||||
mkdir -p $(DESTDIR)$(MANPREFIX)/man1
|
||||
install -m 0644 someblocks.1 $(DESTDIR)$(MANPREFIX)/man1/someblocks.1
|
||||
uninstall:
|
||||
rm -f $(DESTDIR)$(PREFIX)/bin/someblocks
|
||||
rm -f $(DESTDIR)$(MANPREFIX)/man1/someblocks.1
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
# someblocks
|
||||
Modular status bar for [somebar](https://gitlab.com/raphaelr/somebar) written in c.
|
||||
Modular status bar for [somebar](https://git.sr.ht/~raphi/somebar) written in c.
|
||||
|
||||
This is a fork of [dwmblocks](https://github.com/torrinfail/dwmblocks), modified
|
||||
to connect to somebar instead of dwm.
|
||||
|
||||
The mailing list for this project is
|
||||
[~raphi/public-inbox@lists.sr.ht](mailto:~raphi/public-inbox@lists.sr.ht).
|
||||
# usage
|
||||
To use someblocks first run 'make' and then install it with 'sudo make install'.
|
||||
After that you can put someblocks in your startup script to have it start with dwl/somebar.
|
||||
|
|
12
blocks.def.h
12
blocks.def.h
|
@ -1,11 +1,13 @@
|
|||
//Modify this file to change what commands output to your statusbar, and recompile using the make command.
|
||||
static const Block blocks[] = {
|
||||
/*Icon*/ /*Command*/ /*Update Interval*/ /*Update Signal*/
|
||||
{"Mem:", "free -h | awk '/^Mem/ { print $3\"/\"$2 }' | sed s/i//g", 30, 0},
|
||||
|
||||
{"", "date '+%b %d (%a) %I:%M%p'", 5, 0},
|
||||
{"", "music", 0, 11},
|
||||
{"", "cpu", 40, 4},
|
||||
{"", "volume", 0, 10},
|
||||
{"", "battery", 40, 2},
|
||||
{"", "clock", 60, 1},
|
||||
};
|
||||
|
||||
//sets delimeter between status commands. NULL character ('\0') means no delimeter.
|
||||
//Sets delimiter between status commands. NULL character ('\0') means no delimiter.
|
||||
static char delim[] = " | ";
|
||||
static unsigned int delimLen = 5;
|
||||
static unsigned int delimLen = 3;
|
||||
|
|
22
someblocks.1
Normal file
22
someblocks.1
Normal file
|
@ -0,0 +1,22 @@
|
|||
.TH someblocks 1 someblocks\-1.0
|
||||
.SH NAME
|
||||
someblocks \- Modular status bar for somebar
|
||||
.SH SYNOPSIS
|
||||
.B someblocks
|
||||
.RB [ \-d
|
||||
.IR delimiter ]
|
||||
.RB [ \-s
|
||||
.IR path ]
|
||||
.RB [ \-p ]
|
||||
.SH DESCRIPTION
|
||||
Modular status bar for somebar written in c.
|
||||
.SH OPTIONS
|
||||
.TP
|
||||
.B \-d
|
||||
Sets the delimiter between blocks
|
||||
.TP
|
||||
.B \-s
|
||||
Sets the path to the somebar control FIFO. The default value is
|
||||
$XDG_RUNTIME_DIR/somebar-0
|
||||
.SH BUGS
|
||||
Send bug reports to ~raphi/public-inbox@lists.sr.ht
|
56
someblocks.c
56
someblocks.c
|
@ -1,3 +1,4 @@
|
|||
#define _POSIX_C_SOURCE 200809L
|
||||
#include<stdlib.h>
|
||||
#include<stdio.h>
|
||||
#include<string.h>
|
||||
|
@ -94,15 +95,18 @@ void getsigcmds(unsigned int signal)
|
|||
|
||||
void setupsignals()
|
||||
{
|
||||
struct sigaction sa = {0};
|
||||
#ifndef __OpenBSD__
|
||||
/* initialize all real time signals with dummy handler */
|
||||
for (int i = SIGRTMIN; i <= SIGRTMAX; i++)
|
||||
signal(i, dummysighandler);
|
||||
/* initialize all real time signals with dummy handler */
|
||||
sa.sa_handler = dummysighandler;
|
||||
for (int i = SIGRTMIN; i <= SIGRTMAX; i++)
|
||||
sigaction(i, &sa, NULL);
|
||||
#endif
|
||||
|
||||
sa.sa_handler = sighandler;
|
||||
for (unsigned int i = 0; i < LENGTH(blocks); i++) {
|
||||
if (blocks[i].signal > 0)
|
||||
signal(SIGMINUS+blocks[i].signal, sighandler);
|
||||
sigaction(SIGMINUS+blocks[i].signal, &sa, NULL);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -121,7 +125,7 @@ void pstdout()
|
|||
{
|
||||
if (!getstatus(statusstr[0], statusstr[1]))//Only write out if text has changed.
|
||||
return;
|
||||
printf("%s\n",statusstr[0]);
|
||||
printf("all status %s\n",statusstr[0]);
|
||||
fflush(stdout);
|
||||
}
|
||||
|
||||
|
@ -130,21 +134,19 @@ void psomebar()
|
|||
{
|
||||
if (!getstatus(statusstr[0], statusstr[1]))//Only write out if text has changed.
|
||||
return;
|
||||
if (somebarFd < 0) {
|
||||
somebarFd = open(somebarPath, O_WRONLY|O_CLOEXEC);
|
||||
if (somebarFd < 0 && errno == ENOENT) {
|
||||
// assume somebar is not ready yet
|
||||
sleep(1);
|
||||
somebarFd = open(somebarPath, O_WRONLY|O_CLOEXEC);
|
||||
}
|
||||
if (somebarFd < 0) {
|
||||
perror("open");
|
||||
return;
|
||||
}
|
||||
}
|
||||
write(somebarFd, "status ", 7);
|
||||
write(somebarFd, statusstr[0], strlen(statusstr[0]));
|
||||
write(somebarFd, "\n", 1);
|
||||
if (somebarFd < 0) {
|
||||
somebarFd = open(somebarPath, O_WRONLY|O_CLOEXEC);
|
||||
if (somebarFd < 0 && errno == ENOENT) {
|
||||
// assume somebar is not ready yet
|
||||
sleep(1);
|
||||
somebarFd = open(somebarPath, O_WRONLY|O_CLOEXEC);
|
||||
}
|
||||
if (somebarFd < 0) {
|
||||
perror("open");
|
||||
return;
|
||||
}
|
||||
}
|
||||
dprintf(somebarFd, "all status %s\n", statusstr[0]);
|
||||
}
|
||||
|
||||
|
||||
|
@ -183,8 +185,8 @@ void termhandler()
|
|||
|
||||
void sigpipehandler()
|
||||
{
|
||||
close(somebarFd);
|
||||
somebarFd = -1;
|
||||
close(somebarFd);
|
||||
somebarFd = -1;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
|
@ -194,9 +196,15 @@ int main(int argc, char** argv)
|
|||
strncpy(delim, argv[++i], delimLen);
|
||||
else if (!strcmp("-p",argv[i]))
|
||||
writestatus = pstdout;
|
||||
else if (!strcmp("-s",argv[i]))
|
||||
strcpy(somebarPath, argv[++i]);
|
||||
}
|
||||
strcpy(somebarPath, getenv("XDG_RUNTIME_DIR"));
|
||||
strcat(somebarPath, "/somebar-0");
|
||||
|
||||
if (!strlen(somebarPath)) {
|
||||
strcpy(somebarPath, getenv("XDG_RUNTIME_DIR"));
|
||||
strcat(somebarPath, "/somebar-0");
|
||||
}
|
||||
|
||||
delimLen = MIN(delimLen, strlen(delim));
|
||||
delim[delimLen++] = '\0';
|
||||
signal(SIGTERM, termhandler);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue