From c8c04b04b5fe89e4a30dd1b88d336692a7dd260d Mon Sep 17 00:00:00 2001 From: Michael Pavone Date: Sun, 10 Mar 2019 22:22:23 -0700 Subject: Grab keyboard devices at startup so keyboard input stops going to terminal while running --- render_fbdev.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'render_fbdev.c') diff --git a/render_fbdev.c b/render_fbdev.c index 5f84cb1..e9624df 100755 --- a/render_fbdev.c +++ b/render_fbdev.c @@ -1297,6 +1297,12 @@ void window_setup(void) 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 @@ void render_init(int width, int height, char * title, uint8_t fullscreen) char *names[] = {"Keyboard", "Mouse", "Gamepad"}; ioctl(fd, EVIOCGNAME(sizeof(name)), name); printf("%s is a %s\n%s\n", filename, names[dtype - 1], name); - //set FD to non-blocking mode for event polling - fcntl(fd, F_SETFL, O_NONBLOCK); + 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); cur_devices++; } free(filename); -- cgit v1.2.3