frontend: input: detect dead devices, always set keynames
[pcsx_rearmed.git] / frontend / linux / in_evdev.c
index e6bdad1..f11f3a4 100644 (file)
@@ -261,9 +261,11 @@ static void in_evdev_free(void *drv_data)
        free(dev);
 }
 
-static int in_evdev_get_bind_count(void)
+static const char * const *
+in_evdev_get_key_names(int *count)
 {
-       return KEY_CNT;
+       *count = KEY_CNT;
+       return in_evdev_keys;
 }
 
 static void or_binds(const int *binds, int key, int *result)
@@ -408,7 +410,8 @@ static int in_evdev_update_keycode(void *data, int *is_down)
        if (rd < (int) sizeof(ev)) {
                if (errno != EAGAIN) {
                        perror("in_evdev: error reading");
-                       sleep(1);
+                       //sleep(1);
+                       ret_kc = -2;
                }
                goto out;
        }
@@ -585,10 +588,11 @@ static int in_evdev_clean_binds(void *drv_data, int *binds, int *def_binds)
        in_evdev_t *dev = drv_data;
        int i, t, ret, offs, count = 0;
 
+       memset(keybits, 0, sizeof(keybits));
        ret = ioctl(dev->fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits);
        if (ret == -1) {
                perror("in_evdev: ioctl failed");
-               memset(keybits, 0xff, sizeof(keybits)); /* mark all as good */
+               // memset(keybits, 0xff, sizeof(keybits)); /* mark all as good */
        }
 
        if (dev->abs_lzone != 0) {
@@ -620,7 +624,7 @@ void in_evdev_init(void *vdrv)
        drv->prefix = in_evdev_prefix;
        drv->probe = in_evdev_probe;
        drv->free = in_evdev_free;
-       drv->get_bind_count = in_evdev_get_bind_count;
+       drv->get_key_names = in_evdev_get_key_names;
        drv->get_def_binds = in_evdev_get_def_binds;
        drv->clean_binds = in_evdev_clean_binds;
        drv->set_config = in_evdev_set_config;