Fix mouse click handling

This commit is contained in:
allacee 2021-08-31 14:48:19 +03:00 committed by Utkarsh Verma
parent 968ceac7f3
commit 9b42cdba27
No known key found for this signature in database
GPG Key ID: 817656CF818EFCCC
2 changed files with 10 additions and 17 deletions

View File

@ -1,5 +1,5 @@
#define CMDLENGTH 50
#define DELIMITER ""
#define DELIMITER "<"
typedef struct {
char* command;
@ -18,4 +18,5 @@ static Block blocks[] = {
{"sb-volume", 0, 5},
{"sb-battery", 5, 6},
{"sb-date", 20, 7},
{"sb-network", 5, 8}};
{"sb-network", 5, 8}
};

22
main.c
View File

@ -100,17 +100,14 @@ void setRoot() {
XCloseDisplay(dpy);
}
void buttonHandler(int sig, siginfo_t *si, void *ucontext) {
sig = si->si_value.sival_int >> 8;
void signalHandler(int sig, siginfo_t *si, void *ucontext) {
sig -= SIGRTMIN;
int i = 0;
while (blocks[i].signal != sig) i++;
const char button[2] = {'0' + si->si_value.sival_int & 0xff, '\0'};
getCommand(i, button);
}
void signalHandler(int signal) { getSignalCommand(signal - SIGRTMIN); }
void termHandler(int signal) {
statusContinue = 0;
exit(EXIT_SUCCESS);
@ -142,17 +139,12 @@ void setupSignals() {
// Handle block update signals
struct sigaction sa;
for (int i = 0; i < LEN(blocks); i++) {
if (blocks[i].signal > 0) {
signal(SIGRTMIN + blocks[i].signal, signalHandler);
sigaddset(&sa.sa_mask, SIGRTMIN + blocks[i].signal);
}
}
// Handle mouse events
sa.sa_sigaction = buttonHandler;
sa.sa_flags = SA_SIGINFO;
sigaction(SIGUSR1, &sa, NULL);
sa.sa_sigaction = signalHandler;
for (int i = 0; i < LEN(blocks); i++) {
if (blocks[i].signal > 0)
sigaction(SIGRTMIN + blocks[i].signal, &sa, NULL);
}
// Handle exit of forks
struct sigaction sigchld_action = {