input: move default bind handling to input core

git-svn-id: file:///home/notaz/opt/svn/PicoDrive@952 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
notaz 2012-07-22 14:36:53 +00:00
parent cca8800dfb
commit a70e251871
2 changed files with 34 additions and 11 deletions

View file

@ -52,15 +52,27 @@ static int menu_last_used_dev = 0;
static int *in_alloc_binds(int drv_id, int key_count)
{
const struct in_default_bind *defbinds;
int *binds;
int i;
binds = calloc(key_count * IN_BINDTYPE_COUNT * 2, sizeof(binds[0]));
if (binds == NULL)
return NULL;
DRV(drv_id).get_def_binds(binds + key_count * IN_BINDTYPE_COUNT);
memcpy(binds, binds + key_count * IN_BINDTYPE_COUNT,
sizeof(binds[0]) * key_count * IN_BINDTYPE_COUNT);
defbinds = DRV(drv_id).defbinds;
if (defbinds != NULL) {
for (i = 0; ; i++) {
if (defbinds[i].bit == 0 && defbinds[i].code == 0)
break;
binds[IN_BIND_OFFS(defbinds[i].code, defbinds[i].btype)] =
1 << defbinds[i].bit;
}
/* always have a copy of defbinds */
memcpy(binds + key_count * IN_BINDTYPE_COUNT, binds,
sizeof(binds[0]) * key_count * IN_BINDTYPE_COUNT);
}
return binds;
}
@ -536,8 +548,10 @@ static int in_set_blocking(int is_blocking)
int in_set_config(int dev_id, int what, const void *val, int size)
{
const char * const *names;
const int *ival = val;
in_dev_t *dev;
int count;
if (what == IN_CFG_BLOCKING)
return in_set_blocking(*ival);
@ -546,9 +560,10 @@ int in_set_config(int dev_id, int what, const void *val, int size)
if (dev == NULL)
return -1;
if (what == IN_CFG_KEY_NAMES) {
const char * const *names = val;
int count = size / sizeof(names[0]);
switch (what) {
case IN_CFG_KEY_NAMES:
names = val;
count = size / sizeof(names[0]);
if (count < dev->key_count) {
lprintf("input: set_key_names: not enough keys\n");
@ -557,6 +572,12 @@ int in_set_config(int dev_id, int what, const void *val, int size)
dev->key_names = names;
return 0;
case IN_CFG_DEFAULT_DEV:
/* just set last used dev, for now */
menu_last_used_dev = dev_id;
return 0;
default:
break;
}
if (dev->probed)
@ -891,7 +912,6 @@ void in_debug_dump(void)
/* stubs for drivers that choose not to implement something */
static void in_def_free(void *drv_data) {}
static void in_def_get_def_binds(int *binds) {}
static int in_def_clean_binds(void *drv_data, int *b, int *db) { return 1; }
static int in_def_get_config(void *drv_data, int what, int *val) { return -1; }
static int in_def_set_config(void *drv_data, int what, int val) { return -1; }
@ -905,7 +925,7 @@ static const char *in_def_get_key_name(int keycode) { return NULL; }
if (d.f == NULL) d.f = in_def_##f
/* to be called by drivers */
int in_register_driver(const in_drv_t *drv)
int in_register_driver(const in_drv_t *drv, const struct in_default_bind *defbinds)
{
int count_new = in_driver_count + 1;
in_drv_t *new_drivers;
@ -919,7 +939,6 @@ int in_register_driver(const in_drv_t *drv)
memcpy(&new_drivers[in_driver_count], drv, sizeof(new_drivers[0]));
CHECK_ADD_STUB(new_drivers[in_driver_count], free);
CHECK_ADD_STUB(new_drivers[in_driver_count], get_def_binds);
CHECK_ADD_STUB(new_drivers[in_driver_count], clean_binds);
CHECK_ADD_STUB(new_drivers[in_driver_count], get_config);
CHECK_ADD_STUB(new_drivers[in_driver_count], set_config);
@ -928,6 +947,8 @@ int in_register_driver(const in_drv_t *drv)
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)
new_drivers[in_driver_count].defbinds = defbinds;
in_drivers = new_drivers;
in_driver_count = count_new;