Compare commits

...

10 commits

Author SHA1 Message Date
ef12a93743 change 2023-05-01 06:44:07 +03:00
Raphael Robatsch
28d7e79d47 release v1.0.1 2022-12-11 19:31:29 +01:00
Raphael Robatsch
d575da7a3c add changelog 2022-12-10 13:55:30 +01:00
Raphael Robatsch
221daf2f5d use sigaction(2) instead of signal(2)
To prevent crashes
2022-12-03 19:12:30 +01:00
Raphael Robatsch
e7214b60fa add manpage 2022-04-20 22:22:07 +02:00
Leonardo Hernández Hernández
d072368de0 allow user to set path of the fifo 2022-04-19 08:49:11 +02:00
Leonardo Hernández Hernández
ed1e85d804 use dprintf() instead of write() calls 2022-04-19 08:42:34 +02:00
Raphael Robatsch
c6d81febf6 replace mailing list 2021-11-15 19:36:59 +01:00
Raphael Robatsch
bf9cbfbf2b style: spaces -> tabs 2021-10-29 20:39:29 +02:00
Raphael Robatsch
968842909e update readme 2021-10-28 17:27:05 +02:00
6 changed files with 75 additions and 30 deletions

6
CHANGELOG.md Normal file
View 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

View file

@ -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

View file

@ -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.

View file

@ -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
View 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

View file

@ -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);