From a8f8dc812622fa5583c42a49104191322854a4fb Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Tue, 12 May 2020 22:54:15 +0200 Subject: [PATCH] removed bsd compatibility --- README.md | 5 +---- hkd.c | 51 ++++++++++++++------------------------------------- 2 files changed, 15 insertions(+), 41 deletions(-) diff --git a/README.md b/README.md index 78a2bce..f517fca 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/hkd.c b/hkd.c index 5d5a219..694ddee 100644 --- a/hkd.c +++ b/hkd.c @@ -10,19 +10,8 @@ #include #include #include - -#ifdef __linux__ - #define OS linux - #include - #include -#endif -#ifdef __FreeBSD__ - #define OS bsd - #include -#endif -#ifndef OS - #define OS unix -#endif +#include +#include #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;