Created
June 2, 2020 22:51
-
-
Save josefandersson/3d72975d8aa40e7379111ce3bf3817bb to your computer and use it in GitHub Desktop.
Send signals to dwmblock blocks
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example usage:
dwmblockssendsignal $(pgrep -n dwmblocks) 13 2
...would send "$BUTTON" 2 to block with "Update Signal" 13 in blocks[] in blocks.h.