diff --git a/data/keyd-application-mapper.1.gz b/data/keyd-application-mapper.1.gz index 38f4e1a..48f8a76 100644 Binary files a/data/keyd-application-mapper.1.gz and b/data/keyd-application-mapper.1.gz differ diff --git a/data/keyd.1.gz b/data/keyd.1.gz index 12d359d..075476d 100644 Binary files a/data/keyd.1.gz and b/data/keyd.1.gz differ diff --git a/src/keyboard.h b/src/keyboard.h index bcb371a..3003cba 100644 --- a/src/keyboard.h +++ b/src/keyboard.h @@ -6,6 +6,7 @@ #ifndef KEYBOARD_H #define KEYBOARD_H +#include "keyd.h" #include "config.h" #include "layer.h" @@ -22,9 +23,10 @@ struct cache_entry { /* May correspond to more than one physical input device. */ struct keyboard { - struct config original_config; + char config_path[PATH_MAX]; struct config config; + struct config original_config; /* * Cache descriptors to preserve code->descriptor diff --git a/src/keyd.c b/src/keyd.c index 9e6a86b..ff7fa64 100644 --- a/src/keyd.c +++ b/src/keyd.c @@ -29,6 +29,8 @@ #include "keys.h" #include "ipc.h" +#define MAX_KEYBOARDS 64 + /* config variables */ static const char *virtual_keyboard_name; @@ -39,8 +41,13 @@ static const char *socket_file; static struct device devices[MAX_DEVICES]; static size_t nr_devices = 0; + static struct keyboard *active_kbd = NULL; +static struct keyboard *keyboards[MAX_KEYBOARDS]; +static size_t nr_keyboards; + + /* loop() callback functions */ static void (*device_add_cb) (struct device *dev); @@ -53,6 +60,37 @@ static int (*device_event_cb) (struct device *dev, uint8_t code, uint8_t process struct vkbd *vkbd; +struct keyboard *get_keyboard(const char *config_path) +{ + size_t i; + struct keyboard *kbd; + + for (i = 0; i < nr_keyboards; i++) + if (!strcmp(keyboards[i]->config_path, config_path)) + return keyboards[i]; + + + assert(nr_keyboards < MAX_KEYBOARDS); + kbd = calloc(1, sizeof(struct keyboard)); + + if (config_parse(&kbd->config, config_path)) { + printf("\tfailed to parse %s\n", config_path); + free(kbd); + return NULL; + } + + memcpy(&kbd->original_config, &kbd->config, sizeof kbd->config); + strcpy(kbd->config_path, config_path); + + kbd->layer_state[0].active = 1; + kbd->layer_state[0].activation_time = 1; + + keyboards[nr_keyboards++] = kbd; + + return kbd; +} + + static void daemon_remove_cb(struct device *dev) { struct keyboard *kbd = dev->data; @@ -99,26 +137,14 @@ static void daemon_add_cb(struct device *dev) printf("\tmatched %s\n", config_path); - kbd = calloc(1, sizeof(struct keyboard)); - if (config_parse(&kbd->config, config_path)) { - printf("\tfailed to parse %s\n", config_path); - free(kbd); + dev->data = get_keyboard(config_path); + if (!dev->data) return; - } - - memcpy(&kbd->original_config, &kbd->config, sizeof kbd->config); - - kbd->layer_state[0].active = 1; - kbd->layer_state[0].activation_time = 1; if (device_grab(dev) < 0) { printf("\tgrab failed\n"); - - free(kbd); return; } - - dev->data = kbd; } static void panic_check(uint8_t code, uint8_t pressed) @@ -405,8 +431,8 @@ static void cleanup() { size_t i; - for (i = 0; i < nr_devices; i++) - free(devices[i].data); + for (i = 0; i < nr_keyboards; i++) + free(keyboards[i]); free_vkbd(vkbd); diff --git a/src/keyd.h b/src/keyd.h index 7d7db46..7ef4df5 100644 --- a/src/keyd.h +++ b/src/keyd.h @@ -6,6 +6,10 @@ #ifndef KEYD_H_ #define KEYD_H_ +#ifndef PATH_MAX +#define PATH_MAX 1024 +#endif + void set_led(int led, int state); #endif