diff --git a/input.cpp b/input.cpp index c3ca788..d8ea1a1 100644 --- a/input.cpp +++ b/input.cpp @@ -9,12 +9,12 @@ #include #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "input.h" #include "user_io.h" @@ -1376,68 +1376,98 @@ static uint32_t mouse_timer = 0; #define BTN_TGL 100 #define BTN_OSD 101 -static int uinp_fd = -1; -static int input_uinp_setup() -{ - if (uinp_fd <= 0) - { - struct uinput_user_dev uinp; - - if (!(uinp_fd = open("/dev/uinput", O_WRONLY | O_NDELAY))) - { - printf("Unable to open /dev/uinput\n"); - uinp_fd = -1; - return 0; - } - - memset(&uinp, 0, sizeof(uinp)); - strncpy(uinp.name, UINPUT_NAME, UINPUT_MAX_NAME_SIZE); - uinp.id.version = 4; - uinp.id.bustype = BUS_USB; - - ioctl(uinp_fd, UI_SET_EVBIT, EV_KEY); - for (int i = 0; i < 256; i++) ioctl(uinp_fd, UI_SET_KEYBIT, i); - - write(uinp_fd, &uinp, sizeof(uinp)); - if (ioctl(uinp_fd, UI_DEV_CREATE)) - { - printf("Unable to create UINPUT device."); - close(uinp_fd); - uinp_fd = -1; - return 0; - } - } - return 1; -} - -void input_uinp_destroy() -{ - if (uinp_fd > 0) - { - ioctl(uinp_fd, UI_DEV_DESTROY); - close(uinp_fd); - uinp_fd = -1; - } -} - -static void uinp_send_key(uint16_t key, int press) -{ - if (uinp_fd > 0) - { - static struct input_event event; - - memset(&event, 0, sizeof(event)); - gettimeofday(&event.time, NULL); - event.type = EV_KEY; - event.code = key; - event.value = press ? 1 : 0; - write(uinp_fd, &event, sizeof(event)); - event.type = EV_SYN; - event.code = SYN_REPORT; - event.value = 0; - write(uinp_fd, &event, sizeof(event)); - } -} +static int uinp_fd = -1; +static int input_uinp_setup() +{ + if (uinp_fd <= 0) + { + struct uinput_user_dev uinp; + + if (!(uinp_fd = open("/dev/uinput", O_WRONLY | O_NDELAY))) + { + printf("Unable to open /dev/uinput\n"); + uinp_fd = -1; + return 0; + } + + memset(&uinp, 0, sizeof(uinp)); + strncpy(uinp.name, UINPUT_NAME, UINPUT_MAX_NAME_SIZE); + uinp.id.version = 4; + uinp.id.bustype = BUS_USB; + + ioctl(uinp_fd, UI_SET_EVBIT, EV_KEY); + for (int i = 0; i < 256; i++) ioctl(uinp_fd, UI_SET_KEYBIT, i); + + write(uinp_fd, &uinp, sizeof(uinp)); + if (ioctl(uinp_fd, UI_DEV_CREATE)) + { + printf("Unable to create UINPUT device."); + close(uinp_fd); + uinp_fd = -1; + return 0; + } + } + return 1; +} + +void input_uinp_destroy() +{ + if (uinp_fd > 0) + { + ioctl(uinp_fd, UI_DEV_DESTROY); + close(uinp_fd); + uinp_fd = -1; + } +} + +static unsigned long uinp_repeat = 0; +static struct input_event uinp_ev; +static void uinp_send_key(uint16_t key, int press) +{ + if (uinp_fd > 0) + { + if (!uinp_ev.value && press) + { + uinp_repeat = GetTimer(REPEATDELAY); + } + + memset(&uinp_ev, 0, sizeof(uinp_ev)); + gettimeofday(&uinp_ev.time, NULL); + uinp_ev.type = EV_KEY; + uinp_ev.code = key; + uinp_ev.value = press; + write(uinp_fd, &uinp_ev, sizeof(uinp_ev)); + + static struct input_event ev; + ev.time = uinp_ev.time; + ev.type = EV_SYN; + ev.code = SYN_REPORT; + ev.value = 0; + write(uinp_fd, &ev, sizeof(ev)); + } +} + +static void uinp_check_key() +{ + if (uinp_fd > 0) + { + if (!grabbed) + { + if (uinp_ev.value && CheckTimer(uinp_repeat)) + { + uinp_repeat = GetTimer(REPEATRATE); + uinp_send_key(uinp_ev.code, 2); + } + } + else + { + if (uinp_ev.value) + { + uinp_send_key(uinp_ev.code, 0); + } + } + } +} static void mouse_cb(unsigned char b, int16_t x = 0, int16_t y = 0, int16_t w = 0) { @@ -2971,6 +3001,8 @@ int input_poll(int getchar) int ret = input_test(getchar); if (getchar) return ret; + uinp_check_key(); + static int prev_dx = 0; static int prev_dy = 0; diff --git a/menu.cpp b/menu.cpp index c4dfa3d..1471f0a 100644 --- a/menu.cpp +++ b/menu.cpp @@ -3952,8 +3952,8 @@ void HandleUI(void) ttypid = fork(); if (!ttypid) { - system("/sbin/agetty -a root -l /tmp/script --nohostname -L tty2 xterm"); - exit(0); + execl("/sbin/agetty", "/sbin/agetty", "-a", "root", "-l", "/tmp/script", "--nohostname", "-L", "tty2", "xterm", NULL); + exit(0); //should never be reached } } else