# HG changeset patch # User Michael Pavone # Date 1552281743 25200 # Node ID 2b4d5cfec6d9cb9359f9b7cd4626ca552b4a3a53 # Parent fc9bea5ee07954c49b72a061bf335953a8810295 Grab keyboard devices at startup so keyboard input stops going to terminal while running diff -r fc9bea5ee079 -r 2b4d5cfec6d9 render_fbdev.c --- a/render_fbdev.c Sun Mar 10 22:11:32 2019 -0700 +++ b/render_fbdev.c Sun Mar 10 22:22:23 2019 -0700 @@ -1297,6 +1297,12 @@ void restore_tty(void) { ioctl(STDIN_FILENO, KDSETMODE, KD_TEXT); + for (int i = 0; i < cur_devices; i++) + { + if (device_types[i] == DEV_KEYBOARD) { + ioctl(device_fds[i], EVIOCGRAB, 0); + } + } } void render_init(int width, int height, char * title, uint8_t fullscreen) @@ -1380,11 +1386,15 @@ char *names[] = {"Keyboard", "Mouse", "Gamepad"}; ioctl(fd, EVIOCGNAME(sizeof(name)), name); printf("%s is a %s\n%s\n", filename, names[dtype - 1], name); + + if (dtype == DEV_GAMEPAD) { + handle_joy_added(joystick_counter++); + } else if (dtype == DEV_KEYBOARD && isatty(STDIN_FILENO)) { + ioctl(fd, EVIOCGRAB, 1); + } + //set FD to non-blocking mode for event polling fcntl(fd, F_SETFL, O_NONBLOCK); - if (dtype == DEV_GAMEPAD) { - handle_joy_added(joystick_counter++); - } cur_devices++; } free(filename);