Files
furui/evdev.c
2026-04-01 22:30:31 +09:00

85 lines
2.0 KiB
C

/*
This file is part of Furui.
Furui is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Furui is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Furui. If not, see <https://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include "evdev.h"
struct libevdev *furui_evdev_open(const char *path) {
int fd;
struct libevdev *dev;
int err;
fd = open(path, O_RDONLY | O_NONBLOCK);
if (fd == -1) {
perror("open");
exit(EXIT_FAILURE);
}
dev = libevdev_new();
if (dev == NULL) {
perror("libevdev_new");
exit(EXIT_FAILURE);
}
err = libevdev_set_fd(dev, fd);
if (err < 0) {
perror("libevdev_set_fd");
exit(EXIT_FAILURE);
}
err = libevdev_grab(dev, LIBEVDEV_GRAB);
if (err < 0) {
perror("libevdev_grab");
exit(EXIT_FAILURE);
}
return dev;
}
void furui_evdev_set_delay(struct libevdev *dev, int delay) {
#if 0
if (!libevdev_has_event_type(dev, EV_REP)) {
fprintf(stderr, "Does not have repeat capability\n");
exit(EXIT_FAILURE);
}
/* XXX does not work */
if (libevdev_set_event_value(dev, EV_REP, REP_DELAY, delay)) {
fprintf(stderr, "Could not set repeat delay\n");
exit(EXIT_FAILURE);
}
#else
int ret;
unsigned int repeat[2];
ret = ioctl(libevdev_get_fd(dev), EVIOCGREP, repeat);
if (ret == -1) {
perror("ioctl");
fprintf(stderr, "Could not get repeat rate\n");
exit(EXIT_FAILURE);
}
repeat[0] = delay;
ret = ioctl(libevdev_get_fd(dev), EVIOCSREP, repeat);
if (ret == -1) {
perror("ioctl");
fprintf(stderr, "Could not set repeat delay\n");
exit(EXIT_FAILURE);
}
#endif
}