From: Paul Cercueil Date: Mon, 7 Oct 2013 18:41:22 +0000 (+0200) Subject: Allow the platform code to override the key names X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d685ce4625e9f3b25b0852d31960cb429da06a9d;p=libpicofe.git Allow the platform code to override the key names --- diff --git a/in_sdl.c b/in_sdl.c index af8d636..046f92d 100644 --- a/in_sdl.c +++ b/in_sdl.c @@ -165,11 +165,16 @@ static const char * const in_sdl_keys[SDLK_LAST] = { static void in_sdl_probe(const in_drv_t *drv) { + const struct in_pdata *pdata = drv->pdata; + const char * const * key_names = in_sdl_keys; struct in_sdl_state *state; SDL_Joystick *joy; int i, joycount; char name[256]; + if (pdata->key_names) + key_names = pdata->key_names; + state = calloc(1, sizeof(*state)); if (state == NULL) { fprintf(stderr, "in_sdl: OOM\n"); @@ -178,7 +183,7 @@ static void in_sdl_probe(const in_drv_t *drv) state->drv = drv; in_register(IN_SDL_PREFIX "keys", -1, state, SDLK_LAST, - in_sdl_keys, 0); + key_names, 0); /* joysticks go here too */ SDL_InitSubSystem(SDL_INIT_JOYSTICK); @@ -199,7 +204,7 @@ static void in_sdl_probe(const in_drv_t *drv) state->drv = drv; snprintf(name, sizeof(name), IN_SDL_PREFIX "%s", SDL_JoystickName(i)); - in_register(name, -1, state, SDLK_LAST, in_sdl_keys, 0); + in_register(name, -1, state, SDLK_LAST, key_names, 0); } if (joycount > 0) @@ -218,9 +223,13 @@ static void in_sdl_free(void *drv_data) } static const char * const * -in_sdl_get_key_names(int *count) +in_sdl_get_key_names(const in_drv_t *drv, int *count) { + const struct in_pdata *pdata = drv->pdata; *count = SDLK_LAST; + + if (pdata->key_names) + return pdata->key_names; return in_sdl_keys; } @@ -413,11 +422,15 @@ static int in_sdl_menu_translate(void *drv_data, int keycode, char *charcode) { struct in_sdl_state *state = drv_data; const struct in_pdata *pdata = state->drv->pdata; + const char * const * key_names = in_sdl_keys; const struct menu_keymap *map; int map_len; int ret = 0; int i; + if (pdata->key_names) + key_names = pdata->key_names; + if (state->joy) { map = pdata->joy_map; map_len = pdata->jmap_size; @@ -444,10 +457,10 @@ static int in_sdl_menu_translate(void *drv_data, int keycode, char *charcode) } if (charcode != NULL && (unsigned int)keycode < SDLK_LAST && - in_sdl_keys[keycode] != NULL && in_sdl_keys[keycode][1] == 0) + key_names[keycode] != NULL && key_names[keycode][1] == 0) { ret |= PBTN_CHAR; - *charcode = in_sdl_keys[keycode][0]; + *charcode = key_names[keycode][0]; } } diff --git a/input.c b/input.c index dc8bedd..ca9dac2 100644 --- a/input.c +++ b/input.c @@ -808,7 +808,8 @@ int in_config_parse_dev(const char *name) if (in_devices[i].name == NULL) return -1; - in_devices[i].key_names = DRV(drv_id).get_key_names(&in_devices[i].key_count); + in_devices[i].key_names = DRV(drv_id).get_key_names(&DRV(drv_id), + &in_devices[i].key_count); in_devices[i].drv_id = drv_id; if (i + 1 > in_dev_count) diff --git a/input.h b/input.h index 44ab06b..360b65b 100644 --- a/input.h +++ b/input.h @@ -83,7 +83,7 @@ struct InputDriver { void (*probe)(const in_drv_t *drv); void (*free)(void *drv_data); const char * const * - (*get_key_names)(int *count); + (*get_key_names)(const in_drv_t *drv, int *count); int (*clean_binds)(void *drv_data, int *binds, int *def_finds); int (*get_config)(void *drv_data, int what, int *val); int (*set_config)(void *drv_data, int what, int val); @@ -116,6 +116,7 @@ struct in_pdata { size_t kmap_size; const struct menu_keymap *joy_map; size_t jmap_size; + const char * const *key_names; }; /* to be called by drivers */ diff --git a/linux/in_evdev.c b/linux/in_evdev.c index 08e3596..ff714ce 100644 --- a/linux/in_evdev.c +++ b/linux/in_evdev.c @@ -290,9 +290,13 @@ static void in_evdev_free(void *drv_data) } static const char * const * -in_evdev_get_key_names(int *count) +in_evdev_get_key_names(const in_drv_t *drv, int *count) { + const struct in_pdata *pdata = drv->pdata; *count = KEY_CNT; + + if (pdata->key_names) + return pdata->key_names; return in_evdev_keys; }