removed bsd compatibility
This commit is contained in:
parent
aaaa94c41d
commit
a8f8dc8126
@ -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.
|
actions specified can run you are good to go.
|
||||||
|
|
||||||
## Compatibility
|
## Compatibility
|
||||||
hkd works using the evdev interface so the following systems work:
|
hkd only works in linux as it uses the linux-specific epoll and inotify apis
|
||||||
* linux
|
|
||||||
* FreeBSD
|
|
||||||
* dragonflyBSD
|
|
||||||
|
|
||||||
## Compiling
|
## Compiling
|
||||||
hkd doesn't require any libraries and has no dependency other than a standard C
|
hkd doesn't require any libraries and has no dependency other than a standard C
|
||||||
|
51
hkd.c
51
hkd.c
@ -10,19 +10,8 @@
|
|||||||
#include <poll.h>
|
#include <poll.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
|
#include <linux/input.h>
|
||||||
#ifdef __linux__
|
#include <sys/epoll.h>
|
||||||
#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
|
|
||||||
|
|
||||||
#define ANSI_COLOR_RED "\x1b[31m"
|
#define ANSI_COLOR_RED "\x1b[31m"
|
||||||
#define ANSI_COLOR_GREEN "\x1b[32m"
|
#define ANSI_COLOR_GREEN "\x1b[32m"
|
||||||
@ -83,45 +72,33 @@ int main (void)
|
|||||||
ssize_t rb; // Read bits
|
ssize_t rb; // Read bits
|
||||||
|
|
||||||
/* Prepare for epoll */
|
/* Prepare for epoll */
|
||||||
#if OS == linux
|
|
||||||
fprintf(stderr, yellow("using epoll based polling\n"));
|
fprintf(stderr, yellow("using epoll based polling\n"));
|
||||||
struct epoll_event epoll_read_ev;
|
struct epoll_event epoll_read_ev;
|
||||||
epoll_read_ev.events = EPOLLIN;
|
epoll_read_ev.events = EPOLLIN;
|
||||||
int ev_fd = epoll_create(1);
|
int ev_fd = epoll_create(1);
|
||||||
if (ev_fd < 0)
|
if (ev_fd < 0)
|
||||||
die("epoll_create");
|
die("epoll_create");
|
||||||
for (int i = 0; i < fd_num; i++)
|
for (int i = 0; i < fd_num; i++)
|
||||||
if (epoll_ctl(ev_fd, EPOLL_CTL_ADD, fds[i].fd, &epoll_read_ev) < 0)
|
if (epoll_ctl(ev_fd, EPOLL_CTL_ADD, fds[i].fd, &epoll_read_ev) < 0)
|
||||||
die("epoll_ctl");
|
die("epoll_ctl");
|
||||||
#endif
|
|
||||||
|
|
||||||
/* MAIN EVENT LOOP */
|
/* MAIN EVENT LOOP */
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// TODO: better error reporting
|
// TODO: better error reporting
|
||||||
/* On linux use epoll(2) as it gives better performance */
|
/* On linux use epoll(2) as it gives better performance */
|
||||||
#if OS == linux
|
|
||||||
static struct epoll_event ev_type;
|
static struct epoll_event ev_type;
|
||||||
if (epoll_wait(ev_fd, &ev_type, fd_num, -1) == -1 || term)
|
if (epoll_wait(ev_fd, &ev_type, fd_num, -1) == -1 || term)
|
||||||
break;
|
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 int i;
|
||||||
static unsigned int prev_size;
|
static unsigned int prev_size;
|
||||||
|
|
||||||
prev_size = pb.size;
|
prev_size = pb.size;
|
||||||
for (i = 0; i < fd_num; i++) {
|
for (i = 0; i < fd_num; i++) {
|
||||||
#if OS == linux
|
|
||||||
if (ev_type.events == EPOLLIN) {
|
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));
|
rb = read(fds[i].fd, &event, sizeof(struct input_event));
|
||||||
if (rb != sizeof(struct input_event)) continue;
|
if (rb != sizeof(struct input_event)) continue;
|
||||||
|
Loading…
Reference in New Issue
Block a user