X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=frontend%2Flinux%2Fin_evdev.c;h=f88d74c853d8d42aed172950e385e434a1d520a5;hp=0b73302ccef334f0b1c0dd2782fc0556b885683e;hb=2924e5711a8279228df4c03bc0a970c349e55938;hpb=698517be481301b4525c29873134a67b8343af3c diff --git a/frontend/linux/in_evdev.c b/frontend/linux/in_evdev.c index 0b73302c..f88d74c8 100644 --- a/frontend/linux/in_evdev.c +++ b/frontend/linux/in_evdev.c @@ -49,6 +49,8 @@ typedef struct { #define KEYBITS_BIT_CLEAR(x) (keybits[(x)/sizeof(keybits[0])/8] &= \ ~(1 << ((x) & (sizeof(keybits[0])*8-1)))) +int in_evdev_allow_abs_only; + static const char * const in_evdev_prefix = "evdev:"; static const char * const in_evdev_keys[KEY_CNT] = { [0 ... KEY_MAX] = NULL, @@ -151,7 +153,7 @@ static void in_evdev_probe(void) for (i = 0;; i++) { int support = 0, count = 0; - int u, ret, fd, kc_first, kc_last; + int u, ret, fd, kc_first = KEY_MAX, kc_last = 0; in_evdev_t *dev; char name[64]; @@ -170,30 +172,29 @@ static void in_evdev_probe(void) goto skip; } - if (!(support & (1 << EV_KEY))) - goto skip; - - ret = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits); - if (ret == -1) { - printf("in_evdev: ioctl failed on %s\n", name); - goto skip; - } + if (support & (1 << EV_KEY)) { + ret = ioctl(fd, EVIOCGBIT(EV_KEY, sizeof(keybits)), keybits); + if (ret == -1) { + printf("in_evdev: ioctl failed on %s\n", name); + goto skip; + } - /* check for interesting keys */ - kc_first = KEY_MAX; - kc_last = 0; - for (u = 0; u < KEY_CNT; u++) { - if (KEYBITS_BIT(u)) { - if (u < kc_first) - kc_first = u; - if (u > kc_last) - kc_last = u; - if (u != KEY_POWER && u != KEY_SLEEP && u != BTN_TOUCH) - count++; + /* check for interesting keys */ + for (u = 0; u < KEY_CNT; u++) { + if (KEYBITS_BIT(u)) { + if (u < kc_first) + kc_first = u; + if (u > kc_last) + kc_last = u; + if (u != KEY_POWER && u != KEY_SLEEP && u != BTN_TOUCH) + count++; + if (u == BTN_TOUCH) /* we can't deal with ts currently */ + goto skip; + } } } - if (count == 0) + if (count == 0 && !in_evdev_allow_abs_only) goto skip; dev = calloc(1, sizeof(*dev)); @@ -237,6 +238,11 @@ static void in_evdev_probe(void) } no_abs: + if (count == 0 && dev->abs_lzone == 0) { + free(dev); + goto skip; + } + dev->fd = fd; dev->kc_first = kc_first; dev->kc_last = kc_last; @@ -261,9 +267,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) @@ -402,60 +410,60 @@ 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); + ret_kc = -2; } + 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: @@ -530,48 +538,13 @@ 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; - char bit; -} in_evdev_def_binds[] = -{ - /* MXYZ SACB RLDU */ - { KEY_UP, IN_BINDTYPE_PLAYER12, 0 }, - { KEY_DOWN, IN_BINDTYPE_PLAYER12, 1 }, - { KEY_LEFT, IN_BINDTYPE_PLAYER12, 2 }, - { KEY_RIGHT, IN_BINDTYPE_PLAYER12, 3 }, - { KEY_S, IN_BINDTYPE_PLAYER12, 4 }, /* B */ - { KEY_D, IN_BINDTYPE_PLAYER12, 5 }, /* C */ - { KEY_A, IN_BINDTYPE_PLAYER12, 6 }, /* A */ - { KEY_ENTER, IN_BINDTYPE_PLAYER12, 7 }, - { KEY_BACKSLASH, IN_BINDTYPE_EMU, PEVB_MENU }, - /* Pandora */ - { KEY_PAGEDOWN, IN_BINDTYPE_PLAYER12, 4 }, - { KEY_END, IN_BINDTYPE_PLAYER12, 5 }, - { KEY_HOME, IN_BINDTYPE_PLAYER12, 6 }, - { KEY_LEFTALT, IN_BINDTYPE_PLAYER12, 7 }, - { KEY_RIGHTSHIFT,IN_BINDTYPE_EMU, PEVB_STATE_SAVE }, - { KEY_RIGHTCTRL, IN_BINDTYPE_EMU, PEVB_STATE_LOAD }, - { KEY_LEFTCTRL, IN_BINDTYPE_EMU, PEVB_MENU }, - /* Caanoo */ - { BTN_THUMB, IN_BINDTYPE_PLAYER12, 4 }, /* B */ - { BTN_THUMB2, IN_BINDTYPE_PLAYER12, 5 }, /* C */ - { BTN_TRIGGER, IN_BINDTYPE_PLAYER12, 6 }, /* A */ - { BTN_BASE3, IN_BINDTYPE_PLAYER12, 7 }, - { BTN_TOP2, IN_BINDTYPE_EMU, PEVB_STATE_SAVE }, - { BTN_PINKIE, IN_BINDTYPE_EMU, PEVB_STATE_LOAD }, - { BTN_BASE, IN_BINDTYPE_EMU, PEVB_MENU }, -}; -#endif - static void in_evdev_get_def_binds(int *binds) { int i; - for (i = 0; in_evdev_defbinds[i].bit != 0; i++) { + 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; } @@ -584,10 +557,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) { @@ -619,7 +593,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;