Skip to content

Instantly share code, notes, and snippets.

@toniz4
Created August 17, 2020 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save toniz4/41d168719e22bf7bc4ecff09d424b7d2 to your computer and use it in GitHub Desktop.
Save toniz4/41d168719e22bf7bc4ecff09d424b7d2 to your computer and use it in GitHub Desktop.
diff -up dwmblocks/dwmblocks.c dwmblocksnew/dwmblocks.c
--- dwmblocks/dwmblocks.c 2020-08-17 04:10:55.645971091 -0300
+++ dwmblocksnew/dwmblocks.c 2020-08-17 03:55:40.295990745 -0300
@@ -26,6 +26,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();
@@ -43,15 +44,32 @@ static int screen;
static Window root;
static char statusbar[LENGTH(blocks)][CMDLENGTH] = {0};
static char statusstr[2][STATUSLENGTH];
+static char button[] = "\0";
static int statusContinue = 1;
static void (*writestatus) () = setroot;
//opens process *cmd and stores output in *output
void getcmd(const Block *block, char *output)
{
+ if (block->signal)
+ {
+ output[0] = block->signal;
+ output++;
+ }
strcpy(output, block->icon);
char *cmd = block->command;
- FILE *cmdf = popen(cmd,"r");
+ FILE *cmdf;
+ if (*button)
+ {
+ setenv("BUTTON", button, 1);
+ cmdf = popen(cmd,"r");
+ *button = '\0';
+ unsetenv("BUTTON");
+ }
+ else
+ {
+ cmdf = popen(cmd,"r");
+ }
if (!cmdf)
return;
char c;
@@ -95,10 +113,16 @@ 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);
}
}
@@ -156,6 +180,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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment