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;
}
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);
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");
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)
/* 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; }
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;
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);
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;
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 {
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);
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 {
};
/* 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);