commit 7731b234e3e2044ee0373f42ec4ad5672f66d5fe
parent 2c11fc61c9556b56013d3eec0bb84f65d9c81953
Author: Gregory Williams <gregwills85@gmail.com>
Date: Tue, 11 Nov 2025 21:10:42 -0700
someblocks.c: Add support for dwlb
Adds option '-b' to support dwlb bar: https://github.com/kolunmi/dwlb
If this option is selected, a socket will be opened to communicate with
dwlb status bar and status text will be written here.
Signed-off-by: Gregory Williams <gregwills85@gmail.com>
Diffstat:
3 files changed, 41 insertions(+), 9 deletions(-)
diff --git a/README.md b/README.md
@@ -20,3 +20,5 @@ This is so you can edit your status bar commands and they will not get overwritt
# patches
Here are some patches to someblocks that add features that I either don't want to merge in, or that require a dwl/somebar patch to work.
I do not maintain these but I will take pull requests to update them.
+# dwlb
+To run and output status to dwlb, use 'someblocks -b'
diff --git a/blocks.def.h b/blocks.def.h
@@ -1,12 +1,8 @@
//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},
-
- /* Updates whenever "pkill -SIGRTMIN+10 someblocks" is ran */
- /* {"", "date '+%b %d (%a) %I:%M%p'", 0, 10}, */
+ {"", "gde-sbclock day", 60, 0},
+ {"", "gde-sbclock time", 60, 0},
};
diff --git a/someblocks.c b/someblocks.c
@@ -6,6 +6,9 @@
#include<fcntl.h>
#include<errno.h>
#include<signal.h>
+#include<stdbool.h>
+#include<sys/socket.h>
+#include<sys/un.h>
#ifdef __OpenBSD__
#define SIGPLUS SIGUSR1+1
#define SIGMINUS SIGUSR1-1
@@ -149,6 +152,32 @@ void psomebar()
dprintf(somebarFd, "status %s\n", statusstr[0]);
}
+void pdwlb()
+{
+ int dwlbSock = -1;
+ struct sockaddr_un sockaddr;
+
+ if (!getstatus(statusstr[0], statusstr[1]))//Only write out if text has changed.
+ return;
+
+ if ((dwlbSock = socket(AF_UNIX, SOCK_STREAM, 1)) == -1) {
+ perror("socket");
+ return;
+ }
+ snprintf(sockaddr.sun_path, sizeof(sockaddr.sun_path), "%s", somebarPath);
+ sockaddr.sun_family = AF_UNIX;
+
+ /* Try a couple times dwlb may not be ready */
+ for (int i = 0; i < 5; i++) {
+ if (connect(dwlbSock, (struct sockaddr *)&sockaddr, sizeof(struct sockaddr_un)) == -1) {
+ sleep(1);
+ continue;
+ }
+ break;
+ }
+ dprintf(dwlbSock, "all status %s", statusstr[0]);
+ close(dwlbSock);
+}
void statusloop()
{
@@ -192,12 +221,17 @@ void sigpipehandler()
int main(int argc, char** argv)
{
for (int i = 0; i < argc; i++) {//Handle command line arguments
- if (!strcmp("-d",argv[i]))
+ if (!strcmp("-d",argv[i])) {
strncpy(delim, argv[++i], delimLen);
- else if (!strcmp("-p",argv[i]))
+ } else if (!strcmp("-p",argv[i])) {
writestatus = pstdout;
- else if (!strcmp("-s",argv[i]))
+ } else if (!strcmp("-b",argv[i])) {
+ writestatus = pdwlb;
+ strcpy(somebarPath, getenv("XDG_RUNTIME_DIR"));
+ strcat(somebarPath, "/dwlb/dwlb-0");
+ } else if (!strcmp("-s",argv[i])) {
strcpy(somebarPath, argv[++i]);
+ }
}
if (!strlen(somebarPath)) {