From 215aec76b681d91991b209cf5b876fde844ba11a Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 22 Jul 2012 14:36:53 +0000 Subject: [PATCH] input: move default bind handling to input core git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@952 be3aeb3a-fb24-0410-a615-afba39da0efa --- common/input.c | 39 ++++++++++++++++++++++++++++++--------- common/input.h | 6 ++++-- 2 files changed, 34 insertions(+), 11 deletions(-) diff --git a/common/input.c b/common/input.c index 0b1984b..a683464 100644 --- a/common/input.c +++ b/common/input.c @@ -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; diff --git a/common/input.h b/common/input.h index 524366f..da6349b 100644 --- a/common/input.h +++ b/common/input.h @@ -61,6 +61,7 @@ enum { IN_CFG_KEY_NAMES, IN_CFG_ABS_DEAD_ZONE, /* dead zone for analog-digital mapping */ IN_CFG_ABS_AXIS_COUNT, /* number of abs axes (ro) */ + IN_CFG_DEFAULT_DEV, }; enum { @@ -79,7 +80,6 @@ typedef struct { void (*free)(void *drv_data); const char * const * (*get_key_names)(int *count); - void (*get_def_binds)(int *binds); 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); @@ -90,6 +90,8 @@ typedef struct { int (*menu_translate)(void *drv_data, int keycode); int (*get_key_code)(const char *key_name); const char * (*get_key_name)(int keycode); + + const struct in_default_bind *defbinds; } in_drv_t; struct in_default_bind { @@ -99,7 +101,7 @@ struct in_default_bind { }; /* 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, 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); -- 2.39.5