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) static int *in_alloc_binds(int drv_id, int key_count)
{ {
const struct in_default_bind *defbinds;
int *binds; int *binds;
int i;
binds = calloc(key_count * IN_BINDTYPE_COUNT * 2, sizeof(binds[0])); binds = calloc(key_count * IN_BINDTYPE_COUNT * 2, sizeof(binds[0]));
if (binds == NULL) if (binds == NULL)
return NULL; return NULL;
DRV(drv_id).get_def_binds(binds + key_count * IN_BINDTYPE_COUNT); defbinds = DRV(drv_id).defbinds;
memcpy(binds, binds + key_count * IN_BINDTYPE_COUNT, if (defbinds != NULL) {
sizeof(binds[0]) * key_count * IN_BINDTYPE_COUNT); 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; 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) int in_set_config(int dev_id, int what, const void *val, int size)
{ {
const char * const *names;
const int *ival = val; const int *ival = val;
in_dev_t *dev; in_dev_t *dev;
int count;
if (what == IN_CFG_BLOCKING) if (what == IN_CFG_BLOCKING)
return in_set_blocking(*ival); 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) if (dev == NULL)
return -1; return -1;
if (what == IN_CFG_KEY_NAMES) { switch (what) {
const char * const *names = val; case IN_CFG_KEY_NAMES:
int count = size / sizeof(names[0]); names = val;
count = size / sizeof(names[0]);
if (count < dev->key_count) { if (count < dev->key_count) {
lprintf("input: set_key_names: not enough keys\n"); 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; dev->key_names = names;
return 0; 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) if (dev->probed)
@ -891,7 +912,6 @@ void in_debug_dump(void)
/* stubs for drivers that choose not to implement something */ /* stubs for drivers that choose not to implement something */
static void in_def_free(void *drv_data) {} 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_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_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; } 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 if (d.f == NULL) d.f = in_def_##f
/* to be called by drivers */ /* 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; int count_new = in_driver_count + 1;
in_drv_t *new_drivers; 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])); 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], 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], clean_binds);
CHECK_ADD_STUB(new_drivers[in_driver_count], get_config); CHECK_ADD_STUB(new_drivers[in_driver_count], get_config);
CHECK_ADD_STUB(new_drivers[in_driver_count], set_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], menu_translate);
CHECK_ADD_STUB(new_drivers[in_driver_count], get_key_code); CHECK_ADD_STUB(new_drivers[in_driver_count], get_key_code);
CHECK_ADD_STUB(new_drivers[in_driver_count], get_key_name); 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_drivers = new_drivers;
in_driver_count = count_new; in_driver_count = count_new;

View file

@ -61,6 +61,7 @@ enum {
IN_CFG_KEY_NAMES, IN_CFG_KEY_NAMES,
IN_CFG_ABS_DEAD_ZONE, /* dead zone for analog-digital mapping */ IN_CFG_ABS_DEAD_ZONE, /* dead zone for analog-digital mapping */
IN_CFG_ABS_AXIS_COUNT, /* number of abs axes (ro) */ IN_CFG_ABS_AXIS_COUNT, /* number of abs axes (ro) */
IN_CFG_DEFAULT_DEV,
}; };
enum { enum {
@ -79,7 +80,6 @@ typedef struct {
void (*free)(void *drv_data); void (*free)(void *drv_data);
const char * const * const char * const *
(*get_key_names)(int *count); (*get_key_names)(int *count);
void (*get_def_binds)(int *binds);
int (*clean_binds)(void *drv_data, int *binds, int *def_finds); int (*clean_binds)(void *drv_data, int *binds, int *def_finds);
int (*get_config)(void *drv_data, int what, int *val); int (*get_config)(void *drv_data, int what, int *val);
int (*set_config)(void *drv_data, int what, int val); int (*set_config)(void *drv_data, int what, int val);
@ -90,6 +90,8 @@ typedef struct {
int (*menu_translate)(void *drv_data, int keycode); int (*menu_translate)(void *drv_data, int keycode);
int (*get_key_code)(const char *key_name); int (*get_key_code)(const char *key_name);
const char * (*get_key_name)(int keycode); const char * (*get_key_name)(int keycode);
const struct in_default_bind *defbinds;
} in_drv_t; } in_drv_t;
struct in_default_bind { struct in_default_bind {
@ -99,7 +101,7 @@ struct in_default_bind {
}; };
/* to be called by drivers */ /* 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);
void in_register(const char *nname, int drv_fd_hnd, void *drv_data, void in_register(const char *nname, int drv_fd_hnd, void *drv_data,
int key_count, const char * const *key_names, int combos); 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); void in_combos_find(const int *binds, int last_key, int *combo_keys, int *combo_acts);