changeset 1781:2b4d5cfec6d9

Grab keyboard devices at startup so keyboard input stops going to terminal while running
author Michael Pavone <pavone@retrodev.com>
date Sun, 10 Mar 2019 22:22:23 -0700
parents fc9bea5ee079
children b2bffd98063d
files render_fbdev.c
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- 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);