removed bsd compatibility

xkbcommon
Alessandro Mauri 4 years ago
parent aaaa94c41d
commit a8f8dc8126
  1. 5
      README.md
  2. 51
      hkd.c

@ -4,10 +4,7 @@ this means, that hotkeys will work in x11 waylnad and even tty, as long as the
actions specified can run you are good to go.
## Compatibility
hkd works using the evdev interface so the following systems work:
* linux
* FreeBSD
* dragonflyBSD
hkd only works in linux as it uses the linux-specific epoll and inotify apis
## Compiling
hkd doesn't require any libraries and has no dependency other than a standard C

51
hkd.c

@ -10,19 +10,8 @@
#include <poll.h>
#include <signal.h>
#include <sys/wait.h>
#ifdef __linux__
#define OS linux
#include <linux/input.h>
#include <sys/epoll.h>
#endif
#ifdef __FreeBSD__
#define OS bsd
#include <dev/evdev/input.h>
#endif
#ifndef OS
#define OS unix
#endif
#include <linux/input.h>
#include <sys/epoll.h>
#define ANSI_COLOR_RED "\x1b[31m"
#define ANSI_COLOR_GREEN "\x1b[32m"
@ -83,45 +72,33 @@ int main (void)
ssize_t rb; // Read bits
/* Prepare for epoll */
#if OS == linux
fprintf(stderr, yellow("using epoll based polling\n"));
struct epoll_event epoll_read_ev;
epoll_read_ev.events = EPOLLIN;
int ev_fd = epoll_create(1);
if (ev_fd < 0)
die("epoll_create");
for (int i = 0; i < fd_num; i++)
if (epoll_ctl(ev_fd, EPOLL_CTL_ADD, fds[i].fd, &epoll_read_ev) < 0)
die("epoll_ctl");
#endif
fprintf(stderr, yellow("using epoll based polling\n"));
struct epoll_event epoll_read_ev;
epoll_read_ev.events = EPOLLIN;
int ev_fd = epoll_create(1);
if (ev_fd < 0)
die("epoll_create");
for (int i = 0; i < fd_num; i++)
if (epoll_ctl(ev_fd, EPOLL_CTL_ADD, fds[i].fd, &epoll_read_ev) < 0)
die("epoll_ctl");
/* MAIN EVENT LOOP */
for (;;) {
// TODO: better error reporting
/* On linux use epoll(2) as it gives better performance */
#if OS == linux
static struct epoll_event ev_type;
if (epoll_wait(ev_fd, &ev_type, fd_num, -1) == -1 || term)
break;
// TODO: use and test kqueue(2) for BSD systems
/* On other systems use poll(2) to wait por a file dscriptor
* to become ready for reading. */
#else // TODO: add unix and bsd cases
if (poll(fds, fd_num, -1) != -1 || term)
break;
#endif
static int i;
static unsigned int prev_size;
prev_size = pb.size;
for (i = 0; i < fd_num; i++) {
#if OS == linux
if (ev_type.events == EPOLLIN) {
#else // TODO: add unix and bsd cases
if (fds[i].revents == fds[i].events) {
#endif
rb = read(fds[i].fd, &event, sizeof(struct input_event));
if (rb != sizeof(struct input_event)) continue;

Loading…
Cancel
Save