#define KEYBITS_WORD_BITS (sizeof(keybits_t) * 8)
struct in_sdl_state {
+ const in_drv_t *drv;
SDL_Joystick *joy;
int joy_id;
int axis_keydown[2];
[SDLK_COMPOSE] = "compose",
};
-static void in_sdl_probe(void)
+static void in_sdl_probe(const in_drv_t *drv)
{
struct in_sdl_state *state;
SDL_Joystick *joy;
return;
}
+ state->drv = drv;
in_register(IN_SDL_PREFIX "keys", -1, state, SDLK_LAST,
in_sdl_keys, 0);
}
state->joy = joy;
state->joy_id = i;
+ 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);
return ret_kc;
}
-struct menu_keymap {
- short key;
- short pbtn;
-};
-
-static const struct menu_keymap key_pbtn_map[] =
-{
- { SDLK_UP, PBTN_UP },
- { SDLK_DOWN, PBTN_DOWN },
- { SDLK_LEFT, PBTN_LEFT },
- { SDLK_RIGHT, PBTN_RIGHT },
- /* XXX: maybe better set this from it's plat code somehow */
- { SDLK_RETURN, PBTN_MOK },
- { SDLK_ESCAPE, PBTN_MBACK },
- { SDLK_SEMICOLON, PBTN_MA2 },
- { SDLK_QUOTE, PBTN_MA3 },
- { SDLK_BACKSLASH, PBTN_MENU },
- { SDLK_LEFTBRACKET, PBTN_L },
- { SDLK_RIGHTBRACKET, PBTN_R },
-};
-#define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
-
-static const struct menu_keymap joybtn_pbtn_map[] =
-{
- { SDLK_UP, PBTN_UP },
- { SDLK_DOWN, PBTN_DOWN },
- { SDLK_LEFT, PBTN_LEFT },
- { SDLK_RIGHT, PBTN_RIGHT },
- /* joystick */
- { SDLK_WORLD_0, PBTN_MOK },
- { SDLK_WORLD_1, PBTN_MBACK },
- { SDLK_WORLD_2, PBTN_MA2 },
- { SDLK_WORLD_3, PBTN_MA3 },
-};
-#define JOYBTN_PBTN_MAP_SIZE (sizeof(joybtn_pbtn_map) / sizeof(joybtn_pbtn_map[0]))
-
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 struct menu_keymap *map;
int map_len;
int ret = 0;
int i;
- map = state->joy ? joybtn_pbtn_map : key_pbtn_map;
- map_len = state->joy ? JOYBTN_PBTN_MAP_SIZE : KEY_PBTN_MAP_SIZE;
+ if (state->joy) {
+ map = pdata->joy_map;
+ map_len = pdata->jmap_size;
+ } else {
+ map = pdata->key_map;
+ map_len = pdata->kmap_size;
+ }
if (keycode < 0)
{
.menu_translate = in_sdl_menu_translate,
};
-void in_sdl_init(const struct in_default_bind *defbinds,
- void (*handler)(void *event))
+int in_sdl_init(const struct in_pdata *pdata, void (*handler)(void *event))
{
- in_register_driver(&in_sdl_drv, defbinds);
+ if (!pdata) {
+ fprintf(stderr, "in_sdl: Missing input platform data\n");
+ return -1;
+ }
+
+ in_register_driver(&in_sdl_drv, pdata->defbinds, pdata);
ext_event_handler = handler;
+ return 0;
}
-struct in_default_bind;
-
-void in_sdl_init(const struct in_default_bind *defbinds,
- void (*handler)(void *event));
+int in_sdl_init(const struct in_pdata *pdata, void (*handler)(void *event));
for (i = 0; i < in_driver_count; i++) {
in_probe_dev_id = i;
- in_drivers[i].probe();
+ in_drivers[i].probe(&DRV(i));
}
/* get rid of devs without binds and probes */
if (d.f == NULL) d.f = in_def_##f
/* to be called by drivers */
-int in_register_driver(const in_drv_t *drv, const struct in_default_bind *defbinds)
+int in_register_driver(const in_drv_t *drv,
+ const struct in_default_bind *defbinds, const void *pdata)
{
int count_new = in_driver_count + 1;
in_drv_t *new_drivers;
CHECK_ADD_STUB(new_drivers[in_driver_count], menu_translate);
CHECK_ADD_STUB(new_drivers[in_driver_count], get_key_code);
CHECK_ADD_STUB(new_drivers[in_driver_count], get_key_name);
- if (defbinds != NULL)
+ if (pdata)
+ new_drivers[in_driver_count].pdata = pdata;
+ if (defbinds)
new_drivers[in_driver_count].defbinds = defbinds;
in_drivers = new_drivers;
in_driver_count = count_new;
#define IN_BIND_OFFS(key, btype) \
((key) * IN_BINDTYPE_COUNT + (btype))
-typedef struct {
+typedef struct InputDriver in_drv_t;
+
+struct InputDriver {
const char *prefix;
- void (*probe)(void);
+ void (*probe)(const in_drv_t *drv);
void (*free)(void *drv_data);
const char * const *
(*get_key_names)(int *count);
const char * (*get_key_name)(int keycode);
const struct in_default_bind *defbinds;
-} in_drv_t;
+ const void *pdata;
+};
struct in_default_bind {
unsigned short code;
unsigned char bit;
};
+struct menu_keymap {
+ short key;
+ short pbtn;
+};
+
+struct in_pdata {
+ const struct in_default_bind *defbinds;
+ const struct menu_keymap *key_map;
+ size_t kmap_size;
+ const struct menu_keymap *joy_map;
+ size_t jmap_size;
+};
+
/* to be called by drivers */
-int in_register_driver(const in_drv_t *drv, const struct in_default_bind *defbinds);
+int in_register_driver(const in_drv_t *drv,
+ const struct in_default_bind *defbinds, const void *pdata);
void in_register(const char *nname, int drv_fd_hnd, void *drv_data,
int key_count, const char * const *key_names, int combos);
void in_combos_find(const int *binds, int last_key, int *combo_keys, int *combo_acts);
int abs_mult[MAX_ABS_DEVS]; /* 16.16 multiplier to IN_ABS_RANGE */
int abs_adj[MAX_ABS_DEVS]; /* adjust for centering */
unsigned int abs_to_digital:1;
+
+ const in_drv_t *drv;
} in_evdev_t;
#ifndef KEY_CNT
};
-static void in_evdev_probe(void)
+static void in_evdev_probe(const in_drv_t *drv)
{
long keybits[KEY_CNT / sizeof(long) / 8];
long absbits[(ABS_MAX+1) / sizeof(long) / 8];
if (dev == NULL)
goto skip;
+ dev->drv = drv;
+
ret = ioctl(fd, EVIOCGKEY(sizeof(keybits)), keybits);
if (ret == -1) {
printf("Warning: EVIOCGKEY not supported, will have to track state\n");
return ret_kc;
}
-static const struct {
- short key;
- short pbtn;
-} key_pbtn_map[] =
-{
- { KEY_UP, PBTN_UP },
- { KEY_DOWN, PBTN_DOWN },
- { KEY_LEFT, PBTN_LEFT },
- { KEY_RIGHT, PBTN_RIGHT },
- /* XXX: maybe better set this from it's plat code somehow */
- /* Pandora */
- { KEY_END, PBTN_MOK },
- { KEY_PAGEDOWN, PBTN_MBACK },
- { KEY_HOME, PBTN_MA2 },
- { KEY_PAGEUP, PBTN_MA3 },
- { KEY_LEFTCTRL, PBTN_MENU },
- { KEY_RIGHTSHIFT, PBTN_L },
- { KEY_RIGHTCTRL, PBTN_R },
- /* Caanoo */
- { BTN_THUMB2, PBTN_MOK },
- { BTN_THUMB, PBTN_MBACK },
- { BTN_TRIGGER, PBTN_MA2 },
- { BTN_TOP, PBTN_MA3 },
- { BTN_BASE, PBTN_MENU },
- { BTN_TOP2, PBTN_L },
- { BTN_PINKIE, PBTN_R },
- /* "normal" keyboards */
- { KEY_ENTER, PBTN_MOK },
- { KEY_ESC, PBTN_MBACK },
- { KEY_SEMICOLON, PBTN_MA2 },
- { KEY_APOSTROPHE, PBTN_MA3 },
- { KEY_BACKSLASH, PBTN_MENU },
- { KEY_LEFTBRACE, PBTN_L },
- { KEY_RIGHTBRACE, PBTN_R },
-};
-
-#define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
-
static int in_evdev_menu_translate(void *drv_data, int keycode, char *charcode)
{
in_evdev_t *dev = drv_data;
+ const struct in_pdata *pdata = dev->drv->pdata;
int ret = 0;
int i;
{
/* menu -> kc */
keycode = -keycode;
- for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
- if (key_pbtn_map[i].pbtn == keycode) {
- int k = key_pbtn_map[i].key;
+ for (i = 0; i < pdata->kmap_size; i++)
+ if (pdata->key_map[i].pbtn == keycode) {
+ int k = pdata->key_map[i].key;
/* should really check EVIOCGBIT, but this is enough for now */
if (dev->kc_first <= k && k <= dev->kc_last)
return k;
}
else
{
- for (i = 0; i < KEY_PBTN_MAP_SIZE; i++) {
- if (key_pbtn_map[i].key == keycode) {
- ret = key_pbtn_map[i].pbtn;
+ for (i = 0; i < pdata->kmap_size; i++) {
+ if (pdata->key_map[i].key == keycode) {
+ ret = pdata->key_map[i].pbtn;
break;
}
}
.menu_translate = in_evdev_menu_translate,
};
-void in_evdev_init(const struct in_default_bind *defbinds)
+int in_evdev_init(const struct in_pdata *pdata)
{
- in_register_driver(&in_evdev_drv, defbinds);
+ if (!pdata) {
+ fprintf(stderr, "in_sdl: Missing input platform data\n");
+ return -1;
+ }
+
+ in_register_driver(&in_evdev_drv, pdata->defbinds, pdata);
+ return 0;
}
-
-struct in_default_bind;
extern int in_evdev_allow_abs_only;
-void in_evdev_init(const struct in_default_bind *defbinds);
+int in_evdev_init(const struct in_pdata *pdata);