diff --git a/hid-linux.c b/hid-linux.c
-index f2e0bce..8cb3e30 100644
+index f2e0bce..c011dbd 100644
--- a/hid-linux.c
+++ b/hid-linux.c
@@ -43,11 +43,8 @@
#define DEBUG_HID_LINUX
-@@ -64,468 +61,592 @@ while (0);
+@@ -64,468 +61,602 @@ while (0);
# define DEBUG(_format_, args...) (void)0
#endif
};
-static char keycode2ascii(int keycode)
++static int hid_linux_detect_binding (void);
++static void hid_linux_key_inject (int code, uint32_t keycode);
++static char *hid_linux_xs_read (const char *key);
++
++
+static char
+keycode2ascii (int keycode)
{
+ DEBUG ("binding payload %d\n",
+ (int) (linux_hid_binding[i].payload));
+ linux_hid_binding[i].cb (linux_hid_binding[i].payload);
-+ linux_hid_reset_keyboard ();
++ hid_linux_reset_keyboard ();
+ return 1;
+ }
}
- return;
- hid_linux_key_inject(code, keycode);
+ if (code == 1)
-+ if (linux_hid_detect_binding ())
++ if (hid_linux_detect_binding ())
+ return;
-+ linux_hid_key_inject (code, keycode);
++ hid_linux_key_inject (code, keycode);
}
-static void hid_linux_read(void *opaque)
+ double div = 1;
+ char *str = NULL;
+
-+ str = linux_hid_xs_read ("touchpad-limit");
++ str = hid_linux_xs_read ("touchpad-limit");
+ if (str)
+ l = strtol (str, NULL, 10);
-+ str = linux_hid_xs_read ("touchpad-div");
++ str = hid_linux_xs_read ("touchpad-div");
+ if (str)
+ div = strtol (str, NULL, 10) / 1000.;
+
+ for (i = 0; i < 256; i++)
+ if (linux_hid_driver.key_status[i])
+ {
-+ linux_hid_key_inject (0, i);
++ hid_linux_key_inject (0, i);
+ linux_hid_driver.key_status[i] = 0;
+ }
-+}
-+
-+
+ }
+
+
+static int
+hid_linux_secure_read (int fd)
+{
+
+ if (read_sz <= 0)
+ return -1;
-+
+
+-static void hid_linux_redirect_fds(int *fd, IOHandler *cb)
+ for (i = 0; i < read_sz / (sizeof (struct input_event)); i++)
+ if (event[i].type == EV_KEY && event[i].code < BTN_MOUSE &&
+ event[i].value > 0)
+ linux_hid_driver.secure_key (keycode2ascii (event[i].code));
+
+ return 0;
- }
-
-
-
--static void hid_linux_redirect_fds(int *fd, IOHandler *cb)
-+static int hid_linux_do_read (void *opaque)
++}
++
++
++
++static int
++hid_linux_do_read (void *opaque)
{
- assert(fd != NULL);
+ int result;
- fd++;
+ /* The read failed - stop watching and close the fd */
+
-+ fprintf(stderr,"read failed on /dev/input/event%d fd=%d dropping it\n",slot,linux_hid_driver.fds[slot]);
++ fprintf (stderr,
++ "read failed on /dev/input/event%d fd=%d dropping it\n", slot,
++ linux_hid_driver.fds[slot]);
+
+ qemu_set_fd_handler (linux_hid_driver.fds[slot], NULL, NULL, NULL);
+ close (linux_hid_driver.fds[slot]);
+
+
+ if (strcasestr (name, "keyboard"))
-+ {
+ {
+- if (fd != -1)
+- close(fd);
+ fprintf (stderr, "/dev/input/event%d added keyboard on fd %d (%s)\n",
+ slot, fd, name);
+ linux_hid_driver.types[slot] = HID_TYPE_KEYBOARD;
-+
+
+- sprintf(path, "%s%i", EVENT_PATH, i++);
+ set_handler (slot, linux_hid_driver.keyboard_grabbed);
-+
+
+- if (i>=HID_LINUX_MAX_DEV_NO)
+- break;
+ }
+ else
- {
-- if (fd != -1)
-- close(fd);
++ {
+ fprintf (stderr, "/dev/input/event%d added mouse on fd %d (%s)\n",
+ slot, fd, name);
+ linux_hid_driver.types[slot] = HID_TYPE_MOUSE;
+ set_handler (slot, linux_hid_driver.mouse_grabbed);
+ }
-- sprintf(path, "%s%i", EVENT_PATH, i++);
-
-- if (i>=HID_LINUX_MAX_DEV_NO)
-- break;
-+ return 0;
-+}
-
- if (stat(path, &st) == -1)
- continue;
- assert(c != HID_LINUX_MAX_DEV);
- if (hid_linux_driver.controller_paths[c])
- continue;
++ return 0;
++}
- if ((fd = open(path, O_RDONLY)) == -1)
- break;
- DEBUG("Input get name failed on %s\n", path);
- break;
- }
-+static void
-+hid_linux_scan (void *opaque)
-+{
-+ char name[128];
-+ int i;
- if (ioctl(fd, EVIOCGID, &id) == -1)
- {
- DEBUG("Input get id failed on %s\n", path);
- continue;
- }
-+ fprintf (stderr, "hid_linux_scan()\n");
- /* Only get devices on usb and i8042 */
- if (id.bustype != BUS_I8042 && id.bustype != BUS_USB)
- continue;
++static void
++hid_linux_scan (void *opaque)
++{
++ char name[128];
++ int i;
- if (strcasestr(name, "keyboard"))
- {
- DEBUG("Add %s %s as a mouse, fd=%d, bus=%d\n", path, name, fd, id.bustype);
- controllers = hid_linux_driver.mouse_fds;
- }
-+ for (i = 0; i < N_DEVS; ++i)
-+ {
++ fprintf (stderr, "hid_linux_scan()\n");
- for ( j = 0; j < (HID_LINUX_MAX_DEV / 2) && controllers[j] != -1; j++)
- ;
- assert(j != (HID_LINUX_MAX_DEV / 2));
-+/* Do We already have this device open and working */
-+ if (linux_hid_driver.fds[i] >= 0)
-+ continue;
- controllers[j] = fd;
- controllers[j + 1] = -1;
++ for (i = 0; i < N_DEVS; ++i)
++ {
++
++/* Do We already have this device open and working */
++ if (linux_hid_driver.fds[i] >= 0)
++ continue;
++
+ sprintf (name, "/dev/input/event%d", i);
- if (grab)
- hid_linux_driver.controller_paths[c + 1] = NULL;
+/* Switch to NBIO*/
+ {
-+ long arg;
++ long arg = 0;
+ arg = fcntl (linux_hid_driver.fds[i], F_GETFL, arg);
+ arg |= O_NONBLOCK;
+ fcntl (linux_hid_driver.fds[i], F_SETFL, arg);
- close(fd);
+
+/* Schedule ourselves */
-+ qemu_mod_timer (linux_hid_driver.scan_timer, qemu_get_clock (rt_clock) + 2000);
++ qemu_mod_timer (linux_hid_driver.scan_timer,
++ qemu_get_clock (rt_clock) + 2000);
+
}
+
+/* Kick off the periodic scan for devices */
+ if (!linux_hid_driver.scan_timer)
-+ linux_hid_driver.scan_timer = qemu_new_timer (rt_clock, hid_linux_scan, NULL);
++ linux_hid_driver.scan_timer =
++ qemu_new_timer (rt_clock, hid_linux_scan, NULL);
+
-+ linux_hid_scan ();
++ hid_linux_scan (NULL);
}