mirror of
https://github.com/RaySollium99/libpicofe.git
synced 2025-09-04 14:37:46 -04:00
Allow the platform code to override the key names
This commit is contained in:
parent
c19e28f626
commit
d685ce4625
4 changed files with 27 additions and 8 deletions
23
in_sdl.c
23
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];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
3
input.c
3
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)
|
||||
|
|
3
input.h
3
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 */
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue