diff --git a/src/main.c b/src/main.c index 7ae8ef8..a0a56f9 100644 --- a/src/main.c +++ b/src/main.c @@ -60,6 +60,7 @@ typedef struct Mouse { typedef struct Input { int kbd_fd; int mouse_fd; + int home_fd; char map[KEY_MAX / 8 + 1]; u8 controller; Mouse mouse; @@ -84,6 +85,12 @@ init_input(void) { fprintf(stderr, "error: couldn't open keyboard %s: %s.\n", KBD_PATH, strerror(errno)); } + // NOTE: nook home and power buttons event handler. + in.home_fd = open("/dev/input/event1", O_RDONLY | O_NONBLOCK); + if (in.home_fd == -1) { + fprintf(stderr, "error: couldn't open home buttons %s: %s.\n", "/dev/input/event1", strerror(errno)); + } + // in.mouse_fd = open(MOUSE_PATH, O_RDONLY | O_NONBLOCK); in.mouse_fd = open("/dev/input/event2", O_RDONLY | O_NONBLOCK); if (in.mouse_fd == -1) { @@ -161,10 +168,25 @@ poll_mouse(void) { } } +void +poll_home(void) { + if (in.home_fd == -1) { + return; + } + + struct input_event event; + if (read(in.home_fd, &event, sizeof(event)) != -1) { + if (event.code == 102 && event.value == 1) { + exit(EXIT_SUCCESS); + } + } +} + void poll_input(void) { poll_keyboard(); poll_mouse(); + poll_home(); } void