Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions beep.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,17 +106,29 @@ void do_beep(int freq) {
perror("ioctl");
}
} else {
/* BEEP_TYPE_EVDEV */
struct input_event e;

e.type = EV_SND;
e.code = SND_TONE;
e.value = freq;
/* BEEP_TYPE_EVDEV */
struct input_event e;
unsigned long evbit = 0;

e.type = EV_SND;

/* check supported events and act accordingly */
ioctl(console_fd, EVIOCGBIT(EV_SND, sizeof(evbit)), &evbit);
if(evbit & (1 << SND_TONE)) {
e.code = SND_TONE;
e.value = freq;
} else if(evbit & (1 << SND_BELL)) {
e.code = SND_BELL;
e.value = (freq != 0);
} else {
perror("no supported event type");
return;
}

if(write(console_fd, &e, sizeof(struct input_event)) < 0) {
putchar('\a'); /* See above */
perror("write");
}
if(write(console_fd, &e, sizeof(struct input_event)) < 0) {
putchar('\a'); /* See above */
perror("write");
}
}
}

Expand Down