in_evdev: revert multi event handling from r901 to avoid unwanted blocking
authornotaz <notasas@gmail.com>
Thu, 9 Dec 2010 22:21:07 +0000 (22:21 +0000)
committernotaz <notasas@gmail.com>
Thu, 9 Dec 2010 22:21:07 +0000 (22:21 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@910 be3aeb3a-fb24-0410-a615-afba39da0efa

platform/linux/in_evdev.c

index 0b73302..a51fe2d 100644 (file)
@@ -402,60 +402,59 @@ static int in_evdev_update_keycode(void *data, int *is_down)
        struct input_event ev;
        int rd;
 
-       while (1)
-       {
-               rd = read(dev->fd, &ev, sizeof(ev));
-               if (rd < (int) sizeof(ev)) {
-                       if (errno != EAGAIN) {
-                               perror("in_evdev: error reading");
-                               sleep(1);
-                       }
-                       goto out;
+       /* do single event, the caller sometimes wants
+        * to do select() in blocking mode */
+       rd = read(dev->fd, &ev, sizeof(ev));
+       if (rd < (int) sizeof(ev)) {
+               if (errno != EAGAIN) {
+                       perror("in_evdev: error reading");
+                       sleep(1);
                }
+               goto out;
+       }
 
-               if (ev.type == EV_KEY) {
-                       if (ev.value < 0 || ev.value > 1)
-                               continue;
-                       ret_kc = ev.code;
-                       ret_down = ev.value;
+       if (ev.type == EV_KEY) {
+               if (ev.value < 0 || ev.value > 1)
                        goto out;
+               ret_kc = ev.code;
+               ret_down = ev.value;
+               goto out;
+       }
+       else if (ev.type == EV_ABS)
+       {
+               int lzone = dev->abs_lzone, down = 0, *last;
+
+               // map absolute to up/down/left/right
+               if (lzone != 0 && ev.code == ABS_X) {
+                       if (ev.value < dev->abs_min_x + lzone)
+                               down = KEY_LEFT;
+                       else if (ev.value > dev->abs_max_x - lzone)
+                               down = KEY_RIGHT;
+                       last = &dev->abs_lastx;
                }
-               else if (ev.type == EV_ABS)
-               {
-                       int lzone = dev->abs_lzone, down = 0, *last;
-
-                       // map absolute to up/down/left/right
-                       if (lzone != 0 && ev.code == ABS_X) {
-                               if (ev.value < dev->abs_min_x + lzone)
-                                       down = KEY_LEFT;
-                               else if (ev.value > dev->abs_max_x - lzone)
-                                       down = KEY_RIGHT;
-                               last = &dev->abs_lastx;
-                       }
-                       else if (lzone != 0 && ev.code == ABS_Y) {
-                               if (ev.value < dev->abs_min_y + lzone)
-                                       down = KEY_UP;
-                               else if (ev.value > dev->abs_max_y - lzone)
-                                       down = KEY_DOWN;
-                               last = &dev->abs_lasty;
-                       }
-                       else
-                               continue;
-
-                       if (down == *last)
-                               continue;
-
-                       if (down == 0 || *last != 0) {
-                               /* key up or direction change, return up event for old key */
-                               ret_kc = *last;
-                               ret_down = 0;
-                               *last = 0;
-                               goto out;
-                       }
-                       ret_kc = *last = down;
-                       ret_down = 1;
+               else if (lzone != 0 && ev.code == ABS_Y) {
+                       if (ev.value < dev->abs_min_y + lzone)
+                               down = KEY_UP;
+                       else if (ev.value > dev->abs_max_y - lzone)
+                               down = KEY_DOWN;
+                       last = &dev->abs_lasty;
+               }
+               else
+                       goto out;
+
+               if (down == *last)
+                       goto out;
+
+               if (down == 0 || *last != 0) {
+                       /* key up or direction change, return up event for old key */
+                       ret_kc = *last;
+                       ret_down = 0;
+                       *last = 0;
                        goto out;
                }
+               ret_kc = *last = down;
+               ret_down = 1;
+               goto out;
        }
 
 out: