From a440e14c7c3bf681710173b32af25160eaef9c90 Mon Sep 17 00:00:00 2001 From: pbentes Date: Tue, 6 May 2025 22:33:25 +0100 Subject: [PATCH] Apply statuscmd --- dwmblocks.c | 35 ++++++++++++++++++-- patches/dwmblocks-statuscmd-b6b0be4.diff | 42 ++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 patches/dwmblocks-statuscmd-b6b0be4.diff diff --git a/dwmblocks.c b/dwmblocks.c index c8f77b7..5b0aa59 100644 --- a/dwmblocks.c +++ b/dwmblocks.c @@ -28,6 +28,7 @@ typedef struct { void dummysighandler(int num); #endif void sighandler(int num); +void buttonhandler(int sig, siginfo_t *si, void *ucontext); void getcmds(int time); void getsigcmds(unsigned int signal); void setupsignals(); @@ -52,16 +53,33 @@ static void (*writestatus) () = pstdout; static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0}; static char statusstr[2][STATUSLENGTH]; ++static char button[] = "\0"; static int statusContinue = 1; static int returnStatus = 0; //opens process *cmd and stores output in *output void getcmd(const Block *block, char *output) { + if (block->signal) + { + output[0] = block->signal; + output++; + } //make sure status is same until output is ready char tempstatus[CMDLENGTH] = {0}; strcpy(tempstatus, block->icon); - FILE *cmdf = popen(block->command, "r"); + FILE *cmdf; + if (*button) + { + setenv("BUTTON", button, 1); + cmdf = popen(block->command,"r"); + *button = '\0'; + unsetenv("BUTTON"); + } + else + { + cmdf = popen(block->command,"r"); + } if (!cmdf) return; int i = strlen(block->icon); @@ -109,9 +127,15 @@ void setupsignals() signal(i, dummysighandler); #endif + struct sigaction sa; for (unsigned int i = 0; i < LENGTH(blocks); i++) { - if (blocks[i].signal > 0) + if (blocks[i].signal > 0) { signal(SIGMINUS+blocks[i].signal, sighandler); + sigaddset(&sa.sa_mask, SIGRTMIN+blocks[i].signal); // ignore signal when handling SIGUSR1 + } + sa.sa_sigaction = buttonhandler; + sa.sa_flags = SA_SIGINFO; + sigaction(SIGUSR1, &sa, NULL); } } @@ -177,6 +201,13 @@ void dummysighandler(int signum) { return; } + +void buttonhandler(int sig, siginfo_t *si, void *ucontext) +{ + *button = '0' + si->si_value.sival_int & 0xff; + getsigcmds(si->si_value.sival_int >> 8); + writestatus(); +} #endif void sighandler(int signum) diff --git a/patches/dwmblocks-statuscmd-b6b0be4.diff b/patches/dwmblocks-statuscmd-b6b0be4.diff new file mode 100644 index 0000000..37c69c1 --- /dev/null +++ b/patches/dwmblocks-statuscmd-b6b0be4.diff @@ -0,0 +1,42 @@ +diff -up a/dwmblocks.c b/dwmblocks.c +--- a/dwmblocks.c 2020-12-22 14:25:05.289247774 +0200 ++++ b/dwmblocks.c 2020-12-22 14:29:39.744943965 +0200 +@@ -28,6 +28,7 @@ typedef struct { + void dummysighandler(int num); + #endif + void sighandler(int num); ++void buttonhandler(int sig, siginfo_t *si, void *ucontext); + void getcmds(int time); + void getsigcmds(unsigned int signal); + void setupsignals(); +@@ -105,9 +123,15 @@ void setupsignals() + signal(i, dummysighandler); + #endif + ++ struct sigaction sa; + for (unsigned int i = 0; i < LENGTH(blocks); i++) { +- if (blocks[i].signal > 0) ++ if (blocks[i].signal > 0) { + signal(SIGMINUS+blocks[i].signal, sighandler); ++ sigaddset(&sa.sa_mask, SIGRTMIN+blocks[i].signal); // ignore signal when handling SIGUSR1 ++ } ++ sa.sa_sigaction = buttonhandler; ++ sa.sa_flags = SA_SIGINFO; ++ sigaction(SIGUSR1, &sa, NULL); + } + + } +@@ -173,6 +197,13 @@ void dummysighandler(int signum) + { + return; + } ++ ++void buttonhandler(int sig, siginfo_t *si, void *ucontext) ++{ ++ *button = '0' + si->si_value.sival_int & 0xff; ++ getsigcmds(si->si_value.sival_int >> 8); ++ writestatus(); ++} + #endif + + void sighandler(int signum)