dwm/patch/fsignal.c

40 lines
1.1 KiB
C

int
fake_signal(void)
{
char fsignal[256];
char indicator[9] = "fsignal:";
char str_signum[16];
int i, v, signum;
size_t len_fsignal, len_indicator = strlen(indicator);
// Get root name property
if (gettextprop(root, XA_WM_NAME, fsignal, sizeof(fsignal))) {
len_fsignal = strlen(fsignal);
// Check if this is indeed a fake signal
if (len_indicator > len_fsignal ? 0 : strncmp(indicator, fsignal, len_indicator) == 0) {
memcpy(str_signum, &fsignal[len_indicator], len_fsignal - len_indicator);
str_signum[len_fsignal - len_indicator] = '\0';
// Convert string value into managable integer
for (i = signum = 0; i < strlen(str_signum); i++) {
v = str_signum[i] - '0';
if (v >= 0 && v <= 9) {
signum = signum * 10 + v;
}
}
// Check if a signal was found, and if so handle it
if (signum)
for (i = 0; i < LENGTH(signals); i++)
if (signum == signals[i].signum && signals[i].func)
signals[i].func(&(signals[i].arg));
// A fake signal was sent
return 1;
}
}
// No fake signal was sent, so proceed with update
return 0;
}