X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=linux%2Fin_evdev.c;h=d863c0226a80acc9d8db2c5b64dbefb18f8359d8;hb=bde5dcbb2c2e10c5cf999d65295e768d027144c4;hp=065676b7bd7e1351903b58653de6ce62790f8384;hpb=74065be8cdfbcccb7e12d7e19f0a7cb35538db06;p=libpicofe.git diff --git a/linux/in_evdev.c b/linux/in_evdev.c index 065676b..d863c02 100644 --- a/linux/in_evdev.c +++ b/linux/in_evdev.c @@ -1,3 +1,13 @@ +/* + * (C) Gražvydas "notaz" Ignotas, 2008-2010 + * + * This work is licensed under the terms of any of these licenses + * (at your option): + * - GNU GPL, version 2 or later. + * - GNU LGPL, version 2.1 or later. + * See the COPYING file in the top-level directory. + */ + #include #include #include @@ -392,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: @@ -520,6 +529,8 @@ static int in_evdev_menu_translate(void *drv_data, int keycode) return 0; } +/* FIXME: move to plat */ +#if 0 static const struct { short code; char btype; @@ -553,16 +564,18 @@ static const struct { { BTN_PINKIE, IN_BINDTYPE_EMU, PEVB_STATE_LOAD }, { BTN_BASE, IN_BINDTYPE_EMU, PEVB_MENU }, }; - -#define DEF_BIND_COUNT (sizeof(in_evdev_def_binds) / sizeof(in_evdev_def_binds[0])) +#endif static void in_evdev_get_def_binds(int *binds) { int i; - for (i = 0; i < DEF_BIND_COUNT; i++) - binds[IN_BIND_OFFS(in_evdev_def_binds[i].code, in_evdev_def_binds[i].btype)] = - 1 << in_evdev_def_binds[i].bit; + for (i = 0; ; i++) { + if (in_evdev_defbinds[i].bit == 0 && in_evdev_defbinds[i].code == 0) + break; + binds[IN_BIND_OFFS(in_evdev_defbinds[i].code, in_evdev_defbinds[i].btype)] = + 1 << in_evdev_defbinds[i].bit; + } } /* remove binds of missing keys, count remaining ones */ @@ -572,10 +585,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) {