Skip to content

Instantly share code, notes, and snippets.

@josefandersson
Created June 2, 2020 22:51
Show Gist options
  • Save josefandersson/3d72975d8aa40e7379111ce3bf3817bb to your computer and use it in GitHub Desktop.
Save josefandersson/3d72975d8aa40e7379111ce3bf3817bb to your computer and use it in GitHub Desktop.
Send signals to dwmblock blocks
#include <signal.h>
#include <stdio.h>
static int send(int pid, int sigval);
int
main(int argc, char* argv[])
{
if (argc < 4) {
printf("Usage: command <PID> <BLOCK> <DATA>\n");
return 0;
}
int pid = atoi(argv[1]);
int blocksig = atoi(argv[2]);
int data = atoi(argv[3]);
if (send(pid, (blocksig << 8) | data) == 0) return 0;
else return 1;
}
int
send(int pid, int sival)
{
union sigval sv;
sv.sival_int = sival;
return sigqueue(pid, SIGUSR1, sv);
}
@josefandersson
Copy link
Author

Example usage: dwmblockssendsignal $(pgrep -n dwmblocks) 13 2
...would send "$BUTTON" 2 to block with "Update Signal" 13 in blocks[] in blocks.h.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment